mirror of https://github.com/alibaba/ice.git
refactor: register formatWinPath method
This commit is contained in:
parent
fdee4e4f64
commit
1b6ff3bf0f
|
|
@ -5,6 +5,7 @@ import * as globby from 'globby'
|
||||||
import Generator from './generator'
|
import Generator from './generator'
|
||||||
import PageGenerator from './generator/pageGenerator'
|
import PageGenerator from './generator/pageGenerator'
|
||||||
import getPages from './utils/getPages'
|
import getPages from './utils/getPages'
|
||||||
|
import formatWinPath from './utils/formatWinPath'
|
||||||
|
|
||||||
export default (api) => {
|
export default (api) => {
|
||||||
const { onHook, onGetWebpackConfig, registerMethod, context, getAllPlugin, setValue, modifyUserConfig } = api
|
const { onHook, onGetWebpackConfig, registerMethod, context, getAllPlugin, setValue, modifyUserConfig } = api
|
||||||
|
|
@ -23,7 +24,7 @@ export default (api) => {
|
||||||
// get runtime module
|
// get runtime module
|
||||||
const runtimeModules = plugins.map(({ pluginPath }) => {
|
const runtimeModules = plugins.map(({ pluginPath }) => {
|
||||||
const modulePath = path.join(path.dirname(pluginPath), 'module.js');
|
const modulePath = path.join(path.dirname(pluginPath), 'module.js');
|
||||||
return fse.existsSync(modulePath) ? modulePath.split(path.sep).join('/') : false;
|
return fse.existsSync(modulePath) ? formatWinPath(modulePath) : false;
|
||||||
}).filter(Boolean);
|
}).filter(Boolean);
|
||||||
|
|
||||||
// modify entry to src/app
|
// modify entry to src/app
|
||||||
|
|
@ -56,7 +57,7 @@ export default (api) => {
|
||||||
const excludes = runtimeModules.map(modulePath => {
|
const excludes = runtimeModules.map(modulePath => {
|
||||||
// add default node_modules
|
// add default node_modules
|
||||||
if (modulePath.includes('node_modules')) {
|
if (modulePath.includes('node_modules')) {
|
||||||
return process.platform === 'win32' ? modulePath.split(path.sep).join('/') : modulePath;
|
return process.platform === 'win32' ? formatWinPath(modulePath) : modulePath;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -99,6 +100,7 @@ export default (api) => {
|
||||||
|
|
||||||
// register utils method
|
// register utils method
|
||||||
registerMethod('getPages', getPages);
|
registerMethod('getPages', getPages);
|
||||||
|
registerMethod('formatWinPath', formatWinPath);
|
||||||
|
|
||||||
// registerMethod for modify page
|
// registerMethod for modify page
|
||||||
registerMethod('addPageExport', pageGenerator.addPageExport);
|
registerMethod('addPageExport', pageGenerator.addPageExport);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
import * as path from 'path'
|
||||||
|
|
||||||
|
function formatWinPath(pathStr: string): string {
|
||||||
|
return pathStr.split(path.sep).join('/')
|
||||||
|
}
|
||||||
|
|
||||||
|
export default formatWinPath
|
||||||
|
|
@ -42,7 +42,7 @@ export default class Generator {
|
||||||
if (fse.pathExistsSync(pageModelsDir)) {
|
if (fse.pathExistsSync(pageModelsDir)) {
|
||||||
const pageModels = recursiveReaddir(pageModelsDir).map(item => path.parse(item))
|
const pageModels = recursiveReaddir(pageModelsDir).map(item => path.parse(item))
|
||||||
|
|
||||||
pageModelsDir = pageModelsDir.split(path.sep).join('/')
|
pageModelsDir = this.applyMethod('formatWinPath', pageModelsDir)
|
||||||
|
|
||||||
let importStr = ''
|
let importStr = ''
|
||||||
let modelsStr = ''
|
let modelsStr = ''
|
||||||
|
|
@ -75,7 +75,7 @@ export default class Generator {
|
||||||
|
|
||||||
let models = []
|
let models = []
|
||||||
if (fse.pathExistsSync(appModelsDir)) {
|
if (fse.pathExistsSync(appModelsDir)) {
|
||||||
appModelsDir = appModelsDir.split(path.sep).join('/')
|
appModelsDir = this.applyMethod('formatWinPath', appModelsDir)
|
||||||
models = fse.readdirSync(appModelsDir).map(item => path.parse(item).name)
|
models = fse.readdirSync(appModelsDir).map(item => path.parse(item).name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue