.gitignore000066400000000000000000000001171516425035600130540ustar00rootroot00000000000000/build /node_modules /*.log /yarn.lock .idea/workspace.xml .idea/tasks.xml .idea/000077500000000000000000000000001516425035600120455ustar00rootroot00000000000000.idea/modules.xml000066400000000000000000000004061516425035600142370ustar00rootroot00000000000000 .idea/tools.iml000066400000000000000000000005201516425035600137050ustar00rootroot00000000000000 .idea/vcs.xml000066400000000000000000000002471516425035600133650ustar00rootroot00000000000000 .npmignore000066400000000000000000000002221516425035600130600ustar00rootroot00000000000000/.idea /artifacts /build /test /node_modules /*.iml /*.ipr /*.iws /.travis.yml /.scrutinizer.yml /Gruntfile.js /*.lock *.log /corifeus-boot.json .scrutinizer.yml000066400000000000000000000005471516425035600142550ustar00rootroot00000000000000checks: javascript: true filter: excluded_paths: - test/* - node_modules/* - build/* - docs/* build: environment: node: 7.8 dependencies: before: - npm install -g grunt-cli tests: override: - command: 'grunt' coverage: file: 'build/coverage/clover.xml' format: 'clover' .travis.yml000066400000000000000000000001321516425035600131720ustar00rootroot00000000000000language: node_js node_js: - "7" - "node" before_script: - npm install grunt-cli -g Gruntfile.js000066400000000000000000000004541516425035600133650ustar00rootroot00000000000000module.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); };LICENSE000066400000000000000000000021401516425035600120670ustar00rootroot00000000000000MIT License Copyright (c) 2017 Patrik Laszlo / patrikx3 / https://patrikx3.tk and contributors 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.md000066400000000000000000000056671516425035600123620ustar00rootroot00000000000000[//]: #@corifeus-header [![Build Status](https://travis-ci.org/patrikx3/tools.svg?branch=master)](https://travis-ci.org/patrikx3/tools) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/patrikx3/tools/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/tools/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/patrikx3/tools/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/patrikx3/tools/?branch=master) [![NPM](https://nodei.co/npm/p3x-tools.png?downloads=true&downloadRank=true&stars=true)](https://www.npmjs.com/package/p3x-tools/) --- # Tools ## Issues / Support This is an open source project. Time is a precious thing, so I have rarely time to give support and fix issues for someone else. I fix a bug, when I have an error that I need. If you got an issue, error or bug, I hope someone will have time to do it for you, otherwise, you are on your own. Though, if I know the solution, I will tell you. Besides, core errors will be fixed by me. ***If you want to extend, fix bugs or add in new features, I promptly merge pull requests or you can become a ```patrikx3``` member.*** ### Node Version Requirement ``` >=7.8.0 ``` ### Built on Node ``` v7.10.0 ``` The ```async``` and ```await``` keywords are required. Install NodeJs: https://nodejs.org/en/download/package-manager/ # Description [//]: #@corifeus-header:end ## Install ```javascript npm install -g p3x p3x -h p3x for -h p3x git -h p3x github -h p3x ncu -h p3x npm -h p3x rm -h ``` ## Examples ```javascript p3x for node_modules 'echo $FOUND; ls -all' p3x git each 'ls -all' p3x npm unpublish --dry --username patrixk3 --search corifeus,p3x p3x rm --dry node_modules ``` **It is used for primarily Unix/BSD/Linux/OSX, using Bash.** * Functions * NPM find (recursive) * NPM remove resursive delete directories * NPM unpublish packages (able to keep only the latest version by minor version) * Major.Minor.Commit-Build * So instead * 4.1.55-44 * 4.1.54-33 * 4.0.53-32 * 4.0.52-30 * 1.3.44-23 * 1.3.40-20 * 1.3.28-10 * 1.3.22-9 * 1.3.21-8 * 1.2.20-7 * 1.1.10-5 * 1.0.9-5 * Becomes * 4.1.55-44 * 4.0.53-32 * 1.3.44-23 * 1.2.20-7 * 1.1.10-5 * 1.0.9-5 # Docs ## Unpublish Version: ```Major.Minor.Commit-Build``` 1. unpublish all, keep all last minor versions 1. corifeus - ```publish all``` 1. p3x-systemd-manager - ```ncu -a, publish``` 1. p3x-angular-compile - ```ncu -a, publish``` 1. p3x-aes-folder - ```ncu -a, publish``` 1. server-scripts - ```ncu -a``` 1. linux-defaults - ```ncu -a``` 1. corifeus - ```ncu -a``` [//]: #@corifeus-footer --- [**P3X-TOOLS**](https://patrikx3.github.com/tools) Build v1.1.54-84 [Corifeus](http://www.corifeus.tk) by [Patrik Laszlo](http://patrikx3.tk) [//]: #@corifeus-footer:end bin/000077500000000000000000000000001516425035600116355ustar00rootroot00000000000000bin/p3x.js000077500000000000000000000015331516425035600127120ustar00rootroot00000000000000#!/usr/bin/env node 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') /* 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();package.json000066400000000000000000000021621516425035600133540ustar00rootroot00000000000000{ "name": "p3x-tools", "version": "1.1.54-84", "corifeus": { "prefix": "p3x-", "publish": true, "type": "p3x", "code": "Screw" }, "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.tk/tools", "devDependencies": { "corifeus-builder": "^1.7.606-50" }, "dependencies": { "commander": "^2.9.0", "corifeus-utils": "^1.1.270-55", "fs-extra": "^3.0.1", "github-api": "^3.0.0", "globby": "^6.1.0", "ini": "^1.3.4", "tmp-promise": "^1.0.3" }, "engines": { "node": ">=7.8.0" } }src/000077500000000000000000000000001516425035600116545ustar00rootroot00000000000000src/command/000077500000000000000000000000001516425035600132725ustar00rootroot00000000000000src/command/each.js000066400000000000000000000100561516425035600145320ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const find = require('../find'); const path = require('path'); const git = require('../git'); const mz = require('mz'); const npmLib = require('../npm'); const lib = require('../lib'); const loadCommander = (command) => { commander .command(`${command} [plusCommands...]`) .option('-d, --dry', 'Do not actually remove packages, just show what it does') .option('-a, --all', 'All') .option('-s, --serial', 'Serial ') .action(async function (plusCommands, options) { await executeCommand(command, plusCommands, options); }) ; } loadCommander('pkg'); loadCommander('build'); loadCommander('publish'); const getPkgAndDeps = async(file) => { const pkg = JSON.parse((await mz.fs.readFile(file)).toString()); let deps = Object.keys(Object.assign(pkg.dependencies || {}, pkg.devDependencies || {})); return [pkg, deps]; } const executeCommand = async (command, plusCommands, options) => { let errors = []; plusCommands = plusCommands.join(' ').trim(); 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); 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' ] }); if (command === 'publish') { list = list.filter(item => { return item.pkg.hasOwnProperty('corifeus') && item.pkg.corifeus.publish === true; }) options.serial = true; } if (plusCommands === '') { plusCommands = 'list'; } if (plusCommands === 'start') { plusCommands = `ncu -a --loglevel verbose --packageFile package.json yarn install ${npmLib.command.publish({ all: options.all } )}`; } 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 (plusCommands === 'ncu') { plusCommands = `ncu ${options.all ? '-a' : ''} --loglevel verbose --packageFile package.json`; } if (hasBuilder !== undefined ) { count++ switch (plusCommands) { case 'count': break; case 'deps': break; case 'list': console.info(pkg.name) break; default: if (options.dry) { console.info('------------------------------------'); console.info(findData.path); console.info(pkg.name); console.info(plusCommands) } else { await lib.executeCommandByPath({ findData: findData, command: plusCommands, errors: errors, }) } } } }, options.serial) console.info(`Count: ${count}`) if (errors.length > 0) { console.error(`Errors: ${errors.length}`); console.error(errors) } }src/command/for.js000066400000000000000000000040501516425035600144150ustar00rootroot00000000000000// 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 = require('../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.js000066400000000000000000000045751516425035600144260ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const find = require('../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', ] 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') .action(async function (command, plusCommands, options) { let paths; if (command === undefined) { command = 'list'; } plusCommands = plusCommands.join(' ').trim(); switch(command) { case 'truncate': case 'renew': const truncate = require('../git').truncate; await truncate(options); break; case 'each': case 'count': case 'list': case 'push': paths = await find('.git'); paths = paths.map(pathActual => { if (pathActual.dir === pathActual.path) { pathActual.dir = path.dirname(pathActual.dir); } return pathActual; }) if (command === 'count') { console.info(paths.length); return } await paths.forEachAsync(async (findData) => { if (command === 'list') { console.log(path.basename(findData.dir)); } else { await utils.repeat(2, async() => { await lib.executeCommandByPath({ findData: findData, command: `git add . git commit -am 'p3x-robot-push' || true git push || true ${plusCommands === '' ? 'true' : plusCommands}`, }) }, true) } }, true) break; default: console.error(`Unknown command: ${command}`) } }) ; src/command/github.js000066400000000000000000000046021516425035600151140ustar00rootroot00000000000000const commander = require('commander'); const utils = require('corifeus-utils'); const find = require('../find'); const path = require('path'); const github = require('../github'); const defaultGithubExcludes = [ 'cookie', 'jGrowl', 'stackicons', 'grunt-angular-templates', ] //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 p3x-robot sunday release') .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.tk/') .option('-x, --exclude ', `Exclude paths, default is ${defaultGithubExcludes.join(',')}`, (val) => { return val.split(','); }) .action(async function (command, options) { const user = options.user || 'patrikx3'; const gitUrl = options.git || 'https://git.patrikx3.tk' ; const note = options.note || 'p3x-robot sunday release' 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 '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, }) break; default: console.error(`Unknown command: ${command}`) } }) ; src/command/npm.js000066400000000000000000000052221516425035600144230ustar00rootroot00000000000000const 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.js000066400000000000000000000005261516425035600144040ustar00rootroot00000000000000/* 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/rm.js000066400000000000000000000015271516425035600142530ustar00rootroot00000000000000const commander = require('commander'); const fsExtra = require('fs-extra'); 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') .action(async function (dirs, options) { const find = require('../find'); const files = await find({ find: dirs, type: 'd' }); 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)); } console.info(`Delete ${file}`) }) Promise.all(promises); }) ;src/find.js000066400000000000000000000046541516425035600131430ustar00rootroot00000000000000const utils = require('corifeus-utils'); const path = require('path'); const mz = require('mz'); const multi = async (options) => { await options.find.forEachAsync(async (findable) => { const resolved = path.resolve(options.root, findable); const finds = await mz.fs.exists(resolved); if (finds) { const stat = await mz.fs.stat(resolved); if ( (options.type.hasOwnProperty('d') && stat.isDirectory()) || (options.type.hasOwnProperty('f') && stat.isFile()) ) { options.results.push({ path: resolved, dir: stat.isFile() ? path.dirname(resolved) : resolved, // stat: stat }); } } const foundHit= await mz.fs.readdir(options.root) const foundHitPromises = []; await foundHit.forEachAsync(async (foundDir) => { const resolvedFoundDir = path.resolve(options.root, foundDir); const stat = await mz.fs.stat(resolvedFoundDir); if (!stat.isDirectory()) { return; } if (options.find.includes(foundDir) || options.exclude.includes(foundDir)) { return; } const newOptions = Object.assign({}, options) newOptions.root = resolvedFoundDir; foundHitPromises.push(multi(newOptions)) }) await Promise.all(foundHitPromises); }) return options.results; } module.exports = async (options) => { if (typeof options === 'string') { options = { find: options } } options.root = options.root || process.cwd(); options.results = options.results || []; options.type = options.type || { d: true, f: true, }; console.log(`Options: ${JSON.stringify(options, null, 2)}`) if (!Array.isArray(options.find)) { options.find = [options.find]; } options.find = options.find.map(findable => { findable= findable.trim(); if (findable.startsWith('./')) { findable = findable.substr(2); } if (findable.endsWith('/')) { findable = findable.substr(0, findable.length - 1); } return findable; }) options.exclude = options.exclude || [ 'node_modules', 'bower_components', ]; return await multi(options); }; src/git.js000066400000000000000000000014131516425035600127740ustar00rootroot00000000000000const 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 "p3x-robot" 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, true) } } 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/github.js000066400000000000000000000115721516425035600135020ustar00rootroot00000000000000const 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 {user , exclude } = options; const gh = new GitHub(); const response = await gh.getUser(user).listRepos(); const repos = response.data return repos.filter(repo => { return repo.full_name === `${user}/${repo.name}` && !exclude.includes(repo.name) }); } const mirror = async(options) => { let { 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, }); await repos.forEachAsync(async(repo) => { await utils.childProcess.exec(` git clone 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 ${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) => { await utils.childProcess.exec(` rm -rf ${tmpDir.path}/git/${repo.name}/.git 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 repos.forEachAsync(async(repo) => { await utils.childProcess.exec(` cd ${tmpDir.path}/github/${repo.name} pwd 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 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.js000066400000000000000000000010551516425035600127610ustar00rootroot00000000000000const utils = require('corifeus-utils'); const executeCommandByPath = async (options) => { const { findData, command, errors } = options; try { await utils.childProcess.exec(` bash -c ' pushd ${findData.dir} set -e export FOUND_DIR=${findData.dir} export FOUND=${findData.path} ${command} popd ' `, true) } catch (e) { if (errors !== undefined) { errors.push(e); } throw e; } } module.exports.executeCommandByPath = executeCommandByPath;src/npm-unpublish.js000066400000000000000000000112031516425035600150100ustar00rootroot00000000000000const 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(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, 2)} ` }) 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.js000066400000000000000000000003271516425035600130060ustar00rootroot00000000000000module.exports.command = { publish: (options = {all: true}) => `grunt cory-npm cory-replace grunt publish || true sleep 3 npm publish ${options.all ? 'npm publish --registry https://registry.npmjs.org' : ''}` }src/pdf.js000066400000000000000000000026451516425035600127720ustar00rootroot00000000000000//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, 2)); 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/000077500000000000000000000000001516425035600120445ustar00rootroot00000000000000test/scripts/000077500000000000000000000000001516425035600135335ustar00rootroot00000000000000test/scripts/find-modules.js000077500000000000000000000002771516425035600164700ustar00rootroot00000000000000#!/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.js000077500000000000000000000002741516425035600201670ustar00rootroot00000000000000#!/usr/bin/env node const path = '/tmp/tmp-22337ZMnl1XYmwIs4/github'; const github = require('../../src/github'); github.replaceInitSh(path, 'https://123:121@git.patrikx3.tk', 'patrikx3');test/scripts/transform-git-modules.js000066400000000000000000000003561516425035600203370ustar00rootroot00000000000000#!/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');tools.iml000066400000000000000000000005171516425035600127330ustar00rootroot00000000000000