forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts-array.ts
More file actions
57 lines (56 loc) · 2.98 KB
/
scripts-array.ts
File metadata and controls
57 lines (56 loc) · 2.98 KB
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 {
writeMultipleFiles,
expectFileToMatch,
appendToFile
} from '../../utils/fs';
import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { oneLineTrim } from 'common-tags';
export default function () {
return writeMultipleFiles({
'src/string-script.js': 'console.log(\'string-script\');',
'src/input-script.js': 'console.log(\'input-script\');',
'src/lazy-script.js': 'console.log(\'lazy-script\');',
'src/pre-rename-script.js': 'console.log(\'pre-rename-script\');',
'src/pre-rename-lazy-script.js': 'console.log(\'pre-rename-lazy-script\');',
'src/common-entry-script.js': 'console.log(\'common-entry-script\');',
'src/common-entry-style.css': '.common-entry-style { color: red }',
})
.then(() => appendToFile('src/main.ts', 'import \'./string-script.js\';'))
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['scripts'] = [
'string-script.js',
{ input: 'input-script.js' },
{ input: 'lazy-script.js', lazy: true },
{ input: 'pre-rename-script.js', output: 'renamed-script' },
{ input: 'pre-rename-lazy-script.js', output: 'renamed-lazy-script', lazy: true },
{ input: 'common-entry-script.js', output: 'common-entry' }
];
app['styles'] = [{ input: 'common-entry-style.css', output: 'common-entry' }];
}))
.then(() => ng('build', '--extract-css'))
// files were created successfully
.then(() => expectFileToMatch('dist/scripts.bundle.js', 'string-script'))
.then(() => expectFileToMatch('dist/scripts.bundle.js', 'input-script'))
.then(() => expectFileToMatch('dist/lazy-script.bundle.js', 'lazy-script'))
.then(() => expectFileToMatch('dist/renamed-script.bundle.js', 'pre-rename-script'))
.then(() => expectFileToMatch('dist/renamed-lazy-script.bundle.js', 'pre-rename-lazy-script'))
.then(() => expectFileToMatch('dist/common-entry.bundle.js', 'common-entry-script'))
.then(() => expectFileToMatch('dist/common-entry.bundle.css', '.common-entry-style'))
// index.html lists the right bundles
.then(() => expectFileToMatch('dist/index.html', oneLineTrim`
<link href="common-entry.bundle.css" rel="stylesheet"/>
`))
.then(() => expectFileToMatch('dist/index.html', oneLineTrim`
<script type="text/javascript" src="inline.bundle.js"></script>
<script type="text/javascript" src="polyfills.bundle.js"></script>
<script type="text/javascript" src="scripts.bundle.js"></script>
<script type="text/javascript" src="renamed-script.bundle.js"></script>
<script type="text/javascript" src="common-entry.bundle.js"></script>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
`))
// ensure scripts aren't using script-loader when imported from the app
.then(() => expectFileToMatch('dist/main.bundle.js', 'console.log(\'string-script\');'));
}