UNPKG

ng-afelio

Version:
120 lines (119 loc) 4.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@angular-devkit/core"); const schematics_1 = require("@angular-devkit/schematics"); const workspace_1 = require("@schematics/angular/utility/workspace"); // function installNgxBuildPlus(mustApplyInstall: boolean): Rule { // return (host: Tree, context: SchematicContext) => { // const builder: NodeDependency = { // type: NodeDependencyType.Dev, // name: 'ngx-build-plus', // version: '^10.1.1', // overwrite: true, // }; // const untilDestroy: NodeDependency = { // type: NodeDependencyType.Default, // name: '@ngneat/until-destroy', // version: '^8.0.3', // overwrite: true, // }; // addPackageJsonDependency(host, builder); // addPackageJsonDependency(host, untilDestroy); // if (mustApplyInstall) { // context.addTask(new NodePackageInstallTask(), []); // } // }; // } function updateConfig() { // function setOption(target: TargetDefinition) { // if (!target.options) { // target.options = {}; // } // target.options['plugin'] = 'ng-afelio/builders/plugin.js'; // } return (0, workspace_1.updateWorkspace)((workspace) => { // for (const [, project] of workspace.projects) { // for (const [name, target] of project.targets) { // switch (name) { // case 'build': // target.builder = 'ngx-build-plus:browser'; // setOption(target); // break; // case 'serve': // target.builder = 'ngx-build-plus:dev-server'; // setOption(target); // break; // case 'test': // target.builder = 'ngx-build-plus:karma'; // setOption(target); // break; // default: // break; // } // } // } if (!workspace.extensions['cli']) { workspace.extensions['cli'] = {}; } workspace.extensions['cli']['schematicCollections'] = [ 'ng-afelio', '@schematics/angular' ]; }); } function updateScripts() { return (host) => { const packageFile = '/package.json'; const text = host.read(packageFile); if (!text) { throw new schematics_1.SchematicsException(`Can not find "package.json" file in your project.`); } const sourceText = text.toString('utf8'); const toInsert = `"start": "ng-afelio start"`; const alreadyInstalled = sourceText.indexOf(toInsert) !== -1; if (!alreadyInstalled) { const toReplaceMatch = sourceText.match(/"start": "(.+)"/); if (toReplaceMatch) { const jsonContent = JSON.parse(sourceText); jsonContent.scripts['ng-afelio'] = 'ng-afelio'; jsonContent.scripts['start'] = 'ng-afelio serve'; jsonContent.scripts['build'] = 'ng-afelio build'; host.overwrite(packageFile, JSON.stringify(jsonContent, null, 2)); } } return host; }; } function default_1(options) { return async (host) => { // const workspace = await getWorkspace(host); // const project = workspace.projects.get(options.project); // if (!project) { // throw new SchematicsException(`Project "${options.project}" not found.`); // } const templateSource = (0, schematics_1.apply)((0, schematics_1.url)('./files'), [ (0, schematics_1.template)({ ...core_1.strings, ...options, }), (0, schematics_1.move)('/'), ]); const templateConfigSource = (0, schematics_1.apply)((0, schematics_1.url)('../../templates/config'), [ (0, schematics_1.move)('/'), ]); const uiKitToInstall = options.uiKit && options.uiKit !== 'none'; return (0, schematics_1.chain)([ (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([ (0, schematics_1.mergeWith)(templateConfigSource), (0, schematics_1.mergeWith)(templateSource, schematics_1.MergeStrategy.Overwrite), // installNgxBuildPlus(!uiKitToInstall), updateConfig(), updateScripts(), ...(uiKitToInstall ? [ (0, schematics_1.schematic)('install-uikit', { type: options.uiKit }), ] : []), ])), ]); }; } exports.default = default_1;