-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
731e51c
commit 2eabff8
Showing
2 changed files
with
31 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
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() |