UNPKG

@mbc-cqrs-serverless/cli

Version:

a CLI to get started with MBC CQRS serverless framework

41 lines (40 loc) 1.85 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"); function createController(options) { return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./files'), [ (0, schematics_1.template)({ ...core_1.strings, ...options, }), (0, schematics_1.move)((0, core_1.normalize)(`/src/${core_1.strings.dasherize(options.name)}`)), ])); } function createUnitTest(options) { return (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./units'), [ (0, schematics_1.template)({ ...core_1.strings, ...options, specFileSuffix: 'spec', }), (0, schematics_1.move)((0, core_1.normalize)(`/test/unit/${core_1.strings.dasherize(options.name)}`)), ])); } function main(options) { return (tree, _context) => { const filePath = (0, core_1.normalize)(`/src/${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.controller.ts`); const unitPath = (0, core_1.normalize)(`/test/unit/${core_1.strings.dasherize(options.name)}/${core_1.strings.dasherize(options.name)}.controller.spec.ts`); const isFileExists = tree.exists(filePath); const isUnitExists = tree.exists(unitPath); if (isFileExists || isUnitExists) { if (isFileExists) _context.logger.info(`Controller file already exists at: ${filePath}`); if (isUnitExists) _context.logger.info(`Unit test file already exists at: ${unitPath}`); return; } return (0, schematics_1.chain)([createController(options), createUnitTest(options)]); }; }