@nx/nuxt
Version:
49 lines (48 loc) • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
const devkit_1 = require("@nx/devkit");
const executor_utils_1 = require("../../utils/executor-utils");
const path_1 = require("path");
async function default_1(tree) {
const projects = (0, devkit_1.getProjects)(tree);
for (const project of projects.values()) {
const nuxtConfigPath = findNuxtConfig(tree, project.root);
if (!nuxtConfigPath) {
continue;
}
const nuxtConfig = await getInfoFromNuxtConfig(nuxtConfigPath, project.root);
const buildDir = nuxtConfig.buildDir ?? '.nuxt';
const tsConfigPath = (0, devkit_1.joinPathFragments)(project.root, 'tsconfig.json');
if (tree.exists(tsConfigPath)) {
(0, devkit_1.updateJson)(tree, tsConfigPath, (json) => {
if (!json.include) {
json.include = [];
}
if (!json.include.includes(buildDir + '/nuxt.d.ts')) {
json.include.push(buildDir + '/nuxt.d.ts');
}
return json;
});
}
}
await (0, devkit_1.formatFiles)(tree);
}
function findNuxtConfig(tree, projectRoot) {
const allowsExt = ['js', 'mjs', 'ts', 'cjs', 'mts', 'cts'];
for (const ext of allowsExt) {
if (tree.exists((0, devkit_1.joinPathFragments)(projectRoot, `nuxt.config.${ext}`))) {
return (0, devkit_1.joinPathFragments)(projectRoot, `nuxt.config.${ext}`);
}
}
}
async function getInfoFromNuxtConfig(configFilePath, projectRoot) {
const { loadNuxtConfig } = await (0, executor_utils_1.loadNuxtKitDynamicImport)();
const config = await loadNuxtConfig({
cwd: (0, devkit_1.joinPathFragments)(devkit_1.workspaceRoot, projectRoot),
configFile: (0, path_1.basename)(configFilePath),
});
return {
buildDir: config?.buildDir,
};
}