@jamarsto/kiunzi-micro-frontend-tools
Version:
Kiunzi framework Micro-frontend scaffolding
81 lines • 3.69 kB
JavaScript
;
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.applicationType = void 0;
const schematics_1 = require("@angular-devkit/schematics");
const core_1 = require("@angular-devkit/core");
function applicationType(options) {
return (0, schematics_1.chain)([
(0, schematics_1.externalSchematic)('@angular-architects/module-federation', 'ng-add', { project: options.project, port: options.port }),
generateAppFiles(options)
]);
}
exports.applicationType = applicationType;
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 appProject = validateProject(workspace, 'application', options.project);
validateProject(workspace, 'library', options.library);
const appTemplateSource = (0, schematics_1.apply)((0, schematics_1.url)(`./files/${options.type}`), [
(0, schematics_1.applyTemplates)({
classify: core_1.strings.classify,
dasherize: core_1.strings.dasherize,
project: options.project,
library: options.library
}),
(0, schematics_1.move)((0, core_1.normalize)(appProject.root))
]);
return (0, schematics_1.chain)([
(0, schematics_1.mergeWith)(appTemplateSource, schematics_1.MergeStrategy.AllowCreationConflict)
]);
});
}
function validateProject(workspace, type, 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 !== type) {
throw new schematics_1.SchematicsException(`Project '${name}' is not of type '${type}'!`);
}
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