UNPKG

@nxext/stencil

Version:

Nx plugin for stenciljs

78 lines 4.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = update; const tslib_1 = require("tslib"); const devkit_1 = require("@nx/devkit"); const lint_1 = require("../../utils/lint"); const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file"); const versions_1 = require("../../utils/versions"); const child_process_1 = require("nx/src/utils/child-process"); function update(host) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (!isDepInstalled(host, versions_1.deprecatedStencilEslintPlugin)) { devkit_1.logger.info(`[@nxext/stencil - migration - change-stencil-eslint-plugin] ${versions_1.deprecatedStencilEslintPlugin} is not installed. Nothing to be done.`); devkit_1.logger.info(`[@nxext/stencil - migration - change-stencil-eslint-plugin] ${versions_1.stencilEslintPlugin} will be installed the first time the Stencil app is generated.`); return; } const updatePackageJsonTask = updatePackageJson(host); const updateEslintConfigFilesCallbacks = yield updateEslintConfigFiles(host); return (0, devkit_1.runTasksInSerial)(updatePackageJsonTask, ...updateEslintConfigFilesCallbacks); }); } function updatePackageJson(host) { (0, devkit_1.removeDependenciesFromPackageJson)(host, [versions_1.deprecatedStencilEslintPlugin], [versions_1.deprecatedStencilEslintPlugin]); return (0, devkit_1.addDependenciesToPackageJson)(host, lint_1.extraEslintDependencies.dependencies, lint_1.extraEslintDependencies.devDependencies); } function updateEslintConfigFiles(host) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const generatorCallbacks = []; const projects = (0, devkit_1.getProjects)(host); const projectData = [{ name: 'root', root: '', lint: false } /* root config */].concat(Array.from(projects).map((value) => { var _a; return ({ name: value[1].name, root: value[1].root, lint: Boolean((_a = value[1].targets) === null || _a === void 0 ? void 0 : _a.lint), }); })); for (const project of projectData) { const eslintConfigFileName = (0, eslint_file_1.findEslintFile)(host, project.root); if (eslintConfigFileName) { const eslintConfigFileRootPath = (0, devkit_1.joinPathFragments)(project.root, eslintConfigFileName); const eslintConfigContent = host.read(eslintConfigFileRootPath, 'utf-8'); if (eslintConfigContent) { const eslintConfigContentChanged = eslintConfigContent .replace(new RegExp(`plugin:${(0, lint_1.getEsLintPluginBaseName)(versions_1.deprecatedStencilEslintPlugin)}/`, 'g'), `plugin:${(0, lint_1.getEsLintPluginBaseName)(versions_1.stencilEslintPlugin)}/`) .replace(new RegExp(versions_1.deprecatedStencilEslintPlugin, 'g'), versions_1.stencilEslintPlugin); if (eslintConfigContentChanged !== eslintConfigContent) { host.write(eslintConfigFileRootPath, eslintConfigContentChanged); if (project.lint) { generatorCallbacks.push(() => { (0, child_process_1.runNxSync)(`run ${project.name}:lint`, { stdio: 'inherit' }); }); } } } } } return generatorCallbacks; }); } function isDepInstalled(host, depName) { var _a, _b, _c, _d; const json = (0, devkit_1.readJson)(host, './package.json'); if ((_a = json.dependencies) === null || _a === void 0 ? void 0 : _a[depName]) { return 'dep'; } if ((_b = json.devDependencies) === null || _b === void 0 ? void 0 : _b[depName]) { return 'devDep'; } if ((_c = json.peerDependencies) === null || _c === void 0 ? void 0 : _c[depName]) { return 'peerDep'; } if ((_d = json.optionalDependencies) === null || _d === void 0 ? void 0 : _d[depName]) { return 'optDep'; } return null; } //# sourceMappingURL=change-stencil-eslint-plugin.js.map