UNPKG

ng-afelio

Version:
56 lines (55 loc) 2.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schematics_1 = require("@angular-devkit/schematics"); const workspace_1 = require("@schematics/angular/utility/workspace"); const model_converter_1 = require("./model-converter"); function generateModelsRule(folderSource, outputFolder, apiName, clean) { return async (host) => { console.log(clean, (0, model_converter_1.isDir)(folderSource), host.exists(outputFolder), outputFolder); if (clean && (0, model_converter_1.isDir)(folderSource)) { console.log('clean'); try { host.delete(outputFolder); } catch (e) { console.error(e); } } const newHost = await (0, model_converter_1.generateModelsFromGeneratedApi)(folderSource, outputFolder, apiName); return () => host.merge(newHost, schematics_1.MergeStrategy.Overwrite); }; } function default_1(options) { return async (host) => { if (!options.project) { throw new schematics_1.SchematicsException('Option (project) is required.'); } const workspace = await (0, workspace_1.getWorkspace)(host); const project = workspace.projects.get(options.project); console.log('Hello', options, project); if (project && options.path === undefined) { options.path = (0, workspace_1.buildDefaultPath)(project); // options.path = process.cwd(); } // const parsedPath = parseName(options.path as string, options.name); // options.name = parsedPath.name; // options.path = relativeCwdFromRelativeProjectPath(parsedPath.path); // validateName(options.name); // const templateSource = apply(url('./files'), [ // options.spec ? noop() : filter(p => !p.endsWith('.spec.ts')), // template({ // ...strings, // ...options, // }), // move(parsedPath.path), // ]); return (0, schematics_1.chain)([ (0, schematics_1.branchAndMerge)((0, schematics_1.chain)([ // mergeWith(templateSource), // addIntoIndex(options.path, options), generateModelsRule(options.input, options.path, options.apiName, options.clean) ])), ]); }; } exports.default = default_1;