refactor: adjust code to stricter rules

This commit is contained in:
Karl-Philipp Wulfert
2019-05-24 17:53:55 +02:00
parent 14b6420c33
commit ac0166020e
2 changed files with 188 additions and 69 deletions

View File

@@ -37,7 +37,10 @@ const currentWorkingDirectory = cwd();
// configure commander
commander
.version(JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json')).toString()).version)
.version(JSON.parse(
readFileSync(resolve(__dirname, '..', 'package.json'))
.toString(),
).version)
.option('-p, --path <path>', `Path of project to add files to (${currentWorkingDirectory})`, currentWorkingDirectory)
.option('-r, --replace', 'Whether to replace existing files or not', false)
.parse(process.argv);
@@ -54,7 +57,8 @@ if (!existsSync(resolve(path, 'package.json'))) {
const packageJsonPath = resolve(path, 'package.json');
// read package.json in provided path
const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
const packageJson = JSON.parse(readFileSync(packageJsonPath)
.toString());
// check if provided path is this package
if (packageJson.name === '@openstapps/configuration') {
@@ -93,8 +97,10 @@ checkCIConfig(rules, path);
checkCopyrightYears(path, 'src');
const indentation = 2;
if (packageJsonChanged) {
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, 2));
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, indentation));
consoleLog(`Changes were written to '${packageJsonPath}'.`);
}