Skip to content

Commit 907ce5c

Browse files
rsarkyvikerman
authored andcommitted
feat(@schematics/angular): Add --minimal flag to generate a barebones (#12498)
project
1 parent 2bdf99b commit 907ce5c

File tree

7 files changed

+38
-5
lines changed

7 files changed

+38
-5
lines changed

packages/schematics/angular/application/index.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
240240
return addProjectToWorkspace(workspace, options.name, project);
241241
}
242242

243+
function minimalPathFilter(path: string): boolean {
244+
const toRemoveList: RegExp[] = [/e2e\//, /editorconfig/, /README/, /karma.conf.js/,
245+
/protractor.conf.js/, /test.ts/, /tsconfig.spec.json/,
246+
/tslint.json/, /favicon.ico/];
247+
248+
return !toRemoveList.some(re => re.test(path));
249+
}
250+
243251
export default function (options: ApplicationOptions): Rule {
244252
return (host: Tree, context: SchematicContext) => {
245253
if (!options.name) {
@@ -248,12 +256,19 @@ export default function (options: ApplicationOptions): Rule {
248256
validateProjectName(options.name);
249257
const prefix = options.prefix || 'app';
250258
const appRootSelector = `${prefix}-root`;
251-
const componentOptions = {
259+
const componentOptions = !options.minimal ?
260+
{
252261
inlineStyle: options.inlineStyle,
253262
inlineTemplate: options.inlineTemplate,
254263
spec: !options.skipTests,
255264
styleext: options.style,
256265
viewEncapsulation: options.viewEncapsulation,
266+
} :
267+
{
268+
inlineStyle: true,
269+
InlineTemplate: true,
270+
spec: false,
271+
styleext: options.style,
257272
};
258273

259274
const workspace = getWorkspace(host);
@@ -287,6 +302,7 @@ export default function (options: ApplicationOptions): Rule {
287302
options.skipPackageJson ? noop() : addDependenciesToPackageJson(),
288303
mergeWith(
289304
apply(url('./files/src'), [
305+
options.minimal ? filter(minimalPathFilter) : noop(),
290306
template({
291307
utils: strings,
292308
...options,
@@ -297,6 +313,7 @@ export default function (options: ApplicationOptions): Rule {
297313
])),
298314
mergeWith(
299315
apply(url('./files/root'), [
316+
options.minimal ? filter(minimalPathFilter) : noop(),
300317
template({
301318
utils: strings,
302319
...options,
@@ -308,6 +325,7 @@ export default function (options: ApplicationOptions): Rule {
308325
])),
309326
mergeWith(
310327
apply(url('./files/lint'), [
328+
options.minimal ? filter(minimalPathFilter) : noop(),
311329
template({
312330
utils: strings,
313331
...options,

packages/schematics/angular/application/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
"type": "boolean",
6767
"default": false,
6868
"description": "Do not add dependencies to package.json."
69+
},
70+
"minimal": {
71+
"description": "Create a barebones project without any testing frameworks",
72+
"type": "boolean",
73+
"default": false
6974
}
7075
},
7176
"required": [

packages/schematics/angular/ng-new/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default function (options: NgNewOptions): Rule {
4242
version: options.version,
4343
experimentalAngularNext: options.experimentalIvy,
4444
newProjectRoot: options.newProjectRoot || 'projects',
45+
minimal: options.minimal,
4546
};
4647
const applicationOptions: ApplicationOptions = {
4748
projectRoot: '',

packages/schematics/angular/ng-new/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@
136136
"description": "Flag to toggle creation of an application in the new workspace.",
137137
"type": "boolean",
138138
"default": true
139+
},
140+
"minimal": {
141+
"description": "Create a barebones project without any testing frameworks",
142+
"type": "boolean",
143+
"default": false
139144
}
140145
},
141146
"required": [

packages/schematics/angular/workspace/files/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
"@angular/cli": "<%= experimentalAngularNext ? 'next' : '~' + version %>",
2929
"@angular/compiler-cli": "<%= experimentalAngularNext ? 'next' : latestVersions.Angular %>",
3030
"@angular/language-service": "<%= experimentalAngularNext ? 'next' : latestVersions.Angular %>",
31-
"@types/jasmine": "~2.8.8",
32-
"@types/jasminewd2": "~2.0.3",
3331
"@types/node": "~8.9.4",
32+
<% if (!minimal) { %>"@types/jasmine": "~2.8.8",
33+
"@types/jasminewd2": "~2.0.3",
3434
"codelyzer": "~4.3.0",
3535
"jasmine-core": "~2.99.1",
3636
"jasmine-spec-reporter": "~4.2.1",
@@ -39,7 +39,7 @@
3939
"karma-coverage-istanbul-reporter": "~2.0.1",
4040
"karma-jasmine": "~1.1.2",
4141
"karma-jasmine-html-reporter": "^0.2.2",
42-
"protractor": "~5.4.0",
42+
"protractor": "~5.4.0",<% } %>
4343
"ts-node": "~7.0.0",
4444
"tslint": "~5.11.0",
4545
"typescript": "<%= latestVersions.TypeScript %>"

packages/schematics/angular/workspace/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@
7373
"$default": {
7474
"$source": "ng-cli-version"
7575
}
76+
},
77+
"minimal": {
78+
"description": "Create a barebones project without any testing frameworks",
79+
"type": "boolean",
80+
"default": false
7681
}
7782
},
7883
"required": [

tests/legacy-cli/e2e_runner.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ const allTests = glob.sync(path.join(e2eRoot, testGlob), { nodir: true, ignore:
114114
// Replace windows slashes.
115115
.map(name => name.replace(/\\/g, '/'))
116116
.filter(name => !name.endsWith('/build-app-shell-with-schematic.ts'))
117-
.filter(name => !name.endsWith('/new-minimal.ts'))
118117
// IS this test still valid? \/
119118
.filter(name => !name.endsWith('/module-id.ts'))
120119
// Do we want to support this?

0 commit comments

Comments
 (0)