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

fix(cli): uni_modules with easycom

上级 6ae16fb3
...@@ -339,12 +339,18 @@ const isDirectory = source => fs.lstatSync(source).isDirectory() ...@@ -339,12 +339,18 @@ 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)) {
let importComponentsDir = '@/components'
const uniModulesDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules')
if (!absolute && componentsPath.includes(uniModulesDir)) {
importComponentsDir = `@/uni_modules/${path.basename(path.dirname(componentsPath))}/components`
}
fs.readdirSync(componentsPath).forEach(name => {
const folder = path.resolve(componentsPath, name) const folder = path.resolve(componentsPath, name)
if (!isDirectory(folder)) { if (!isDirectory(folder)) {
return return
} }
const importDir = absolute ? normalizePath(folder) : `@/components/${name}` const importDir = absolute ? normalizePath(folder) : `${importComponentsDir}/${name}`
// 读取文件夹文件列表,比对文件名(fs.existsSync在大小写不敏感的系统会匹配不准确) // 读取文件夹文件列表,比对文件名(fs.existsSync在大小写不敏感的系统会匹配不准确)
const files = fs.readdirSync(folder) const files = fs.readdirSync(folder)
if (files.includes(name + '.vue')) { if (files.includes(name + '.vue')) {
...@@ -353,6 +359,7 @@ function getAutoComponentsByDir (componentsPath, absolute = false) { ...@@ -353,6 +359,7 @@ function getAutoComponentsByDir (componentsPath, absolute = false) {
components[`^${name}$`] = `${importDir}/${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
} }
......
...@@ -172,6 +172,12 @@ function getCondition (pagesJson) { ...@@ -172,6 +172,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 = {
pages: [], pages: [],
...@@ -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.
先完成此消息的编辑!
想要评论请 注册