.editorconfig000066400000000000000000000006371516104162500135420ustar00rootroot00000000000000# EditorConfig helps developers define and maintain consistent # coding styles between different editors and IDEs # editorconfig.org root = true [*] # Change these settings to your own preference indent_style = space indent_size = 4 # We recommend you to keep these unchanged end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.md] trim_trailing_whitespace = false .gitignore000066400000000000000000000003301516104162500130430ustar00rootroot00000000000000/build /node_modules /*.log .idea/workspace.xml .idea/tasks.xml .idea/profiles_settings.xml .idea/inspectionProfiles/Project_Default.xml .idea/inspectionProfiles/profiles_settings.xml node_modules/.yarn-integrity .idea/000077500000000000000000000000001516104162500120375ustar00rootroot00000000000000.idea/codeStyleSettings.xml000066400000000000000000000004251516104162500162360ustar00rootroot00000000000000 .idea/codeStyles/000077500000000000000000000000001516104162500141555ustar00rootroot00000000000000.idea/codeStyles/codeStyleConfig.xml000066400000000000000000000002251516104162500177570ustar00rootroot00000000000000 .idea/misc.xml000066400000000000000000000002561516104162500135170ustar00rootroot00000000000000 .idea/modules.xml000066400000000000000000000004061516104162500142310ustar00rootroot00000000000000 .idea/tools.iml000066400000000000000000000005201516104162500136770ustar00rootroot00000000000000 .idea/vcs.xml000066400000000000000000000002471516104162500133570ustar00rootroot00000000000000 .npmignore000066400000000000000000000002221516104162500130520ustar00rootroot00000000000000/.idea /artifacts /build /test /node_modules /*.iml /*.ipr /*.iws /.travis.yml /.scrutinizer.yml /Gruntfile.js /*.lock *.log /corifeus-boot.json .travis.yml000066400000000000000000000014301516104162500131660ustar00rootroot00000000000000language: node_js node_js: - node before_script: - npm install -g grunt-cli npm env: global: secure: orlTlVoL2gzKnOu7bNMQzlFwQECQT9mImXitnRF1oTylcsYxz1hKiTMIMb2ghOJkLnDxcweYaz2D2kGZmN0a/ysdK7FGZla1PvatShcKka0XOcslzCmheyywIy+fBbV3r4TmFdX0ipNfE8w8nhX30d2iJ8m9PZONDMOA3OgcMkkYF8rEti1TU/ayZyxi9xG3Ah1qv2dk79HK2NCSbba5t6rGR7FQAMw4+h0nEJ46D+SRiJArPsurU1h6r7T6Tv2vvaEAP2njhYNGkwtXsLLRZKxqaxIJIz1WdhdhTOw1cwXa9+Uf2ZeUeVz7Xwmphi/Xs37k92Lq3BrJ2fdz794YhckbeuIpjkheZ0F6djkfNq6XCkxgkX9Vbvi4HFsNx1EjgJuouuYh5kRaxCRL7AelQmls6gfyuI0htlX0/9OcxwUpcs34niWlhD5pfTXxw93yHuAN52VIpEabf53nC2E0EM/opawbetDR30uJByFidZ7lEmGY/3X6FBsAJygpdWKnq7gz97GeGcTF7yHL5PJaPZdDCLGTeKvm/eknBaMXl3z8jZBR0nr64aA2dN1m7SmFYRNsYOMPWE4Nv5z5t1WY8eySEpoDpWhmYIfiVY2pBhwx/L5PGA0GbVFd5T4kEqVO7O/5X+DVzdKJ9GKyTR91YSlNJRmEpwl+7YrGbVOVSJY= Gruntfile.js000066400000000000000000000004541516104162500133570ustar00rootroot00000000000000module.exports = (grunt) => { const builder = require(`corifeus-builder`); const loader = new builder.loader(grunt); loader.js({ replacer: { type: 'p3x', npmio: true, }, }); grunt.registerTask('default', builder.config.task.build.js); };LICENSE000066400000000000000000000022471516104162500120710ustar00rootroot00000000000000 @license p3x-tools v2019.10.104 💣 Tools https://pages.corifeus.com/tools Copyright (c) 2019 Patrik Laszlo / P3X / Corifeus and contributors. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. README.md000066400000000000000000000240531516104162500123420ustar00rootroot00000000000000[//]: #@corifeus-header [![NPM](https://nodei.co/npm/p3x-tools.png?downloads=true&downloadRank=true)](https://www.npmjs.com/package/p3x-tools/) [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://paypal.me/patrikx3) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Corifeus @ Facebook](https://img.shields.io/badge/Facebook-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) [![Build Status](https://api.travis-ci.com/patrikx3/tools.svg?branch=master)](https://travis-ci.com/patrikx3/tools) [![Uptime Robot ratio (30 days)](https://img.shields.io/uptimerobot/ratio/m780749701-41bcade28c1ea8154eda7cca.svg)](https://uptimerobot.patrikx3.com/) # 💣 Tools v2019.10.104 **Note about versioning:** Versions are cut in Major.Minor.Patch schema. Major is always the current year. Minor is either 4 (January - June) or 10 (July - December). Patch is incremental by every build. If there is a breaking change, it should be noted in the readme. **Bugs are evident™ - MATRIX️** ### Node Version Requirement ``` >=10.16.0 ``` ### Built on Node ``` v12.6.0 ``` The ```async``` and ```await``` keywords are required. Install NodeJs: https://nodejs.org/en/download/package-manager/ # Description [//]: #@corifeus-header:end This is an internal tool program (```p3x```) to manage a recursive async and serial command for NPM packages. # Install ```bash sudo npm install -g p3x-tools --unsafe-perm=true --allow-root ``` # Examples All folders exclude ```node_modules``` and ```bower_components``` except it is included. ```bash p3x docker clean # delete images the have exited p3x docker clear # delete all images in docker p3x docker free # delete exited containers p3x pkg yarn install | # installs recursive every project that has a package.json p3x build yarn install | # install recursive every package that has a corifeus-builder p3x npm unpublish # unpublish every package from NPM except the last Minor version (Major.Minor.Build-Commit) p3x link # links every recursive given package together p3x git # you can execute a command on every git dir, recursive p3x rm # remove recursive the given folder p3x ncu -a # updates recursive all packages p3x git pull # recursive pull every folder p3x git push # recursive push every folder p3x git renew|truncate # remote all commits, from #1231 commit to #1 p3x git init repo-name # .git is not required, is auto added, post-update is generated so it is my own, specific for the patrikx3.com server git repo (it adds in the webhook), the names are only lower cased forcefully a-z, digit and dash. ``` and more ... If you want the commands is serials, add the ```-s``` or ```--serial``` flag, otherwise all ```async```. etc ... # Dependencies Fix http://cdn.corifeus.com/git/tools/dependencies-fix.json # Webpack repos * gitlist * redis-ui-material * fortune-cookie * corifeus-builder-angular * sygnus ngivr builder webpack # Default excludes from GitHub: http://cdn.corifeus.com/git/tools/github.json # Github fork upstream 1 . Clone your fork: ```bash git clone git@github.com:YOUR-USERNAME/YOUR-FORKED-REPO.git ``` 2 . Add remote from original repository in your forked repository: ```bash cd into/cloned/fork-repo git remote add upstream https://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git git fetch upstream ``` 3 . Updating your fork from original repo to keep up with their changes: ```bash git pull upstream master git merge upstream/master git push # or git checkout dev git pull upstream dev git merge upstream/dev git push ``` # Warning / deprecate ```js npm deprecate [@] // or better npm deprecate my-thing@"< 0.2.3" "critical bug fixed in v0.2.3" ``` # Really make a bare repo to smaller https://stackoverflow.com/questions/2116778/reduce-git-repository-size https://stackoverflow.com/questions/3797907/how-to-remove-unused-objects-from-a-git-repository/14729486#14729486 ```bash git gc --prune=now --aggressive ``` # Show available versions on NPM ```bash # for example npm show p3x-angular-compile versions --json ``` # Verdaccio NPM fix https://github.com/verdaccio/verdaccio/issues/577 ```text docker run --rm -it node:9.2.0-alpine sh / # npm login --registry https://npm.company.com Username: admin Password: Email: (this IS public) admin@company.com Logged in as admin on https://npm.company.com/. / # cat ~/.npmrc //npm.company.com/:_authToken=Rwl9t+GHjlgP+brFJ6WycIe1y6r3Z+ShUEqsLusmFC11w3n6ex8JdmkMoKv/0U/D / # ``` Another solution is like this: ```text # project .npmrc registry = "https://registry.acmeco.com" ca = null always-auth = true ``` # Swap for Docker https://askubuntu.com/questions/417215/how-does-kernel-support-swap-limit Edit: ```bash sudo nano /etc/default/grub ``` Like: ```text GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1" ``` Update: ```bash sudo update-grub ``` Edit: ```bash touch /etc/sysctl.d/90-swappiness.conf nano /etc/sysctl.d/90-swappiness.conf ``` ```text vm.swappiness=1 ``` **sudo reboot** # How To Configure a Mail Server Using Postfix, Dovecot, MySQL, and SpamAssassin and Sieve to move to Spam / Junk folder https://superuser.com/questions/1248257/how-to-configure-a-mail-server-using-postfix-dovecot-mysql-and-spamassassin-a/1248470#1248470 This is how is solved it (it took 7 months): ```bash apt install dovecot-sieve dovecot-managesieved nano /etc/dovecot/conf.d/90-plugin.conf ``` ## Add or set in: ```text protocol lmtp { mail_plugins = $mail_plugins sieve auth_socket_path = /var/run/dovecot/auth-master } ``` ```text nano /etc/dovecot/sieve.conf ``` ## Add in ```text require ["fileinto", "mailbox"]; if header :contains "X-Spam-Flag" "YES" { # move mail into Folder Spam, create folder if not exists fileinto :create "Spam"; stop; } ``` ## Execute ```bash sievec /etc/dovecot/sieve.conf nano /etc/spamassassin/local.cf ``` Add in or set it, it's like this ( I think you don't need everythign else): ```text report_safe 0 required_score 2.0 use_bayes 1 use_bayes_rules 1 bayes_auto_learn 1 skip_rbl_checks 0 use_razor2 1 use_pyzor 0 add_header all Status _YESNO_, score=_SCORE_ required=_REQD_ version=_VERSION_ bayes_ignore_header X-Bogosity bayes_ignore_header X-Spam-Flag bayes_ignore_header X-Spam-Status ``` ## Edit a new file again ```bash nano /etc/dovecot/conf.d/90-sieve.conf ``` Set this config, you don't need anything else: ```text plugin { sieve = /etc/dovecot/sieve.conf } ``` Edit the mail boxes, so jo have Junk, I think jo just need add or uncomment the Junk setting: ```bash nano /etc/dovecot/conf.d/15-mailboxes.conf ``` ## Add in this config ```text namespace inbox { mailbox Drafts { auto = subscribe special_use = \Drafts } mailbox Junk { auto = subscribe special_use = \Junk } mailbox Trash { auto = subscribe special_use = \Trash } mailbox Sent { auto = subscribe special_use = \Sent } } ``` My user for the e-mail server is ```vmail```, so do like this: ```bash chmod ug+w /etc/dovecot chmod ug+w /etc/dovecot/sieve.conf.svbin ``` ```chown -R vmail:vmail /etc/dovecot``` Restart your mail server: ```bash service postfix reload && service spamassassin restart && service dovecot restart ``` # GRUB for another menu once Make sure `/etc/default/grub` has this: ```text GRUB_DEFAULT=saved` ``` You can choose you menu like: ```bash grep -i "menuentry '" /boot/grub/grub.cfg ``` The boot with your menu: ```bash sudo -i # my workstation boot from win grub-reboot 2 reboot ``` # Git synchronize ```bash git submodule sync ``` # WINDOWS ## IIS Windows 10 Enterprise For `IIS`, I have to use the current user `Domain user` both the web site and the application pools eg. `domain\user`. We have to install the `urlrewrite2` module, I think it is here: https://www.iis.net/downloads/microsoft/url-rewrite ## ALT GR for IntelliJ Idea https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000803070/comments/115000663724 The working solution is to add actionSystem.force.alt.gr=true to custom properties. ## PHP.INI ```ini extension_dir = "C:\php\php-7.2\ext" fastcgi.impersonate = 1 cgi.fix_pathinfo = 0 cgi.force_redirect = 0 error_log=C:\php\php-7.2-error.log extension=php_openssl.dll extension=php_mbstring.dll zend_extension=php_opcache.dll extension=php_gd2.dll extension=php_curl.dll zend_extension=C:\php\xdebug\php_xdebug-2.7.0alpha1-7.2-vc15-nts-x86_64.dll ``` [//]: #@corifeus-footer --- 🙏 This is an open-source project. Star this repository, if you like it, or even donate to maintain the servers and the development. Thank you so much! Possible, this server, rarely, is down, please, hang on for 15-30 minutes and the server will be back up. All my domains ([patrikx3.com](https://patrikx3.com) and [corifeus.com](https://corifeus.com)) could have minor errors, since I am developing in my free time. However, it is usually stable. [**P3X-TOOLS**](https://pages.corifeus.com/tools) Build v2019.10.104 [![Donate for Corifeus / P3X](https://img.shields.io/badge/Donate-Corifeus-003087.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=QZVM4V6HVZJW6) [![Contact Corifeus / P3X](https://img.shields.io/badge/Contact-P3X-ff9900.svg)](https://www.patrikx3.com/en/front/contact) [![Like Corifeus @ Facebook](https://img.shields.io/badge/LIKE-Corifeus-3b5998.svg)](https://www.facebook.com/corifeus.software) ## P3X Sponsors [IntelliJ - The most intelligent Java IDE](https://www.jetbrains.com/?from=patrikx3) [![JetBrains](https://cdn.corifeus.com/assets/svg/jetbrains-logo.svg)](https://www.jetbrains.com/?from=patrikx3) [![NoSQLBooster](https://cdn.corifeus.com/assets/png/nosqlbooster-70x70.png)](https://www.nosqlbooster.com/) [The Smartest IDE for MongoDB](https://www.nosqlbooster.com) [//]: #@corifeus-footer:end bin/000077500000000000000000000000001516104162500116275ustar00rootroot00000000000000bin/p3x.js000077500000000000000000000027601516104162500127070ustar00rootroot00000000000000#!/usr/bin/env node //const os = require('os'); //const process = require('process'); //const cores = os.cpus().length < 4 ? 4 : os.cpus().length; //process.env.UV_THREADPOOL_SIZE = cores; //console.debug(`P3X sets UV_THREADPOOL_SIZE to ${cores} thread pool`) if (!require('fs').existsSync(`${__dirname}/../node_modules`)) { require('child_process').execSync(`cd ${__dirname}/.. && npm install --only=prod`, { stdio: 'inherit' }); } const commander = require('commander'); const utils = require('corifeus-utils'); const pkg = require(`../package.json`); const mz = require('mz'); const start = async() => { // command // required // [command] optional // [command ...] variable options commander .version(pkg.version) .usage('[options]') ; require('../src/command/rm') require('../src/command/npm') require('../src/command/for') require('../src/command/git') require('../src/command/github') require('../src/command/each') require('../src/command/ncu') require('../src/command/docker') require('../src/command/server') require('../src/command/redis') require('../src/command/travis') // redis-cli KEYS chrome:* | xargs redis-cli DEL /* const isInModule = await mz.fs.exists(`${__dirname}/../../node_modules`); if (!isInModule) { require('../src/command/pdf') } */ commander.parse(process.argv); if (!process.argv.slice(2).length) { commander.outputHelp(); } } start();dependencies-fix.json000066400000000000000000000011571516104162500151700ustar00rootroot00000000000000{ "keep": [ ], "keep-by-repo": { "corifeus-app-server-patrikx3": [ ], "onenote": [ "electron", "configstore" ], "redis-ui": [ "electron", "configstore" ], "gitlist": [ "bootswatch", "bootstrap" ], "corifeus-app-web-pages": [ ], "corifeus-builder-angular": [ "core-js", "reflect-metadata", "rxjs", "tslib", "zone.js", "typescript" ] }, "disable-update": [ ] } github.json000066400000000000000000000000511516104162500132300ustar00rootroot00000000000000{ "excludes": [ "stackicons" ] }package.json000066400000000000000000000025531516104162500133520ustar00rootroot00000000000000{ "name": "p3x-tools", "version": "2019.10.104", "corifeus": { "prefix": "p3x-", "publish": true, "type": "p3x", "code": "Lazy", "nodejs": "v12.6.0", "opencollective": false, "reponame": "tools", "build": true }, "bin": { "p3x": "bin/p3x.js" }, "license": "MIT", "description": "💣 Tools", "main": "index.js", "directories": { "test": "test" }, "scripts": { "test": "grunt" }, "repository": { "type": "git", "url": "git+https://github.com/patrikx3/tools.git" }, "keywords": [ "tools", "unpublish", "npm" ], "author": "Patrik Laszlo ", "bugs": { "url": "https://github.com/patrikx3/tools/issues" }, "homepage": "https://pages.corifeus.com/tools", "devDependencies": { "corifeus-builder": "^2019.10.107" }, "dependencies": { "commander": "^2.20.0", "corifeus-utils": "^2019.10.104", "fs-extra": "^8.1.0", "github-api": "^3.2.2", "globby": "^10.0.1", "ini": "^1.3.5", "mz": "^2.7.0", "npm-check-updates": "^3.1.18", "progress": "^2.0.3", "tmp-promise": "^2.0.2", "yamljs": "^0.3.0" }, "engines": { "node": ">=10.16.0" } }src/000077500000000000000000000000001516104162500116465ustar00rootroot00000000000000src/command/000077500000000000000000000000001516104162500132645ustar00rootroot00000000000000src/command/docker.js000066400000000000000000000025441516104162500150760ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); commander .command('docker ') .description(`Commands: free: deletes no-name images and dead containers clean: delete images the have exited clear: delete delete all images `) .action(async function (command, options) { switch (command) { case 'free': console.log('deletes no-name images and dead containers') await utils.childProcess.exec(`docker images --no-trunc | grep '' | awk '{ print $3 }' | xargs -r docker rmi || true docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v || true`, true) case 'clean': console.log('delete images the have exited') await utils.childProcess.exec(`docker rm $(docker ps -q -f status=exited) docker rmi $(docker images -q -f dangling=true) || true`, true) break; case 'clear': console.log('delete all images') await utils.childProcess.exec(`docker rm $(docker ps -a -q) docker rmi $(docker images -q)|| true`, true) break; default: commander.outputHelp(); console.error(`Unknown command: ${command}`) process.exit(1) break; } }) ; src/command/each.js000066400000000000000000000221451516104162500145260ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const find = utils.fs.find; const mz = require('mz'); const npmLib = require('../npm'); const lib = require('../lib'); const _ = require('lodash'); const dependenciesFix = require('../../dependencies-fix.json'); const allCommands = [ 'link', 'publish', 'pkg', 'build', ]; const publishableCommand = [ 'link', 'publish' ]; const read = async (options, bar) => { if (options.read) { if (bar) { bar.interrupt(` Wait for enter... `) } await utils.input.key(); } } const loadCommander = (command) => { commander .command(`${command} [plusCommands...]`) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .option('-z, --disable-ncu', 'Disable ncu') .option('-a, --all', 'All') .option('-s, --serial', 'Serial ') .option('-r, --read', 'read a key') .option('-n, --non-interactive', 'Non interfactive') .option('-p, --disable-progress', 'Disable progress') .option('--registry', 'Registry') .option('-m, --packageManager ', 'Package manager') .option('-o, --only ', 'Only packages', (list) => { return list.split(','); }) .option('-x, --exclude ', 'Exclude packages', (list) => { return list.split(','); }) .action(async function (plusCommands, options) { await executeCommand(command, plusCommands, options); }) ; } allCommands.forEach((cmd) => loadCommander(cmd)) const getPkgAndDeps = async (file) => { const data = (await mz.fs.readFile(file)).toString(); try { const pkg = JSON.parse(data); let deps = Object.keys(Object.assign(pkg.dependencies || {}, pkg.devDependencies || {})); return [pkg, deps]; } catch (e) { console.error(); console.error(file); console.error(); throw e; } } const executeCommand = async (command, plusCommands, options) => { let errors = []; plusCommands = plusCommands.join(' ').trim(); if (plusCommands === 'ncu') { plusCommands = `__NCU__` } if (options.nonInteractive) { plusCommands += ' --non-interactive' } if (options.registry) { plusCommands += ' --registry https://registry.npmjs.com/' } if (options.packageManager) { plusCommands += ' --packageManager ' + options.packageManager } if (options.all && plusCommands !== 'start' && plusCommands !== '__NCU__') { plusCommands += ' -a' } let paths = await find({ find: 'package.json', }); let count = 0; const key = {}; let list = []; await paths.forEachAsync(async (findData) => { const [pkg, deps] = await getPkgAndDeps(findData.path); if (dependenciesFix['disable-update'].includes(pkg.name)) { return; } key[pkg.name] = true; const result = { name: pkg.name, pkg: pkg, deps: deps, findData: findData } list.push(result) }); list = list.map((item) => { item.wants = []; item.deps.forEach((want) => { if (key.hasOwnProperty(want)) { item.wants.push(want); } }) return item; }) list = utils.require.resovleDependencies({ modules: list, debug: false, recursive: [ 'corifeus-utils' ] }); let allList = list.slice(); const reRunAllList = () => { const allListFilter = list.map(item => { return item.pkg.name; }) allList = allList.filter(item => { for (let masterItemName of allListFilter) { if (item.pkg.name === masterItemName) { return true; } if (item.deps.includes(masterItemName)) { return true; } } return false; }) } if (options.only !== undefined) { list = list.filter(item => { return options.only.includes(item.pkg.name); }) reRunAllList(); } if (options.exclude !== undefined) { list = list.filter(item => { return !options.exclude.includes(item.pkg.name); }) reRunAllList(); } if (publishableCommand.includes(command)) { list = list.filter(item => { return item.pkg.hasOwnProperty('corifeus') && item.pkg.corifeus.publish === true; }) } switch (command) { case 'publish': options.serial = true; break; case 'link': plusCommands = `yarn unlink || true yarn link `; break; } if (plusCommands === '') { plusCommands = 'list'; } if (plusCommands === 'start') { plusCommands = `sudo echo "SUDO IS DONE" __NCU__ ${lib.hackNpmInstallPreHook()} npm install --non-interactive ${npmLib.command.publish({all: options.all})}`; } const actual = []; let doActualExecute = false; const displayCommand = `${command} ${plusCommands}`; let bar; if (options.disableProgress !== true && list.length > 0) { bar = lib.newProgress(command, list); } let remained = []; await list.forEachAsync(async (item) => { const {findData, pkg, deps} = item; let hasBuilder; if (pkg.name !== undefined && pkg.name.startsWith('corifeus-builder')) { hasBuilder = true; } else if (command === 'build' || command === 'publish') { hasBuilder = deps.find((dep) => { return dep.startsWith('corifeus-builder'); }) } else { hasBuilder = true; } if (hasBuilder !== undefined) { actual.push(item); switch (plusCommands) { case 'count': case 'deps': case 'list': console.info(pkg.name) if (options.disableProgress !== true) { bar.tick({ token: pkg.name }) } break; default: if (!options.dry) { doActualExecute = true; } await lib.executeCommandByPath({ findData: findData, command: plusCommands, errors: errors, item: item, options: options, bar: bar }) await read(options, bar) } } else { if (options.disableProgress !== true) { bar.tick({ token: pkg.name }) } remained.push(item); } }, options.serial) remained.forEach(allItem => { let found = false; actual.forEach((actualItem) => { if (actualItem.name === allItem.name) { found = true; } }) if (!found) { remained.push(allItem); } }, options.serial) if ((doActualExecute || options.dry) && publishableCommand.includes(command)) { const afterBar = lib.newProgress(`post ${command}`, allList); await allList.forEachAsync(async (item) => { const {findData, pkg, deps} = item; let execCommand; switch (command) { case 'publish': if (options.disableNcu !== true) { execCommand = ` __NCU__ ${lib.hackNpmInstallPreHook()} npm install --non-interactive `; } break; case 'link': if (item.wants.length > 0) { execCommand = ` yarn link ${item.wants.join(' \nyarn link ')} ` } break; } if (execCommand !== undefined) { await lib.executeCommandByPath({ findData: findData, command: execCommand, errors: errors, item: item, options: options, bar: afterBar }) await read(options, afterBar) } }, options.serial) } console.info(`All: ${allList.map((item) => item.name)}`) console.info(); console.info(`Actual: ${actual.map((item) => item.name)}`) console.info(); console.info(`Remained: ${remained.map((item) => item.name)}`) console.info(); console.info(`Actual count: ${actual.length}`) console.info(); console.info(`Serial: ${options.serial ? 'true' : 'false'}`) if (errors.length > 0) { console.error(`Errors: ${errors.length}`); console.error(errors) } console.info(); console.info(displayCommand) console.info(); //console.info('Dependencies fix', JSON.stringify(dependenciesFix, null, 4)) } src/command/for.js000066400000000000000000000040431516104162500144110ustar00rootroot00000000000000// rmdirr dir dirs const commander = require('commander'); const fsExtra = require('fs-extra'); const utils = require('corifeus-utils'); commander .command('for ') .description(` Finds a list of directories (without start ./ and end /) recursively `) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .option('-t, --types ', 'Defaults is all, options: d = directory, f = file, like -t=f,d', (val) => { return val.split(','); }) .option('-x, --exclude ', 'Exclude paths, default is node_module', (val) => { const types = {}; val.split(',').forEach((type) => types[type] = true); }) .action(async function (dir, command, options) { command = command.join(' '); const find = utils.fs.find; console.info(`Directory finding: ${dir}`) const paths = await find({ find: dir, type: options.types || { d: true, f: true } }); const dry = options.dry || false; if (dry) { console.info(`Dry, doesn't do anything, just shows what it does`) } const promises = []; paths.forEach(async (findData) => { const generatedCommand = `bash -c ' pushd ${findData.dir} set -e export FOUND_DIR=${findData.dir} export FOUND=${findData.path} ${command} popd '`; if (dry) { console.info(`Dirs`, path) // console.log(generatedCommand); } else { const run = utils.childProcess.exec(generatedCommand); run.exec.stdout.on('data', (data) => { console.info(data); }); run.exec.stderr.on('data', (data) => { console.error(data); }); promises.push(run); } //console.info(`Path ${path}, Execute ${command}`) }) Promise.all(promises); }) ; src/command/git.js000066400000000000000000000107241516104162500144110ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const find = utils.fs.find; const path = require('path'); const git = require('../git'); const mz = require('mz'); const lib = require('../lib'); //p3x for .git 'cd ..;p3x git truncate' const commands = [ 'truncate', 'renew', 'each', 'push', 'pull', 'init', ] commander .command('git [command] [plusCommands...]') .description(` The versioning is Major.Minor.Commit-Build If you omit the package name, it will use all. commands: ${commands.join(', ')} `) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .option('-a, --all', 'All') .option('-s, --serial', 'Serial') .action(async function (command, plusCommands, options) { let paths; if (command === undefined) { command = 'list'; } plusCommands = plusCommands.join(' ').trim(); switch (command) { case 'init': const validateGitName = (name) => { const regex = /^((\w|\d|-){1,}(\.git)?)$/; name = name.toLowerCase().trim(); if (!regex.test(name)) { throw new Error(`Invalid name: "${name}", ${name.length} characters, allowed is characters, - and numbers, minimum 1 character`); } if (!name.endsWith('.git')) { name = name + '.git'; } return name; } const name = validateGitName(plusCommands); // this is in server-scripts as well (the post-update) await utils.childProcess.exec(`git init --bare ${name} echo "${name.substr(0, name.length - '.git'.length)}" > ${name}/description cat ${__dirname}/../git/post-update > ${name}/hooks/post-update chmod +x ${name}/hooks/post-update`, true) break; case 'truncate': case 'renew': const truncate = require('../git').truncate; await truncate(options); break; case 'each': case 'count': case 'list': case 'push': case 'pull': paths = await find('.git'); paths = paths.map(pathActual => { if (pathActual.dir === pathActual.path) { pathActual.dir = path.dirname(pathActual.dir); } return pathActual; }) let internalCommand; switch (command) { case 'count': console.info(paths.length); break; case 'each': break; case 'list': for (let pathItem of paths) { console.log(path.basename(pathItem.dir)); } break; case 'push': await paths.forEachAsync(async (findData) => { await utils.repeat.async(2, async () => { await lib.executeCommandByPath({ findData: findData, options: options, command: `git add . git commit -am robo8x || true git push || true ${plusCommands === '' ? 'true' : plusCommands}`, }) }, true) }, true) break; case 'pull': internalCommand = `git pull` break; } if (internalCommand !== undefined) { let errors = []; const bar = lib.newProgress(command, paths) await paths.forEachAsync(async (findData) => { await lib.executeCommandByPath({ findData: findData, command: internalCommand, options: options, errors: errors, bar: bar, }) }, options.serial) } break; default: console.error(`Unknown command: ${command}`) } }) ; src/command/github.js000066400000000000000000000053511516104162500151100ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const find = utils.fs.find; const path = require('path'); const github = require('../github'); const defaultGithubExcludes = require('../../github.json').excludes //p3x for .git 'cd ..;p3x git truncate' const commands = [ 'mirror', 'pull', ] commander .command('github ') .description(` commands: ${commands.join(', ')} `) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .option('-u, --user [user]', 'The GitHub repo, default is patrikx3') .option('-n, --note [note]', 'The note in the commit, the default is robo8x chore') .option('-p, --password [password]', 'The GitHub password or token') .option('-b, --branch ', 'The default branch is master') .option('-g, --git ', 'The GIT repo, example is https://user:password@git.patrikx3.com/') .option('-x, --exclude ', `Exclude paths, default is ${defaultGithubExcludes.join(',')}`, (val) => { return val.split(','); }) .option('-o, --only ', `Only included paths, default is all`, (val) => { return val.split(','); }) .action(async function (command, options) { const user = options.user || 'patrikx3'; const gitUrl = options.git || 'https://git.patrikx3.com'; const note = options.note || 'robo8x [chore] ' const branch = options.branch || 'master'; const exclude = options.exclude || defaultGithubExcludes console.info(`User: ${user}`); console.info(`Git url: ${gitUrl}`); console.info(`Note: ${note}`); switch (command) { case 'pull': await utils.childProcess.exec(` GIT_NAME=$(basename \`git rev-parse --show-toplevel\`) git pull https://github.com/patrikx3/$GIT_NAME ${branch}`, true); break; case 'list': const repos = await github.list({ user: user, exclude: exclude, only: options.only }); console.log(repos) break; case 'mirror': if (options.password === undefined) { throw new Error('password required') } await github.mirror({ user: user, password: options.password, gitUrl: gitUrl, dry: options.dry, note: note, exclude: exclude, only: options.only }) break; default: console.error(`Unknown command: ${command}`) } }) ; src/command/ncu.js000066400000000000000000000007021516104162500144060ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const path = require('path'); const mz = require('mz'); const lib = require('../lib'); commander .command('ncu') .description(`This is for global update`) .action(async function (options) { const ncu = require('npm-check-updates'); const result = await ncu.run({ global: true, }) console.log(result); }) ; src/command/npm.js000066400000000000000000000052211516104162500144140ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const mz = require('mz'); const hasin = require('lodash/hasIn'); const globby = require('globby'); const npmLib = require('../npm'); const commands = [ 'publish', 'update', 'login', 'unpublish', ] commander .command('npm [packages...]') .description(` The versioning is Major.Minor.Commit-Build If you omit the package name, it will use all. commands: ${commands.join(', ')} `) .option('-u, --username [username]', 'Author username, defaults to patrikx3', (val) => { return val.split(','); }) .option('-s, --search [term]', `Search for the given packages, the default is 'p3x,corifeus`, (val) => { return val.split(','); }) .option('-a, --all') .option('-d, --dry', 'Do not actually remove packages, just show what it does') .action(async function (command, packages, options) { let search = options.search; if (search === undefined) { search = ['p3x', 'corifeus'] } let username = options.username; if (username === undefined) { username = ['patrikx3']; } const dry = options.dry || false; const all = options.all || false; switch (command) { case 'update': if (await mz.fs.exists('./package.json')) { await utils.childProcess.exec(`ncu -a --loglevel verbose --packageFile package.json`, true) } break; case 'unpublish': const unpublish = require('../npm-unpublish'); await unpublish(username, search, packages, dry, all); break; case 'publish': if (await mz.fs.exists('./package.json')) { const pkg = require(`${process.cwd()}/package.json`); if (hasin(pkg, 'corifeus.publish') && pkg.corifeus.publish === true) { await utils.childProcess.exec(npmLib.command.publish({ all: options.all }), true) } else { console.info(`This package.json has not corifeus.publish = true`); } } else { console.info(`This directory has no package.json`); } break; case 'login': await utils.childProcess.exec(`npm login --registry https://registry.npmjs.org`, true) break; default: console.error(`Unknown command: ${command}`) } }) ; src/command/pdf.js000066400000000000000000000005261516104162500143760ustar00rootroot00000000000000/* const commander = require('commander'); // unpublish commander .command('pdf [file]') .description(` Parse a pdf file `) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .action(async function (file, options) { const pdf = require('../pdf'); await pdf(file); }) ; */src/command/redis.js000066400000000000000000000024431516104162500147330ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const path = require('path'); const mz = require('mz'); const lib = require('../lib'); commander .command('redis [command] [param]') .option('-u, --url ', 'REDIS url') .description(`This is for redis: DEL `) .action(async function (command, param, options) { let addon = ''; if (options.url) { console.log(options.url) const url = new (require('url').URL)(options.url) if (url.hostname) { addon += `-h ${url.hostname} ` } if (url.password) { addon += `-a ${url.password} ` } const pathname = url.pathname.substr(1); if (pathname != '') { addon += `-n ${pathname} ` } } switch (command.toLowerCase()) { case 'del': if (param === undefined) { throw new Error('DEL require a parameter') } const commandExec = `/usr/bin/redis-cli ${addon}KEYS ${param} | xargs redis-cli ${addon}DEL`; //console.info(commandExec); await utils.childProcess.exec(commandExec, true) break; } }) ; src/command/rm.js000066400000000000000000000020741516104162500142430ustar00rootroot00000000000000const commander = require('commander'); const fsExtra = require('fs-extra'); const utils = require('corifeus-utils'); commander .command('rm ') .description(` Delete the list of directories (without start ./ and end /) recursively `) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .option('-f, --file', 'Search for files') .option('--directory', 'Search for files') .action(async function (dirs, options) { const find = utils.fs.find; const files = await find({ find: dirs, type: { d: options.directory || true, f: options.file } }); const dry = options.dry || false; if (dry) { console.info(`Dry, doesn't remove anything`) } const promises = []; files.forEach(async (file) => { if (!dry) { promises.push(fsExtra.remove(file.path)); } console.info(`Delete ${file.path}`) }) Promise.all(promises); }) ;src/command/server.js000066400000000000000000000017541516104162500151370ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const path = require('path'); const mz = require('mz'); const lib = require('../lib'); commander .command('server [command] [param]') .description(`This is for global update`) .option(`-p, --password `) .action(async function (command, param, options) { let url; switch (command) { case 'scale': case 'worker': if (param === undefined) { param = 'auto'; } url = `http://localhost:23502/worker/${param}`; break; default: url = `http://localhost:23502/status`; break; } const response = await utils.http.request({ url: url, headers: { 'Authorization': options.password || '' } }); console.log(JSON.stringify(response.body, null, 4)); }) ; src/command/travis.js000066400000000000000000000076041516104162500151410ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const yaml = require('yamljs') const mz = require('mz'); const path = require('path') const _ = require('lodash'); commander .command('travis [commands...]') .description(` It is imporant, that before you do anything, install the travis Ruby gem. You need the ruby-dev environment as well, so apt install ruby-dev gem install travis (gem search travis - specific version) travis login Based on: http://blog.code4hire.com/2016/06/Adding-GitHub-token-to-Travis-CI-configuration/ Commands: github-token: Adds a github token to all .travis files, recursively arguments: token or repo token, if you use 1 arguments, it is patrikx3 make sure you are logged in travis. `) .option('-s, --serial', 'Serial ') .option('-o, --org', 'Use the ORG environment') .action(async function (commands, options) { switch (commands[0]) { case 'github-token': let repo = commands[1] let githubToken = commands[2] if (repo === undefined) { console.error('2nd repo or token is required') return; } if (githubToken === undefined) { githubToken = repo; repo = 'patrikx3'; } console.log(`found to execute repo ${repo} with token ${githubToken}`) let paths = await utils.fs.find({ find: '.travis.yml', }); await paths.forEachAsync(async (findInfo) => { try { const dir = findInfo.dir const file = findInfo.path; const repoName = path.basename(dir); // if (repoName !== 'corifeus') { // return; // } const travisYml = (await mz.fs.readFile(file)).toString(); const travisJson = yaml.parse(travisYml); // console.log('travisJson'); // console.log(JSON.stringify(travisJson,null,4)) if (_.hasIn(travisJson, 'env.global.secure')) { delete travisJson.env.global.secure if (Object.keys(travisJson.env.global).length === 0) { delete travisJson.env.global; } if (Object.keys(travisJson.env).length === 0) { delete travisJson.env; } // console.log('new travisJson') // console.log( JSON.stringify(travisJson,null,4)) const newTravisYml = yaml.stringify(travisJson, 4) // console.log('new travis yml') // console.log(newTravisYml) await mz.fs.writeFile(file, newTravisYml) } const travisSecureCommand = `bash -c 'pushd ${dir} travis encrypt 'GITHUB_TOKEN=${githubToken}' -r ${repo}/${repoName} --add ${options.org ? '--org' : '--pro'} cat .travis.yml popd ' ` console.log(`Executing: ${travisSecureCommand} `) await utils.childProcess.exec(travisSecureCommand, true) } catch (e) { console.error(e); throw e; } }, options.serial) break; default: commander.outputHelp(); console.error(`Unknown command: ${commands[0]}`) process.exit(1) break; } }) ; src/git.js000066400000000000000000000015311516104162500127670ustar00rootroot00000000000000const utils = require('corifeus-utils'); const globby = require('globby'); const path = require('path'); const truncate = async (options) => { const command = `git config --global credential.helper 'cache --timeout 7200' git checkout --orphan temp git add -A git commit -am "robo8x (truncate)" git branch -D master git branch -m master git branch --set-upstream-to origin/master master git push -f origin master` console.log(command); if (!options.dry) { await utils.childProcess.exec(command, { display: true, maxBuffer: 1024 * 500, }) } } const findModules = async (root) => { const modules = await globby(`${root}/**/.gitmodules`); return modules.map((dir) => { return path.dirname(dir); }); } module.exports.findModules = findModules; module.exports.truncate = truncate; src/git/000077500000000000000000000000001516104162500124315ustar00rootroot00000000000000src/git/post-update000066400000000000000000000052541516104162500146270ustar00rootroot00000000000000#!/usr/bin/env node // this is in server-scripts as well const url = require('url'); const request = (options) => { if (typeof (options) === 'string') { options = { url: options, method: 'GET', } } /* https://nodejs.org/api/http.html#http_http_request_options_callback */ const parsedUrl = url.parse(options.url); let request; if (parsedUrl.protocol === 'https:') { request = require('https').request; if (parsedUrl.port === null) { parsedUrl.port = 443; } } else if (parsedUrl.protocol === 'http:') { request = require('http').request; if (parsedUrl.port === null) { parsedUrl.port = 80; } } else { throw new Error(`Unknown protocol ${parsedUrl.protocol}`); } options.protocol = parsedUrl.protocol; options.port = parsedUrl.port; options.host = parsedUrl.host; options.hostname = parsedUrl.hostname; options.path = parsedUrl.path; let body; if (options.body !== undefined) { if (typeof (options.body) === 'object') { body = JSON.stringify(options.body); options.headers = options.headers || {}; if (!options.headers.hasOwnProperty('Content-Type')) { options.headers['Content-Type'] = 'application/json; charset=utf-8' options.headers['Content-Length'] = Buffer.byteLength(body) } } } return new Promise((resolve, reject) => { const req = request(options, (res) => { res.setEncoding('utf8'); let rawData = ''; res.on('data', (chunk) => { rawData += chunk; }); res.on('end', () => { try { if (res.headers.hasOwnProperty('content-type') && res.headers['content-type'].startsWith('application/json')) { const parsedData = JSON.parse(rawData); res.body = parsedData; } resolve(res); } catch (e) { reject(e); } }); }) req.on('error', reject); if (body !== undefined) { req.write(body); } req.end(); }) } const start = async () => { try { const response = await request({ url: 'http://localhost:23500/post-update', method: 'POST', body: { env: process.env, cwd: process.cwd(), } }) console.log(JSON.stringify(response.body, null, 2)); } catch (e) { console.error(e) } } start(); src/github.js000066400000000000000000000137441516104162500134770ustar00rootroot00000000000000const GitHub = require('github-api'); const tmp = require('tmp-promise'); const utils = require('corifeus-utils'); const globby = require('globby'); const mz = require('mz'); const ini = require('ini'); const url = require('url'); const git = require('./git'); const list = async (options) => { const {only, user, exclude} = options; let {disableArchived} = options if (disableArchived === undefined) { disableArchived = false; } const gh = new GitHub(); const response = await gh.getUser(user).listRepos(); const repos = response.data return repos.filter(repo => { let isOnly; if (only !== undefined) { isOnly = only.includes(repo.name) } else { isOnly = true; } if (disableArchived === true && repo.archived === true) { isOnly = false; } return repo.full_name === `${user}/${repo.name}` && !exclude.includes(repo.name) && isOnly; }); } const mirror = async (options) => { let {only, user, password, gitUrl, dry, note, exclude} = options; let tmpDir; const errors = []; try { tmpDir = await tmp.dir(); console.info(`Generate tmp file: ${tmpDir.path}`); const repos = await list({ user: user, exclude: exclude, only: only, disableArchived: true }); await repos.forEachAsync(async (repo) => { await utils.childProcess.exec(` git clone --depth 5 https://${user}:${password}@github.com/${user}/${repo.name} ${tmpDir.path}/github/${repo.name} cd ${tmpDir.path}/github/${repo.name} git submodule update --init --recursive --remote git clone --depth 5 ${gitUrl}/${repo.name}.git ${tmpDir.path}/git/${repo.name} cd ${tmpDir.path}/git/${repo.name} git submodule update --init --recursive --remote `, true) }) console.info('Remove all Git .git dirs and move to Github .git dirs'); await repos.forEachAsync(async (repo) => { const currentRepo = `${tmpDir.path}/git/${repo.name}`; await utils.childProcess.exec(` rm -rf ${currentRepo}/.git rm -rf ${currentRepo}/secure rm -rf ${currentRepo}/package-lock.json mv ${tmpDir.path}/github/${repo.name}/.git ${tmpDir.path}/git/${repo.name}/ `, true) }) console.info('Move GIT to Github dir'); await utils.childProcess.exec(` mv ${tmpDir.path}/github/ ${tmpDir.path}/github-old/ mv ${tmpDir.path}/git/ ${tmpDir.path}/github/ `, true) console.info('Move submodules to GitHub'); await replaceGitSubmodules(`${tmpDir.path}/github`, user); console.info('Move init.sh to GitHub'); await replaceInitSh(`${tmpDir.path}/github`, gitUrl, user); await replacePkg(`${tmpDir.path}/github`, user); await repos.forEachAsync(async (repo) => { await utils.childProcess.exec(` cd ${tmpDir.path}/github/${repo.name} pwd rm -rf ./idea git add . git status `, true) }) await repos.forEachAsync(async (repo) => { try { await utils.childProcess.exec(` cd ${tmpDir.path}/github/${repo.name} git commit -am "${note} ${new Date().toLocaleString()}" ${dry ? 'true' : 'git push'} `, true) } catch (e) { errors.push(e); } }, true) const modules = await git.findModules(`${tmpDir.path}/github/`) await modules.forEachAsync(async (module) => { await utils.childProcess.exec(` cd ${module} git pull git checkout master git submodule update --init --recursive --remote git submodule foreach --recursive git checkout master git status ${dry ? 'true' : 'git push'} `, true) }, true) console.info('All done') } catch (e) { errors.push(e); } finally { if (tmpDir) { console.info(`Cleanup tmp file ${tmpDir.path}`); if (!dry) { await utils.childProcess.exec(`rm -rf ${tmpDir.path}`, true) } else { console.info('Dry, not cleanup') } } errors.forEach(e => { console.error(e) }) } } const replacePkg = async (root, user) => { const files = await globby(`${root}/**/package.json`) await files.forEachAsync(async (file) => { console.info(`package.json ${file}`) const string = (await mz.fs.readFile(file)).toString(); const result = string.replace(/git\.patrikx3\.com\//g, `github.com/${user}/`); await mz.fs.writeFile(file, result); console.info(`package.json replaced ${file}`) }) } const replaceGitSubmodules = async (root, user) => { const files = await globby(`${root}/**/.gitmodules`) await files.forEachAsync(async (file) => { console.info(`submodule found ${file}`) const string = (await mz.fs.readFile(file)).toString(); const iniFile = ini.parse(string); Object.keys(iniFile).forEach((key) => { const submodule = iniFile[key] submodule.url = `https://github.com/${user}/${submodule.path}`; }) const result = ini.stringify(iniFile); await mz.fs.writeFile(file, result); console.info(`submodule replaced ${file}`) }) } const replaceInitSh = async (root, gitUrl, user) => { const gitUrlObj = url.parse(gitUrl); gitUrl = RegExp.escape(`${gitUrlObj.protocol}//${gitUrlObj.hostname}`); const gitUrlRegexp = new RegExp(gitUrl, 'ig') const files = await globby(`${root}/**/init.sh`) await files.forEachAsync(async (file) => { console.info(`init.sh found ${file}`) const string = (await mz.fs.readFile(file)).toString(); const result = string.replace(gitUrlRegexp, `https://github.com/${user}`) await mz.fs.writeFile(file, result); console.info(` ${result} `); console.info(`init.sh replaced ${file}`) }) } module.exports.list = list; module.exports.mirror = mirror; module.exports.replaceGitSubmodules = replaceGitSubmodules; module.exports.replaceInitSh = replaceInitSh; src/lib.js000066400000000000000000000071741516104162500127630ustar00rootroot00000000000000const utils = require('corifeus-utils'); const progress = require('progress'); const dependenciesFix = require('../dependencies-fix.json'); const dependenciesFixAddon = (options) => { const {repo} = options let exclude = dependenciesFix.keep || []; if (dependenciesFix.hasOwnProperty('keep-by-repo') && dependenciesFix['keep-by-repo'].hasOwnProperty(repo)) { exclude = exclude.concat(dependenciesFix['keep-by-repo'][repo]) } let excludeAddon = ''; if (exclude.length > 0) { excludeAddon = `-x ${exclude.join(',')}` } return excludeAddon; } const getNcu = (options) => { if (options.disableNcu === true) { return ''; } // const command = `ncu ${options.all ? '-u -a' : ''} --loglevel verbose --packageFile package.json ${dependenciesFixAddon(options)}` // return const command = `ncu ${options.all ? '-u' : ''} --loglevel verbose --packageFile package.json ${dependenciesFixAddon(options)}` return command } const executeCommandByPath = async (options) => { // commander options: options.options const { findData, errors, bar } = options; let {command} = options if (command.includes('__NCU__')) { const ncu = getNcu({ all: options.options.all, disableNcu: options.options.disableNcu, repo: options.item.pkg.corifeus === undefined ? options.item.pkg.name : options.item.pkg.corifeus.reponame }) command = command.replace('__NCU__', ncu) // console.warn('command', command) } const name = options.item ? options.item.name : command; const token = `${name} ${command}`; if (options.options.dry) { console.info('------------------------------------'); console.info(findData.path); console.info(name); // console.info(options.item.pkg.corifeus.reponame); console.info(command) console.info(); if (bar) { utils.repeat(2, () => { bar.tick({ token: token }) }) } return; } try { if (bar) { bar.tick({ token: token }) } const execPromise = utils.childProcess.exec(` bash -c ' pushd ${findData.dir} set -e export FOUND_DIR=${findData.dir} export FOUND=${findData.path} ${command} popd ' `, bar === undefined ? true : false) execPromise.exec.stdout.on('data', (data) => { if (bar) { bar.interrupt(data) } if (!bar) { console.log(data); } }); execPromise.exec.stderr.on('data', (data) => { if (bar) { bar.interrupt(data) } else { console.error(data); } }); await execPromise; } catch (e) { if (errors !== undefined) { errors.push(e); } throw e; } finally { /* if (bar) { bar.tick({ token: name }) } */ } } const newProgress = (status, list) => { const bar = new progress(`${status}[:bar] :token`, { total: list.length, width: Math.min(list.length, 20), complete: '=', incomplete: '-', clear: true }) bar.tick(0, { token: 'loading' }) return bar; } const hackNpmInstallPreHook = () => { return `` } module.exports.newProgress = newProgress; module.exports.executeCommandByPath = executeCommandByPath; module.exports.hackNpmInstallPreHook = hackNpmInstallPreHook; src/npm-unpublish.js000066400000000000000000000112151516104162500150050ustar00rootroot00000000000000const utils = require('corifeus-utils') const path = require('path') // npm deprecate ${repo}@${version} "It is deprecated" const exec = require('child_process').exec; const repo = process.argv[2]; const removeVersion = (repo, version, keptVersions, dry, all) => { const semVersion = version.split('.'); if (!all) { const keptVersion = `${semVersion[0]}.${semVersion[1]}` if (!keptVersions.hasOwnProperty(keptVersion)) { console.info(`Kept version ${version}`); keptVersions[keptVersion] = version; return; } } const command = `npm unpublish ${repo}@${version} --registry https://registry.npmjs.org`; if (dry) { console.info(`[DRY] Removed version ${version}`); console.info(command) return; } return new Promise((resolve, reject) => { const run = exec(command, (e, stdout, stderr) => { if (e) { return reject(e); } if (stderr !== '') { return reject(new Error(stderr)); } console.info(`Removed version ${version}`); return resolve(stdout); }) run.stdout.on('data', (data) => { console.info(data); }); run.stderr.on('data', (data) => { console.error(data); }); }) } const findVersions = async (repo) => { return new Promise((resolve, reject) => { exec(`npm show ${repo} --json`, async (e, stdout, stderr) => { if (e) { console.error(e); reject(e); return; } const info = JSON.parse(stdout); const versions = info.versions.reverse(); console.info(`Versions:`, `${versions.length} versions`, versions); resolve(versions) }); }) } const removePackage = async (repo, dry, all) => { console.info(`Remove repo ${repo}`); const versions = await findVersions(repo); const keptVersions = {} if (Object.keys(versions).length > 1) { for (let version of versions) { await removeVersion(repo, version, keptVersions, dry, all); } } const keptVersionsArray = Object.values(keptVersions); const log = `${repo} Total: ${versions.length} Kept Versions: ${keptVersionsArray.length} Remained versions, ${keptVersionsArray.join(' , ')} `; console.info(log); return { versions: versions, kept: keptVersionsArray, log: log }; } module.exports = async (usernames, search, packages, dry, all) => { const isAll = packages.length === 0; console.info(` ---------------------------------------------- Unpublish ---------------------------------------------- Usernames: ${usernames.join(', ')} Search: ${search.join(', ')} Packages: ${isAll ? 'all' : packages.join(', ')} Dry: ${dry} `) const logs = []; const errorLogs = []; const promises = []; const createLog = (repo, dry) => { return new Promise(async (resolve, reject) => { try { const log = await removePackage(repo, dry, all); logs.push(log); resolve(); } catch (e) { reject(e); } }) } //https://registry.npmjs.org/-/v1/search?text=p3x if (isAll) { const searchPromises = []; search.forEach((term) => { searchPromises.push( utils.http.request(`https://registry.npmjs.org/-/v1/search?text=${term}`) ) }) const results = await Promise.all(searchPromises); // find let objects = []; results.forEach(result => { objects = objects.concat(result.body.objects) }) objects = objects.filter((obj) => { if (!obj.package.hasOwnProperty('author')) { errorLogs.push({ pkg: obj.package, log: `000-This package is invalid: ${obj.package.name} ${obj.package.version} ${JSON.stringify(obj.package, null, 4)} ` }) return false; } return usernames.includes(obj.package.author.username); }) objects.forEach((object) => { promises.push(createLog(object.package.name, dry)) }); } else { packages.forEach((pkg) => { promises.push(createLog(pkg, dry)) }) } await Promise.all(promises); logs.forEach((log) => { console.info(log.log); }) errorLogs.forEach((log) => { console.info(log.log); }) console.info(` Total: ${logs.length} Errors: ${errorLogs.length} `) return logs; } src/npm.js000066400000000000000000000004021516104162500127720ustar00rootroot00000000000000module.exports.command = { publish: (options = {all: true}) => `grunt cory-npm cory-replace grunt cory-npm-angular || true (grunt publish -v && sleep 3)|| true npm publish ${options.all ? 'npm publish --registry https://registry.npmjs.org' : ''}` } src/old-lib.js000066400000000000000000000212541516104162500135320ustar00rootroot00000000000000/* const progress = require('progress'); const fs = require('mz/fs'); const path = require('path') const commander = require('commander'); const utils = require('corifeus-utils'); const execRaw = require('child_process').exec; const pkg = require('../package.json'); let loadModules = () => { const srcpath = `${process.cwd()}` const modules = fs.readdirSync(srcpath).filter(file => fs.statSync(path.join(srcpath, file)).isDirectory()).filter(dir => dir.startsWith('corifeus-')); modules.unshift('corifeus'); return modules; } const allProjects = loadModules() let projects; const projectPath = (project) => { return `${__dirname}/../${project === 'corifeus' ? '' : project + '/' }`; } const getPkg = async (project) => { const buffer = await fs.readFile(`${projectPath(project)}package.json`); return JSON.parse(buffer.toString()); } const extractPackages = async function (projects = allProjects) { const pkgs = {}; await utils.array.forEachAsync(projects, async (project) => { pkgs[project] = await getPkg(project) }, true) return pkgs; }; let pkgs; // order is important const settings = { 'corifeus-utils': { publish: true, }, 'corifeus-builder': { publish: true, }, 'corifeus-server': { publish: true, }, 'corifeus-server-deployer': { publish: true, }, 'corifeus-builder-angular': { publish: true, }, 'corifeus-web': { publish: true, }, 'corifeus-web-material': { publish: true, }, } const loadPublishableChildren = () => { Object.keys(settings).forEach((publishable) => { const setting = settings[publishable]; const children = {}; Object.keys(pkgs).forEach((pkgName) => { const pkg = pkgs[pkgName]; const updateDependecies = (repo) => { if (pkg.hasOwnProperty(repo) && pkg[repo].hasOwnProperty(publishable)) { if (Object.keys(pkg[repo]).includes(publishable)) { children[pkgName] = true; } } } updateDependecies('dependencies', publishable); updateDependecies('devDependencies', publishable); setting.children = Object.keys(children); }) }) } const init = async (commanderEnabled = true) => { pkgs = await extractPackages() if (commanderEnabled) { commander .version(pkg.version) .usage('[options]') .option('-v, --verbose', 'Verbose') .option('-n, --npm', 'Npm to original registry') .option('-p, --projects ', 'The list of projects', (val) => { return val.split(','); }) .parse(process.argv); } projects = commander.projects || allProjects loadPublishableChildren(); module.exports.projects = projects } const exec = (project, command, bar) => { return new Promise((resolve, reject) => { const actualCommand = `${project === 'corifeus' ? '' : `pushd ${project}`} ${command} ${project === 'corifeus' ? '' : `popd`} ` if (bar) { bar.interrupt(actualCommand); } else { console.log(actualCommand); } const run = execRaw(`bash -c ' set -e ${actualCommand} '`, { stdio: `inherit`, }, (e) => { if (e) { console.error(e); return reject(e); } if (bar) { bar.tick({ token: `${project}` }) } return resolve(); }) run.stdout.on('data', (data) => { if (commander.verbose && bar) { bar.interrupt(data) } if (!bar) { console.log(data); } }); run.stderr.on('data', (data) => { if (bar) { bar.interrupt(data) } else { console.error(data); } }); }) } const newProgress = (status, total = projects.length) => { const bar = new progress(`${status} [:bar] :token`, { total: total, width: 27, clear: true }) bar.tick(0, { token: `${projects[0]}` }) return bar; } const grunt = async () => { let port = 10000; const promises = []; const barGrunt = newProgress('grunt'); await utils.array.forEachAsync(projects, (project) => { promises.push(exec(project, `grunt --cory-port=${++port}`, barGrunt)); }) await Promise.all(promises); } const publish = async () => { let total = projects.length; const upgradeAbleCount = await getUpgradeAbleCount(); total = total + (total * upgradeAbleCount); const barPublish = newProgress('publish-upgrade', total); await utils.array.forEachAsync(projects, async (project) => { const setting = settings[project]; if (setting !== undefined && setting.hasOwnProperty('publish') ) { await exec(project, `${commander.npm ? '' : 'grunt cory-npm'} npm publish ${commander.npm ? ' --registry https://registry.npmjs.org' : ''}`, barPublish); await upgrade(barPublish) } else { barPublish.tick({ token: '...' }) } }, true) } const getUpgradable = async () => { const upgradeAble = {}; await utils.array.forEachAsync(projects, (project) => { const setting = settings[project]; if (setting !== undefined && setting.hasOwnProperty('publish') && setting.hasOwnProperty('children')) { setting.children.forEach((child) => { upgradeAble[child] = upgradeAble[child] || []; upgradeAble[child].push(project) }) } }) return upgradeAble; } const getUpgradeAbleCount = async() => { const upgradeAble = await getUpgradable(); const upgrades = Object.keys(upgradeAble); let total = upgrades.length; upgrades.forEach(() => total++); return total; } const upgrade = async (progresser) => { const upgradeAble = await getUpgradable(); const upgrades = Object.keys(upgradeAble); if (progresser === undefined) { const total = await getUpgradeAbleCount(); progresser = progresser || newProgress('upgrade', total); } const promises = []; await utils.array.forEachAsync(upgrades, async (project) => { progresser.tick({ token: project }) const pkgFile = `${projectPath(project)}package.json`; const pkg = await getPkg(project); await utils.array.forEachAsync(upgradeAble[project], async(linkUpdate) => { const updateDependecies = async (repo) => { if (pkg.hasOwnProperty(repo) && pkg[repo].hasOwnProperty(linkUpdate)) { const linkPkg = await getPkg(linkUpdate); pkg[repo][linkUpdate] = `^${linkPkg.version}`; } } await updateDependecies('dependencies', linkUpdate); await updateDependecies('devDependencies', linkUpdate); promises.push(fs.writeFile(pkgFile, JSON.stringify(pkg, null, 4))); progresser.interrupt(`${project} => new pkg ${linkUpdate}`); progresser.tick({ token: linkUpdate }) }) }) await Promise.all(promises); } const link = async() => { const upgradeAble = await getUpgradable(); const upgradeAbleKeys = Object.keys(upgradeAble); const projectsGenerated = projects.filter((project) => (settings[project] || {}).hasOwnProperty('children') ); let total = projectsGenerated.length + upgradeAbleKeys.length; const progress = newProgress('link', total); let promises = []; await utils.array.forEachAsync(projectsGenerated, (project) => { const setting = settings[project] || {}; if (setting.hasOwnProperty('publish') && setting.hasOwnProperty('children')) { promises.push( exec(project, `yarn unlink || true yarn link`, progress) ) } }) await Promise.all(promises); promises = []; await utils.array.forEachAsync(upgradeAbleKeys , (project) => { let command = `` upgradeAble[project].forEach((link) => { command += `yarn link ${link} `; }) promises.push(exec(project, command, progress)) }) await Promise.all(promises); } module.exports = { projects: projects, settings: settings, exec: exec, projectPath: projectPath, newProgress: newProgress, grunt: grunt, publish: publish, upgrade: upgrade, link: link, extractPackages: extractPackages, loadModules: loadModules, init: init } */src/pdf.js000066400000000000000000000026471516104162500127660ustar00rootroot00000000000000//const pdfjs = require('pdfjs-dist'); //const fsExtra = require('fs-extra'); const mz = require('mz'); const pdf = async (file) => { const buffer = await mz.fs.readFile(file); const doc = await pdfjs.getDocument(buffer); var numPages = doc.numPages; console.log('# Document Loaded'); console.log('Number of Pages: ' + numPages); console.log(); const meta = await doc.getMetadata() console.log('# Metadata Is Loaded'); console.log('## Info'); console.log(JSON.stringify(meta.info, null, 2)); console.log(); if (meta.metadata) { console.log('## Metadata'); console.log(JSON.stringify(meta.metadata.metadata, null, 4)); console.log(); } for (var pageNum = 1; pageNum <= numPages; pageNum++) { const page = await doc.getPage(pageNum); console.log('# Page ' + pageNum); var viewport = page.getViewport(1.0 /* scale */); console.log('Size: ' + viewport.width + 'x' + viewport.height); console.log(); const content = await page.getTextContent(); // Content contains lots of information about the text layout and // styles, but we need only strings at the moment var strings = content.items.map(function (item) { return item.str; }); console.log('## Text Content'); console.log(strings.join(' ')); // console.log(content); } } module.exports = pdf; test/000077500000000000000000000000001516104162500120365ustar00rootroot00000000000000test/scripts/000077500000000000000000000000001516104162500135255ustar00rootroot00000000000000test/scripts/find-modules.js000077500000000000000000000002771516104162500164620ustar00rootroot00000000000000#!/usr/bin/env node const path = '/tmp/tmp-6503ODo7z962XubX/github'; const git = require('../../src/git'); const start = async() => { console.log(await git.findModules(path)); } start();test/scripts/transform-git-initsh.js000077500000000000000000000002751516104162500201620ustar00rootroot00000000000000#!/usr/bin/env node const path = '/tmp/tmp-22337ZMnl1XYmwIs4/github'; const github = require('../../src/github'); github.replaceInitSh(path, 'https://123:121@git.patrikx3.com', 'patrikx3');test/scripts/transform-git-modules.js000066400000000000000000000003561516104162500203310ustar00rootroot00000000000000#!/usr/bin/env node const path = '/tmp/tmp-22366RXowst8OEp2G/github'; const globby = require('globby') const mz = require('mz'); const ini = require('ini') const utils = require('corifeus-utils'); replaceGitSubmodules(path, 'patrikx3');test/scripts/version.js000077500000000000000000000001171516104162500155520ustar00rootroot00000000000000#!/usr/bin/env node console.log(parseInt(process.versions.node.split('.')[0])) tools.iml000066400000000000000000000006241516104162500127240ustar00rootroot00000000000000