@oblique/cli
Version:
Command Line Interface to manage Oblique projects
199 lines (197 loc) • 9.42 kB
JavaScript
/**
* @file Oblique, The front-end framework for your Swiss branded UI.
* @copyright 2020 - 2026 Federal Office of Information Technology, Systems and Telecommunication FOITT {@link https://www.bit.admin.ch}
* @version 15.4.1 (released on 2026-07-09, supported at least until 2027-02-28)
* @author Oblique team, FOITT, BS-BSC-EN4 <oblique@bit.admin.ch>
* @license MIT {@link https://github.com/oblique-bit/oblique/blob/master/LICENSE}
* @see https://oblique.bit.admin.ch
*/
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.startObCommand = exports.minimumSupportedVersion = exports.recommendedVersion = exports.obTitle = exports.runObCommand = exports.projectNamePlaceholder = exports.obExamples = exports.ngAddOblique = exports.optionDescriptions = exports.nonUpdatableDependencies = exports.currentVersions = exports.version = void 0;
exports.getHelpText = getHelpText;
exports.checkNodeVersion = checkNodeVersion;
exports.commandUsageText = commandUsageText;
exports.exampleUsageText = exampleUsageText;
exports.createAdditionalHelpText = createAdditionalHelpText;
exports.titleText = titleText;
exports.getVersionedDependency = getVersionedDependency;
exports.buildOption = buildOption;
exports.execute = execute;
exports.parseCommandArguments = parseCommandArguments;
const child_process_1 = require("child_process");
const semver_1 = require("semver");
/* Generated content, do not edit */
exports.version = '15.4.1';
/* End of generated content */
exports.currentVersions = {
'@oblique/oblique': exports.version,
'@angular/cli': '^21',
'@angular/material': '21',
'@oblique/toolchain': exports.version,
'@angular/core': '21',
'@angular/cdk': '21',
'@angular-devkit/build-angular': '21',
'@angular-eslint/schematics': '21',
'angular-eslint': '21',
'@types/jest': '30',
'@angular-builders/jest': '21',
'@schematics/angular': '21',
'angular-oauth2-oidc': '20',
jest: '30',
};
exports.nonUpdatableDependencies = ['@angular/flex-layout'];
exports.optionDescriptions = {
ob: {
version: { flags: '-v, --version', description: 'Shows the current version of @oblique/cli', command: 'ob -v' },
help: { flags: '-h, --help', description: getHelpText('ob'), command: 'ob -h' },
},
new: {
obNewCommand: { command: 'ob new <project-name> [...options]', description: 'Create a new Oblique project' },
help: { flags: '-h, --help', description: getHelpText('ob new'), command: 'ob new -h' },
},
update: { obUpdateCommand: { command: 'ob update', description: 'Update an Oblique project' } },
};
exports.ngAddOblique = { command: 'ng add @oblique/oblique', description: 'add Oblique to the project' };
exports.obExamples = [
{ command: exports.optionDescriptions.ob.version.command, description: exports.optionDescriptions.ob.version.description },
{ command: exports.optionDescriptions.ob.help.command, description: exports.optionDescriptions.ob.help.description },
{ command: exports.optionDescriptions.new.obNewCommand.command, description: exports.optionDescriptions.new.obNewCommand.description },
{ command: exports.optionDescriptions.new.help.command, description: exports.optionDescriptions.new.help.description },
{
command: exports.optionDescriptions.update.obUpdateCommand.command,
description: exports.optionDescriptions.update.obUpdateCommand.description,
},
];
const spaceUnit = `\t`;
exports.projectNamePlaceholder = `<project-name>`;
const runObCommand = () => {
console.info(`\n${spaceUnit}Use \`ob new ${exports.projectNamePlaceholder}\` to create a new project\n` +
`${spaceUnit}Use \`ob --help\` to explore the available commands\n` +
`${spaceUnit}Or use \`ob new --help\` to explore the available options for the ob new command\n`);
};
exports.runObCommand = runObCommand;
exports.obTitle = `Oblique Cli`;
exports.recommendedVersion = 22;
exports.minimumSupportedVersion = '22.12.0';
function getHelpText(command) {
return `Shows a help message for the "${command}" command in the console`;
}
function checkNodeVersion() {
console.info('Checks your node version');
if (!isNodeVersionSupported(exports.minimumSupportedVersion)) {
console.error(`Error: Oblique CLI requires Node.js v${exports.minimumSupportedVersion} or higher. You are using v${process.versions.node}. Please upgrade.`);
process.exit(1);
}
else if (!isNodeVersionRecommended(exports.recommendedVersion)) {
console.warn(`Warning: Oblique CLI was tested with Node.js v${exports.recommendedVersion}, but you are using v${process.versions.node}. Compatibility issues may occur.`);
}
}
const startObCommand = (callback, label, options) => {
console.info(`${exports.obTitle.toUpperCase()} ${printCliVersion()}`);
checkNodeVersion();
console.time(label);
callback(options);
console.timeEnd(label);
};
exports.startObCommand = startObCommand;
function commandUsageText(subCommand = '<command>', option = '[...options]') {
if (subCommand === 'new') {
return `${exports.projectNamePlaceholder} ${option}`;
}
return subCommand === 'update' ? option : `${subCommand} ${option}`;
}
function exampleUsageText(examples) {
const title = '\nExamples of use:\n';
return [title, examples.map(example => `${spaceUnit}${example.command}${example.description}`).join('\n')].join('');
}
const paddingSize = 5;
function createAdditionalHelpText(title, examples, maxCommandWidth) {
return [
title,
examples
.map(example => `${spaceUnit}${example.command.padEnd(maxCommandWidth + paddingSize, ' ')}${example.description}`)
.join('\n'),
].join('');
}
function titleText(title, delimiterStart = '\n', delimiterEnd = '\n') {
return `${delimiterStart}${title}${delimiterEnd}`;
}
function getVersionedDependency(dependency) {
return `${dependency}@${exports.currentVersions[dependency]}`;
}
function buildOption(key, value) {
if (value === true || value === 'true') {
return key;
}
if (value === false || value === 'false') {
return `no-${key}`;
}
return `${key}="${value}"`;
}
function execute(config) {
switch (config.name) {
case 'ngNew':
return executeNgCommand(`new ${config.projectName}`, config.options, config.execSyncOptions);
case 'ngAdd':
return executeNgCommand(`add ${getVersionedDependency(config.dependency)}`, config.options, config.execSyncOptions);
case 'ngUpdate':
return executeNgCommand(`update ${buildNgUpdateDependencyArgs(config.dependencies, config.angularDependencies)}`, { ...config.options }, config.execSyncOptions);
case 'npmInstall':
return executeCommand(`npm install ${versionDependencies(config.dependencies).join(' ')} --audit false --fund false`, config.execSyncOptions);
case 'npmUpdate':
return executeCommand('npm update --save --audit false --fund false', config.execSyncOptions);
case 'npmDedupe':
return executeCommand(`npm dedupe --audit false --fund false`, config.execSyncOptions);
case 'npmPrune':
return executeCommand('npm prune --audit false --fund false', config.execSyncOptions);
case 'npmFormat':
return executeCommand('npm run lint -- --fix', config.execSyncOptions);
case 'npmOutdated':
return executeCommand('npm outdated', config.execSyncOptions);
}
}
// See https://nodejs.org/docs/latest/api/process.html#processargv
function parseCommandArguments() {
const [execPath, filePath, commandName, ...args] = process.argv;
return {
execPath,
filePath,
commandName,
arguments: args,
};
}
function buildNgUpdateDependencyArgs(dependencies, angularDependencies) {
const versioned = versionDependencies(dependencies);
const additionalAngular = angularDependencies.filter(dep => !versioned.some(versionedDep => new RegExp(`^${dep}(?:@.+)?$`, 'u').test(versionedDep)));
const angular = additionalAngular
.map(dep => {
if (dep.startsWith('@angular')) {
return `${dep}@${exports.currentVersions['@angular/core']}`;
}
return dep;
})
.join(' ');
return [...versioned, angular].join(' ').trim();
}
function isNodeVersionRecommended(recommendedNodeMajorVersion) {
const currentNodeVersion = process.versions.node;
return (0, semver_1.major)(currentNodeVersion) === recommendedNodeMajorVersion;
}
function isNodeVersionSupported(minimumSupportedNodeVersion) {
const currentNodeVersion = process.versions.node;
return (0, semver_1.gte)(currentNodeVersion, minimumSupportedNodeVersion);
}
function executeNgCommand(command, options = {}, execSyncOptions = {}) {
const parsedOptions = Object.entries(options).map(([key, value]) => `--${buildOption(key, value)}`);
executeCommand(['npx', getVersionedDependency('@angular/cli'), command, ...parsedOptions].join(' '), execSyncOptions);
}
function executeCommand(command, execSyncOptions = {}) {
(0, child_process_1.execSync)(command, { stdio: 'inherit', ...execSyncOptions });
}
function versionDependencies(dependencies) {
return dependencies.map(dependency => getVersionedDependency(dependency));
}
function printCliVersion() {
return `v${exports.version}`;
}