-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy path500-create-project.ts
74 lines (63 loc) · 2.64 KB
/
500-create-project.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
69
70
71
72
73
74
import { join } from 'node:path';
import { getGlobalVariable } from '../utils/env';
import { expectFileToExist } from '../utils/fs';
import { gitClean } from '../utils/git';
import { setRegistry as setNPMConfigRegistry } from '../utils/packages';
import { ng } from '../utils/process';
import { prepareProjectForE2e, updateJsonFile } from '../utils/project';
export default async function () {
const argv: Record<string, unknown> = getGlobalVariable('argv');
if (argv.noproject) {
return;
}
if (argv.reuse && typeof argv.reuse === 'string') {
process.chdir(argv.reuse);
await gitClean();
} else {
// Ensure local test registry is used when outside a project
await setNPMConfigRegistry(true);
await ng('new', 'test-project', '--skip-install');
await expectFileToExist(join(process.cwd(), 'test-project'));
process.chdir('./test-project');
// Setup esbuild builder if requested on the commandline
const useWebpackBuilder = !getGlobalVariable('argv')['esbuild'];
if (useWebpackBuilder) {
await updateJsonFile('angular.json', (json) => {
const build = json['projects']['test-project']['architect']['build'];
build.builder = '@angular-devkit/build-angular:browser';
build.options = {
...build.options,
main: build.options.browser,
browser: undefined,
outputPath: 'dist/test-project/browser',
index: 'src/index.html',
};
build.configurations.development = {
...build.configurations.development,
vendorChunk: true,
namedChunks: true,
buildOptimizer: false,
};
const serve = json['projects']['test-project']['architect']['serve'];
serve.builder = '@angular-devkit/build-angular:dev-server';
const extract = json['projects']['test-project']['architect']['extract-i18n'];
if (extract) {
extract.builder = '@angular-devkit/build-angular:extract-i18n';
}
const test = json['projects']['test-project']['architect']['test'];
test.builder = '@angular-devkit/build-angular:karma';
});
await updateJsonFile('tsconfig.json', (tsconfig) => {
delete tsconfig.compilerOptions.esModuleInterop;
tsconfig.compilerOptions.allowSyntheticDefaultImports = true;
});
}
// Always need `@angular-devkit/build-angular` due to the use of protractor
await updateJsonFile('package.json', (packageJson) => {
packageJson.devDependencies['@angular-devkit/build-angular'] =
packageJson.devDependencies['@angular/build'];
});
}
await prepareProjectForE2e('test-project');
await ng('version');
}