forked from dcloudio/uni-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
235 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
module.exports = { | ||
ignore: [ | ||
"./packages", | ||
], | ||
presets: [ | ||
["@vue/app", { | ||
useBuiltIns: "entry" | ||
}] | ||
] | ||
ignore: [ | ||
"./packages", | ||
], | ||
presets: [ | ||
["@vue/app", { | ||
useBuiltIns: "entry" | ||
}] | ||
], | ||
plugins: [require('./lib/babel-plugin-uni-api/index.js')] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const apis = require('../src/core/helpers/apis') | ||
|
||
function parseApiManifestDeps (manifest) { | ||
Object.keys(manifest).forEach(name => { | ||
const deps = manifest[name][1] | ||
if (deps && deps.length) { | ||
deps.forEach(dep => { | ||
if (manifest[dep[1]]) { | ||
dep[0] = manifest[dep[1]][0] | ||
} else { | ||
console.warn(`依赖模块[${dep[1]}]不存在`) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
|
||
module.exports = { | ||
generateApiManifest (manifest) { | ||
parseApiManifestDeps(manifest) | ||
|
||
const manifestJson = Object.create(null) | ||
const todoApis = [] | ||
apis.forEach(name => { | ||
if (manifest[name]) { | ||
manifestJson[name] = manifest[name] | ||
} else { | ||
todoApis.push(name) | ||
} | ||
}) | ||
|
||
if (todoApis.length) { | ||
console.warn(`${process.env.UNI_PLATFORM} 平台缺少以下 API 实现`) | ||
todoApis.forEach(name => { | ||
console.warn(name) | ||
}) | ||
} | ||
|
||
fs.writeFileSync(path.resolve(__dirname, '../packages/uni-h5/manifest.json'), | ||
JSON.stringify(manifestJson, null, 4) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const path = require('path') | ||
|
||
const isWin = /^win/.test(process.platform) | ||
|
||
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) | ||
|
||
function resolve(...args) { | ||
return normalizePath(path.resolve.apply(path, [__dirname, ...args])) | ||
} | ||
|
||
const srcPath = resolve('../../src/') | ||
const coreApiPath = resolve('../../src/core/service/api') | ||
const platformApiPath = resolve('../../src/platforms/' + process.env.UNI_PLATFORM + '/service/api') | ||
|
||
const apis = require('../../src/core/helpers/apis') | ||
|
||
process.UNI_SERVICE_API_MANIFEST = Object.create(null) | ||
|
||
module.exports = function({ | ||
types: t | ||
}) { | ||
return { | ||
visitor: { | ||
Program: { | ||
enter(path, state) { | ||
state.file.opts.file = normalizePath(state.file.opts.filename) | ||
state.file.opts.isCore = state.file.opts.file.indexOf(coreApiPath) === 0 | ||
state.file.opts.isPlatform = state.file.opts.file.indexOf(platformApiPath) === 0 | ||
}, | ||
exit(path, state) { | ||
const { | ||
file, | ||
methods, | ||
exports, | ||
isPlatform | ||
} = state.file.opts | ||
if (exports && exports.length) { | ||
const deps = [] | ||
methods && methods.forEach(method => { | ||
deps.push(['', method]) | ||
}) | ||
const filepath = file.replace(srcPath, '') | ||
exports.forEach(exportName => { | ||
if (process.UNI_SERVICE_API_MANIFEST[exportName]) { | ||
console.warn(`API[${exportName}] 冲突:`) | ||
console.warn(process.UNI_SERVICE_API_MANIFEST[exportName][0]) | ||
console.warn(filepath) | ||
if (isPlatform) { // 优先使用 platform | ||
process.UNI_SERVICE_API_MANIFEST[exportName] = [filepath, deps] | ||
console.warn(`优先使用` + filepath) | ||
} | ||
} else { | ||
process.UNI_SERVICE_API_MANIFEST[exportName] = [filepath, deps] | ||
} | ||
}) | ||
} | ||
} | ||
}, | ||
ExportNamedDeclaration(path, state) { | ||
const { | ||
file, | ||
isCore, | ||
isPlatform | ||
} = state.file.opts | ||
if ((isCore || isPlatform) && t.isFunctionDeclaration(path.node.declaration)) { | ||
(state.file.opts.exports || (state.file.opts.exports = [])).push(path.node.declaration.id.name) | ||
} | ||
}, | ||
CallExpression(path, state) { | ||
const { | ||
file, | ||
isCore, | ||
isPlatform | ||
} = state.file.opts | ||
|
||
if ( | ||
isCore && | ||
path.node.callee.name === 'invokeMethod' | ||
) { | ||
(state.file.opts.methods || (state.file.opts.methods = new Set())).add(path.node.arguments[0].value) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
import { encode, decode } from 'base64-arraybuffer' | ||
|
||
export const base64ToArrayBuffer = decode | ||
export const arrayBufferToBase64 = encode | ||
import { | ||
encode, | ||
decode | ||
} from 'base64-arraybuffer' | ||
|
||
export function base64ToArrayBuffer (str) { | ||
return decode(str) | ||
} | ||
|
||
export function arrayBufferToBase64 (buffer) { | ||
return encode(buffer) | ||
} |