Skip to content

Commit

Permalink
Refactor script
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonRolev committed Oct 7, 2024
1 parent 731e51c commit 2eabff8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
24 changes: 0 additions & 24 deletions change-package-name.js

This file was deleted.

31 changes: 31 additions & 0 deletions scripts/json-updater.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* Modify keys in the package.json file
Usage: `libMVRgdtf$ >node scripts/json-updater.js --key value --key2 value2 ...`
Example: `libMVRgdtf$ >node scripts/json-updater.js --name @mvr/lib-windows`
*/

const fs = require('fs');
const path = require('path');

class PackageJSONManager {
constructor() {
this.filePath = path.join('package.json')
this.packageJson = JSON.parse(fs.readFileSync(this.filePath, 'utf8'));
}

updateKey(key, value) {
if (!key || !value) return;
this.packageJson[key] = value;
}

save() {
fs.writeFileSync(this.filePath, JSON.stringify(this.packageJson, null, 4) + '\n');
}
}

const manager = new PackageJSONManager();
process.argv.forEach((key, index) => {
if (key.startsWith('--')) {
manager.updateKey(key.substring(2), process.argv[index + 1]);
}
})
manager.save()

0 comments on commit 2eabff8

Please sign in to comment.