Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
usage: `node auto-remove-gtk.js pm2-notrack`
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
You can’t perform that action at this time.