mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 16:42:56 +00:00
feat: transition from TSLint to ESLint
This commit is contained in:
47
src/cli.ts
47
src/cli.ts
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import {Command} from 'commander';
|
||||
import {existsSync, readFileSync, writeFileSync} from 'fs';
|
||||
import {resolve} from 'path';
|
||||
import path from 'path';
|
||||
import {cwd} from 'process';
|
||||
import {
|
||||
checkCIConfig,
|
||||
@@ -39,42 +39,42 @@ const currentWorkingDirectory = cwd();
|
||||
const commander = new Command('openstapps-configuration');
|
||||
|
||||
// configure commander
|
||||
commander
|
||||
.version(JSON.parse(
|
||||
readFileSync(resolve(__dirname, '..', 'package.json'))
|
||||
.toString(),
|
||||
).version);
|
||||
// eslint-disable-next-line unicorn/prefer-module
|
||||
commander.version(JSON.parse(readFileSync(path.resolve(__dirname, '..', 'package.json')).toString()).version);
|
||||
|
||||
commander
|
||||
.option('-p, --path <path>', `Path of project to add files to (${currentWorkingDirectory})`, currentWorkingDirectory)
|
||||
.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);
|
||||
|
||||
// make path absolute
|
||||
const path = resolve(commander.opts().path);
|
||||
const projectPath = path.resolve(commander.opts().path);
|
||||
|
||||
// check for existing package.json in provided path
|
||||
if (!existsSync(resolve(path, 'package.json'))) {
|
||||
throw new Error(`No 'package.json' in '${path}'.`);
|
||||
if (!existsSync(path.resolve(projectPath, 'package.json'))) {
|
||||
throw new Error(`No 'package.json' in '${projectPath}'.`);
|
||||
}
|
||||
|
||||
// path to examined package.json
|
||||
const packageJsonPath = resolve(path, 'package.json');
|
||||
const packageJsonPath = path.resolve(projectPath, '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') {
|
||||
consoleInfo('I\'m not going to check myself!');
|
||||
consoleInfo("I'm not going to check myself!");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// whether or not the contents of the package.json were changed
|
||||
// whether the contents of the package.json were changed
|
||||
let packageJsonChanged = false;
|
||||
|
||||
// whether or not to suggest an overwrite
|
||||
// whether to suggest an overwrite
|
||||
let suggestOverwrite = false;
|
||||
|
||||
const configuration = getConfiguration(packageJson);
|
||||
@@ -85,9 +85,9 @@ checkDependencies(rules, packageJson);
|
||||
|
||||
checkLicenses(rules, packageJson);
|
||||
|
||||
checkConfigurationFilesAreExtended(path);
|
||||
checkConfigurationFilesAreExtended(projectPath);
|
||||
|
||||
suggestOverwrite = suggestOverwrite || checkNeededFiles(rules, path, commander.opts().replace);
|
||||
suggestOverwrite = suggestOverwrite || checkNeededFiles(rules, projectPath, commander.opts().replace);
|
||||
|
||||
const checkedNYCConfiguration = checkNYCConfiguration(rules, packageJson, commander.opts().replace);
|
||||
|
||||
@@ -96,16 +96,17 @@ suggestOverwrite = suggestOverwrite || checkedNYCConfiguration[1];
|
||||
|
||||
packageJsonChanged = packageJsonChanged || checkScripts(rules, packageJson, commander.opts().replace);
|
||||
|
||||
checkContributors(path, packageJson);
|
||||
checkContributors(projectPath, packageJson);
|
||||
|
||||
checkCIConfig(rules, path);
|
||||
checkCIConfig(rules, projectPath);
|
||||
|
||||
checkCopyrightYears(path, 'src');
|
||||
checkCopyrightYears(projectPath, 'src');
|
||||
|
||||
const indentation = 2;
|
||||
|
||||
if (packageJsonChanged) {
|
||||
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, indentation));
|
||||
// eslint-disable-next-line unicorn/no-null
|
||||
writeFileSync(path.resolve(projectPath, 'package.json'), JSON.stringify(packageJson, null, indentation));
|
||||
consoleLog(`Changes were written to '${packageJsonPath}'.`);
|
||||
}
|
||||
|
||||
@@ -114,4 +115,4 @@ if (suggestOverwrite) {
|
||||
npm run check-configuration -- -r`);
|
||||
}
|
||||
|
||||
consoleLog(`Done checking the configuration in '${path}'.`);
|
||||
consoleLog(`Done checking the configuration in '${projectPath}'.`);
|
||||
|
||||
Reference in New Issue
Block a user