智能照明系统APP-本地串口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LightingSystemApp-serial/.svn/pristine/10/1055e263d3a82fbeae7e06a34be...

105 lines
2.4 KiB

3 years ago
const {
removeExt,
getPlatformExts,
getPlatformTarget
} = require('@dcloudio/uni-cli-shared')
const {
normalizeNodeModules
} = require('@dcloudio/uni-cli-shared/lib/platform')
const templates = {}
const compilerOptions = {}
const compiledComponentTemplates = {}
let globalComponents = {}
const components = new Set()
const usingComponents = {}
function resolve (source) {
return new Promise((resolve, reject) => {
this.resolve(this.context, source, (err, filepath) => {
if (err) {
reject(err)
return
}
resolve(filepath)
})
})
}
function restoreNodeModules (str) {
if (process.env.UNI_PLATFORM === 'mp-alipay') {
str = str.replace('node-modules/npm-scope-', 'node-modules/@')
}
str = str.replace('node-modules', 'node_modules')
return str
}
module.exports = {
resolve,
restoreNodeModules,
normalizeNodeModules,
getComponents () {
return components
},
getUsingComponents () {
return usingComponents
},
cacheUsingComponents (name, scopedComponents) {
usingComponents[name] = scopedComponents // 方便写入 json usingComponents
scopedComponents.forEach(scopedComponent => {
components.add(scopedComponent.source + '.js')
})
},
cacheGlobalComponents (newGlobalComponents) {
globalComponents = newGlobalComponents
},
cacheTemplate (name, content) {
templates[removeExt(name)] = content
},
cacheCompilerOptions (name, options = {}) {
name = removeExt(name)
compilerOptions[name] = Object.assign(compilerOptions[name] || {}, options)
},
cacheCompiledComponentTemplates (name, options) {
compiledComponentTemplates[name] = options
},
getCompiledComponentTemplate (name) {
return compiledComponentTemplates[name] || {}
},
getTemplates () {
return templates
},
getCompilerOptions () {
return compilerOptions
},
getGlobalComponents () {
return globalComponents
},
getPages () {
const pages = {}
Object.keys(process.UNI_ENTRY).forEach(page => {
if (compilerOptions[page]) {
pages[page] = compilerOptions[page].name
}
})
return pages
},
getSubPages () {
return process.UNI_SUB_PACKAGES_ROOT
},
getRoot (filePath, subPackages) {
const subPackage = subPackages.find(subPackage => filePath.indexOf(subPackage + '/') === 0)
if (subPackage) {
return subPackage + '/'
}
return ''
},
getPlatformExts,
getPlatformTarget
}