@nxext/stencil
Version:
Nx plugin for stenciljs
72 lines • 3.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createNodesV2 = void 0;
const devkit_1 = require("@nx/devkit");
const node_fs_1 = require("node:fs");
const node_path_1 = require("node:path");
/**
* Infers stencil tasks for any project containing a `stencil.config.ts`.
*
* Scope-by-design: targets shell out to the local `stencil` CLI via
* `nx:run-commands` with `cwd: projectRoot`. No custom executor, no runtime
* path rewriting — the stencil config itself is the source of truth for where
* output lands (typically `<projectRoot>/www` or `<projectRoot>/dist`, plus
* the `<workspaceRoot>/dist/<projectRoot>` convention the @nxext/stencil
* generator templates write).
*
* `{workspaceRoot}/dist/{projectRoot}` is listed as the cache output. That
* covers the nxext-generated template's configured output directory. Users
* with non-standard stencil output paths should override the inferred `outputs`
* locally in their project.json.
*/
exports.createNodesV2 = [
'**/stencil.config*.ts',
(configFiles, rawOptions, context) => {
const options = normalizeOptions(rawOptions);
const workspaceRoot = context.workspaceRoot;
const projectConfigFiles = configFiles.filter((configFile) => {
const projectRoot = (0, node_path_1.dirname)(configFile);
return ((0, node_fs_1.existsSync)((0, node_path_1.join)(workspaceRoot, projectRoot, 'project.json')) ||
(0, node_fs_1.existsSync)((0, node_path_1.join)(workspaceRoot, projectRoot, 'package.json')));
});
return (0, devkit_1.createNodesFromFiles)((configFile) => {
const projectRoot = (0, node_path_1.dirname)(configFile);
return {
projects: {
[projectRoot]: {
targets: buildTargets(projectRoot, options),
metadata: {
technologies: ['stencil'],
},
},
},
};
}, projectConfigFiles, rawOptions, context);
},
];
function normalizeOptions(options) {
var _a, _b, _c, _d;
return {
buildTargetName: (_a = options === null || options === void 0 ? void 0 : options.buildTargetName) !== null && _a !== void 0 ? _a : 'build',
serveTargetName: (_b = options === null || options === void 0 ? void 0 : options.serveTargetName) !== null && _b !== void 0 ? _b : 'serve',
testTargetName: (_c = options === null || options === void 0 ? void 0 : options.testTargetName) !== null && _c !== void 0 ? _c : 'test',
e2eTargetName: (_d = options === null || options === void 0 ? void 0 : options.e2eTargetName) !== null && _d !== void 0 ? _d : 'e2e',
};
}
function buildTargets(projectRoot, options) {
const commonOptions = {
options: { cwd: projectRoot },
metadata: { technologies: ['stencil'] },
};
return {
[options.buildTargetName]: Object.assign({ command: 'stencil build', cache: true, inputs: ['default', '^production'], outputs: [
`{workspaceRoot}/dist/${projectRoot}`,
`{projectRoot}/www`,
`{projectRoot}/dist`,
] }, commonOptions),
[options.serveTargetName]: Object.assign({ command: 'stencil build --dev --watch --serve', cache: false }, commonOptions),
[options.testTargetName]: Object.assign({ command: 'stencil test --spec', cache: true, inputs: ['default', '^production'] }, commonOptions),
[options.e2eTargetName]: Object.assign({ command: 'stencil test --e2e', cache: false }, commonOptions),
};
}
//# sourceMappingURL=plugin.js.map