MCPcopy Create free account
hub / github.com/brody2consult/create-react-native-module / npmAddScriptSync

Function npmAddScriptSync

lib/lib.js:53–66  ·  view source on GitHub ↗
(packageJsonPath, script, fs)

Source from the content-addressed store, hash-verified

51
52// FUTURE TBD make this asynchronous and possibly more functional:
53const npmAddScriptSync = (packageJsonPath, script, fs) => {
54 try {
55 var packageJson = jsonfile.readFileSync(packageJsonPath, { fs });
56 if (!packageJson.scripts) packageJson.scripts = {};
57 packageJson.scripts[script.key] = script.value;
58 jsonfile.writeFileSync(packageJsonPath, packageJson, { fs, spaces: 2 });
59 } catch (e) {
60 if (/ENOENT.*package.json/.test(e.message)) {
61 throw new Error(`The package.json at path: ${packageJsonPath} does not exist.`);
62 } else {
63 throw e;
64 }
65 }
66};
67
68const generateWithNormalizedOptions = ({
69 name,

Callers 1

generateExampleAppFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected