@nakedobjects/schematics
Version:
Schematics for Naked Objects
90 lines • 4.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.newProject = void 0;
const schematics_1 = require("@angular-devkit/schematics");
function getUpdateFiles(localFiles) {
return [
{ path: "src/app/app.module.ts", file: localFiles.get("code/module") },
{ path: "src/app/app.component.ts", file: localFiles.get("code/component") },
{ path: "src/app/app.component.html", file: localFiles.get("code/component_template") },
{ path: "src/styles.css", file: localFiles.get("assets/styles.css") },
{ path: "src/index.html", file: localFiles.get("assets/index.html") },
];
}
function getCreateFiles(localFiles) {
return [
{ path: "src/app/app-routing.module.ts", file: localFiles.get("code/routing") },
{ path: "src/config.json", file: localFiles.get("code/config") },
{ path: "src/assets/alt.calendar.png", file: localFiles.get("assets/alt.calendar.png") },
{ path: "src/assets/alt.list.png", file: localFiles.get("assets/alt.list.png") },
{ path: "src/assets/alt.summary.png", file: localFiles.get("assets/alt.summary.png") },
{ path: "src/assets/alt.table.png", file: localFiles.get("assets/alt.table.png") },
{ path: "src/assets/calendar.png", file: localFiles.get("assets/calendar.png") },
{ path: "src/assets/list.png", file: localFiles.get("assets/list.png") },
{ path: "src/assets/summary.png", file: localFiles.get("assets/summary.png") },
{ path: "src/assets/table.png", file: localFiles.get("assets/table.png") },
{ path: "src/assets/pencil.png", file: localFiles.get("assets/pencil.png") },
{ path: "src/fonts/iconFont.eot", file: localFiles.get("fonts/iconFont.eot") },
{ path: "src/fonts/iconFont.svg", file: localFiles.get("fonts/iconFont.svg") },
{ path: "src/fonts/iconFont.ttf", file: localFiles.get("fonts/iconFont.ttf") },
{ path: "src/fonts/iconFont.woff", file: localFiles.get("fonts/iconFont.woff") },
{ path: "src/fonts/license.txt", file: localFiles.get("fonts/license.txt") },
{ path: "src/theme.css", file: localFiles.get("assets/theme.css") },
{ path: "src/theme.alt.css", file: localFiles.get("assets/theme.alt.css") },
];
}
function updateFile(remoteFiles, { path, file }) {
if (!file) {
console.log(`missing: ${path}`);
}
remoteFiles.overwrite(path, file.content);
}
function createFile(remoteFiles, { path, file }) {
if (!file) {
console.log(`missing: ${path}`);
}
remoteFiles.create(path, file.content);
}
// You don't have to export the function as default. You can also have more than one rule factory
// per file.
function newProject( /* options: any */) {
return (tree, _context) => {
const localFiles = (0, schematics_1.url)("./files")(_context);
const updateFiles = getUpdateFiles(localFiles);
const createFiles = getCreateFiles(localFiles);
if (updateFiles.length > 0) {
updateFiles.forEach(f => updateFile(tree, f));
}
if (createFiles.length > 0) {
createFiles.forEach(f => createFile(tree, f));
}
const config = tree.read(".angular-cli.json");
if (config) {
const asJson = JSON.parse(config.toString());
asJson.apps[0].assets.push("config.json");
tree.overwrite(".angular-cli.json", JSON.stringify(asJson, null, 2));
}
// angular 6
const configA6 = tree.read("angular.json");
if (configA6) {
const asJson = JSON.parse(configA6.toString());
Object.entries(asJson.projects).forEach(([, value]) => {
const options = value.architect &&
value.architect.build &&
value.architect.build.options;
const assets = options && options.assets;
if (assets) {
assets.push("src/config.json");
}
const styles = options && options.styles;
if (styles) {
styles.push("src/theme.css");
}
});
tree.overwrite("angular.json", JSON.stringify(asJson, null, 2));
}
return tree;
};
}
exports.newProject = newProject;
//# sourceMappingURL=index.js.map