|
| 1 | +import { stripIndents } from 'common-tags'; |
| 2 | +import { getGlobalVariable } from '../../../utils/env'; |
1 | 3 | import {
|
| 4 | + replaceInFile, |
2 | 5 | writeMultipleFiles,
|
3 |
| - replaceInFile |
4 | 6 | } from '../../../utils/fs';
|
5 | 7 | import { ng, silentNpm } from '../../../utils/process';
|
6 |
| -import { stripIndents } from 'common-tags'; |
7 | 8 | import { updateJsonFile } from '../../../utils/project';
|
8 | 9 |
|
9 |
| -export default function () { |
| 10 | +const snapshots = require('../../../ng-snapshot/package.json'); |
| 11 | + |
| 12 | +export default async function () { |
10 | 13 | // TODO(architect): Delete this test. It is now in devkit/build-angular.
|
11 | 14 |
|
12 |
| - const extensions = ['css', 'scss', 'less', 'styl']; |
13 |
| - let promise: Promise<any> = Promise.resolve() |
14 |
| - .then(() => silentNpm('install', '@angular/[email protected]')) |
15 |
| - .then(() => silentNpm('install', '@angular/[email protected]')); |
| 15 | + const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots']; |
| 16 | + await updateJsonFile('package.json', packageJson => { |
| 17 | + const dependencies = packageJson['dependencies']; |
| 18 | + dependencies['@angular/material'] = isSnapshotBuild ? snapshots.dependencies['@angular/material'] : 'latest'; |
| 19 | + dependencies['@angular/cdk'] = isSnapshotBuild ? snapshots.dependencies['@angular/cdk'] : 'latest'; |
| 20 | + }); |
| 21 | + |
| 22 | + await silentNpm('install'); |
16 | 23 |
|
17 |
| - extensions.forEach(ext => { |
18 |
| - promise = promise.then(() => { |
19 |
| - return writeMultipleFiles({ |
20 |
| - [`src/styles.${ext}`]: stripIndents` |
21 |
| - @import "~@angular/material/prebuilt-themes/indigo-pink.css"; |
| 24 | + for (const ext of ['css', 'scss', 'less', 'styl']) { |
| 25 | + await writeMultipleFiles({ |
| 26 | + [`src/styles.${ext}`]: stripIndents` |
| 27 | + @import "~@angular/material/prebuilt-themes/indigo-pink.css"; |
| 28 | + `, |
| 29 | + [`src/app/app.component.${ext}`]: stripIndents` |
| 30 | + @import "~@angular/material/prebuilt-themes/indigo-pink.css"; |
| 31 | + `, |
| 32 | + }); |
| 33 | + |
| 34 | + // change files to use preprocessor |
| 35 | + await updateJsonFile('angular.json', workspaceJson => { |
| 36 | + const appArchitect = workspaceJson.projects['test-project'].architect; |
| 37 | + appArchitect.build.options.styles = [ |
| 38 | + { input: `src/styles.${ext}` }, |
| 39 | + ]; |
| 40 | + }); |
| 41 | + |
| 42 | + await replaceInFile('src/app/app.component.ts', './app.component.css', `./app.component.${ext}`); |
| 43 | + |
| 44 | + // run build app |
| 45 | + await ng('build', '--extract-css', '--source-map'); |
| 46 | + await writeMultipleFiles({ |
| 47 | + [`src/styles.${ext}`]: stripIndents` |
| 48 | + @import "@angular/material/prebuilt-themes/indigo-pink.css"; |
22 | 49 | `,
|
23 |
| - [`src/app/app.component.${ext}`]: stripIndents` |
24 |
| - @import "~@angular/material/prebuilt-themes/indigo-pink.css"; |
| 50 | + [`src/app/app.component.${ext}`]: stripIndents` |
| 51 | + @import "@angular/material/prebuilt-themes/indigo-pink.css"; |
25 | 52 | `,
|
26 |
| - }) |
27 |
| - // change files to use preprocessor |
28 |
| - .then(() => updateJsonFile('angular.json', workspaceJson => { |
29 |
| - const appArchitect = workspaceJson.projects['test-project'].architect; |
30 |
| - appArchitect.build.options.styles = [ |
31 |
| - { input: `src/styles.${ext}` }, |
32 |
| - ]; |
33 |
| - })) |
34 |
| - .then(() => replaceInFile('src/app/app.component.ts', |
35 |
| - './app.component.css', `./app.component.${ext}`)) |
36 |
| - // run build app |
37 |
| - .then(() => ng('build', '--extract-css', '--source-map')) |
38 |
| - .then(() => writeMultipleFiles({ |
39 |
| - [`src/styles.${ext}`]: stripIndents` |
40 |
| - @import "@angular/material/prebuilt-themes/indigo-pink.css"; |
41 |
| - `, |
42 |
| - [`src/app/app.component.${ext}`]: stripIndents` |
43 |
| - @import "@angular/material/prebuilt-themes/indigo-pink.css"; |
44 |
| - `, |
45 |
| - })) |
46 |
| - .then(() => ng('build', '--extract-css')); |
47 | 53 | });
|
48 |
| - }); |
49 | 54 |
|
50 |
| - return promise; |
| 55 | + await ng('build', '--extract-css'); |
| 56 | + } |
51 | 57 | }
|
0 commit comments