UNPKG

@nxext/stencil

Version:

Nx plugin for stenciljs

53 lines 2.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.componentGenerator = componentGenerator; const tslib_1 = require("tslib"); const devkit_1 = require("@nx/devkit"); const path_1 = require("path"); const insert_statement_1 = require("../../utils/insert-statement"); const generator_1 = require("../storybook-configuration/generator"); const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup"); function componentGenerator(host, options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { (0, ts_solution_setup_1.assertNotUsingTsSolutionSetup)(host, '@nxext/stencil', 'component'); if (!/[-]/.test(options.name)) { throw new Error((0, devkit_1.stripIndents) ` "${options.name}" tag must contain a dash (-) to work as a valid web component. Please refer to https://html.spec.whatwg.org/multipage/custom-elements.html#valid-custom-element-name for more info. `); } const componentFileName = (0, devkit_1.names)(options.name).fileName; const className = (0, devkit_1.names)(options.name).className; const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.project); const componentDirectory = options.directory ? (0, devkit_1.joinPathFragments)(`${options.directory}/${componentFileName}`) : componentFileName; const componentOptions = ((projectConfig || {}).generators || { '@nxext/stencil:component': {}, })['@nxext/stencil:component']; if (!componentOptions) { devkit_1.logger.info((0, devkit_1.stripIndents) ` Style options for components not set, please run "nx migrate @nxext/stencil" `); } options = Object.assign(Object.assign({}, options), componentOptions); (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files/component'), (0, devkit_1.joinPathFragments)(`${projectConfig.sourceRoot}/components/${componentDirectory}`), { componentFileName: componentFileName, className: className, style: options.style, }); const storiesPath = `${projectConfig.sourceRoot}/components/${componentDirectory}/${componentFileName}.stories.tsx`; if (!host.exists('.storybook')) { host.delete((0, devkit_1.joinPathFragments)(storiesPath)); } else { const classPathValue = `${(0, generator_1.getProjectTsImportPath)(host, options.project)}/${componentFileName}`; (0, insert_statement_1.insertStatement)(host, storiesPath, `import { ${className} } from '${classPathValue}'`); } if (!options.skipFormat) { yield (0, devkit_1.formatFiles)(host); } }); } exports.default = componentGenerator; //# sourceMappingURL=component.js.map