UNPKG

@oblique/cli

Version:

Command Line Interface to manage Oblique projects

183 lines (181 loc) 8.79 kB
/** * @file Oblique, The front-end framework for your Swiss branded UI. * @copyright 2020 - 2025 Federal Office of Information Technology, Systems and Telecommunication FOITT {@link https://www.bit.admin.ch} * @version 14.1.2 (released on 2025-12-01, supported at least until 2026-09-30) * @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 */ "use strict"; 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.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 = '14.1.2'; /* End of generated content */ exports.currentVersions = { '@oblique/oblique': exports.version, '@angular/cli': '^20.2', '@angular/material': '20', '@oblique/toolchain': exports.version, '@angular/core': '20', '@angular/cdk': '20', '@angular/animations': '20', '@angular/platform-browser-dynamic': '20', '@types/jest': '29', '@angular-builders/jest': '20', '@schematics/angular': '20', 'angular-oauth2-oidc': '20', jest: '29', }; 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 (typeof value === 'string') { return `${key}="${value}"`; } return value ? key : `no-${key}`; } 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 ${versionDependencies(config.dependencies).join(' ')}`, { 'allow-dirty': true, ...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 { argv } = process; return { execPath: argv[0], filePath: argv[1], // eslint-disable-next-line @typescript-eslint/no-magic-numbers commandName: argv[2], // eslint-disable-next-line @typescript-eslint/no-magic-numbers arguments: argv.slice(3), }; } 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}`; }