|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | +const projectRootPath = fs.realpathSync(__dirname + '/../../../'); |
| 4 | + |
| 5 | +let voltoPath = path.join(projectRootPath, 'node_modules/@plone/volto'); |
| 6 | +let configFile; |
| 7 | +if (fs.existsSync(`${projectRootPath}/tsconfig.json`)) |
| 8 | + configFile = `${projectRootPath}/tsconfig.json`; |
| 9 | +else if (fs.existsSync(`${projectRootPath}/jsconfig.json`)) |
| 10 | + configFile = `${projectRootPath}/jsconfig.json`; |
| 11 | + |
| 12 | +if (configFile) { |
| 13 | + const jsConfig = require(configFile).compilerOptions; |
| 14 | + const pathsConfig = jsConfig.paths; |
| 15 | + if (pathsConfig['@plone/volto']) |
| 16 | + voltoPath = `./${jsConfig.baseUrl}/${pathsConfig['@plone/volto'][0]}`; |
| 17 | +} |
| 18 | + |
| 19 | +const AddonConfigurationRegistry = require(`${voltoPath}/addon-registry.js`); |
| 20 | +const reg = new AddonConfigurationRegistry(projectRootPath); |
| 21 | + |
| 22 | +// Extends ESlint configuration for adding the aliases to `src` directories in Volto addons |
| 23 | +const addonAliases = Object.keys(reg.packages).map((o) => [ |
| 24 | + o, |
| 25 | + reg.packages[o].modulePath, |
| 26 | +]); |
| 27 | + |
| 28 | +const addonExtenders = reg.getEslintExtenders().map((m) => require(m)); |
| 29 | + |
| 30 | +const defaultConfig = { |
| 31 | + extends: `${voltoPath}/.eslintrc`, |
| 32 | + settings: { |
| 33 | + 'import/resolver': { |
| 34 | + alias: { |
| 35 | + map: [ |
| 36 | + ['@plone/volto', '@plone/volto/src'], |
| 37 | + ['@plone/volto-slate', '@plone/volto/packages/volto-slate/src'], |
| 38 | + ...addonAliases, |
| 39 | + ['@package', `${__dirname}/src`], |
| 40 | + ['@root', `${__dirname}/src`], |
| 41 | + ['~', `${__dirname}/src`], |
| 42 | + ], |
| 43 | + extensions: ['.js', '.jsx', '.json'], |
| 44 | + }, |
| 45 | + 'babel-plugin-root-import': { |
| 46 | + rootPathSuffix: 'src', |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
| 50 | + rules: { |
| 51 | + 'react/jsx-no-target-blank': [ |
| 52 | + 'error', |
| 53 | + { |
| 54 | + allowReferrer: true, |
| 55 | + }, |
| 56 | + ], |
| 57 | + } |
| 58 | +}; |
| 59 | + |
| 60 | +const config = addonExtenders.reduce( |
| 61 | + (acc, extender) => extender.modify(acc), |
| 62 | + defaultConfig, |
| 63 | +); |
| 64 | + |
| 65 | +module.exports = config; |
0 commit comments