|
| 1 | +import { getGlobalVariable } from '../../../utils/env'; |
1 | 2 | import { writeMultipleFiles, expectFileToMatch, replaceInFile, createDir } from '../../../utils/fs';
|
2 | 3 | import { ng } from '../../../utils/process';
|
3 | 4 | import { updateJsonFile } from '../../../utils/project';
|
4 | 5 |
|
5 |
| -export default function () { |
6 |
| - return ( |
7 |
| - Promise.resolve() |
8 |
| - .then(() => createDir('src/style-paths')) |
9 |
| - .then(() => |
10 |
| - writeMultipleFiles({ |
11 |
| - 'src/style-paths/_variables.scss': '$primary-color: red;', |
12 |
| - 'src/styles.scss': ` |
| 6 | +export default async function () { |
| 7 | + // esbuild currently only supports Sass |
| 8 | + const esbuild = getGlobalVariable('argv')['esbuild']; |
| 9 | + |
| 10 | + await createDir('src/style-paths'); |
| 11 | + await writeMultipleFiles({ |
| 12 | + 'src/style-paths/_variables.scss': '$primary-color: red;', |
| 13 | + 'src/styles.scss': ` |
13 | 14 | @import 'variables';
|
14 | 15 | h1 { color: $primary-color; }
|
15 |
| - `, |
16 |
| - 'src/app/app.component.scss': ` |
| 16 | + `, |
| 17 | + 'src/app/app.component.scss': ` |
17 | 18 | @import 'variables';
|
18 | 19 | h2 { background-color: $primary-color; }
|
19 |
| - `, |
20 |
| - 'src/style-paths/variables.styl': '$primary-color = green', |
21 |
| - 'src/styles.styl': ` |
| 20 | + `, |
| 21 | + 'src/style-paths/variables.styl': '$primary-color = green', |
| 22 | + 'src/styles.styl': ` |
22 | 23 | @import 'variables'
|
23 | 24 | h3
|
24 | 25 | color: $primary-color
|
25 |
| - `, |
26 |
| - 'src/app/app.component.styl': ` |
| 26 | + `, |
| 27 | + 'src/app/app.component.styl': ` |
27 | 28 | @import 'variables'
|
28 | 29 | h4
|
29 | 30 | background-color: $primary-color
|
30 |
| - `, |
31 |
| - 'src/style-paths/variables.less': '@primary-color: #ADDADD;', |
32 |
| - 'src/styles.less': ` |
| 31 | + `, |
| 32 | + 'src/style-paths/variables.less': '@primary-color: #ADDADD;', |
| 33 | + 'src/styles.less': ` |
33 | 34 | @import 'variables';
|
34 | 35 | h5 { color: @primary-color; }
|
35 |
| - `, |
36 |
| - 'src/app/app.component.less': ` |
| 36 | + `, |
| 37 | + 'src/app/app.component.less': ` |
37 | 38 | @import 'variables';
|
38 | 39 | h6 { color: @primary-color; }
|
39 |
| - `, |
40 |
| - }), |
41 |
| - ) |
42 |
| - .then(() => |
43 |
| - replaceInFile( |
44 |
| - 'src/app/app.component.ts', |
45 |
| - `'./app.component.css\'`, |
46 |
| - `'./app.component.scss', './app.component.styl', './app.component.less'`, |
47 |
| - ), |
48 |
| - ) |
49 |
| - .then(() => |
50 |
| - updateJsonFile('angular.json', (workspaceJson) => { |
51 |
| - const appArchitect = workspaceJson.projects['test-project'].architect; |
52 |
| - appArchitect.build.options.styles = [ |
53 |
| - { input: 'src/styles.scss' }, |
54 |
| - { input: 'src/styles.styl' }, |
55 |
| - { input: 'src/styles.less' }, |
56 |
| - ]; |
57 |
| - appArchitect.build.options.stylePreprocessorOptions = { |
58 |
| - includePaths: ['src/style-paths'], |
59 |
| - }; |
60 |
| - }), |
61 |
| - ) |
62 |
| - // files were created successfully |
63 |
| - .then(() => ng('build', '--configuration=development')) |
64 |
| - .then(() => expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/)) |
65 |
| - .then(() => expectFileToMatch('dist/test-project/main.js', /h2.*{.*color: red;.*}/)) |
66 |
| - .then(() => expectFileToMatch('dist/test-project/styles.css', /h3\s*{\s*color: #008000;\s*}/)) |
67 |
| - .then(() => expectFileToMatch('dist/test-project/main.js', /h4.*{.*color: #008000;.*}/)) |
68 |
| - .then(() => expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/)) |
69 |
| - .then(() => expectFileToMatch('dist/test-project/main.js', /h6.*{.*color: #ADDADD;.*}/)) |
70 |
| - .then(() => ng('build', '--aot', '--configuration=development')) |
71 |
| - .then(() => expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/)) |
72 |
| - .then(() => expectFileToMatch('dist/test-project/main.js', /h2.*{.*color: red;.*}/)) |
73 |
| - .then(() => expectFileToMatch('dist/test-project/styles.css', /h3\s*{\s*color: #008000;\s*}/)) |
74 |
| - .then(() => expectFileToMatch('dist/test-project/main.js', /h4.*{.*color: #008000;.*}/)) |
75 |
| - .then(() => expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/)) |
76 |
| - .then(() => expectFileToMatch('dist/test-project/main.js', /h6.*{.*color: #ADDADD;.*}/)) |
| 40 | + `, |
| 41 | + }); |
| 42 | + |
| 43 | + await replaceInFile( |
| 44 | + 'src/app/app.component.ts', |
| 45 | + `'./app.component.css\'`, |
| 46 | + `'./app.component.scss'` + (esbuild ? '' : `, './app.component.styl', './app.component.less'`), |
77 | 47 | );
|
| 48 | + |
| 49 | + await updateJsonFile('angular.json', (workspaceJson) => { |
| 50 | + const appArchitect = workspaceJson.projects['test-project'].architect; |
| 51 | + appArchitect.build.options.styles = [{ input: 'src/styles.scss' }]; |
| 52 | + if (!esbuild) { |
| 53 | + appArchitect.build.options.styles.push( |
| 54 | + { input: 'src/styles.styl' }, |
| 55 | + { input: 'src/styles.less' }, |
| 56 | + ); |
| 57 | + } |
| 58 | + appArchitect.build.options.stylePreprocessorOptions = { |
| 59 | + includePaths: ['src/style-paths'], |
| 60 | + }; |
| 61 | + }); |
| 62 | + |
| 63 | + await ng('build', '--configuration=development'); |
| 64 | + |
| 65 | + expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/); |
| 66 | + expectFileToMatch('dist/test-project/main.js', /h2.*{.*color: red;.*}/); |
| 67 | + if (!esbuild) { |
| 68 | + // These checks are for the less and stylus files |
| 69 | + expectFileToMatch('dist/test-project/styles.css', /h3\s*{\s*color: #008000;\s*}/); |
| 70 | + expectFileToMatch('dist/test-project/main.js', /h4.*{.*color: #008000;.*}/); |
| 71 | + expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/); |
| 72 | + expectFileToMatch('dist/test-project/main.js', /h6.*{.*color: #ADDADD;.*}/); |
| 73 | + } |
| 74 | + |
| 75 | + // esbuild currently only supports AOT and not JIT mode |
| 76 | + if (!esbuild) { |
| 77 | + ng('build', '--no-aot', '--configuration=development'); |
| 78 | + |
| 79 | + expectFileToMatch('dist/test-project/styles.css', /h1\s*{\s*color: red;\s*}/); |
| 80 | + expectFileToMatch('dist/test-project/main.js', /h2.*{.*color: red;.*}/); |
| 81 | + expectFileToMatch('dist/test-project/styles.css', /h3\s*{\s*color: #008000;\s*}/); |
| 82 | + expectFileToMatch('dist/test-project/main.js', /h4.*{.*color: #008000;.*}/); |
| 83 | + expectFileToMatch('dist/test-project/styles.css', /h5\s*{\s*color: #ADDADD;\s*}/); |
| 84 | + expectFileToMatch('dist/test-project/main.js', /h6.*{.*color: #ADDADD;.*}/); |
| 85 | + } |
78 | 86 | }
|
0 commit comments