(packageJsonPath, script, fs)
| 51 | |
| 52 | // FUTURE TBD make this asynchronous and possibly more functional: |
| 53 | const 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 | |
| 68 | const generateWithNormalizedOptions = ({ |
| 69 | name, |
no outgoing calls
no test coverage detected