|
|
"use strict";
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
exports.uniApiPlugin = void 0;
|
|
|
const utils_1 = require("../utils");
|
|
|
const uni_cli_shared_1 = require("@dcloudio/uni-cli-shared");
|
|
|
let enableFacialRecognition = false;
|
|
|
function isEnableFacialRecognition() {
|
|
|
return enableFacialRecognition;
|
|
|
}
|
|
|
function setEnableFacialRecognition(enable) {
|
|
|
enableFacialRecognition = enable;
|
|
|
}
|
|
|
function checkGetMetaInfo(code) {
|
|
|
return code.includes('window.getMetaInfo');
|
|
|
}
|
|
|
function checkFacialRecognition(code) {
|
|
|
return code.includes('getFacialRecognitionMetaInfo');
|
|
|
}
|
|
|
function uniApiPlugin() {
|
|
|
let viteServer = undefined;
|
|
|
const inputDir = (0, uni_cli_shared_1.normalizePath)(process.env.UNI_INPUT_DIR);
|
|
|
return {
|
|
|
name: 'uni:h5-api',
|
|
|
enforce: 'pre',
|
|
|
configureServer(server) {
|
|
|
viteServer = server;
|
|
|
},
|
|
|
transform(code, id) {
|
|
|
if (!viteServer)
|
|
|
return;
|
|
|
// 通过transform阶段识别,仅判断inputDir内部的文件,避免框架文件影响
|
|
|
if (!isEnableFacialRecognition() &&
|
|
|
(0, uni_cli_shared_1.normalizePath)(id).startsWith(inputDir)) {
|
|
|
if (checkFacialRecognition(code)) {
|
|
|
setEnableFacialRecognition(true);
|
|
|
// 开发模式触发重新刷新
|
|
|
viteServer.hot.send({
|
|
|
type: 'full-reload',
|
|
|
path: '*',
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
generateBundle(_options, bundle) {
|
|
|
if (viteServer)
|
|
|
return;
|
|
|
if (!isEnableFacialRecognition()) {
|
|
|
const filesNames = Object.keys(bundle);
|
|
|
for (const fileName of filesNames) {
|
|
|
const chunk = bundle[fileName];
|
|
|
if (chunk && chunk.type === 'chunk' && chunk.code) {
|
|
|
setEnableFacialRecognition(checkFacialRecognition(chunk.code) || checkGetMetaInfo(chunk.code));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
transformIndexHtml: {
|
|
|
order: 'post',
|
|
|
handler() {
|
|
|
if (!isEnableFacialRecognition()) {
|
|
|
return;
|
|
|
}
|
|
|
return [
|
|
|
{
|
|
|
tag: 'script',
|
|
|
attrs: {
|
|
|
src: utils_1.AliYunCloudAuthWebSDK,
|
|
|
},
|
|
|
injectTo: 'head',
|
|
|
},
|
|
|
];
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
}
|
|
|
exports.uniApiPlugin = uniApiPlugin;
|