forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path500-create-project.ts
77 lines (70 loc) · 2.83 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
75
76
77
import {join} from 'path';
import {git, ng, silentNpm} from '../utils/process';
import {expectFileToExist} from '../utils/fs';
import {updateTsConfig, updateJsonFile} from '../utils/project';
import {gitClean, gitCommit} from '../utils/git';
import {getGlobalVariable} from '../utils/env';
let packages = require('../../../lib/packages');
export default function() {
const argv = getGlobalVariable('argv');
let createProject = null;
// This is a dangerous flag, but is useful for testing packages only.
if (argv.noproject) {
return Promise.resolve();
} else if (argv.reuse) {
// If we're set to reuse an existing project, just chdir to it and clean it.
createProject = Promise.resolve()
.then(() => process.chdir(argv.reuse))
.then(() => gitClean());
} else {
// Otherwise create a project from scratch.
createProject = Promise.resolve()
.then(() => ng('new', 'test-project', '--skip-npm', ...(argv['ng4'] ? ['--ng4'] : [])))
.then(() => expectFileToExist(join(process.cwd(), 'test-project')))
.then(() => process.chdir('./test-project'));
}
return Promise.resolve()
.then(() => createProject)
.then(() => updateJsonFile('package.json', json => {
Object.keys(packages).forEach(pkgName => {
json['dependencies'][pkgName] = packages[pkgName].dist;
});
}))
.then(() => {
if (argv['nightly'] || argv['ng-sha']) {
const label = argv['ng-sha'] ? `#2.0.0-${argv['ng-sha']}` : '';
return updateJsonFile('package.json', json => {
// Install over the project with nightly builds.
Object.keys(json['dependencies'] || {})
.filter(name => name.match(/^@angular\//))
.forEach(name => {
const pkgName = name.split(/\//)[1];
if (pkgName == 'cli') {
return;
}
json['dependencies'][`@angular/${pkgName}`]
= `github:angular/${pkgName}-builds${label}`;
});
Object.keys(json['devDependencies'] || {})
.filter(name => name.match(/^@angular\//))
.forEach(name => {
const pkgName = name.split(/\//)[1];
if (pkgName == 'cli') {
return;
}
json['devDependencies'][`@angular/${pkgName}`]
= `github:angular/${pkgName}-builds${label}`;
});
});
}
})
.then(() => silentNpm('install'))
// Force sourcemaps to be from the root of the filesystem.
.then(() => updateTsConfig(json => {
json['compilerOptions']['sourceRoot'] = '/';
}))
.then(() => git('config', 'user.email', '[email protected]'))
.then(() => git('config', 'user.name', 'Angular CLI E2e'))
.then(() => git('config', 'commit.gpgSign', 'false'))
.then(() => gitCommit('tsconfig-e2e-update'));
}