/
remote.ts
57 lines (48 loc) · 1.68 KB
/
remote.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
import { formatFiles, getProjects, Tree } from '@nrwl/devkit';
import type { Schema } from './schema';
import applicationGenerator from '../application/application';
import { normalizeProjectName } from '../utils/project';
import { setupMf } from '../setup-mf/setup-mf';
import { E2eTestRunner } from '../../utils/test-runners';
import { addSsr, findNextAvailablePort } from './lib';
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial';
export async function remote(tree: Tree, options: Schema) {
const projects = getProjects(tree);
if (options.host && !projects.has(options.host)) {
throw new Error(
`The name of the application to be used as the host app does not exist. (${options.host})`
);
}
const appName = normalizeProjectName(options.name, options.directory);
const port = options.port ?? findNextAvailablePort(tree);
const appInstallTask = await applicationGenerator(tree, {
...options,
routing: true,
skipDefaultProject: true,
port,
});
const skipE2E =
!options.e2eTestRunner || options.e2eTestRunner === E2eTestRunner.None;
await setupMf(tree, {
appName,
mfType: 'remote',
routing: true,
host: options.host,
port,
skipPackageJson: options.skipPackageJson,
skipFormat: true,
skipE2E,
e2eProjectName: skipE2E ? undefined : `${appName}-e2e`,
standalone: options.standalone,
});
let installTasks = [appInstallTask];
if (options.ssr) {
let ssrInstallTask = await addSsr(tree, { appName, port });
installTasks.push(ssrInstallTask);
}
if (!options.skipFormat) {
await formatFiles(tree);
}
return runTasksInSerial(...installTasks);
}
export default remote;