@@ -5,52 +5,57 @@ import { getChangelogMarkdown } from '@soybeanjs/changelog';
55import { version } from '../package.json' ;
66import { hasTagOnGitHub , isRepoShallow , sendRelease } from './github' ;
77
8- const cli = cac ( 'githublogen' ) ;
8+ function setupCli ( ) {
9+ const cli = cac ( 'githublogen' ) ;
910
10- cli . version ( version ) . option ( '-t, --token <path>' , 'GitHub Token' ) . help ( ) ;
11+ cli . version ( version ) . option ( '-t, --token <path>' , 'GitHub Token' ) . help ( ) ;
1112
12- cli . command ( '' ) . action ( async ( args : any ) => {
13- try {
14- const cwd = process . cwd ( ) ;
13+ cli . command ( '' ) . action ( async ( args : any ) => {
14+ try {
15+ const cwd = process . cwd ( ) ;
1516
16- const { options, commits, markdown } = await getChangelogMarkdown (
17- {
18- cwd,
19- ...args
20- } ,
21- false
22- ) ;
23- console . log ( 'markdown: ' , markdown ) ;
17+ const { options, commits, markdown } = await getChangelogMarkdown (
18+ {
19+ cwd,
20+ ...args
21+ } ,
22+ false
23+ ) ;
2424
25- consola . log ( cyan ( options . from ) + dim ( ' -> ' ) + blue ( options . to ) + dim ( ` (${ commits . length } commits)` ) ) ;
25+ consola . log ( cyan ( options . from ) + dim ( ' -> ' ) + blue ( options . to ) + dim ( ` (${ commits . length } commits)` ) ) ;
2626
27- if ( ! ( await hasTagOnGitHub ( options . to , options . github . repo , options . github . token ) ) ) {
28- consola . error ( yellow ( `Current ref "${ bold ( options . to ) } " is not available as tags on GitHub. Release skipped.` ) ) ;
27+ if ( ! ( await hasTagOnGitHub ( options . to , options . github . repo , options . github . token ) ) ) {
28+ consola . error ( yellow ( `Current ref "${ bold ( options . to ) } " is not available as tags on GitHub. Release skipped.` ) ) ;
2929
30- if ( process . exitCode ) {
31- process . exitCode = 1 ;
30+ if ( process . exitCode ) {
31+ process . exitCode = 1 ;
32+ }
3233 }
33- }
3434
35- if ( ! commits . length && ( await isRepoShallow ( ) ) ) {
36- consola . error (
37- yellow (
38- 'The repo seems to be clone shallowly, which make changelog failed to generate. You might want to specify `fetch-depth: 0` in your CI config.'
39- )
40- ) ;
41- if ( process . exitCode ) {
42- process . exitCode = 1 ;
35+ if ( ! commits . length && ( await isRepoShallow ( ) ) ) {
36+ consola . error (
37+ yellow (
38+ 'The repo seems to be clone shallowly, which make changelog failed to generate. You might want to specify `fetch-depth: 0` in your CI config.'
39+ )
40+ ) ;
41+ if ( process . exitCode ) {
42+ process . exitCode = 1 ;
43+ }
44+ return ;
4345 }
44- return ;
45- }
4646
47- await sendRelease ( options , markdown ) ;
48- } catch ( e : any ) {
49- consola . error ( red ( String ( e ) ) ) ;
50- if ( e ?. stack ) {
51- consola . error ( dim ( e . stack ?. split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ) ) ;
47+ await sendRelease ( options , markdown ) ;
48+ } catch ( e : any ) {
49+ consola . error ( red ( String ( e ) ) ) ;
50+ if ( e ?. stack ) {
51+ consola . error ( dim ( e . stack ?. split ( '\n' ) . slice ( 1 ) . join ( '\n' ) ) ) ;
52+ }
53+
54+ process . exit ( 1 ) ;
5255 }
56+ } ) ;
57+
58+ cli . parse ( ) ;
59+ }
5360
54- process . exit ( 1 ) ;
55- }
56- } ) ;
61+ setupCli ( ) ;
0 commit comments