2018-08-01 01:01:16 +02:00
|
|
|
const { statSync, existsSync, readdirSync } = require('fs');
|
|
|
|
const { join, resolve } = require('path');
|
|
|
|
const DEFAULT_ROOT = 'client/build';
|
2018-11-09 17:22:23 +01:00
|
|
|
const CUSTOM_ROOT = 'site/custom/build';
|
2018-12-03 22:32:57 +01:00
|
|
|
const DEFAULT_SCSS_ROOT = 'client/scss';
|
2018-11-09 17:22:23 +01:00
|
|
|
const CUSTOM_SCSS_ROOT = 'site/custom/scss';
|
2018-08-01 01:01:16 +02:00
|
|
|
|
|
|
|
const getFolders = path => {
|
|
|
|
if (existsSync(path)) {
|
|
|
|
return readdirSync(path).filter(file => statSync(join(path, file)).isDirectory());
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
};
|
|
|
|
|
2018-08-13 21:36:47 +02:00
|
|
|
const addAliasesForCustomComponentFolder = (name, aliasObject) => {
|
|
|
|
// creates an alias for each component in the folder that is passed to this function
|
2018-08-01 01:01:16 +02:00
|
|
|
const folderPath = resolve(`${CUSTOM_ROOT}/${name}`);
|
|
|
|
const components = getFolders(folderPath);
|
|
|
|
for (let i = 0; i < components.length; i++) {
|
|
|
|
let folderName = components[i];
|
|
|
|
let aliasName = `@${name}/${folderName}`;
|
2018-08-13 21:36:47 +02:00
|
|
|
aliasObject[aliasName] = resolve(`${CUSTOM_ROOT}/${name}/${folderName}/index.js`);
|
|
|
|
}
|
|
|
|
return aliasObject;
|
|
|
|
};
|
|
|
|
|
2018-08-01 01:01:16 +02:00
|
|
|
module.exports = () => {
|
|
|
|
let moduleAliases = {};
|
2018-09-26 03:20:59 +02:00
|
|
|
|
|
|
|
moduleAliases['chainquery'] = resolve('./server/chainquery/bundle');
|
|
|
|
moduleAliases['server'] = resolve('./server');
|
|
|
|
|
2018-08-01 01:01:16 +02:00
|
|
|
// aliases for configs
|
2018-11-07 21:28:58 +01:00
|
|
|
moduleAliases['@config'] = resolve('site/config');
|
2018-11-15 17:08:33 +01:00
|
|
|
moduleAliases['@private'] = resolve('site/private');
|
2018-08-01 01:01:16 +02:00
|
|
|
|
2018-12-07 03:28:28 +01:00
|
|
|
// aliases for utils
|
|
|
|
moduleAliases['@globalutils'] = resolve('utils');
|
|
|
|
moduleAliases['@clientutils'] = resolve(`${DEFAULT_ROOT}/utils`);
|
|
|
|
// moduleAliases['@serverutils'] = resolve('server/utils');
|
|
|
|
|
2018-08-13 21:36:47 +02:00
|
|
|
// create specific aliases for locally defined components in the following folders
|
|
|
|
moduleAliases = addAliasesForCustomComponentFolder('containers', moduleAliases);
|
|
|
|
moduleAliases = addAliasesForCustomComponentFolder('components', moduleAliases);
|
|
|
|
moduleAliases = addAliasesForCustomComponentFolder('pages', moduleAliases);
|
2018-08-01 01:01:16 +02:00
|
|
|
|
2018-08-13 21:36:47 +02:00
|
|
|
// default component aliases
|
2018-08-01 01:01:16 +02:00
|
|
|
moduleAliases['@containers'] = resolve(`${DEFAULT_ROOT}/containers`);
|
|
|
|
moduleAliases['@components'] = resolve(`${DEFAULT_ROOT}/components`);
|
|
|
|
moduleAliases['@pages'] = resolve(`${DEFAULT_ROOT}/pages`);
|
|
|
|
moduleAliases['@actions'] = resolve(`${DEFAULT_ROOT}/actions`);
|
|
|
|
moduleAliases['@reducers'] = resolve(`${DEFAULT_ROOT}/reducers`);
|
|
|
|
moduleAliases['@sagas'] = resolve(`${DEFAULT_ROOT}/sagas`);
|
|
|
|
moduleAliases['@app'] = resolve(`${DEFAULT_ROOT}/app.js`);
|
|
|
|
|
2018-12-07 03:28:28 +01:00
|
|
|
|
2018-08-01 01:01:16 +02:00
|
|
|
// return finished aliases
|
|
|
|
return moduleAliases;
|
|
|
|
};
|