react-app-alias
Advanced tools
Comparing version 2.0.2 to 2.1.0
{ | ||
"name": "react-app-alias", | ||
"version": "2.0.2", | ||
"version": "2.1.0", | ||
"description": "Alias for craco or rewire react app", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -102,2 +102,26 @@ const fs = require('fs') | ||
function autoscan(tasks) { | ||
const dirlist = dir => | ||
fs.readdirSync(dir).filter( | ||
file => fs.statSync(path.resolve(dir, file)).isDirectory()) | ||
if(!Array.isArray(tasks)) tasks = tasks ? [tasks] : [] | ||
tasks = tasks.map(task => (task===task+'') ? {path: task} : task) | ||
tasks = tasks.map(task => ({ | ||
prefix: '', | ||
suffix: '', | ||
...task, | ||
})) | ||
const aliasMap = tasks.map(task => ( | ||
dirlist(task.path).reduce( | ||
(a, alias) => ({ | ||
...a, | ||
[task.prefix + alias + task.suffix]: | ||
path.join(task.path, alias) | ||
}), | ||
{} | ||
) | ||
)).reduce((a, map) => ({...a, ...map}), {}) | ||
return aliasMap | ||
} | ||
function configFilePath(configPath = '') { | ||
@@ -144,3 +168,3 @@ if( | ||
const paths = configPathsRaw(confPath) | ||
return Object.keys(paths).reduce( (a, path) => { | ||
const aliasMap = Object.keys(paths).reduce( (a, path) => { | ||
const value = paths[path] | ||
@@ -151,2 +175,3 @@ const target = Array.isArray(value) ? value[0] : value | ||
}, {}) | ||
return aliasMap | ||
} | ||
@@ -159,5 +184,10 @@ | ||
const aliasMap = options.alias || configPaths(configPath) | ||
const aliasAutoMap = autoscan(options.autoscan) | ||
const opts = { | ||
...options, | ||
aliasMap, | ||
aliasMap: { | ||
...aliasAutoMap, | ||
...aliasMap, | ||
}, | ||
} | ||
@@ -189,2 +219,3 @@ return opts | ||
aliasJest, | ||
autoscan, | ||
configFilePath, | ||
@@ -191,0 +222,0 @@ configPathsRaw, |
7201
202