|
| 1 | +import { ngbench } from '../../utils/process'; |
| 2 | +import { replaceInFile, moveFile } from '../../utils/fs'; |
| 3 | +import { updateJsonFile } from '../../utils/project'; |
| 4 | + |
| 5 | + |
| 6 | +export default function () { |
| 7 | + const extensions = ['css', 'scss', 'less', 'styl']; |
| 8 | + let promise = Promise.resolve(); |
| 9 | + |
| 10 | + extensions.forEach(ext => { |
| 11 | + promise = promise.then(() => { |
| 12 | + // change files to use preprocessor |
| 13 | + return updateJsonFile('.angular-cli.json', configJson => { |
| 14 | + const app = configJson['apps'][0]; |
| 15 | + app['styles'] = [`styles.${ext}`]; |
| 16 | + }) |
| 17 | + .then(() => replaceInFile('src/app/app.component.ts', |
| 18 | + './app.component.css', `./app.component.${ext}`)) |
| 19 | + .then(() => moveFile('src/styles.css', `src/styles.${ext}`)) |
| 20 | + .then(() => moveFile('src/app/app.component.css', `src/app/app.component.${ext}`)) |
| 21 | + // run benchmarks |
| 22 | + .then(() => ngbench( |
| 23 | + '--comment', 'component styles', |
| 24 | + '--match-edit-file', `src/app/app.component.${ext}`, |
| 25 | + '--match-edit-string', 'h1{color:blue}' |
| 26 | + )) |
| 27 | + .then(() => ngbench( |
| 28 | + '--comment', `.${ext} CSS extension`, |
| 29 | + '--match-edit-file', `src/styles.${ext}`, |
| 30 | + '--match-edit-string', 'h1{color:blue}' |
| 31 | + )) |
| 32 | + // change files back |
| 33 | + .then(() => replaceInFile('src/app/app.component.ts', |
| 34 | + `./app.component.${ext}`, './app.component.css')) |
| 35 | + .then(() => moveFile(`src/styles.${ext}`, 'src/styles.css')) |
| 36 | + .then(() => moveFile(`src/app/app.component.${ext}`, 'src/app/app.component.css')); |
| 37 | + |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + return promise; |
| 42 | +} |
0 commit comments