UNPKG

@nestjs/schematics

Version:

Nest - modern, fast, powerful node.js web framework (@schematics)

35 lines (34 loc) 1.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.main = main; const core_1 = require("@angular-devkit/core"); const schematics_1 = require("@angular-devkit/schematics"); const formatting_1 = require("../../utils/formatting"); const name_parser_1 = require("../../utils/name.parser"); const source_root_helpers_1 = require("../../utils/source-root.helpers"); function main(options) { options = transform(options); return (0, schematics_1.chain)([(0, source_root_helpers_1.mergeSourceRoot)(options), (0, schematics_1.mergeWith)(generate(options))]); } function transform(options) { const target = Object.assign({}, options); if (!target.name) { throw new schematics_1.SchematicsException('Option (name) is required.'); } const location = new name_parser_1.NameParser().parse(target); target.name = (0, formatting_1.normalizeToKebabOrSnakeCase)(location.name); target.path = (0, formatting_1.normalizeToKebabOrSnakeCase)(location.path); target.path = target.flat ? target.path : (0, core_1.join)(target.path, target.name); return target; } function generate(options) { return (context) => (0, schematics_1.apply)((0, schematics_1.url)('./files'), [ (0, schematics_1.template)({ ...core_1.strings, ...options, }), (0, schematics_1.move)(options.path), ])(context); }