Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions packages/cli/lib/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const command: BuildCommandType = {
t: "screenview",
cd: "Build"
});
command.build(argv);
await command.build();
},
async build() {
Util.log("Build started.");
Expand All @@ -39,22 +39,15 @@ const command: BuildCommandType = {

await PackageManager.installPackages();
if (config.project.theme.includes(".less") || config.project.theme.includes(".sass")) {
fs.mkdirSync("./themes");
const source = path.join(config.project.igniteuiSource, "/css/themes/", config.project.theme.split(".")[0]);
const source = path.join(config.project.igniteuiSource, "css", "themes", config.project.theme.split(".")[0]);
const destination = path.join(config.project.sourceRoot, "themes");

Util.ensureDirectoryExists(destination);
if (!Util.isDirectory(source)) {
fs.copyFileSync(source, destination);
return;
if (Util.isDirectory(source)) {
fs.cpSync(source, destination, { recursive: true, force: true });
} else {
fs.copyFileSync(source, path.join(destination, path.basename(source)));
}

const entries = fs.readdirSync(source, { withFileTypes: true });
entries.forEach((entry) => {
const sourcePath = path.join(source, entry.name);
const destinationPath = path.join(destination, entry.name);
fs.copyFileSync(sourcePath, destinationPath);
});
}
}
};
Expand Down
61 changes: 61 additions & 0 deletions spec/unit/build-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { App, Config, GoogleAnalytics, PackageManager, ProjectConfig, TEMPLATE_MANAGER, Util } from "@igniteui/cli-core";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import { default as buildCmd } from "../../packages/cli/lib/commands/build";

describe("Unit - Build command", () => {
let originalCwd: string;
let tempRoot: string;

beforeEach(() => {
originalCwd = process.cwd();
tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "igniteui-build-"));

spyOn(GoogleAnalytics, "post");
spyOn(Util, "log");
spyOn(Util, "ensureDirectoryExists").and.callFake((directory: string) => fs.mkdirSync(directory, { recursive: true }));
spyOn(Util, "isDirectory").and.callFake((directory: string) => fs.statSync(directory).isDirectory());
spyOn(ProjectConfig, "hasLocalConfig").and.returnValue(true);
spyOn(PackageManager, "ensureIgniteUISource").and.returnValue(Promise.resolve());
spyOn(PackageManager, "installPackages").and.returnValue(Promise.resolve());

App.container.set(TEMPLATE_MANAGER, jasmine.createSpyObj("TemplateManager", ["getProjectLibrary"]));
});

afterEach(() => {
process.chdir(originalCwd);
fs.rmSync(tempRoot, { recursive: true, force: true });
});

describe("jQuery", () => {
it("Should recursively copy theme folders into the project themes directory", async () => {
const igniteuiSource = path.join(tempRoot, "node_modules", "ignite-ui");
const sourceRoot = path.join(tempRoot, "project");
const sourceThemeRoot = path.join(igniteuiSource, "css", "themes", "infragistics");
const sourceImage = path.join(sourceThemeRoot, "images", "foo.png");

fs.mkdirSync(path.dirname(sourceImage), { recursive: true });
fs.mkdirSync(sourceRoot, { recursive: true });
fs.writeFileSync(path.join(sourceThemeRoot, "infragistics.theme.css"), "theme css");
fs.writeFileSync(sourceImage, "image asset");
process.chdir(sourceRoot);

const config = {
project: {
framework: "jquery",
igniteuiSource,
sourceRoot,
theme: "infragistics.less"
}
} as Config;
spyOn(ProjectConfig, "getConfig").and.returnValue(config);

await buildCmd.build();

const copiedImage = path.join(sourceRoot, "themes", "images", "foo.png");
expect(fs.existsSync(path.join(sourceRoot, "themes", "infragistics.theme.css"))).toBeTrue();
expect(fs.readFileSync(copiedImage, "utf8")).toBe("image asset");
});
});
});