mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 16:13:06 +00:00
43
src/cli.ts
43
src/cli.ts
@@ -18,7 +18,8 @@ import {copyFileSync, existsSync, readFileSync, writeFileSync} from 'fs';
|
||||
import {resolve, sep} from 'path';
|
||||
import {cwd} from 'process';
|
||||
import {isDeepStrictEqual} from 'util';
|
||||
import {EXPECTED_LICENSES, NEEDED_FILES, NYC_CONFIGURATION, SCRIPTS} from './configuration';
|
||||
import {parse, stringify} from 'yaml';
|
||||
import {EXPECTED_CI_CONFIG, EXPECTED_LICENSES, NEEDED_FILES, NYC_CONFIGURATION, SCRIPTS} from './configuration';
|
||||
|
||||
/* tslint:disable:no-console */
|
||||
|
||||
@@ -28,7 +29,7 @@ import {EXPECTED_LICENSES, NEEDED_FILES, NYC_CONFIGURATION, SCRIPTS} from './con
|
||||
*/
|
||||
function consoleInfo(...args: string[]): void {
|
||||
args.forEach((arg) => {
|
||||
console.info(chalk.cyan(arg));
|
||||
console.info('\n' + chalk.cyan(arg));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -38,7 +39,7 @@ function consoleInfo(...args: string[]): void {
|
||||
*/
|
||||
function consoleWarn(...args: string[]): void {
|
||||
args.forEach((arg) => {
|
||||
console.warn(chalk.red.bold(arg));
|
||||
console.warn('\n' + chalk.red.bold(arg));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ function consoleWarn(...args: string[]): void {
|
||||
*/
|
||||
function consoleLog(...args: string[]): void {
|
||||
args.forEach((arg) => {
|
||||
console.log(chalk.green.bold(arg));
|
||||
console.log('\n' + chalk.green.bold(arg));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -157,16 +158,46 @@ Object.keys(SCRIPTS).forEach((scriptName) => {
|
||||
|
||||
// check if script exists
|
||||
if (typeof scriptToCheck === 'undefined' || commander.replace) {
|
||||
packageJson.scripts[scriptName] = SCRIPTS[scriptName];
|
||||
packageJson.scripts[scriptName] = SCRIPTS[scriptName].replace('\n', '\\n');
|
||||
|
||||
packageJsonChanged = true;
|
||||
|
||||
consoleInfo(`Added "${scriptName}" script to "${packageJsonPath}".`);
|
||||
} else if (typeof scriptToCheck === 'string' && scriptToCheck !== SCRIPTS[scriptName]) {
|
||||
consoleWarn(`NPM script "${scriptName}" should be "${SCRIPTS[scriptName]}".`);
|
||||
consoleWarn(`NPM script "${scriptName}" should be "${SCRIPTS[scriptName].replace('\n', '\\n')}".`);
|
||||
}
|
||||
});
|
||||
|
||||
// check CI config if it exists
|
||||
const pathToCiConfig = resolve(path, '.gitlab-ci.yml');
|
||||
if (existsSync(pathToCiConfig)) {
|
||||
// read CI config
|
||||
const buffer = readFileSync(pathToCiConfig);
|
||||
try {
|
||||
const ciConfig = parse(buffer.toString());
|
||||
|
||||
// check entries
|
||||
for (const entry in EXPECTED_CI_CONFIG) {
|
||||
if (!EXPECTED_CI_CONFIG.hasOwnProperty(entry)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isDeepStrictEqual(EXPECTED_CI_CONFIG[entry], ciConfig[entry])) {
|
||||
consoleWarn(`Entry '${entry}' in ${pathToCiConfig} is incorrect. Expected value is:`);
|
||||
consoleInfo(stringify((() => {
|
||||
const completeEntry: any = {};
|
||||
completeEntry[entry] = EXPECTED_CI_CONFIG[entry];
|
||||
return completeEntry;
|
||||
})()));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
consoleWarn(`Could not parse ${pathToCiConfig} because of '${error.message}'.
|
||||
Please ensure consistency of CI config manually.`);
|
||||
consoleInfo(stringify(EXPECTED_CI_CONFIG));
|
||||
}
|
||||
}
|
||||
|
||||
if (packageJsonChanged) {
|
||||
writeFileSync(resolve(path, 'package.json'), JSON.stringify(packageJson, null, 2));
|
||||
consoleLog(`Changes were written to "${packageJsonPath}".`);
|
||||
|
||||
@@ -72,3 +72,52 @@ export const EXPECTED_LICENSES = [
|
||||
'AGPL-3.0-only',
|
||||
'GPL-3.0-only',
|
||||
];
|
||||
|
||||
/* tslint:disable:object-literal-sort-keys */
|
||||
/**
|
||||
* Expected values in CI config
|
||||
*/
|
||||
export const EXPECTED_CI_CONFIG: any = {
|
||||
image: 'registry.gitlab.com/openstapps/projectmanagement/node',
|
||||
cache: {
|
||||
key: '${CI_COMMIT_REF_SLUG}',
|
||||
paths: [
|
||||
'node_modules',
|
||||
],
|
||||
},
|
||||
audit: {
|
||||
allow_failure: true,
|
||||
except: [
|
||||
'schedules',
|
||||
],
|
||||
script: [
|
||||
'npm audit',
|
||||
],
|
||||
stage: 'test',
|
||||
},
|
||||
'scheduled-audit': {
|
||||
only: [
|
||||
'schedules',
|
||||
],
|
||||
script: [
|
||||
'npm audit',
|
||||
],
|
||||
stage: 'test',
|
||||
},
|
||||
pages: {
|
||||
artifacts: {
|
||||
'paths': [
|
||||
'public',
|
||||
],
|
||||
},
|
||||
only: [
|
||||
'/^v[0-9]+\\.[0-9]+\\.[0-9]+$/',
|
||||
],
|
||||
script: [
|
||||
'npm run documentation',
|
||||
'mv docs public',
|
||||
],
|
||||
stage: 'deploy',
|
||||
},
|
||||
};
|
||||
/* tslint:enable */
|
||||
|
||||
Reference in New Issue
Block a user