@nx-dotnet/nxdoc
Version:
> This package is unstable! Documentation formatting could change in the future. See something that you think should be different? [Open an issue](https://github.com/nx-dotnet/nx-dotnet/issues) on github and help shape this plugin.
121 lines • 5.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = default_1;
exports.findProjectsWithGeneratorsOrExecutors = findProjectsWithGeneratorsOrExecutors;
exports.projectContainsGeneratorsOrExecutors = projectContainsGeneratorsOrExecutors;
const devkit_1 = require("@nx/devkit");
const fs_1 = require("fs");
const path = require("node:path");
async function default_1(host, options) {
const projects = await findProjectsWithGeneratorsOrExecutors(host);
const packageDetails = [];
options.exclude ?? (options.exclude = []);
const excludedProjects = Array.isArray(options.exclude)
? options.exclude
: options.exclude.split(',');
for (const project of projects) {
if (excludedProjects.includes(project.name)) {
continue;
}
packageDetails.push(generateDocsForProject(options, project, host));
}
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'templates/root'), options.outputDirectory, {
packageDetails,
includeFrontMatter: !options.skipFrontMatter,
});
if (!options.skipFormat) {
await (0, devkit_1.formatFiles)(host);
}
}
function generateDocsForProject(options, project, host) {
let gettingStartedFile = options.gettingStartedFile.replace('<src>', project.root);
if (options.verboseLogging) {
console.log('Loading getting started file:', gettingStartedFile);
}
gettingStartedFile = host.exists(gettingStartedFile)
? gettingStartedFile
: null;
if (!gettingStartedFile && options.verboseLogging) {
console.log('Getting started file not found');
}
const generatorsCollection = project.generators
? (0, devkit_1.readJson)(host, `${project.root}/generators.json`)
: {};
const generators = Object.fromEntries(Object.entries(generatorsCollection.generators ?? {}).filter(([, config]) => !config.hidden));
const executorsCollection = project.executors
? (0, devkit_1.readJson)(host, `${project.root}/executors.json`)
: {};
const executors = Object.fromEntries(Object.entries(executorsCollection.executors ?? {}).filter(([, config]) => !config.hidden));
const packageName = (0, devkit_1.readJson)(host, `${project.root}/package.json`).name;
const projectFileName = (0, devkit_1.names)(project.name).fileName;
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'templates/index'), options.outputDirectory, {
projectFileName,
packageName,
project,
generators,
executors,
underscore: '_',
gettingStartedMd: gettingStartedFile
? (0, fs_1.readFileSync)(gettingStartedFile).toString()
: '',
frontMatter: options.skipFrontMatter
? null
: {
title: `${packageName}`,
summary: `${packageName}`,
},
});
for (const [generatorName, config] of Object.entries(generators)) {
const generatorFileName = (0, devkit_1.names)(generatorName).fileName;
const schema = (0, devkit_1.readJson)(host, path.relative(process.cwd(), path.resolve(project.root, config.schema)));
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'templates/detail'), `${options.outputDirectory}/${projectFileName}/Generators`, {
projectFileName,
project,
generatorName,
generatorFileName,
schema,
packageName,
});
}
Object.entries(executors).forEach(([generatorName, config]) => {
const generatorFileName = (0, devkit_1.names)(generatorName).fileName;
const schema = typeof config === 'string'
? {}
: (0, devkit_1.readJson)(host, path.relative(process.cwd(), path.resolve(project.root, config.schema)));
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'templates/detail'), `${options.outputDirectory}/${projectFileName}/Executors`, {
projectFileName,
project,
generatorName,
generatorFileName,
schema,
packageName,
});
});
return {
packageName,
projectFileName,
project,
generators: Object.keys(generators).length,
executors: Object.keys(executors).length,
};
}
async function findProjectsWithGeneratorsOrExecutors(host) {
const projects = [];
(0, devkit_1.getProjects)(host).forEach((configuration, project) => {
const res = projectContainsGeneratorsOrExecutors(host, configuration);
if (res) {
projects.push({
...configuration,
name: project,
...res,
});
}
});
return projects;
}
function projectContainsGeneratorsOrExecutors(host, project) {
const executors = host.isFile(`${project.root}/executors.json`);
const generators = host.isFile(`${project.root}/generators.json`);
return !(executors || generators) ? false : { generators, executors };
}
//# sourceMappingURL=generator.js.map