Skip to content

Commit

Permalink
fix(@schematics/angular): reintroduce .sass as a supported file ext…
Browse files Browse the repository at this point in the history
…ention

Sass Indented (.sass) is fully supported by the Sass team and we should still offer and support it.

Fixes #13739
  • Loading branch information
Alan authored and hansl committed Mar 4, 2019
1 parent d1a0697 commit 08c4cb7
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 31 deletions.
11 changes: 2 additions & 9 deletions packages/schematics/angular/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
url,
} from '@angular-devkit/schematics';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import { styleToFileExtention } from '../component/index';
import { Schema as ComponentOptions } from '../component/schema';
import { Schema as E2eOptions } from '../e2e/schema';
import {
Expand Down Expand Up @@ -187,8 +186,6 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
});
}

const styleExt = styleToFileExtention(options.style);

const project: WorkspaceProject = {
root: projectRoot,
sourceRoot: join(normalize(projectRoot), 'src'),
Expand All @@ -209,7 +206,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
join(normalize(projectRoot), 'src', 'assets'),
],
styles: [
`${projectRoot}src/styles.${styleExt}`,
`${projectRoot}src/styles.${options.style}`,
],
scripts: [],
es5BrowserSupport: true,
Expand Down Expand Up @@ -262,7 +259,7 @@ function addAppToWorkspaceFile(options: ApplicationOptions, workspace: Workspace
tsConfig: `${rootFilesRoot}tsconfig.spec.json`,
karmaConfig: `${rootFilesRoot}karma.conf.js`,
styles: [
`${projectRoot}src/styles.${styleExt}`,
`${projectRoot}src/styles.${options.style}`,
],
scripts: [],
assets: [
Expand Down Expand Up @@ -349,8 +346,6 @@ export default function (options: ApplicationOptions): Rule {
rootSelector: appRootSelector,
};

const styleExt = styleToFileExtention(options.style);

return chain([
addAppToWorkspaceFile(options, workspace),
mergeWith(
Expand All @@ -361,7 +356,6 @@ export default function (options: ApplicationOptions): Rule {
...options,
'dot': '.',
relativePathToWorkspaceRoot,
styleExt,
}),
move(sourceRoot),
])),
Expand Down Expand Up @@ -423,7 +417,6 @@ export default function (options: ApplicationOptions): Rule {
...options as any, // tslint:disable-line:no-any
selector: appRootSelector,
...componentOptions,
styleExt,
}),
move(sourceDir),
]), MergeStrategy.Overwrite),
Expand Down
6 changes: 3 additions & 3 deletions packages/schematics/angular/application/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,13 +302,13 @@ describe('Application Schematic', () => {
const prj = config.projects.foo;
const buildOpt = prj.architect.build.options;
expect(buildOpt.styles).toEqual([
'src/styles.scss',
'src/styles.sass',
]);
const testOpt = prj.architect.test.options;
expect(testOpt.styles).toEqual([
'src/styles.scss',
'src/styles.sass',
]);
expect(tree.exists('src/styles.scss')).toBe(true);
expect(tree.exists('src/styles.sass')).toBe(true);
});

it('should set the relative tsconfig paths', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { Component } from '@angular/core';
`,<% } else { %>
templateUrl: './app.component.html',<% } if(inlineStyle) { %>
styles: []<% } else { %>
styleUrls: ['./app.component.<%= styleExt %>']<% } %>
styleUrls: ['./app.component.<%= style %>']<% } %>
})
export class AppComponent {
title = '<%= name %>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }
`,<% } else { %>
templateUrl: './<%= dasherize(name) %>.component.html',<% } if(inlineStyle) { %>
styles: []<% } else { %>
styleUrls: ['./<%= dasherize(name) %>.component.<%= styleExt %>']<% } %><% if(!!viewEncapsulation) { %>,
styleUrls: ['./<%= dasherize(name) %>.component.<%= style %>']<% } %><% if(!!viewEncapsulation) { %>,
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
})
Expand Down
12 changes: 1 addition & 11 deletions packages/schematics/angular/component/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,12 @@ export default function (options: ComponentOptions): Rule {

const templateSource = apply(url('./files'), [
options.skipTests ? filter(path => !path.endsWith('.spec.ts.template')) : noop(),
options.inlineStyle ? filter(path => !path.endsWith('.__styleExt__.template')) : noop(),
options.inlineStyle ? filter(path => !path.endsWith('.__style__.template')) : noop(),
options.inlineTemplate ? filter(path => !path.endsWith('.html.template')) : noop(),
applyTemplates({
...strings,
'if-flat': (s: string) => options.flat ? '' : s,
...options,
styleExt: styleToFileExtention(options.style),
}),
move(parsedPath.path),
]);
Expand All @@ -172,12 +171,3 @@ export default function (options: ComponentOptions): Rule {
]);
};
}

export function styleToFileExtention(style: Style | undefined): string {
switch (style) {
case Style.Sass:
return 'scss';
default:
return style || 'css';
}
}
4 changes: 2 additions & 2 deletions packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ describe('Component Schematic', () => {
const options = { ...defaultOptions, style: Style.Sass };
const tree = schematicRunner.runSchematic('component', options, appTree);
const content = tree.readContent('/projects/bar/src/app/foo/foo.component.ts');
expect(content).toMatch(/styleUrls: \['.\/foo.component.scss/);
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.component.scss');
expect(content).toMatch(/styleUrls: \['.\/foo.component.sass/);
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.component.sass');
expect(tree.files).not.toContain('/projects/bar/src/app/foo/foo.component.css');
});

Expand Down
9 changes: 5 additions & 4 deletions packages/schematics/angular/ng-new/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@
"message": "Which stylesheet format would you like to use?",
"type": "list",
"items": [
{ "value": "css", "label": "CSS (.css )" },
{ "value": "sass", "label": "Sass (.scss) [ http://sass-lang.com ]" },
{ "value": "less", "label": "Less (.less) [ http://lesscss.org ]" },
{ "value": "styl", "label": "Stylus (.styl) [ http://stylus-lang.com ]" }
{ "value": "css", "label": "CSS" },
{ "value": "scss", "label": "SCSS [ http://sass-lang.com/documentation/file.SASS_REFERENCE.html#syntax ]" },
{ "value": "sass", "label": "Sass [ http://sass-lang.com/documentation/file.INDENTED_SYNTAX.html ]" },
{ "value": "less", "label": "Less [ http://lesscss.org ]" },
{ "value": "styl", "label": "Stylus [ http://stylus-lang.com ] " }
]
}
},
Expand Down

0 comments on commit 08c4cb7

Please sign in to comment.