UNPKG

@o3r/eslint-config-otter

Version:

Recommended eslint configuration for Otter project

73 lines 3.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ngAdd = void 0; const path = require("node:path"); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@o3r/schematics"); const linter_1 = require("./linter"); /** * Add Otter eslint-config to an Angular Project * @param options */ function ngAddFn(options) { /* ng add rules */ return async (tree, context) => { const devDependenciesToInstall = [ 'eslint', '@angular-eslint/builder', '@angular-eslint/eslint-plugin', '@stylistic/eslint-plugin-ts', '@typescript-eslint/parser', '@typescript-eslint/eslint-plugin', '@typescript-eslint/utils', 'eslint-plugin-jest', 'eslint-plugin-jsdoc', 'eslint-plugin-prefer-arrow', 'eslint-plugin-unicorn', 'jest', 'jsonc-eslint-parser', 'yaml-eslint-parser' ]; const depsInfo = (0, schematics_2.getO3rPeerDeps)(path.resolve(__dirname, '..', '..', 'package.json'), true, /^@(?:o3r|ama-sdk|eslint-)/); const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined; const linterSchematicsFolder = __dirname; const { NodeDependencyType } = await Promise.resolve().then(() => require('@schematics/angular/utility/dependencies')); const packageJsonPath = path.resolve(__dirname, '..', '..', 'package.json'); const dependencies = depsInfo.o3rPeerDeps.reduce((acc, dep) => { acc[dep] = { inManifest: [{ range: `${options.exactO3rVersion ? '' : '~'}${depsInfo.packageVersion}`, types: (0, schematics_2.getProjectNewDependenciesTypes)(workspaceProject) }], ngAddOptions: { exactO3rVersion: options.exactO3rVersion } }; return acc; }, (0, schematics_2.getPackageInstallConfig)(packageJsonPath, tree, options.projectName, true, !!options.exactO3rVersion)); Object.entries((0, schematics_2.getExternalDependenciesVersionRange)(devDependenciesToInstall, packageJsonPath, context.logger)) .forEach(([dep, range]) => { dependencies[dep] = { inManifest: [{ range, types: [NodeDependencyType.Dev] }] }; }); return () => (0, schematics_1.chain)([ (0, schematics_2.removePackages)(['@otter/eslint-config-otter', '@otter/eslint-plugin']), (0, schematics_2.setupDependencies)({ projectName: options.projectName, dependencies, ngAddToRun: depsInfo.o3rPeerDeps }), (0, schematics_2.addVsCodeRecommendations)(['dbaeumer.vscode-eslint', 'stylelint.vscode-stylelint']), (0, linter_1.updateLinterConfigs)(options, linterSchematicsFolder) ])(tree, context); }; } /** * Add Otter eslint-config to an Angular Project * @param options */ const ngAdd = (options) => (0, schematics_2.createOtterSchematic)(ngAddFn)(options); exports.ngAdd = ngAdd; //# sourceMappingURL=index.js.map