MCPcopy
hub / github.com/QwikDev/qwik / runBuildCommand

Function runBuildCommand

packages/qwik/src/cli/utils/run-build-command.ts:10–339  ·  view source on GitHub ↗
(app: AppCommand)

Source from the content-addressed store, hash-verified

8 stdout?: string;
9}
10export async function runBuildCommand(app: AppCommand) {
11 const pkgJsonScripts = app.packageJson.scripts;
12 if (!pkgJsonScripts) {
13 throw new Error(`No "scripts" property found in package.json`);
14 }
15 const pkgManager = getPackageManager();
16
17 const getScript = (name: string) => {
18 if (pkgJsonScripts[name]) {
19 return `${pkgManager} run ${name}`;
20 }
21 return undefined;
22 };
23
24 const isPreviewBuild = app.args.includes('preview');
25 const buildLibScript = getScript('build.lib');
26 const isLibraryBuild = !!buildLibScript;
27 const buildClientScript = getScript('build.client');
28 const buildPreviewScript = isPreviewBuild ? getScript('build.preview') : undefined;
29 const buildServerScript = !isPreviewBuild ? getScript('build.server') : undefined;
30 const buildStaticScript = getScript('build.static');
31 const runSsgScript = getScript('ssg');
32 const buildTypes = getScript('build.types');
33 const lint = getScript('lint');
34 const mode = app.getArg('mode');
35
36 const prebuildScripts = Object.keys(pkgJsonScripts)
37 .filter((s) => s.startsWith('prebuild.'))
38 .map(getScript)
39 .filter(isString);
40
41 const postbuildScripts = Object.keys(pkgJsonScripts)
42 .filter((s) => s.startsWith('postbuild.'))
43 .map(getScript)
44 .filter(isString);
45
46 const scripts = [
47 buildTypes,
48 buildClientScript,
49 buildLibScript,
50 buildPreviewScript,
51 buildServerScript,
52 buildStaticScript,
53 lint,
54 ].filter(isString);
55
56 if (!isLibraryBuild && !buildClientScript) {
57 console.log(pkgJsonScripts);
58 throw new Error(`"build.client" script not found in package.json`);
59 }
60
61 if (isPreviewBuild && !buildPreviewScript && !buildStaticScript) {
62 throw new Error(
63 `Neither "build.preview" or "build.static" script found in package.json for preview`
64 );
65 }
66
67 console.log(``);

Callers 2

run.tsFile · 0.90
runCommandFunction · 0.90

Calls 5

getPackageManagerFunction · 0.90
pmRunCmdFunction · 0.90
getScriptFunction · 0.85
attachArgFunction · 0.85
getArgMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…