Created
January 23, 2023 00:51
-
-
Save emkis/3d626b20e75727e2e0712a98736c874b to your computer and use it in GitHub Desktop.
Script to clean `package.json` properties before publishing a package
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
import packageJson from '../package.json' | |
import { writeFile } from 'fs/promises' | |
import { resolve } from 'node:path' | |
const unwantedProperties = ['keywords', 'files', 'scripts', 'devDependencies'] | |
unwantedProperties.forEach(deleteProperty) | |
rewritePackageJson() | |
function deleteProperty(key: string) { | |
delete packageJson[key] | |
} | |
async function rewritePackageJson() { | |
try { | |
const packagePath = resolve(__dirname, '..', 'package.json') | |
const content = JSON.stringify(packageJson) | |
await writeFile(packagePath, content) | |
} catch { | |
console.log(`Failed to rewrite the cleaned package.json file`) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment