@rxap/plugin-library
Version:
This package provides generators and executors for managing and maintaining Nx plugin libraries. It includes functionality for generating index exports, fixing dependencies, generating JSON schemas, and more. It helps streamline the development process fo
202 lines • 8.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createNodesV2 = void 0;
exports.normalizeOptions = normalizeOptions;
const tslib_1 = require("tslib");
const workspace_utilities_1 = require("@rxap/workspace-utilities");
const fs_1 = require("fs");
const glob_1 = require("glob");
const path_1 = require("path");
require("colors");
function normalizeOptions(options) {
return options !== null && options !== void 0 ? options : {};
}
exports.createNodesV2 = [
'**/tsconfig.lib.json',
(configFilePaths, options, context) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const normalizedOptions = normalizeOptions(options);
const includedConfigFilePaths = yield Promise.all(configFilePaths.map((configFilePath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
if (yield shouldHaveProjectConfiguration(configFilePath, normalizedOptions, context)) {
return configFilePath;
}
return undefined;
}))).then((configFilePathOrUndefinedList) => configFilePathOrUndefinedList.filter((value) => value !== undefined));
const results = yield Promise.all(includedConfigFilePaths.map((configFilePath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
const [projectPath, projectConfiguration] = yield createProjectConfiguration(configFilePath, normalizedOptions, context);
return [configFilePath, projectPath, projectConfiguration];
})));
return results.map(([configFilePath, projectPath, projectConfiguration]) => [
configFilePath,
{
projects: {
[projectPath]: projectConfiguration,
},
},
]);
}),
];
function shouldHaveProjectConfiguration(configFilePath, options, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const projectPath = (0, path_1.dirname)(configFilePath);
const tree = new workspace_utilities_1.FsTree(context.workspaceRoot);
if (!(0, workspace_utilities_1.FindProjectByPath)(tree, projectPath)) {
// console.log(`The folder of the file '${ configFilePath }' is not the root of a project. Skipping`.yellow);
return false;
}
// skip project that are in the workspace root
if (projectPath === '.') {
return false;
}
return true;
});
}
function createProjectConfiguration(configFilePath, options, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a;
const projectPath = (0, path_1.dirname)(configFilePath);
const targets = {};
const tree = new workspace_utilities_1.FsTree(context.workspaceRoot);
const projectConfiguration = (0, workspace_utilities_1.FindProjectByPath)(tree, projectPath);
if (!projectConfiguration) {
throw new Error(`Could not find project in '${projectPath}'`);
}
if ((0, workspace_utilities_1.IsPublishable)(tree, projectConfiguration)) {
targets['readme'] = createReadmeTarget(projectPath);
}
if ((0, workspace_utilities_1.IsLibraryProject)(projectConfiguration)) {
if (!(0, workspace_utilities_1.IsPluginProject)(projectConfiguration) && !(0, workspace_utilities_1.IsN8NNodesProject)(projectConfiguration) && projectConfiguration.name !== 'workspace-tools') {
targets['index-export'] = createIndexExportTarget();
}
if ((0, workspace_utilities_1.HasPackageJson)(tree, projectPath)) {
const packageJson = (0, workspace_utilities_1.GetPackageJson)(tree, projectPath);
if ((0, workspace_utilities_1.IsPublishable)(tree, projectConfiguration)) {
if ('nx-migrations' in packageJson) {
targets['update-package-group'] = createUpdatePackageGroupTarget();
}
targets['update-dependencies'] = createUpdateDependenciesTarget();
}
}
if ((0, workspace_utilities_1.IsAngularProject)(projectConfiguration) && (0, workspace_utilities_1.IsPublishable)(tree, projectConfiguration)) {
targets['check-version'] = createCheckVersionTarget('@angular/core');
}
if ((0, workspace_utilities_1.IsPluginProject)(projectConfiguration)) {
targets['check-version'] = createCheckVersionTarget('nx');
targets['generate-schema'] = createSchemaGenerateTarget();
}
if ((0, workspace_utilities_1.IsNestJsProject)(projectConfiguration)) {
targets['check-version'] = createCheckVersionTarget('@nestjs/core');
}
if ((0, workspace_utilities_1.IsSchematicProject)(projectConfiguration)) {
targets['check-version'] = createCheckVersionTarget('@angular-devkit/schematics');
}
if ((0, fs_1.existsSync)((0, path_1.join)(projectPath, 'generators.json'))) {
targets['expose-as-schematic'] = createExposeAsSchematicTarget();
}
if ((_a = (0, glob_1.globSync)((0, path_1.join)(projectPath, 'src/**/*.schema.json'))) === null || _a === void 0 ? void 0 : _a.length) {
targets['index-json-schema'] = createIndexJsonSchemaTarget();
targets['bundle-json-schema'] = createBundleJsonSchemaTarget();
}
}
return [projectPath, {
targets
}];
});
}
function createIndexJsonSchemaTarget() {
return {
inputs: [
'{projectRoot}/src/**/template.schema.json',
'{projectRoot}/src/**/*.schema.json',
],
outputs: [
'{projectRoot}/template.schema.json',
'{projectRoot}/schematic-input.schema.json',
],
executor: '@rxap/plugin-library:index-json-schema',
cache: true,
};
}
function createBundleJsonSchemaTarget() {
return {
inputs: [
'{projectRoot}/src/**/template.schema.json',
'{projectRoot}/src/**/*.schema.json',
],
outputs: [
'{projectRoot}/template.schema.json',
'{projectRoot}/schematic-input.schema.json',
],
executor: '@rxap/plugin-library:bundle-json-schema',
cache: true,
};
}
function createExposeAsSchematicTarget() {
return {
executor: '@rxap/plugin-library:expose-as-schematic',
inputs: ['{projectRoot}/generators.json}'],
outputs: ['{projectRoot}/generators.json}'],
cache: true,
};
}
function createCheckVersionTarget(packageName) {
return {
executor: '@rxap/plugin-library:check-version',
inputs: ['{projectRoot}/package.json', '{workspaceRoot}/package.json'],
options: { packageName },
cache: true,
};
}
function createUpdatePackageGroupTarget() {
return {
executor: '@rxap/plugin-library:update-package-group',
inputs: ['production', '{projectRoot}/package.json'],
outputs: ['{projectRoot}/package.json'],
dependsOn: ['update-dependencies', '^update-dependencies']
};
}
function createUpdateDependenciesTarget() {
return {
executor: '@rxap/plugin-library:update-dependencies',
outputs: ['{projectRoot}/package.json'],
inputs: ['{workspaceRoot}/package.json', '{projectRoot}/package.json'],
};
}
function createReadmeTarget(projectPath) {
const inputs = [];
const potentialInputFiles = ['GETSTARTED.md', 'GUIDES.md', 'package.json', 'collection.json', 'generators.json', 'executors.json', 'builders.json'];
for (const potentialInputFile of potentialInputFiles) {
if ((0, fs_1.existsSync)((0, path_1.join)(projectPath, potentialInputFile))) {
inputs.push(`{projectRoot}/${potentialInputFile}`);
}
}
if ((0, fs_1.existsSync)((0, path_1.join)(projectPath, 'README.md.handlebars'))) {
inputs.push(`{projectRoot}/README.md.handlebars`);
}
return {
executor: '@rxap/plugin-library:readme',
outputs: ['{projectRoot}/README.md'],
cache: false,
inputs
};
}
function createIndexExportTarget() {
return {
executor: '@rxap/plugin-library:index-export',
outputs: ['{projectRoot}/src/index.ts'],
cache: true,
inputs: [
`{projectRoot}/src/lib/**/*.ts`,
'!{projectRoot}/src/lib/**/*.{spec,stories,cy}.ts',
'!{projectRoot}/src/index.ts'
]
};
}
function createSchemaGenerateTarget() {
return {
executor: '@rxap/plugin-library:generate-schema',
outputs: ['{projectRoot}/**/schema.d.ts'],
inputs: ['{projectRoot}/**/schema.json'],
cache: true,
};
}
//# sourceMappingURL=plugin.js.map