Skip to content

Commit 7011355

Browse files
committed
feat(@angular/cli): inline style and templates in defaults
* `inlineStyle` and `inlineTemplate` are now generated in `.angular-cli.json`. * default stays `false` for both, but if `ng new [name]` is specified with `-is` or `-it`, those will be stored as `true` in `.angular-cli.json` respectively * added unit tests and e2e test
1 parent e87598e commit 7011355

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

packages/@angular/cli/blueprints/ng/files/angular-cli.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252
},
5353
"defaults": {
5454
"styleExt": "<%= styleExt %>",<% if (!minimal) { %>
55-
"component": {}<% } else { %>
55+
"component": {
56+
"inlineStyle": <%= inlineStyle %>,
57+
"inlineTemplate": <%= inlineTemplate %>
58+
}<% } else { %>
5659
"component": {
5760
"spec": false,
5861
"inlineStyle": true,

tests/acceptance/new.spec.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import { forEach } from 'lodash';
88

99
const ng = require('../helpers/ng');
1010
const tmp = require('../helpers/tmp');
11+
const readConfigFile = require('../helpers/config-file');
1112
const walkSync = require('walk-sync');
1213
const SilentError = require('silent-error');
1314
const Blueprint = require('@angular/cli/ember-cli/lib/models/blueprint');
1415

1516
const root = process.cwd();
1617

17-
1818
describe('Acceptance: ng new', function () {
1919
beforeEach(function () {
2020
return tmp.setup('./tmp').then(function () {
@@ -180,4 +180,19 @@ describe('Acceptance: ng new', function () {
180180
});
181181
});
182182

183+
it(`should set inline-style in .angular-cli.json when passed --inline-style`, () => {
184+
return ng(['new', 'foo', '--skip-install', '--skip-git', `--inline-style`])
185+
.then(() => {
186+
const configFile = readConfigFile();
187+
expect(configFile.defaults.component.inlineStyle).to.equal(true);
188+
});
189+
});
190+
191+
it(`should set inline-template in .angular-cli.json when passed --inline-template`, () => {
192+
return ng(['new', 'foo', '--skip-install', '--skip-git', `--inline-template`])
193+
.then(() => {
194+
const configFile = readConfigFile();
195+
expect(configFile.defaults.component.inlineTemplate).to.equal(true);
196+
});
197+
});
183198
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// tslint:disable:max-line-length
2+
import { createProject } from '../../../utils/project';
3+
import { ng } from '../../../utils/process';
4+
import { expectFileNotToExist, expectFileToExist } from '../../../utils/fs';
5+
import { join } from 'path';
6+
7+
export default () => {
8+
const componentDir = join('src', 'app', 'test-component');
9+
10+
return Promise.resolve()
11+
.then(() => createProject('test-project-inline-style-and-template', '--inline-template', '--inline-style'))
12+
.then(() => expectFileNotToExist('src/app/app.component.html'))
13+
.then(() => expectFileNotToExist('src/app/app.component.css'))
14+
.then(() => ng('generate', 'component', 'test-component'))
15+
.then(() => expectFileToExist(componentDir))
16+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.ts')))
17+
.then(() => expectFileToExist(join(componentDir, 'test-component.component.spec.ts')))
18+
// template and style files should not exist
19+
.then(() => expectFileNotToExist(join(componentDir, 'test-component.component.html')))
20+
.then(() => expectFileNotToExist(join(componentDir, 'test-component.component.css')))
21+
22+
// Try to run the unit tests.
23+
.then(() => ng('test', '--single-run'));
24+
};

tests/helpers/config-file.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const fs = require('fs-extra');
2+
3+
const readConfigFile = () => {
4+
return JSON.parse(fs.readFileSync('.angular-cli.json', 'utf8'));
5+
};
6+
7+
module.exports = readConfigFile;

0 commit comments

Comments
 (0)