Skip to content

Commit

Permalink
Merge pull request #439 from IgniteUI/bpenkov/cli-config-theme-import…
Browse files Browse the repository at this point in the history
…-fix

Add default styles to angular workspace for sass projects
  • Loading branch information
bazal4o authored Feb 8, 2019
2 parents f73abc9 + 57e848b commit 1a18ed3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
19 changes: 17 additions & 2 deletions schematics/cli-config/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ describe("cli-config schematic", () => {
});

it("should add the default css theme to the workspace", () => {
const cssFile = "/src/styles.css";
tree.create(cssFile, "");
const targetFile = "/angular.json";
expect(tree.exists(targetFile)).toBeTruthy();

Expand All @@ -127,6 +125,23 @@ describe("cli-config schematic", () => {
.toBeGreaterThan(0);
});

it("should not add the default css theme to the workspace if the global styles file is scss", () => {
// if the global styles file is scss or sass - the default theme is imported there
const stylesheet = "/src/styles.scss";
tree.create(stylesheet, "");
const targetFile = "/angular.json";
expect(tree.exists(targetFile)).toBeTruthy();

runner.runSchematic("cli-config", {}, tree);
const workspace = getWorkspace(tree) as any;
const currentProjectName = workspace.defaultProject;

// the schematic creates the hierarchy that leads to the styles object within the workspace,
// providing that it is not already present
expect(workspace.projects[currentProjectName].architect.build).toBeFalsy();
expect(workspace.projects[currentProjectName].architect.test).toBeFalsy();
});

it("should add the default sass theme correctly", () => {
const targetFile = "/src/styles.sass";
tree.create(targetFile, "");
Expand Down
7 changes: 4 additions & 3 deletions schematics/utils/theme-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ const sassImports =
export function importDefaultTheme(tree: Tree): Tree {
if (tree.exists("/src/styles.sass")) {
importDefaultThemeSass(tree, "sass");
return tree;
} else if (tree.exists("/src/styles.scss")) {
importDefaultThemeSass(tree, "scss");
} else if (tree.exists("/src/styles.css")) {
importDefaultThemeCss(tree);
return tree;
}

importIgDefaultTheme(tree);
return tree;
}

Expand Down Expand Up @@ -59,7 +60,7 @@ function importDefaultThemeSass(tree: Tree, ext: string): Tree {
return tree;
}

function importDefaultThemeCss(tree: Tree): Tree {
function importIgDefaultTheme(tree: Tree): Tree {
const targetFile = "/angular.json";
const workspace = getWorkspace(tree);
const importedStylesToBuild = importDefaultThemeToAngularWorkspace(workspace, "build");
Expand Down

0 comments on commit 1a18ed3

Please sign in to comment.