feat: add configuration for configuration checks

Fixes #13
This commit is contained in:
Karl-Philipp Wulfert
2019-04-18 13:05:46 +02:00
parent 748cea493c
commit da2d7f6f91
6 changed files with 447 additions and 288 deletions

View File

@@ -20,12 +20,15 @@ import {
checkCIConfig,
checkConfigurationFilesAreExtended,
checkContributors,
checkDependencies,
checkLicenses,
checkNeededFiles,
checkNYCConfiguration,
checkScripts,
consoleInfo,
consoleLog,
getConfiguration,
getRules,
} from './common';
// current working directory
@@ -43,18 +46,12 @@ const path = resolve(commander.path);
// check for existing package.json in provided path
if (!existsSync(resolve(path, 'package.json'))) {
throw new Error(`No package.json in "${path}".`);
throw new Error(`No 'package.json' in '${path}'.`);
}
// path to examined package.json
const packageJsonPath = resolve(path, 'package.json');
// whether or not the contents of the package.json were changed
let packageJsonChanged = false;
// whether or not to suggest an overwrite
let suggestOverwrite = false;
// read package.json in provided path
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
@@ -64,26 +61,38 @@ if (packageJson.name === '@openstapps/configuration') {
process.exit(0);
}
checkLicenses(packageJson);
// whether or not the contents of the package.json were changed
let packageJsonChanged = false;
// whether or not to suggest an overwrite
let suggestOverwrite = false;
const configuration = getConfiguration(packageJson);
const rules = getRules(configuration);
checkDependencies(rules, packageJson);
checkLicenses(rules, packageJson);
checkConfigurationFilesAreExtended(path);
suggestOverwrite = suggestOverwrite || checkNeededFiles(path, commander.replace);
suggestOverwrite = suggestOverwrite || checkNeededFiles(rules, path, commander.replace);
const checkedNYCConfiguration = checkNYCConfiguration(packageJson, commander.replace);
const checkedNYCConfiguration = checkNYCConfiguration(rules, packageJson, commander.replace);
packageJsonChanged = packageJsonChanged || checkedNYCConfiguration[0];
suggestOverwrite = suggestOverwrite || checkedNYCConfiguration[1];
packageJsonChanged = packageJsonChanged || checkScripts(packageJson, commander.replace);
packageJsonChanged = packageJsonChanged || checkScripts(rules, packageJson, commander.replace);
checkContributors(packageJson);
checkCIConfig(path);
checkCIConfig(rules, path);
if (packageJsonChanged) {
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, 2));
consoleLog(`Changes were written to "${packageJsonPath}".`);
consoleLog(`Changes were written to '${packageJsonPath}'.`);
}
if (suggestOverwrite) {