mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 00:23:03 +00:00
35
src/cli.ts
35
src/cli.ts
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user