提交 c276f6c6 编写于 作者: fxy060608's avatar fxy060608

fix(cli): uni_modules with easycom

上级 6ae16fb3
...@@ -339,20 +339,27 @@ const isDirectory = source => fs.lstatSync(source).isDirectory() ...@@ -339,20 +339,27 @@ const isDirectory = source => fs.lstatSync(source).isDirectory()
function getAutoComponentsByDir (componentsPath, absolute = false) { function getAutoComponentsByDir (componentsPath, absolute = false) {
const components = {} const components = {}
try { try {
fs.existsSync(componentsPath) && fs.readdirSync(componentsPath).forEach(name => { if (fs.existsSync(componentsPath)) {
const folder = path.resolve(componentsPath, name) let importComponentsDir = '@/components'
if (!isDirectory(folder)) { const uniModulesDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules')
return if (!absolute && componentsPath.includes(uniModulesDir)) {
importComponentsDir = `@/uni_modules/${path.basename(path.dirname(componentsPath))}/components`
} }
const importDir = absolute ? normalizePath(folder) : `@/components/${name}` fs.readdirSync(componentsPath).forEach(name => {
// 读取文件夹文件列表,比对文件名(fs.existsSync在大小写不敏感的系统会匹配不准确) const folder = path.resolve(componentsPath, name)
const files = fs.readdirSync(folder) if (!isDirectory(folder)) {
if (files.includes(name + '.vue')) { return
components[`^${name}$`] = `${importDir}/${name}.vue` }
} else if (files.includes(name + '.nvue')) { const importDir = absolute ? normalizePath(folder) : `${importComponentsDir}/${name}`
components[`^${name}$`] = `${importDir}/${name}.nvue` // 读取文件夹文件列表,比对文件名(fs.existsSync在大小写不敏感的系统会匹配不准确)
} const files = fs.readdirSync(folder)
}) if (files.includes(name + '.vue')) {
components[`^${name}$`] = `${importDir}/${name}.vue`
} else if (files.includes(name + '.nvue')) {
components[`^${name}$`] = `${importDir}/${name}.nvue`
}
})
}
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
...@@ -365,8 +372,9 @@ function initAutoComponents () { ...@@ -365,8 +372,9 @@ function initAutoComponents () {
global.uniModules.forEach(module => { global.uniModules.forEach(module => {
componentsDirs.push(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, 'components')) componentsDirs.push(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, 'components'))
}) })
componentsDirs.forEach(componentsDir => { componentsDirs.forEach((componentsDir) => {
const currentComponents = getAutoComponentsByDir(componentsDir, true) // 根目录 components 使用相对路径,uni_modules 使用绝对路径
const currentComponents = getAutoComponentsByDir(componentsDir, false)
Object.keys(currentComponents).forEach(name => { Object.keys(currentComponents).forEach(name => {
(allComponents[name] || (allComponents[name] = [])).push(currentComponents[name]) (allComponents[name] || (allComponents[name] = [])).push(currentComponents[name])
}) })
...@@ -384,7 +392,6 @@ function initAutoComponents () { ...@@ -384,7 +392,6 @@ function initAutoComponents () {
conflictFiles.forEach(files => { conflictFiles.forEach(files => {
let usedFile let usedFile
console.warn('easycom组件冲突:[' + files.map((file, index) => { console.warn('easycom组件冲突:[' + files.map((file, index) => {
file = path.relative(process.env.UNI_INPUT_DIR, file)
if (index === 0) { if (index === 0) {
usedFile = file usedFile = file
} }
......
...@@ -171,6 +171,12 @@ function getCondition (pagesJson) { ...@@ -171,6 +171,12 @@ function getCondition (pagesJson) {
} }
return false return false
} }
function trimAppJson (app) {
delete app.topWindow
delete app.leftWindow
delete app.rightWindow
}
module.exports = function (pagesJson, manifestJson, project = {}) { module.exports = function (pagesJson, manifestJson, project = {}) {
const app = { const app = {
...@@ -245,14 +251,14 @@ module.exports = function (pagesJson, manifestJson, project = {}) { ...@@ -245,14 +251,14 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
return { return {
app: { app: {
name: 'app', name: 'app',
content: app content: trimAppJson(app)
} }
} }
} }
return { return {
app: { app: {
name: 'app', name: 'app',
content: app content: trimAppJson(app)
}, },
project: { project: {
name: 'project.config', name: 'project.config',
...@@ -311,7 +317,7 @@ module.exports = function (pagesJson, manifestJson, project = {}) { ...@@ -311,7 +317,7 @@ module.exports = function (pagesJson, manifestJson, project = {}) {
return { return {
app: { app: {
name: 'app', name: 'app',
content: app content: trimAppJson(app)
}, },
project: { project: {
name: 'project.config', name: 'project.config',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册