-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
export.impl.ts
68 lines (61 loc) · 1.78 KB
/
export.impl.ts
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
import 'dotenv/config';
import {
ExecutorContext,
parseTargetString,
readTargetOptions,
runExecutor,
} from '@nrwl/devkit';
import exportApp from 'next/dist/export';
import { PHASE_EXPORT } from 'next/dist/next-server/lib/constants';
import { resolve } from 'path';
import { prepareConfig } from '../../utils/config';
import {
NextBuildBuilderOptions,
NextExportBuilderOptions,
} from '../../utils/types';
import { createProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import { calculateProjectDependencies } from '@nrwl/workspace/src/utilities/buildable-libs-utils';
import { assertDependentProjectsHaveBeenBuilt } from '../../utils/buildable-libs';
export default async function exportExecutor(
options: NextExportBuilderOptions,
context: ExecutorContext
) {
const projGraph = createProjectGraph();
const { dependencies } = calculateProjectDependencies(
projGraph,
context.root,
context.projectName,
'build', // this should be generalized
context.configurationName
);
assertDependentProjectsHaveBeenBuilt(dependencies, context);
const buildTarget = parseTargetString(options.buildTarget);
const build = await runExecutor(buildTarget, {}, context);
for await (const result of build) {
if (!result.success) {
return result;
}
}
const buildOptions = readTargetOptions<NextBuildBuilderOptions>(
buildTarget,
context
);
const root = resolve(context.root, buildOptions.root);
const config = await prepareConfig(
PHASE_EXPORT,
buildOptions,
context,
dependencies
);
await exportApp(
root,
{
statusMessage: 'Exporting',
silent: options.silent,
threads: options.threads,
outdir: `${buildOptions.outputPath}/exported`,
} as any,
config
);
return { success: true };
}