Skip to content

Commit

Permalink
feat(@angular/cli): add barebones option to ng new
Browse files Browse the repository at this point in the history
This feature allows users to specify `--barebones` (`-b`) to create a no-frills app.
  • Loading branch information
Brocco authored and hansl committed Jun 7, 2017
1 parent 2be0bf2 commit a7668e0
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/documentation/new.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ Default applications are created in a directory of the same name, with an initia
</p>
</details>

<details>
<summary>minimal</summary>
<p>
<code>--minimal</code> <em>default value: false</em>
</p>
<p>
Should create a minimal app.
</p>
</details>

<details>
<summary>prefix</summary>
<p>
Expand Down
4 changes: 2 additions & 2 deletions packages/@angular/cli/blueprints/ng/files/__path__/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<title><%= jsComponentName %></title>
<base href="/">

<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1"><% if (!minimal) { %>
<link rel="icon" type="image/x-icon" href="favicon.ico"><% } %>
</head>
<body>
<<%= prefix %>-root></<%= prefix %>-root>
Expand Down
27 changes: 25 additions & 2 deletions packages/@angular/cli/blueprints/ng/files/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,30 @@
}
},
"defaults": {
"styleExt": "<%= styleExt %>",
"component": {}
"styleExt": "<%= styleExt %>",<% if (!minimal) { %>
"component": {}<% } else { %>
"component": {
"spec": false,
"inlineStyle": true,
"inlineTemplate": true
},
"directive": {
"spec": false
},
"class": {
"spec": false
},
"guard": {
"spec": false
},
"module": {
"spec": false
},
"pipe": {
"spec": false
},
"service": {
"spec": false
} <% } %>
}
}
11 changes: 7 additions & 4 deletions packages/@angular/cli/blueprints/ng/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build": "ng build",<% if (!minimal){ %>
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"e2e": "ng e2e"<% } else { %>
"test": "echo \"Error: no test... minimal project\" && exit 1",
"lint": "echo \"Error: no lint... minimal project\" && exit 1",
"e2e": "echo \"Error: no e2e... minimal project\" && exit 1"<% } %>
},
"private": true,
"dependencies": {
Expand All @@ -28,7 +31,7 @@
"devDependencies": {
"@angular/cli": "<%= version %>",
"@angular/compiler-cli": "^4.0.0",
"@angular/language-service": "^4.0.0",
"@angular/language-service": "^4.0.0",<% if (!minimal) { %>
"@types/jasmine": "2.5.45",
"@types/node": "~6.0.60",
"codelyzer": "~3.0.1",
Expand All @@ -42,7 +45,7 @@
"karma-coverage-istanbul-reporter": "^1.2.1",
"protractor": "~5.1.2",
"ts-node": "~3.0.4",
"tslint": "~5.3.2",
"tslint": "~5.3.2",<% } %>
"typescript": "~2.3.3"
}
}
24 changes: 22 additions & 2 deletions packages/@angular/cli/blueprints/ng/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export default Blueprint.extend({
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] }
{ name: 'skip-git', type: Boolean, default: false, aliases: ['sg'] },
{ name: 'minimal',
type: Boolean,
default: false,
description: 'Should create a minimal app.'
}
],

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

locals: function(options: any) {
if (options.minimal) {
options.inlineStyle = true;
options.inlineTemplate = true;
options.skipTests = true;
}

this.styleExt = options.style === 'stylus' ? 'styl' : options.style;
if (!options.style) {
this.styleExt = CliConfig.getValue('defaults.styleExt') || 'css';
Expand Down Expand Up @@ -54,7 +65,8 @@ export default Blueprint.extend({
routing: options.routing,
inlineStyle: options.inlineStyle,
inlineTemplate: options.inlineTemplate,
tests: this.tests
tests: this.tests,
minimal: options.minimal
};
},

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

if (this.options && this.options.minimal) {
const toRemoveList: RegExp[] = [/e2e\//, /editorconfig/, /README/, /karma.conf.js/,
/protractor.conf.js/, /test.ts/, /tsconfig.spec.json/, /tslint.json/, /favicon.ico/];
fileList = fileList.filter(p => {
return !toRemoveList.some(re => re.test(p));
});
}

const cliConfig = CliConfig.fromProject();
const ngConfig = cliConfig && cliConfig.config;
if (!ngConfig || ngConfig.packageManager != 'yarn') {
Expand Down
8 changes: 7 additions & 1 deletion packages/@angular/cli/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const InitCommand: any = Command.extend({
{ name: 'prefix', type: String, default: 'app', aliases: ['p'] },
{ name: 'routing', type: Boolean, default: false },
{ name: 'inline-style', type: Boolean, default: false, aliases: ['is'] },
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] }
{ name: 'inline-template', type: Boolean, default: false, aliases: ['it'] },
{
name: 'minimal',
type: Boolean,
default: false,
description: 'Should create a minimal app.'
}
],

anonymousOptions: ['<glob-pattern>'],
Expand Down
6 changes: 6 additions & 0 deletions packages/@angular/cli/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ const NewCommand = Command.extend({
default: false,
aliases: ['it'],
description: 'Should have an inline template.'
},
{
name: 'minimal',
type: Boolean,
default: false,
description: 'Should create a minimal app.'
}
],

Expand Down
1 change: 1 addition & 0 deletions packages/@angular/cli/tasks/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default Task.extend({
routing: commandOptions.routing,
inlineStyle: commandOptions.inlineStyle,
inlineTemplate: commandOptions.inlineTemplate,
minimal: commandOptions.minimal,
ignoredUpdateFiles: ['favicon.ico'],
skipGit: commandOptions.skipGit,
skipTests: commandOptions.skipTests
Expand Down
28 changes: 28 additions & 0 deletions tests/e2e/tests/commands/new/new-minimal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {ng} from '../../../utils/process';
import {createProject} from '../../../utils/project';
import {expectFileNotToExist, expectFileToMatch} from '../../../utils/fs';
import {expectToFail} from '../../../utils/utils';


export default function() {
return Promise.resolve()
.then(() => createProject('minimal-project', '--minimal'))
.then(() => expectFileNotToExist('.editorconfig'))
.then(() => expectFileNotToExist('README.md'))
.then(() => expectFileNotToExist('karma.conf.js'))
.then(() => expectFileNotToExist('protractor.conf.js'))
.then(() => expectFileNotToExist('src/test.ts'))
.then(() => expectFileNotToExist('src/tsconfig.spec.json'))
.then(() => expectFileNotToExist('tslint.json'))
.then(() => expectFileNotToExist('src/app/app.component.html'))
.then(() => expectFileNotToExist('src/app/app.component.css'))
.then(() => expectFileNotToExist('src/app/app.component.spec.ts'))
.then(() => expectFileNotToExist('src/app/favicon.ico'))

.then(() => expectToFail(() => expectFileToMatch('package.json', '"protractor":')))
.then(() => expectToFail(() => expectFileToMatch('package.json', '"karma":')))
.then(() => expectToFail(() => expectFileToMatch('package.json', '"jasmine-core":')))

// Try to run a build.
.then(() => ng('build'));
}

0 comments on commit a7668e0

Please sign in to comment.