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

feat(qa): add manifest.json

上级 3f207413
......@@ -4,7 +4,7 @@ const webpack = require('webpack')
const CopyPlugin = require('copy-webpack-plugin')
const HandlerPlugin = require('@hap-toolkit/packager/lib/plugin/handler-plugin')
const ZipPlugin = require('@hap-toolkit/packager/lib/plugin/zip-plugin')
const ZipPlugin = require('@hap-toolkit/packager/lib/plugin/zip-plugin')
const NotifyPlugin = require('@hap-toolkit/packager/lib/plugin/notify-plugin')
const Css2jsonPlugin = require('@hap-toolkit/dsl-vue/lib/plugin/css2json-plugin')
......@@ -17,15 +17,23 @@ const env = {
NODE_PHASE: process.env.NODE_PHASE
}
const dslFilename = 'vue.' + (process.env.NODE_ENV === 'production' ? 'prod' : 'dev') + '.js'
const manifest = global.framework.manifest
const dslFilename = ('vue.' + (process.env.NODE_ENV === 'production' ? 'prod' : 'dev') + '.js')
function genPriorities(e) {
const manifest = process.UNI_MANIFEST.quickapp || {}
const entryPagePath = process.UNI_PAGES.pages[0].path
const versionCode = parseInt(manifest.versionCode || process.UNI_MANIFEST.versionCode) || 1
if (!manifest.package) {
console.error(`maniest.json quickapp 节点缺少 package 配置`)
process.exit(0)
}
function genPriorities(entryPagePath) {
const o = [/^i18n\/.+\.json$/i, 'manifest.json', 'app.js', /^common\//i];
if (e && e.router && e.router.entry) {
const n = e.router.entry;
o.splice(3, 0, new RegExp(`^${n}/$`), new RegExp(`^${n}/.+`))
} else colorconsole.error('manifest.json 中未配置入口页面 router.entry');
if (entryPagePath) {
o.splice(3, 0, new RegExp(`^${entryPagePath}/$`), new RegExp(`^${entryPagePath}/.+`))
} else console.error('未配置入口页面');
return o
}
......@@ -50,23 +58,22 @@ module.exports = {
new CopyPlugin([{
from: path.resolve(__dirname, '../dist/' + dslFilename),
to: 'dsl.js'
}, {
from: path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json')
}]),
new HandlerPlugin({}),
new Css2jsonPlugin(),
new InstVuePlugin(),
// TODO 目前 manifest,entryPagePath 是启动时读取一次
new ZipPlugin({
name: manifest.package,
icon: manifest.icon,
versionCode: manifest.versionCode,
output: path.resolve(process.env.UNI_OUTPUT_DIR),
pathBuild: path.resolve(process.env.UNI_OUTPUT_DIR, 'build'),
versionCode,
output: path.resolve(process.env.UNI_OUTPUT_DIR, '..'),
pathBuild: process.env.UNI_OUTPUT_DIR,
pathSignFolder: './sign',
sign: process.env.NODE_ENV === 'production' ? 'release' : 'debug',
priorities: genPriorities(manifest),
priorities: genPriorities(entryPagePath),
subpackages: undefined,
comment: '{"toolkit":"0.6.13","timeStamp":"2020-03-08T13:22:31.014Z","node":"v12.15.0","platform":"darwin","arch":"x64","extends":null}',
comment: '',
cwd: process.env.UNI_INPUT_DIR,
disableStreamPack: undefined,
disableSubpackages: undefined
......
global.framework = {}
global.framework.manifest = require('/Users/fxy/Documents/demo/my-qa-project/src/manifest.json')
const ATTRS = {
'name': 'name',
'versionName': 'versionName',
'versionCode': 'versionCode'
}
function merge(to, from) {
Object.keys(ATTRS).forEach(name => {
if (!to[name]) {
to[name] = from[name]
}
})
}
module.exports = function parseBase(manifest, manifestJson) {
merge(manifest, manifestJson)
manifest.versionCode = parseInt(manifest.versionCode) || 1
if (!manifest.config) {
manifest.config = {}
}
if (!manifest.config.dsl) {
manifest.config.dsl = {}
}
manifest.config.dsl.name = 'vue'
return manifest
}
const PLATFORMS = [
'h5',
'app-plus',
'mp-weixin',
'mp-qq',
'mp-baidu',
'mp-alipay',
'mp-toutiao',
'quickapp'
]
const DISPLAY = {
'navigationBarBackgroundColor': 'titleBarBackgroundColor',
'navigationBarTextStyle': (style, val) => {
if (val === 'black') {
style.titleBarTextColor = '#000000'
style.statusBarTextStyle = 'dark'
} else {
style.titleBarTextColor = '#ffffff'
style.statusBarTextStyle = 'light'
}
},
'navigationBarTitleText': 'titleBarText',
'navigationStyle': (style, val) => {
if (val === 'custom') {
style.titleBar = false
}
}
}
function parseStyle(style = {}) {
const ret = {}
Object.keys(style).forEach(name => {
if (!PLATFORMS.includes(name)) {
const transform = DISPLAY[name]
if (transform) {
if (typeof transform === 'string') {
ret[transform] = style[name]
} else if (typeof transform === 'function') {
transform(ret, style[name])
}
} else {
ret[name] = style[name]
}
}
})
if (style.quickapp) {
Object.assign(ret, style.quickapp)
}
return ret
}
module.exports = function parseDisplay(manifest, pages, globalStyle = {}) {
const display = {
pages: {}
}
// globalStyle
Object.assign(display, parseStyle(globalStyle))
pages.forEach(page => {
const key = page.path.substr(0, page.path.lastIndexOf('/'))
display.pages[key] = parseStyle(page.style)
})
manifest.display = display
}
const parseBase = require('./base-parser')
const parsePages = require('./pages-parser')
const parseDisplay = require('./display-parser')
module.exports = function(pagesJson, manifestJson, loader) {
const manifest = manifestJson.quickapp || {}
parseBase(manifest, manifestJson)
parsePages(manifest, pagesJson.pages)
parseDisplay(manifest, pagesJson.pages, pagesJson.globalStyle)
global.framework.manifest = manifest
loader.emitFile('manifest.json', JSON.stringify(manifest))
return ''
}
module.exports = function parsePages(manifest, pages) {
const entryPagePath = pages[0].path
const router = {
entry: entryPagePath.substr(0, entryPagePath.lastIndexOf('/')),
pages: {}
}
pages.forEach(page => {
const lastIndex = page.path.lastIndexOf('/')
const key = page.path.substr(0, lastIndex)
router.pages[key] = {
component: page.path.substr(lastIndex + 1)
}
})
manifest.router = router
}
module.exports = function parseEntry() {
}
require('./env')
global.framework = {}
const chainWebpack = require('./chain-webpack')
const configureWebpack = require('./configure-webpack')
......
......@@ -20,9 +20,10 @@ module.exports = (api, options) => {
initBuildCommand(api, options)
if (process.env.UNI_PLATFORM === 'quickapp') {
process.env.UNI_OUTPUT_DIR = path.resolve(process.env.UNI_OUTPUT_DIR, 'build')
Object.assign(options, {
assetsDir,
outputDir: path.resolve(process.env.UNI_OUTPUT_DIR, 'build')
outputDir: process.env.UNI_OUTPUT_DIR
})
require('./lib/options')(options)
const platformOptions = {
......
......@@ -18,27 +18,27 @@ if (process.env.UNI_CLOUD_SPACES) {
if (spaces.length === 1) {
const space = spaces[0]
console.log(`本项目的uniCloud使用的默认服务空间spaceId为:${space.id}`)
}
process.env.UNI_CLOUD_PROVIDER = JSON.stringify(spaces.map(space => {
if (space.clientSecret) {
return {
provider: 'aliyun',
spaceName: space.name,
spaceId: space.id,
clientSecret: space.clientSecret,
endpoint: space.apiEndpoint
}
} else {
return {
provider: 'tencent',
spaceName: space.name,
spaceId: space.id
}
}
}
process.env.UNI_CLOUD_PROVIDER = JSON.stringify(spaces.map(space => {
if (space.clientSecret) {
return {
provider: 'aliyun',
spaceName: space.name,
spaceId: space.id,
clientSecret: space.clientSecret,
endpoint: space.apiEndpoint
}
} else {
return {
provider: 'tencent',
spaceName: space.name,
spaceId: space.id
}
}
}))
}
} catch (e) {}
}
}
if (
process.UNI_CLOUD &&
......@@ -88,7 +88,7 @@ if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache
delete process.env.UNI_USING_CACHE
}
const {
const {
normalizePath,
isSupportSubPackages,
runByHBuilderX,
......@@ -120,6 +120,9 @@ if (Array.isArray(pagesJsonObj.subPackages)) {
const manifestJsonObj = getManifestJson()
const platformOptions = manifestJsonObj[process.env.UNI_PLATFORM] || {}
process.UNI_PAGES = pagesJsonObj
process.UNI_MANIFEST = manifestJsonObj
if (manifestJsonObj.debug) {
process.env.VUE_APP_DEBUG = true
}
......@@ -212,7 +215,7 @@ if (process.env.UNI_PLATFORM === 'app-plus') {
normalizePath(path.resolve(process.env.UNI_INPUT_DIR, filepath))
)
}
}
}
} else { // 其他平台,待确认配置方案
if (
manifestJsonObj['app-plus'] &&
......
......@@ -69,6 +69,9 @@ module.exports = function (content) {
if (process.env.UNI_PLATFORM === 'h5') {
return require('./platforms/h5')(pagesJson, manifestJson)
}
if (process.env.UNI_PLATFORM === 'quickapp') {
return require('./platforms/quickapp')(pagesJson, manifestJson, this)
}
if (!process.env.UNI_USING_V3) {
parsePages(pagesJson, function (page) {
......
......@@ -41,7 +41,11 @@ module.exports = function (content) {
}
}
if (process.env.UNI_USING_COMPONENTS || process.env.UNI_PLATFORM === 'h5') {
if (
process.env.UNI_USING_COMPONENTS ||
process.env.UNI_PLATFORM === 'h5' ||
process.env.UNI_PLATFORM === 'quickapp'
) {
return require('./index-new').call(this, content)
}
......
module.exports = function (pagesJson, manifestJson, loader) {
return require('@dcloudio/uni-quickapp/lib/manifest')(pagesJson, manifestJson, loader)
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册