From 13662b57a5a9e57b1cd1569e792f46b9c2a9e1f6 Mon Sep 17 00:00:00 2001 From: Cyrille Tuzi Date: Tue, 8 May 2018 14:51:28 +0200 Subject: [PATCH] feat(@schematics/angular): editor option --- packages/schematics/angular/ng-new/index.ts | 1 + packages/schematics/angular/ng-new/index_spec.ts | 8 ++++++++ packages/schematics/angular/ng-new/schema.d.ts | 4 ++++ packages/schematics/angular/ng-new/schema.json | 5 +++++ .../angular/workspace/files/__dot__vscode/settings.json | 3 +++ packages/schematics/angular/workspace/index.ts | 3 +++ packages/schematics/angular/workspace/index_spec.ts | 8 ++++++++ packages/schematics/angular/workspace/schema.d.ts | 4 ++++ packages/schematics/angular/workspace/schema.json | 5 +++++ 9 files changed, 41 insertions(+) create mode 100644 packages/schematics/angular/workspace/files/__dot__vscode/settings.json diff --git a/packages/schematics/angular/ng-new/index.ts b/packages/schematics/angular/ng-new/index.ts index 1728de90fd..7b85f0489e 100644 --- a/packages/schematics/angular/ng-new/index.ts +++ b/packages/schematics/angular/ng-new/index.ts @@ -40,6 +40,7 @@ export default function (options: NgNewOptions): Rule { name: options.name, version: options.version, newProjectRoot: options.newProjectRoot || 'projects', + editor: options.editor, }; const applicationOptions: ApplicationOptions = { projectRoot: '', diff --git a/packages/schematics/angular/ng-new/index_spec.ts b/packages/schematics/angular/ng-new/index_spec.ts index fb25a4d41f..04a386805f 100644 --- a/packages/schematics/angular/ng-new/index_spec.ts +++ b/packages/schematics/angular/ng-new/index_spec.ts @@ -46,4 +46,12 @@ describe('Ng New Schematic', () => { const content = tree.readContent('/bar/angular.json'); expect(content).toMatch(/"prefix": "pre"/); }); + + it('should create VS Code settings', () => { + const options: NgNewOptions = { ...defaultOptions, editor: 'vscode' }; + + const tree = schematicRunner.runSchematic('ng-new', options); + const files = tree.files; + expect(files.indexOf('/bar/.vscode/settings.json')).toBeGreaterThanOrEqual(0); + }); }); diff --git a/packages/schematics/angular/ng-new/schema.d.ts b/packages/schematics/angular/ng-new/schema.d.ts index dfdc8f1082..03791fe23a 100644 --- a/packages/schematics/angular/ng-new/schema.d.ts +++ b/packages/schematics/angular/ng-new/schema.d.ts @@ -67,4 +67,8 @@ export interface Schema { * Skip creating spec files. */ skipTests?: boolean; + /** + * Specifies the editor used, for specific configuration. + */ + editor?: ('vscode'); } diff --git a/packages/schematics/angular/ng-new/schema.json b/packages/schematics/angular/ng-new/schema.json index 9a53a97e89..e3608028e0 100644 --- a/packages/schematics/angular/ng-new/schema.json +++ b/packages/schematics/angular/ng-new/schema.json @@ -111,6 +111,11 @@ "type": "boolean", "default": false, "alias": "S" + }, + "editor": { + "description": "Specifies the editor used, for specific configuration.", + "enum": ["vscode"], + "type": "string" } }, "required": [ diff --git a/packages/schematics/angular/workspace/files/__dot__vscode/settings.json b/packages/schematics/angular/workspace/files/__dot__vscode/settings.json new file mode 100644 index 0000000000..d7af577958 --- /dev/null +++ b/packages/schematics/angular/workspace/files/__dot__vscode/settings.json @@ -0,0 +1,3 @@ +{ + "tslint.alwaysShowRuleFailuresAsWarnings": true +} diff --git a/packages/schematics/angular/workspace/index.ts b/packages/schematics/angular/workspace/index.ts index 98f9aa0069..8047766c71 100644 --- a/packages/schematics/angular/workspace/index.ts +++ b/packages/schematics/angular/workspace/index.ts @@ -11,7 +11,9 @@ import { SchematicContext, Tree, apply, + filter, mergeWith, + noop, template, url, } from '@angular-devkit/schematics'; @@ -22,6 +24,7 @@ export default function (options: WorkspaceOptions): Rule { return (host: Tree, context: SchematicContext) => { return mergeWith(apply(url('./files'), [ + options.editor === 'vscode' ? noop() : filter(path => path.indexOf('vscode') === -1), template({ utils: strings, ...options, diff --git a/packages/schematics/angular/workspace/index_spec.ts b/packages/schematics/angular/workspace/index_spec.ts index 669403396c..ee0992f8f9 100644 --- a/packages/schematics/angular/workspace/index_spec.ts +++ b/packages/schematics/angular/workspace/index_spec.ts @@ -55,4 +55,12 @@ describe('Workspace Schematic', () => { expect(pkg.dependencies['zone.js']).toEqual(latestVersions.ZoneJs); expect(pkg.devDependencies['typescript']).toEqual(latestVersions.TypeScript); }); + + it('should create VS Code settings', () => { + const options: WorkspaceOptions = { ...defaultOptions, editor: 'vscode' }; + + const tree = schematicRunner.runSchematic('workspace', options); + const files = tree.files; + expect(files.indexOf('/.vscode/settings.json')).toBeGreaterThanOrEqual(0); + }); }); diff --git a/packages/schematics/angular/workspace/schema.d.ts b/packages/schematics/angular/workspace/schema.d.ts index 0db451ca11..cd810ac8cd 100644 --- a/packages/schematics/angular/workspace/schema.d.ts +++ b/packages/schematics/angular/workspace/schema.d.ts @@ -35,4 +35,8 @@ export interface Schema { * The version of the Angular CLI to use. */ version?: string; + /** + * Specifies the editor used, for specific configuration. + */ + editor?: ('vscode'); } diff --git a/packages/schematics/angular/workspace/schema.json b/packages/schematics/angular/workspace/schema.json index 81e2a50423..0b7b4b285a 100644 --- a/packages/schematics/angular/workspace/schema.json +++ b/packages/schematics/angular/workspace/schema.json @@ -65,6 +65,11 @@ "type": "string", "description": "The version of the Angular CLI to use.", "visible": false + }, + "editor": { + "description": "Specifies the editor used, for specific configuration.", + "enum": ["vscode"], + "type": "string" } }, "required": [