-
-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add script to prune
package.json
for release
- Loading branch information
Showing
2 changed files
with
38 additions
and
8 deletions.
There are no files selected for viewing
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
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,26 @@ | ||
const fs = require("node:fs"); | ||
const path = require("node:path"); | ||
|
||
const packagePath = path.join(process.cwd(), "package.json"); | ||
const package = JSON.parse(fs.readFileSync(packagePath, "utf8")); | ||
|
||
const keys_to_remove = ["prettier", "standard-version", "devDependencies"]; | ||
const scripts_to_keep = ["postinstall"]; | ||
|
||
for (const key of keys_to_remove) { | ||
delete package[key]; | ||
} | ||
|
||
if (package.scripts) { | ||
const preserved_scripts = {}; | ||
|
||
for (const script of scripts_to_keep) { | ||
if (package.scripts[script]) { | ||
preserved_scripts[script] = package.scripts[script]; | ||
} | ||
} | ||
|
||
package.scripts = preserved_scripts; | ||
} | ||
|
||
fs.writeFileSync(packagePath, JSON.stringify(package, null, 2) + "\n"); |