UNPKG

@jamarsto/kiunzi-micro-frontend-tools

Version:
79 lines 3.44 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.libraryType = void 0; const schematics_1 = require("@angular-devkit/schematics"); const core_1 = require("@angular-devkit/core"); function libraryType(options) { return (0, schematics_1.chain)([ generateAppFiles(options) ]); } exports.libraryType = libraryType; function generateAppFiles(options) { return (tree) => __awaiter(this, void 0, void 0, function* () { const host = createHost(tree); const { workspace } = yield core_1.workspaces.readWorkspace('/', host); const libProject = validateProject(workspace, options.project); const libTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)(`./files/library`), [ (0, schematics_1.applyTemplates)({ classify: core_1.strings.classify, dasherize: core_1.strings.dasherize, authority: options.authority, client: options.client }), (0, schematics_1.move)((0, core_1.normalize)(libProject.root)) ]); return (0, schematics_1.chain)([ (0, schematics_1.mergeWith)(libTemplateSource, schematics_1.MergeStrategy.AllowCreationConflict) ]); }); } function validateProject(workspace, name) { const project = workspace.projects.get(name); if (!project) { throw new schematics_1.SchematicsException(`Project '${name}' not found!`); } const projectType = project.extensions['projectType']; if (projectType !== 'library') { throw new schematics_1.SchematicsException(`Project '${name}' is not of type 'library'!`); } return project; } function createHost(tree) { return { readFile(path) { return __awaiter(this, void 0, void 0, function* () { const data = tree.read(path); if (!data) { throw new schematics_1.SchematicsException('File not found.'); } return core_1.virtualFs.fileBufferToString(data); }); }, writeFile(path, data) { return __awaiter(this, void 0, void 0, function* () { return tree.overwrite(path, data); }); }, isDirectory(path) { return __awaiter(this, void 0, void 0, function* () { return !tree.exists(path) && tree.getDir(path).subfiles.length > 0; }); }, isFile(path) { return __awaiter(this, void 0, void 0, function* () { return tree.exists(path); }); }, }; } //# sourceMappingURL=index.js.map