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 vikerman committed Mar 11, 2019
1 parent 9ad9c9d commit 0fca5f7
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
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 @@ -351,8 +348,6 @@ export default function (options: ApplicationOptions): Rule {
projectRoot: newProjectRoot ? `${newProjectRoot}/${options.name}-e2e` : 'e2e',
};

const styleExt = styleToFileExtention(options.style);

return chain([
addAppToWorkspaceFile(options, workspace),
mergeWith(
Expand All @@ -363,7 +358,6 @@ export default function (options: ApplicationOptions): Rule {
...options,
'dot': '.',
relativePathToWorkspaceRoot,
styleExt,
}),
move(sourceRoot),
])),
Expand Down Expand Up @@ -425,7 +419,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
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
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
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
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
Expand Up @@ -253,8 +253,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
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 0fca5f7

Please sign in to comment.