(starterPackageJSON, starterKytConfig, paths, kytVersion)
| 133 | // the user's package.json configuration. |
| 134 | |
| 135 | export const updateUserPackageJSON = (starterPackageJSON, starterKytConfig, paths, kytVersion) => { |
| 136 | let newUserPackageJSON; |
| 137 | // Create a package.json definition if |
| 138 | // the user doesn't already have one. |
| 139 | if (shell.test('-f', paths.userPackageJSONPath)) { |
| 140 | const userJSON = fs.readFileSync(paths.userPackageJSONPath, 'utf8'); |
| 141 | newUserPackageJSON = JSON.parse(userJSON); |
| 142 | } else { |
| 143 | newUserPackageJSON = cloneDeep(fakePackageJson); |
| 144 | logger.task('Creating a new package.json. You should fill it in.'); |
| 145 | } |
| 146 | // Clone the package.json so that we have a backup. |
| 147 | const oldUserPackageJSON = cloneDeep(newUserPackageJSON); |
| 148 | |
| 149 | // Add dependencies from starter-kyts |
| 150 | const kytPrefVersion = |
| 151 | kytVersion || checkStarterKytVersion(newUserPackageJSON, starterPackageJSON); |
| 152 | newUserPackageJSON = updatePackageJSONDependencies(newUserPackageJSON, starterPackageJSON); |
| 153 | newUserPackageJSON = addKytDependency(newUserPackageJSON, kytPrefVersion); |
| 154 | newUserPackageJSON = addPackageJsonScripts( |
| 155 | newUserPackageJSON, |
| 156 | starterPackageJSON, |
| 157 | starterKytConfig |
| 158 | ); |
| 159 | fs.writeFileSync(paths.userPackageJSONPath, JSON.stringify(newUserPackageJSON, null, 2)); |
| 160 | |
| 161 | return { oldUserPackageJSON, newUserPackageJSON }; |
| 162 | }; |
no test coverage detected