Skip to content

Commit 6617ed7

Browse files
committed
Add prebuild all command
1 parent 122c289 commit 6617ed7

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Command } from '@commander-js/extra-typings';
22
import { getBuildCommand } from './build.js';
33
import { getListCommand } from './list.js';
4-
import { getLintCommand, getTscCommand } from './prebuild.js';
4+
import { getLintCommand, getPrebuildAllCommand, getTscCommand } from './prebuild.js';
55
import getTemplateCommand from './template.js';
66
import { getTestCommand } from './testing.js';
77

88
export const getMainCommand = () => new Command()
99
.addCommand(getBuildCommand())
1010
.addCommand(getLintCommand())
1111
.addCommand(getListCommand())
12+
.addCommand(getPrebuildAllCommand())
1213
.addCommand(getTemplateCommand())
1314
.addCommand(getTestCommand())
1415
.addCommand(getTscCommand());

lib/buildtools/src/commands/prebuild.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import pathlib from 'path';
77
import { Command } from '@commander-js/extra-typings';
88
import { resolveEitherBundleOrTab } from '../build/manifest.js';
9+
import { runPrebuild } from '../prebuild/index.js';
910
import { formatLintResult, runEslint } from '../prebuild/lint.js';
1011
import { formatTscResult, runTsc } from '../prebuild/tsc.js';
1112
import { logCommandErrorAndExit } from './commandUtils.js';
@@ -63,3 +64,30 @@ export const getTscCommand = () => new Command('tsc')
6364
}
6465
}
6566
});
67+
68+
export const getPrebuildAllCommand = () => new Command('prebuild')
69+
.argument('[directory]', 'Directory to prebuild tasks in', process.cwd())
70+
.option('--ci')
71+
.action(async (directory, { ci }) => {
72+
const fullyResolved = pathlib.resolve(directory);
73+
const asset = await resolveEitherBundleOrTab(fullyResolved);
74+
75+
if (!asset) {
76+
logCommandErrorAndExit(`No tab or bundle found at ${fullyResolved}`);
77+
}
78+
79+
const { tsc, lint } = await runPrebuild(asset);
80+
console.log(formatTscResult(tsc));
81+
console.log(formatLintResult(lint));
82+
83+
[tsc, lint].forEach(({ severity }) => {
84+
switch (severity) {
85+
case 'warn': {
86+
if (!ci) return;
87+
}
88+
case 'error': {
89+
process.exit(1);
90+
}
91+
}
92+
});
93+
});

lib/buildtools/src/prebuild/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,18 @@ export async function runBuilderWithPrebuild<T extends ResolvedBundle | Resolved
5050
lint: lintResult
5151
};
5252
}
53+
54+
/**
55+
* Run just tsc and ESLint simultaneously without running any build tasks
56+
*/
57+
export async function runPrebuild(asset: ResolvedBundle | ResolvedTab) {
58+
const [tscResult, lintResult] = await Promise.all([
59+
runTsc(asset, false),
60+
runEslint(asset, false)
61+
]);
62+
63+
return {
64+
tsc: tscResult,
65+
lint: lintResult
66+
};
67+
}

0 commit comments

Comments
 (0)