Skip to content

Commit a7668e0

Browse files
Broccohansl
authored andcommitted
feat(@angular/cli): add barebones option to ng new
This feature allows users to specify `--barebones` (`-b`) to create a no-frills app.
1 parent 2be0bf2 commit a7668e0

File tree

9 files changed

+108
-11
lines changed

9 files changed

+108
-11
lines changed

docs/documentation/new.md

+10
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ Default applications are created in a directory of the same name, with an initia
4848
</p>
4949
</details>
5050

51+
<details>
52+
<summary>minimal</summary>
53+
<p>
54+
<code>--minimal</code> <em>default value: false</em>
55+
</p>
56+
<p>
57+
Should create a minimal app.
58+
</p>
59+
</details>
60+
5161
<details>
5262
<summary>prefix</summary>
5363
<p>

packages/@angular/cli/blueprints/ng/files/__path__/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<title><%= jsComponentName %></title>
66
<base href="/">
77

8-
<meta name="viewport" content="width=device-width, initial-scale=1">
9-
<link rel="icon" type="image/x-icon" href="favicon.ico">
8+
<meta name="viewport" content="width=device-width, initial-scale=1"><% if (!minimal) { %>
9+
<link rel="icon" type="image/x-icon" href="favicon.ico"><% } %>
1010
</head>
1111
<body>
1212
<<%= prefix %>-root></<%= prefix %>-root>

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

+25-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,30 @@
5151
}
5252
},
5353
"defaults": {
54-
"styleExt": "<%= styleExt %>",
55-
"component": {}
54+
"styleExt": "<%= styleExt %>",<% if (!minimal) { %>
55+
"component": {}<% } else { %>
56+
"component": {
57+
"spec": false,
58+
"inlineStyle": true,
59+
"inlineTemplate": true
60+
},
61+
"directive": {
62+
"spec": false
63+
},
64+
"class": {
65+
"spec": false
66+
},
67+
"guard": {
68+
"spec": false
69+
},
70+
"module": {
71+
"spec": false
72+
},
73+
"pipe": {
74+
"spec": false
75+
},
76+
"service": {
77+
"spec": false
78+
} <% } %>
5679
}
5780
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
"scripts": {
66
"ng": "ng",
77
"start": "ng serve",
8-
"build": "ng build",
8+
"build": "ng build",<% if (!minimal){ %>
99
"test": "ng test",
1010
"lint": "ng lint",
11-
"e2e": "ng e2e"
11+
"e2e": "ng e2e"<% } else { %>
12+
"test": "echo \"Error: no test... minimal project\" && exit 1",
13+
"lint": "echo \"Error: no lint... minimal project\" && exit 1",
14+
"e2e": "echo \"Error: no e2e... minimal project\" && exit 1"<% } %>
1215
},
1316
"private": true,
1417
"dependencies": {
@@ -28,7 +31,7 @@
2831
"devDependencies": {
2932
"@angular/cli": "<%= version %>",
3033
"@angular/compiler-cli": "^4.0.0",
31-
"@angular/language-service": "^4.0.0",
34+
"@angular/language-service": "^4.0.0",<% if (!minimal) { %>
3235
"@types/jasmine": "2.5.45",
3336
"@types/node": "~6.0.60",
3437
"codelyzer": "~3.0.1",
@@ -42,7 +45,7 @@
4245
"karma-coverage-istanbul-reporter": "^1.2.1",
4346
"protractor": "~5.1.2",
4447
"ts-node": "~3.0.4",
45-
"tslint": "~5.3.2",
48+
"tslint": "~5.3.2",<% } %>
4649
"typescript": "~2.3.3"
4750
}
4851
}

packages/@angular/cli/blueprints/ng/index.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ export default Blueprint.extend({
1515
{ name: 'routing', type: Boolean, default: false },
1616
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
1717
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
18-
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }
18+
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
19+
{ name: 'minimal',
20+
type: Boolean,
21+
default: false,
22+
description: 'Should create a minimal app.'
23+
}
1924
],
2025

2126
beforeInstall: function(options: any) {
@@ -26,6 +31,12 @@ export default Blueprint.extend({
2631
},
2732

2833
locals: function(options: any) {
34+
if (options.minimal) {
35+
options.inlineStyle = true;
36+
options.inlineTemplate = true;
37+
options.skipTests = true;
38+
}
39+
2940
this.styleExt = options.style === 'stylus' ? 'styl' : options.style;
3041
if (!options.style) {
3142
this.styleExt = CliConfig.getValue('defaults.styleExt') || 'css';
@@ -54,7 +65,8 @@ export default Blueprint.extend({
5465
routing: options.routing,
5566
inlineStyle: options.inlineStyle,
5667
inlineTemplate: options.inlineTemplate,
57-
tests: this.tests
68+
tests: this.tests,
69+
minimal: options.minimal
5870
};
5971
},
6072

@@ -78,6 +90,14 @@ export default Blueprint.extend({
7890
fileList = fileList.filter(p => p.indexOf('app.component.spec.ts') < 0);
7991
}
8092

93+
if (this.options && this.options.minimal) {
94+
const toRemoveList: RegExp[] = [/e2e\//, /editorconfig/, /README/, /karma.conf.js/,
95+
/protractor.conf.js/, /test.ts/, /tsconfig.spec.json/, /tslint.json/, /favicon.ico/];
96+
fileList = fileList.filter(p => {
97+
return !toRemoveList.some(re => re.test(p));
98+
});
99+
}
100+
81101
const cliConfig = CliConfig.fromProject();
82102
const ngConfig = cliConfig && cliConfig.config;
83103
if (!ngConfig || ngConfig.packageManager != 'yarn') {

packages/@angular/cli/commands/init.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ const InitCommand: any = Command.extend({
2020
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
2121
{ name: 'routing', type: Boolean, default: false },
2222
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
23-
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
23+
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
24+
{
25+
name: 'minimal',
26+
type: Boolean,
27+
default: false,
28+
description: 'Should create a minimal app.'
29+
}
2430
],
2531

2632
anonymousOptions: ['<glob-pattern>'],

packages/@angular/cli/commands/new.ts

+6
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ const NewCommand = Command.extend({
116116
default: false,
117117
aliases: ['it'],
118118
description: 'Should have an inline template.'
119+
},
120+
{
121+
name: 'minimal',
122+
type: Boolean,
123+
default: false,
124+
description: 'Should create a minimal app.'
119125
}
120126
],
121127

packages/@angular/cli/tasks/init.ts

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ export default Task.extend({
7676
routing: commandOptions.routing,
7777
inlineStyle: commandOptions.inlineStyle,
7878
inlineTemplate: commandOptions.inlineTemplate,
79+
minimal: commandOptions.minimal,
7980
ignoredUpdateFiles: ['favicon.ico'],
8081
skipGit: commandOptions.skipGit,
8182
skipTests: commandOptions.skipTests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import {ng} from '../../../utils/process';
2+
import {createProject} from '../../../utils/project';
3+
import {expectFileNotToExist, expectFileToMatch} from '../../../utils/fs';
4+
import {expectToFail} from '../../../utils/utils';
5+
6+
7+
export default function() {
8+
return Promise.resolve()
9+
.then(() => createProject('minimal-project', '--minimal'))
10+
.then(() => expectFileNotToExist('.editorconfig'))
11+
.then(() => expectFileNotToExist('README.md'))
12+
.then(() => expectFileNotToExist('karma.conf.js'))
13+
.then(() => expectFileNotToExist('protractor.conf.js'))
14+
.then(() => expectFileNotToExist('src/test.ts'))
15+
.then(() => expectFileNotToExist('src/tsconfig.spec.json'))
16+
.then(() => expectFileNotToExist('tslint.json'))
17+
.then(() => expectFileNotToExist('src/app/app.component.html'))
18+
.then(() => expectFileNotToExist('src/app/app.component.css'))
19+
.then(() => expectFileNotToExist('src/app/app.component.spec.ts'))
20+
.then(() => expectFileNotToExist('src/app/favicon.ico'))
21+
22+
.then(() => expectToFail(() => expectFileToMatch('package.json', '"protractor":')))
23+
.then(() => expectToFail(() => expectFileToMatch('package.json', '"karma":')))
24+
.then(() => expectToFail(() => expectFileToMatch('package.json', '"jasmine-core":')))
25+
26+
// Try to run a build.
27+
.then(() => ng('build'));
28+
}

0 commit comments

Comments
 (0)