@o3r/eslint-config-otter
Version:
Recommended eslint configuration for Otter project
85 lines • 3.62 kB
JavaScript
;
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");
/**
* List of external dependencies to be added to the project as peer dependencies
*/
const dependenciesToInstall = [];
/**
* List of external dependencies to be added to the project as dev dependencies
*/
const devDependenciesToInstall = [
'@angular-eslint/builder',
'@angular-eslint/eslint-plugin',
'@stylistic/eslint-plugin-ts',
'@typescript-eslint/eslint-plugin',
'@typescript-eslint/parser',
'@typescript-eslint/utils',
'eslint',
'eslint-import-resolver-node',
'eslint-plugin-jsdoc',
'eslint-plugin-prefer-arrow',
'eslint-plugin-unicorn',
'jsonc-eslint-parser'
];
/**
* Add Otter eslint-config to an Angular Project
* @param options
*/
function ngAddFn(options) {
/* ng add rules */
return (tree, context) => {
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 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));
try {
require.resolve('jest');
devDependenciesToInstall.push('eslint-plugin-jest', 'jest');
}
catch { }
const projectDirectory = workspaceProject?.root || '.';
const projectPackageJson = tree.readJson(path.posix.join(projectDirectory, 'package.json'));
const externalDependenciesInfo = (0, schematics_2.getExternalDependenciesInfo)({
devDependenciesToInstall,
dependenciesToInstall,
o3rPackageJsonPath: packageJsonPath,
projectPackageJson,
projectType: workspaceProject?.projectType
}, context.logger);
return () => (0, schematics_1.chain)([
(0, schematics_2.removePackages)(['@otter/eslint-config-otter', '@otter/eslint-plugin']),
(0, schematics_2.setupDependencies)({
projectName: options.projectName,
dependencies: {
...dependencies,
...externalDependenciesInfo
},
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