-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·80 lines (70 loc) · 2.23 KB
/
Copy pathcli.js
File metadata and controls
executable file
·80 lines (70 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env node
/**
* External dependencies
*/
const { program } = require( 'commander' );
/**
* Internal dependencies
*/
const { formats } = require( './lib/logger' );
const withOptions = (
/** @type {import('commander').Command} */ command,
/** @type {{description: string, argname: string, defaults?: string|boolean|string[]|null}[]} */ options
) => {
options.forEach( ( { description, argname, defaults } ) => {
command = command.option( argname, description, defaults ?? undefined );
} );
return command;
};
const catchException = ( /** @type {Function} */ handler ) => {
return async ( /** @type {any[]} */ ...args ) => {
try {
await handler( ...args );
} catch ( error ) {
const message =
error instanceof Error ? error.message : 'Unknown error';
console.error( formats.error( message ) );
process.exitCode = 1;
}
};
};
/**
* Internal dependencies
*/
const {
handler: changelogHandler,
options: changelogOptions,
} = require( './commands/changelog' );
const {
handler: readmeHandler,
options: readmeOptions,
} = require( './commands/readme' );
const {
handler: sinceHandler,
options: sinceOptions,
} = require( './commands/since' );
const {
handler: versionsHandler,
options: versionsOptions,
} = require( './commands/versions' );
withOptions( program.command( 'release-plugin-changelog' ), changelogOptions )
.alias( 'changelog' )
.description( 'Generates a changelog from merged pull requests' )
.action( catchException( changelogHandler ) );
withOptions( program.command( 'release-plugin-since' ), sinceOptions )
.alias( 'since' )
.description(
'Updates "n.e.x.t" tags with the current release version in the "Stable tag" of readme.txt'
)
.action( catchException( sinceHandler ) );
withOptions( program.command( 'plugin-readme' ), readmeOptions )
.alias( 'readme' )
.description(
'Updates the changelog in the readme.txt file for the stable tag (requires milestones to be named "$plugin_slug $stable_tag")'
)
.action( catchException( readmeHandler ) );
withOptions( program.command( 'verify-version-consistency' ), versionsOptions )
.alias( 'versions' )
.description( 'Verifies consistency of versions in plugins' )
.action( catchException( versionsHandler ) );
program.parse( process.argv );