Skip to content

Commit

Permalink
wip(esm): updated the cli module
Browse files Browse the repository at this point in the history
for #2543
  • Loading branch information
travi committed Aug 27, 2022
1 parent 38ac59d commit a3435b7
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 58 deletions.
22 changes: 11 additions & 11 deletions cli.js
@@ -1,6 +1,7 @@
const {argv, env, stderr} = require('process'); // eslint-disable-line node/prefer-global/process
const util = require('util');
const hideSensitive = require('./lib/hide-sensitive');
import util from 'node:util';
import yargs from 'yargs';
import {hideBin} from 'yargs/helpers';
import hideSensitive from './lib/hide-sensitive.js';

const stringList = {
type: 'string',
Expand All @@ -11,8 +12,8 @@ const stringList = {
: values.reduce((values, value) => values.concat(value.split(',').map((value) => value.trim())), []),
};

module.exports = async () => {
const cli = require('yargs')
export default async () => {
const cli = yargs(hideBin(process.argv))
.command('$0', 'Run automated package publishing', (yargs) => {
yargs.demandCommand(0, 0).usage(`Run automated package publishing
Expand All @@ -36,29 +37,28 @@ Usage:
.option('debug', {describe: 'Output debugging information', type: 'boolean', group: 'Options'})
.option('d', {alias: 'dry-run', describe: 'Skip publishing', type: 'boolean', group: 'Options'})
.option('h', {alias: 'help', group: 'Options'})
.option('v', {alias: 'version', group: 'Options'})
.strict(false)
.exitProcess(false);

try {
const {help, version, ...options} = cli.parse(argv.slice(2));
const {help, version, ...options} = cli.parse(process.argv.slice(2));

if (Boolean(help) || Boolean(version)) {
return 0;
}

if (options.debug) {
// Debug must be enabled before other requires in order to work
require('debug').enable('semantic-release:*');
(await import('debug')).enable('semantic-release:*');
}

await require('.')(options);
await (await import('./index.js')).default(options);
return 0;
} catch (error) {
if (error.name !== 'YError') {
stderr.write(hideSensitive(env)(util.inspect(error, {colors: true})));
process.stderr.write(hideSensitive(process.env)(util.inspect(error, {colors: true})));
}

return 1;
}
};
}
140 changes: 128 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -52,7 +52,7 @@
"semver": "^7.3.2",
"semver-diff": "^3.1.1",
"signale": "^1.2.1",
"yargs": "^16.2.0"
"yargs": "^17.5.1"
},
"devDependencies": {
"ava": "3.15.0",
Expand Down

0 comments on commit a3435b7

Please sign in to comment.