UNPKG

@nx/plugin

Version:

This plugin is used to create Nx plugins! It contains generators for generating common plugin features like generators, executors, migrations and more.

86 lines (85 loc) 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.presetGenerator = presetGenerator; exports.presetGeneratorInternal = presetGeneratorInternal; const devkit_1 = require("@nx/devkit"); const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup"); const create_package_1 = require("../create-package/create-package"); const plugin_1 = require("../plugin/plugin"); async function presetGenerator(tree, rawOptions) { return await presetGeneratorInternal(tree, { addPlugin: false, useProjectJson: true, ...rawOptions, }); } async function presetGeneratorInternal(tree, rawOptions) { const tasks = []; const options = normalizeOptions(tree, rawOptions); const pluginTask = await (0, plugin_1.pluginGenerator)(tree, { compiler: 'tsc', linter: 'eslint', skipFormat: true, unitTestRunner: 'jest', importPath: options.pluginName, e2eTestRunner: 'jest', publishable: true, // when creating a CLI package, the plugin will be in the packages folder directory: options.createPackageName && options.createPackageName !== 'false' ? `packages/${options.pluginName}` : options.pluginName, rootProject: options.createPackageName ? false : true, useProjectJson: options.useProjectJson, addPlugin: options.addPlugin, }); tasks.push(pluginTask); moveNxPluginToDevDeps(tree); if (options.createPackageName) { const e2eProject = `${options.pluginName}-e2e`; const cliTask = await (0, create_package_1.createPackageGenerator)(tree, { directory: `packages/${options.createPackageName}`, name: options.createPackageName, e2eProject: e2eProject, project: options.pluginName, skipFormat: true, unitTestRunner: 'jest', linter: 'eslint', compiler: 'tsc', useProjectJson: options.useProjectJson, addPlugin: options.addPlugin, }); tasks.push(cliTask); } await (0, devkit_1.formatFiles)(tree); return (0, devkit_1.runTasksInSerial)(...tasks); } function moveNxPluginToDevDeps(tree) { (0, devkit_1.updateJson)(tree, 'package.json', (json) => { if (json.dependencies['@nx/plugin']) { const nxPluginEntry = json.dependencies['@nx/plugin']; delete json.dependencies['@nx/plugin']; json.devDependencies['@nx/plugin'] = nxPluginEntry; } return json; }); } function normalizeOptions(tree, options) { const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(tree); const nxJson = (0, devkit_1.readNxJson)(tree); const addPlugin = options.addPlugin ?? (isTsSolutionSetup && process.env.NX_ADD_PLUGINS !== 'false' && nxJson.useInferencePlugins !== false); return { ...options, pluginName: (0, devkit_1.names)(options.pluginName.includes('/') ? options.pluginName.split('/')[1] : options.pluginName).fileName, createPackageName: options.createPackageName === 'false' // for command line in e2e, it is passed as a string ? undefined : options.createPackageName, addPlugin, useProjectJson: options.useProjectJson ?? !isTsSolutionSetup, }; } exports.default = presetGenerator;