Created
May 23, 2019 19:19
-
-
Save ericlewis/23b41a8ef955c7e323edcd1ccd04a879 to your computer and use it in GitHub Desktop.
usage: `node auto-remove-gtk.js pm2-notrack`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
assert(process.argv.length > 2, 'Must include a package name'); | |
const newName = process.argv[2]; | |
const util = require('util'); | |
const fs = require('fs'); | |
const exec = util.promisify(require('child_process').exec); | |
const readFile = util.promisify(fs.readFile); | |
const writeFile = util.promisify(fs.writeFile); | |
const path = './package/'; | |
const packagePath = `${path}package.json`; | |
async function downloadModule() { | |
return exec('curl `npm v pm2 dist.tarball` | tar xvz'); | |
} | |
async function publishPackage() { | |
return exec(`npm publish ${path}`); | |
} | |
async function cleanup() { | |
return exec(`rm -fr ${path}`); | |
} | |
async function readPackageJSON() { | |
const pack = await readFile(packagePath); | |
return JSON.parse(pack); | |
} | |
async function savePackageJSON(pack) { | |
return writeFile(packagePath, JSON.stringify(pack)); | |
} | |
function removeProbe(pack) { | |
if (pack.dependencies) { | |
delete pack.dependencies.gkt; | |
} | |
if (pack.devDependencies) { | |
delete pack.devDependencies.gkt; | |
} | |
if (pack.peerDependencies) { | |
delete pack.peerDependencies.gkt; | |
} | |
if (pack.optionalDependencies) { | |
delete pack.optionalDependencies.gkt; | |
} | |
return pack; | |
} | |
function changeName(pack, name) { | |
pack.name = name; | |
return pack; | |
} | |
async function makeFreedom() { | |
try { | |
await downloadModule(); | |
const pack = await readPackageJSON(); | |
const problessPack = removeProbe(pack); | |
const fixedPack = changeName(pack, newName); | |
await savePackageJSON(fixedPack); | |
await publishPackage(); | |
await cleanup(); | |
console.log('Success!'); | |
} catch (err) { | |
console.error(err); | |
} | |
} | |
makeFreedom(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment