@nxext/stencil
Version:
Nx plugin for stenciljs
87 lines (85 loc) • 3.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getProjectTsImportPath = getProjectTsImportPath;
exports.storybookConfigurationGenerator = storybookConfigurationGenerator;
const tslib_1 = require("tslib");
const devkit_1 = require("@nx/devkit");
const utillities_1 = require("../../utils/utillities");
const update_preview_1 = require("./lib/update-preview");
const update_main_1 = require("./lib/update-main");
const update_lint_config_1 = require("./lib/update-lint-config");
const internal_1 = require("@nx/js/internal");
/**
* Returns the path portion to be used for import statements or a
* tsconfig.json `paths` entry for `projectName`.
*
* TS-solution (package.json-backed) projects already carry their real
* import path as `package.json.name` (Design 1.4/2.5) - which may differ
* from the `@<npmScope>/<projectName>` guess below (e.g. an explicit
* `--importPath` given at generation time). Prefer reading it directly;
* fall back to the historical npmScope-based guess only when no
* project-level package.json exists yet (legacy, non-buildable projects
* never get one).
*
* @example `@nx-workspace/nx-project`
* @returns path portion of an import statement
*/
function getProjectTsImportPath(tree, projectName) {
const { root } = (0, devkit_1.readProjectConfiguration)(tree, projectName);
const packageJsonPath = (0, devkit_1.joinPathFragments)(root, 'package.json');
if (tree.exists(packageJsonPath)) {
const { name } = (0, devkit_1.readJson)(tree, packageJsonPath);
if (name) {
return name;
}
}
const npmScope = (0, internal_1.getNpmScope)(tree);
return `@${npmScope}/${projectName}`;
}
function storybookConfigurationGenerator(host, rawSchema) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const tasks = [];
const uiFramework = '@storybook/web-components-vite';
const options = normalizeSchema(rawSchema);
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.name);
if (!(0, utillities_1.isBuildableStencilProject)(projectConfig, host)) {
devkit_1.logger.info((0, devkit_1.stripIndents) `
Please use a buildable library for storybook. Storybook needs a generated
Stencil loader to work (yet). They're working on native Stencil support, but
it's not ready yet.
You could make this library buildable with:
nx generate @nxext/stencil:make-lib-buildable ${options.name}
or
ng generate @nxext/stencil:make-lib-buildable ${options.name}
`);
return;
}
yield (0, devkit_1.ensurePackage)('@nx/storybook', devkit_1.NX_VERSION);
const { configurationGenerator } = yield Promise.resolve().then(() => require('@nx/storybook'));
const storybookTask = yield configurationGenerator(host, {
project: options.name,
uiFramework,
linter: options.linter,
tsConfiguration: true,
interactionTests: options.interactionTests,
});
tasks.push(storybookTask);
(0, update_preview_1.updatePreview)(host, options.name);
(0, update_main_1.updateMain)(host, options.name);
(0, update_lint_config_1.updateLintConfig)(host, options);
if (options.configureCypress) {
devkit_1.logger.warn('`configureCypress` was removed from @nx/storybook in v22. Storybook now ships `interactionTests` (Play functions) for UI testing; the option is ignored.');
}
yield (0, devkit_1.formatFiles)(host);
return (0, devkit_1.runTasksInSerial)(...tasks);
});
}
function normalizeSchema(schema) {
const defaults = {
configureCypress: true,
linter: 'eslint',
};
return Object.assign(Object.assign({}, defaults), schema);
}
exports.default = storybookConfigurationGenerator;
//# sourceMappingURL=generator.js.map