Skip to content

Commit 38dbcc2

Browse files
refactor: share commands across lg and lg-build scripts
1 parent 55580b8 commit 38dbcc2

File tree

4 files changed

+65
-63
lines changed

4 files changed

+65
-63
lines changed

tools/build/src/cli-commands.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { Command } from 'commander';
2+
3+
import { buildPackage } from './rollup/build-package';
4+
import { buildTSDoc } from './tsdoc/build-tsdoc';
5+
import { buildTypescript } from './typescript/build-ts';
6+
7+
export function registerBundleCommand(command: Command) {
8+
command
9+
.description('Builds a package using Rollup')
10+
.option('-v, --verbose', 'Enable verbose logging', false)
11+
.option(
12+
'-d, --direct',
13+
'Build package using the lg-build rollup command directly from @lg-tools/build',
14+
true,
15+
)
16+
.action(buildPackage);
17+
}
18+
19+
export function registerBuildTSCommand(command: Command) {
20+
command
21+
.description("Builds a package's TypeScript definitions")
22+
.argument('[pass-through...]', 'Pass-through options for `tsc`')
23+
.option('-v, --verbose', 'Enable verbose logging', false)
24+
.option(
25+
'-d, --downlevel',
26+
'Downlevel TypeScript packages based on the typesVersions field in package.json',
27+
false,
28+
)
29+
.option(
30+
'-u, --update',
31+
'Update package.json typesVersions and exports fields',
32+
false,
33+
)
34+
.allowUnknownOption(true)
35+
.action(buildTypescript);
36+
}
37+
38+
export function registerBuildDocsCommand(command: Command) {
39+
command
40+
.description('Build TSDoc documentation')
41+
.option('-v, --verbose', 'Enable verbose logging', false)
42+
.action(buildTSDoc);
43+
}

tools/build/src/cli.ts

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,16 @@
11
import { Command } from 'commander';
22

3-
import { buildPackage } from './rollup/build-package';
4-
import { buildTSDoc } from './tsdoc/build-tsdoc';
5-
import { buildTypescript } from './typescript/build-ts';
3+
import {
4+
registerBuildDocsCommand,
5+
registerBuildTSCommand,
6+
registerBundleCommand,
7+
} from './cli-commands';
68

79
const build = new Command('lg-build');
810
build.description('Build LeafyGreen packages');
911

10-
build
11-
.command('bundle')
12-
.description('Bundle packages with Rollup')
13-
.option('-v, --verbose', 'Enable verbose logging', false)
14-
.option(
15-
'-d, --direct',
16-
'Build package using the lg-build rollup command directly from @lg-tools/build',
17-
true,
18-
)
19-
.action(buildPackage);
20-
21-
build
22-
.command('tsc')
23-
.description('Build TypeScript packages')
24-
.option('-v, --verbose', 'Enable verbose logging', false)
25-
.option(
26-
'-d, --downlevel',
27-
'Downlevel TypeScript packages based on the typesVersions field in package.json',
28-
false,
29-
)
30-
.option(
31-
'-u, --update',
32-
'Update package.json typesVersions and exports fields',
33-
false,
34-
)
35-
.action(buildTypescript);
36-
37-
build
38-
.command('docs')
39-
.description('Build TSDoc documentation')
40-
.option('-v, --verbose', 'Enable verbose logging', false)
41-
.action(buildTSDoc);
12+
registerBundleCommand(build.command('bundle'));
13+
registerBuildTSCommand(build.command('tsc'));
14+
registerBuildDocsCommand(build.command('docs'));
4215

4316
build.parse(process.argv);

tools/build/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
export { buildAll as build } from './buildAll';
2+
export {
3+
registerBuildDocsCommand,
4+
registerBuildTSCommand,
5+
registerBundleCommand,
6+
} from './cli-commands';
27
export { buildPackage } from './rollup/build-package';
38
export { buildTSDoc } from './tsdoc/build-tsdoc';
49
export { parseTSDoc } from './tsdoc/tsdocParser';

tools/cli/src/index.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { buildPackage, buildTSDoc, buildTypescript } from '@lg-tools/build';
1+
import {
2+
registerBuildDocsCommand,
3+
registerBuildTSCommand,
4+
registerBundleCommand,
5+
} from '@lg-tools/build';
26
import { migrator } from '@lg-tools/codemods';
37
import { createPackage } from '@lg-tools/create';
48
import { installLeafyGreen } from '@lg-tools/install';
@@ -224,33 +228,10 @@ cli
224228
.action(migrator);
225229

226230
/** Build steps */
227-
cli
228-
.command('build-package')
229-
.description('Builds a package')
230-
.option('-v --verbose', 'Prints additional information to the console', false)
231-
.action(buildPackage);
232-
cli
233-
.command('build-ts')
234-
.description("Builds a package's TypeScript definitions")
235-
.argument('[pass-through...]', 'Pass-through options for `tsc`')
236-
.option('-v --verbose', 'Prints additional information to the console', false)
237-
.option(
238-
'--downlevel',
239-
'Builds all TS downlevel targets based on the typesVersions field in package.json',
240-
false,
241-
)
242-
.option(
243-
'-u, --update',
244-
'Update package.json typesVersions and exports fields',
245-
false,
246-
)
247-
.allowUnknownOption(true)
248-
.action(buildTypescript);
249-
cli
250-
.command('build-tsdoc')
251-
.description("Builds a package's TSDoc file")
252-
.option('-v --verbose', 'Prints additional information to the console', false)
253-
.action(buildTSDoc);
231+
232+
registerBundleCommand(cli.command('build-package'));
233+
registerBuildTSCommand(cli.command('build-ts'));
234+
registerBuildDocsCommand(cli.command('build-tsdoc'));
254235

255236
/** Merge editor settings */
256237
cli

0 commit comments

Comments
 (0)