Repository navigation
Expand file tree
/
Copy pathimports.ts
More file actions
70 lines (67 loc) · 2.5 KB
/
Copy pathimports.ts
File metadata and controls
70 lines (67 loc) · 2.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
import {
writeMultipleFiles,
deleteFile,
expectFileToMatch,
replaceInFile
} from '../../../utils/fs';
import { expectToFail } from '../../../utils/utils';
import { ng } from '../../../utils/process';
import { stripIndents } from 'common-tags';
import { updateJsonFile } from '../../../utils/project';
export default function () {
const extensions = ['css', 'scss', 'less', 'styl'];
let promise = Promise.resolve();
extensions.forEach(ext => {
promise = promise.then(() => {
return writeMultipleFiles({
[`src/styles.${ext}`]: stripIndents`
@import './imported-styles.${ext}';
body { background-color: #00f; }
`,
[`src/imported-styles.${ext}`]: stripIndents`
p { background-color: #f00; }
`,
[`src/app/app.component.${ext}`]: stripIndents`
@import './imported-component-styles.${ext}';
.outer {
.inner {
background: #fff;
}
}
`,
[`src/app/imported-component-styles.${ext}`]: stripIndents`
h1 { background: #000; }
`})
// change files to use preprocessor
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['styles'] = [`styles.${ext}`];
}))
.then(() => replaceInFile('src/app/app.component.ts',
'./app.component.css', `./app.component.${ext}`))
// run build app
.then(() => ng('build', '--extract-css', '--sourcemap'))
// verify global styles
.then(() => expectFileToMatch('dist/styles.bundle.css',
/body\s*{\s*background-color: #00f;\s*}/))
.then(() => expectFileToMatch('dist/styles.bundle.css',
/p\s*{\s*background-color: #f00;\s*}/))
// verify global styles sourcemap
.then(() => expectToFail(() =>
expectFileToMatch('dist/styles.bundle.css', '"mappings":""')))
// verify component styles
.then(() => expectFileToMatch('dist/main.bundle.js',
/.outer.*.inner.*background:\s*#[fF]+/))
.then(() => expectFileToMatch('dist/main.bundle.js',
/h1.*background:\s*#000+/))
// change files back
.then(() => updateJsonFile('angular-cli.json', configJson => {
const app = configJson['apps'][0];
app['styles'] = ['styles.css'];
}))
.then(() => replaceInFile('src/app/app.component.ts',
`./app.component.${ext}`, './app.component.css'));
});
});
return promise;
}