mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
feat: add script to check configuration
This commit is contained in:
34
src/cli.ts
34
src/cli.ts
@@ -23,8 +23,12 @@ if (!existsSync(resolve(path, 'package.json'))) {
|
||||
throw new Error(`No package.json in "${path}".`);
|
||||
}
|
||||
|
||||
// path to examined package.json
|
||||
const packageJsonPath = resolve(path, 'package.json');
|
||||
|
||||
// wheter or not the contents of the package.json were changed
|
||||
let packageJsonChanged = false;
|
||||
|
||||
// read package.json in provided path
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
|
||||
|
||||
@@ -78,6 +82,34 @@ NEEDED_FILES.forEach((file) => {
|
||||
if (typeof packageJson.devDependencies === 'object' && Object.keys(packageJson.devDependencies).indexOf('nyc') >= 0) {
|
||||
// add/update NYC configuration
|
||||
packageJson.nyc = NYC_CONFIGURATION;
|
||||
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson));
|
||||
|
||||
packageJsonChanged = true;
|
||||
|
||||
console.info(`Added/updated NYC configuration in "${packageJsonPath}".`);
|
||||
}
|
||||
|
||||
// check if scripts is a map
|
||||
if (typeof packageJson.scripts !== 'object') {
|
||||
packageJson.scripts = {};
|
||||
|
||||
packageJsonChanged = true;
|
||||
}
|
||||
|
||||
const scriptToCheck = packageJson.scripts['check-configuration'];
|
||||
|
||||
// check if "check-configuration" script exists
|
||||
if (typeof scriptToCheck === 'undefined') {
|
||||
// add/update NYC configuration
|
||||
packageJson.scripts['check-configuration'] = 'openstapps-configuration';
|
||||
|
||||
packageJsonChanged = true;
|
||||
|
||||
console.info(`Added "check-configuration" script to "${packageJsonPath}".`);
|
||||
} else if (typeof scriptToCheck === 'string' && scriptToCheck !== 'openstapps-configuration') {
|
||||
console.warn('NPM script "check-configuration" should be "openstapps-configuration".');
|
||||
}
|
||||
|
||||
if (packageJsonChanged) {
|
||||
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, 2));
|
||||
console.log(`Changes were written to "${packageJsonPath}".`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user