@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
71 lines • 3.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoerceInitGenerator = CoerceInitGenerator;
const tslib_1 = require("tslib");
const generators_1 = require("@nx/plugin/generators");
const workspace_utilities_1 = require("@rxap/workspace-utilities");
const path_1 = require("path");
function CoerceInitGenerator(tree, projectName, project, options) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
var _e;
if ((0, workspace_utilities_1.IsAngularProject)(project)) {
const ngPackagr = (0, workspace_utilities_1.ReadNgPackageJson)(tree, project);
(_a = ngPackagr.allowedNonPeerDependencies) !== null && _a !== void 0 ? _a : (ngPackagr.allowedNonPeerDependencies = []);
ngPackagr.allowedNonPeerDependencies.push('@nx/devkit');
ngPackagr.allowedNonPeerDependencies = Array.from(new Set(ngPackagr.allowedNonPeerDependencies));
(0, workspace_utilities_1.WriteNgPackageJson)(tree, project, ngPackagr);
}
if ((0, workspace_utilities_1.HasGenerator)(tree, projectName, 'init')) {
return;
}
console.log(`project: ${projectName} has no init generator`.yellow);
// region setup build assets options
const projectSourceRoot = (0, workspace_utilities_1.GetProjectSourceRoot)(tree, projectName);
const projectRoot = (0, workspace_utilities_1.GetProjectRoot)(tree, projectName);
if ((0, workspace_utilities_1.IsAngularProject)(project)) {
const ngPackagr = (0, workspace_utilities_1.ReadNgPackageJson)(tree, project);
(_b = ngPackagr.assets) !== null && _b !== void 0 ? _b : (ngPackagr.assets = []);
(0, workspace_utilities_1.CoerceAssets)(ngPackagr.assets, [
{
input: (0, path_1.join)('src', 'generators'),
glob: '**/!(*.ts|*.js|*.json)',
output: (0, path_1.join)('src', 'generators'),
},
'generators.json'
]);
(0, workspace_utilities_1.WriteNgPackageJson)(tree, project, ngPackagr);
}
else {
const buildTarget = (0, workspace_utilities_1.GetTarget)(project, 'build');
(_c = buildTarget.options) !== null && _c !== void 0 ? _c : (buildTarget.options = {});
(_d = (_e = buildTarget.options).assets) !== null && _d !== void 0 ? _d : (_e.assets = []);
(0, workspace_utilities_1.CoerceAssets)(buildTarget.options.assets, [
{
input: './' + (0, path_1.join)(projectSourceRoot, 'generators'),
glob: '**/!(*.ts|*.js|*.json)',
output: './src/generators',
},
{
input: './' + projectRoot,
glob: 'generators.json',
output: '.',
},
]);
}
// endregion
try {
yield (0, generators_1.generatorGenerator)(tree, {
path: (0, path_1.join)(projectSourceRoot, 'generators', 'init', 'generator'),
name: 'init',
description: 'Initialize the package in the workspace',
unitTestRunner: 'none',
});
(0, workspace_utilities_1.DeleteRecursive)(tree, (0, path_1.join)(projectSourceRoot, 'generators', 'init'));
}
catch (e) {
console.log(`Error while generating the init generator: ${e.message}`.red);
}
});
}
//# sourceMappingURL=coerce-init-generator.js.map