mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-21 17:12:43 +00:00
14
package-lock.json
generated
14
package-lock.json
generated
@@ -4,6 +4,14 @@
|
|||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/chalk": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/chalk/-/chalk-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-1zzPV9FDe1I/WHhRkf9SNgqtRJWZqrBWgu7JGveuHmmyR9CnAPCie2N/x+iHrgnpYBIcCJWHBoMRv2TRWktsvw==",
|
||||||
|
"requires": {
|
||||||
|
"chalk": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/events": {
|
"@types/events": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "http://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
"resolved": "http://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
|
||||||
@@ -203,9 +211,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"chalk": {
|
"chalk": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.2",
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
|
||||||
"integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==",
|
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ansi-styles": "^3.2.1",
|
"ansi-styles": "^3.2.1",
|
||||||
"escape-string-regexp": "^1.0.5",
|
"escape-string-regexp": "^1.0.5",
|
||||||
|
|||||||
@@ -23,7 +23,9 @@
|
|||||||
],
|
],
|
||||||
"license": "GPL-3.0-only",
|
"license": "GPL-3.0-only",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/chalk": "2.2.0",
|
||||||
"@types/node": "10.12.15",
|
"@types/node": "10.12.15",
|
||||||
|
"chalk": "2.4.2",
|
||||||
"commander": "2.19.0",
|
"commander": "2.19.0",
|
||||||
"tslint": "5.12.0",
|
"tslint": "5.12.0",
|
||||||
"tslint-eslint-rules": "5.4.0"
|
"tslint-eslint-rules": "5.4.0"
|
||||||
|
|||||||
66
src/cli.ts
66
src/cli.ts
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2018 StApps
|
* Copyright (C) 2018, 2019 StApps
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* This program is free software: you can redistribute it and/or modify it
|
||||||
* under the terms of the GNU General Public License as published by the Free
|
* under the terms of the GNU General Public License as published by the Free
|
||||||
* Software Foundation, version 3.
|
* Software Foundation, version 3.
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License along with
|
* You should have received a copy of the GNU General Public License along with
|
||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
import chalk from 'chalk';
|
||||||
import * as commander from 'commander';
|
import * as commander from 'commander';
|
||||||
import {copyFileSync, existsSync, readFileSync, writeFileSync} from 'fs';
|
import {copyFileSync, existsSync, readFileSync, writeFileSync} from 'fs';
|
||||||
import {resolve, sep} from 'path';
|
import {resolve, sep} from 'path';
|
||||||
@@ -20,6 +21,36 @@ import {EXPECTED_LICENSES, NEEDED_FILES, NYC_CONFIGURATION} from './configuratio
|
|||||||
|
|
||||||
/* tslint:disable:no-console */
|
/* tslint:disable:no-console */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for console.info that outputs every argument in cyan
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
function consoleInfo(...args: string[]): void {
|
||||||
|
args.forEach((arg) => {
|
||||||
|
console.info(chalk.cyan(arg));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for console.warn that outputs every argument in red
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
function consoleWarn(...args: string[]): void {
|
||||||
|
args.forEach((arg) => {
|
||||||
|
console.warn(chalk.red.bold(arg));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for console.log that outputs every argument in green
|
||||||
|
* @param args
|
||||||
|
*/
|
||||||
|
function consoleLog(...args: string[]): void {
|
||||||
|
args.forEach((arg) => {
|
||||||
|
console.log(chalk.green.bold(arg));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const currentWorkingDirectory = cwd();
|
const currentWorkingDirectory = cwd();
|
||||||
|
|
||||||
// configure commander
|
// configure commander
|
||||||
@@ -48,13 +79,13 @@ const packageJson = JSON.parse(readFileSync(packageJsonPath).toString());
|
|||||||
|
|
||||||
// check if provided path is this package
|
// check if provided path is this package
|
||||||
if (packageJson.name === '@openstapps/configuration') {
|
if (packageJson.name === '@openstapps/configuration') {
|
||||||
console.info('Not doing anything, because installing dependencies in myself.');
|
consoleInfo('I\'m not going to check myself!');
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if license is one of the expected ones
|
// check if license is one of the expected ones
|
||||||
if (EXPECTED_LICENSES.indexOf(packageJson.license) === -1) {
|
if (EXPECTED_LICENSES.indexOf(packageJson.license) === -1) {
|
||||||
console.warn(`License should be one of "${EXPECTED_LICENSES.join(', ')}"!`);
|
consoleWarn(`License should be one of "${EXPECTED_LICENSES.join(', ')}"!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if configuration files are extended
|
// check if configuration files are extended
|
||||||
@@ -63,11 +94,18 @@ if (EXPECTED_LICENSES.indexOf(packageJson.license) === -1) {
|
|||||||
const expectedPath = `./node_modules/@openstapps/configuration/${file}`;
|
const expectedPath = `./node_modules/@openstapps/configuration/${file}`;
|
||||||
|
|
||||||
if (existsSync(fileToCheck)) {
|
if (existsSync(fileToCheck)) {
|
||||||
const tsconfigJson = JSON.parse(readFileSync(fileToCheck).toString());
|
const configFile = JSON.parse(readFileSync(fileToCheck).toString());
|
||||||
|
|
||||||
if (typeof tsconfigJson.extends !== 'string' || tsconfigJson.extends !== expectedPath) {
|
const configFileExtended =
|
||||||
console.warn(`File "${fileToCheck}" should extend "${expectedPath}"!`);
|
(typeof configFile.extends === 'string' && configFile.extends === expectedPath)
|
||||||
console.warn(readFileSync(resolve(__dirname, '..', 'templates', file)).toString());
|
|| (file === 'tslint.json' && Array.isArray(configFile.extends) && configFile.extends.indexOf(expectedPath) >= 0);
|
||||||
|
|
||||||
|
if (!configFileExtended) {
|
||||||
|
consoleWarn(`
|
||||||
|
File "${fileToCheck}" should extend "${expectedPath}"!
|
||||||
|
|
||||||
|
Example:
|
||||||
|
${readFileSync(resolve(__dirname, '..', 'templates', 'template-' + file))}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -88,9 +126,9 @@ NEEDED_FILES.forEach((file) => {
|
|||||||
// check if file exists or replace flag is set
|
// check if file exists or replace flag is set
|
||||||
if (!existsSync(destination) || commander.replace) {
|
if (!existsSync(destination) || commander.replace) {
|
||||||
copyFileSync(source, destination);
|
copyFileSync(source, destination);
|
||||||
console.info(`Copied file "${source}" to "${destination}".`);
|
consoleInfo(`Copied file "${source}" to "${destination}".`);
|
||||||
} else {
|
} else {
|
||||||
console.info(`Not replacing "${destination}". Use "-r" or "--replace" to do so.`);
|
consoleInfo(`Not replacing "${destination}". Use "-r" or "--replace" to do so.`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -101,7 +139,7 @@ if (typeof packageJson.devDependencies === 'object' && Object.keys(packageJson.d
|
|||||||
|
|
||||||
packageJsonChanged = true;
|
packageJsonChanged = true;
|
||||||
|
|
||||||
console.info(`Added/updated NYC configuration in "${packageJsonPath}".`);
|
consoleInfo(`Added/updated NYC configuration in "${packageJsonPath}".`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if scripts is a map
|
// check if scripts is a map
|
||||||
@@ -120,12 +158,14 @@ if (typeof scriptToCheck === 'undefined') {
|
|||||||
|
|
||||||
packageJsonChanged = true;
|
packageJsonChanged = true;
|
||||||
|
|
||||||
console.info(`Added "check-configuration" script to "${packageJsonPath}".`);
|
consoleInfo(`Added "check-configuration" script to "${packageJsonPath}".`);
|
||||||
} else if (typeof scriptToCheck === 'string' && scriptToCheck !== 'openstapps-configuration') {
|
} else if (typeof scriptToCheck === 'string' && scriptToCheck !== 'openstapps-configuration') {
|
||||||
console.warn('NPM script "check-configuration" should be "openstapps-configuration".');
|
consoleWarn('NPM script "check-configuration" should be "openstapps-configuration".');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageJsonChanged) {
|
if (packageJsonChanged) {
|
||||||
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, 2));
|
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, 2));
|
||||||
console.log(`Changes were written to "${packageJsonPath}".`);
|
consoleLog(`Changes were written to "${packageJsonPath}".`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
consoleLog('Done.');
|
||||||
|
|||||||
Reference in New Issue
Block a user