更新
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
export * from './pages';
|
||||
export * from './manifest';
|
||||
export { polyfillCode, arrayBufferCode, restoreGlobalCode } from './pages/code';
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.restoreGlobalCode = exports.arrayBufferCode = exports.polyfillCode = void 0;
|
||||
__exportStar(require("./pages"), exports);
|
||||
__exportStar(require("./manifest"), exports);
|
||||
var code_1 = require("./pages/code");
|
||||
Object.defineProperty(exports, "polyfillCode", { enumerable: true, get: function () { return code_1.polyfillCode; } });
|
||||
Object.defineProperty(exports, "arrayBufferCode", { enumerable: true, get: function () { return code_1.arrayBufferCode; } });
|
||||
Object.defineProperty(exports, "restoreGlobalCode", { enumerable: true, get: function () { return code_1.restoreGlobalCode; } });
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare function initArguments(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): void;
|
||||
export declare function parseArguments(pagesJson: UniApp.PagesJson): string | undefined;
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseArguments = exports.initArguments = void 0;
|
||||
function initArguments(manifestJson, pagesJson) {
|
||||
const args = parseArguments(pagesJson);
|
||||
if (args) {
|
||||
manifestJson.plus.arguments = args;
|
||||
}
|
||||
}
|
||||
exports.initArguments = initArguments;
|
||||
function parseArguments(pagesJson) {
|
||||
if (process.env.NODE_ENV !== 'development') {
|
||||
return;
|
||||
}
|
||||
// 指定了入口
|
||||
if (process.env.UNI_CLI_LAUNCH_PAGE_PATH) {
|
||||
return JSON.stringify({
|
||||
path: process.env.UNI_CLI_LAUNCH_PAGE_PATH,
|
||||
query: process.env.UNI_CLI_LAUNCH_PAGE_QUERY,
|
||||
});
|
||||
}
|
||||
const condition = pagesJson.condition;
|
||||
if (condition && condition.list?.length) {
|
||||
const list = condition.list;
|
||||
let current = condition.current || 0;
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
}
|
||||
if (current >= list.length) {
|
||||
current = 0;
|
||||
}
|
||||
return JSON.stringify(list[current]);
|
||||
}
|
||||
}
|
||||
exports.parseArguments = parseArguments;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initCheckSystemWebview(manifestJson: Record<string, any>): void;
|
||||
Generated
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initCheckSystemWebview = void 0;
|
||||
function initCheckSystemWebview(manifestJson) {
|
||||
// 检查Android系统webview版本 || 下载X5后启动
|
||||
let plusWebView = manifestJson.plus.webView;
|
||||
if (plusWebView) {
|
||||
manifestJson.plus['uni-app'].webView = plusWebView;
|
||||
delete manifestJson.plus.webView;
|
||||
}
|
||||
else {
|
||||
manifestJson.plus['uni-app'].webView = {
|
||||
minUserAgentVersion: '49.0',
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.initCheckSystemWebview = initCheckSystemWebview;
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
export declare const APP_CONFUSION_FILENAME = "app-confusion.js";
|
||||
export declare function isConfusionFile(filename: string): boolean;
|
||||
export declare function hasConfusionFile(inputDir?: string): boolean;
|
||||
export declare function initConfusion(manifestJson: Record<string, any>): void;
|
||||
Generated
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initConfusion = exports.hasConfusionFile = exports.isConfusionFile = exports.APP_CONFUSION_FILENAME = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const utils_1 = require("../../../utils");
|
||||
const constants_1 = require("../../../constants");
|
||||
const manifest_1 = require("../../manifest");
|
||||
function isJsFile(filename) {
|
||||
return constants_1.EXTNAME_JS_RE.test(filename);
|
||||
}
|
||||
function isStaticJsFile(filename) {
|
||||
return (filename.indexOf('hybrid/html') === 0 ||
|
||||
filename.indexOf('static/') === 0 ||
|
||||
filename.indexOf('/static/') !== -1); // subpackages, uni_modules 中的 static 目录
|
||||
}
|
||||
const dynamicConfusionJsFiles = [];
|
||||
exports.APP_CONFUSION_FILENAME = 'app-confusion.js';
|
||||
function isConfusionFile(filename) {
|
||||
return dynamicConfusionJsFiles.includes((0, utils_1.normalizePath)(filename));
|
||||
}
|
||||
exports.isConfusionFile = isConfusionFile;
|
||||
function hasConfusionFile(inputDir) {
|
||||
if (inputDir) {
|
||||
const manifestJson = (0, manifest_1.parseManifestJsonOnce)(inputDir);
|
||||
const resources = manifestJson['app-plus']?.confusion?.resources;
|
||||
if (resources && parseConfusion(resources)[1].length) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !!dynamicConfusionJsFiles.length;
|
||||
}
|
||||
exports.hasConfusionFile = hasConfusionFile;
|
||||
function parseConfusion(resources) {
|
||||
const res = {};
|
||||
const dynamicJsFiles = [];
|
||||
Object.keys(resources).reduce((res, name) => {
|
||||
const extname = path_1.default.extname(name);
|
||||
if (extname === '.nvue') {
|
||||
res[name.replace('.nvue', '.js')] = resources[name];
|
||||
}
|
||||
else if (isJsFile(name)) {
|
||||
// 静态 js 加密
|
||||
if (isStaticJsFile(name)) {
|
||||
res[name] = resources[name];
|
||||
}
|
||||
else {
|
||||
// 非静态 js 将被合并进 app-confusion.js
|
||||
dynamicJsFiles.push(name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error(`原生混淆仅支持 nvue 页面,错误的页面路径:${name}`);
|
||||
}
|
||||
// TODO 旧编译器会检查要加密的 nvue 页面(包括subnvue)是否被使用?后续有时间再考虑支持吧,意义不太大
|
||||
return res;
|
||||
}, res);
|
||||
if (dynamicJsFiles.length) {
|
||||
res[exports.APP_CONFUSION_FILENAME] = {};
|
||||
}
|
||||
return [res, dynamicJsFiles];
|
||||
}
|
||||
function initConfusion(manifestJson) {
|
||||
dynamicConfusionJsFiles.length = 0;
|
||||
if (!manifestJson.plus.confusion?.resources) {
|
||||
return;
|
||||
}
|
||||
const resources = manifestJson.plus.confusion.resources;
|
||||
const [res, dynamicJsFiles] = parseConfusion(resources);
|
||||
manifestJson.plus.confusion.resources = res;
|
||||
dynamicConfusionJsFiles.push(...dynamicJsFiles);
|
||||
}
|
||||
exports.initConfusion = initConfusion;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initDefaultManifestJson(): any;
|
||||
Generated
Vendored
+47
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initDefaultManifestJson = void 0;
|
||||
function initDefaultManifestJson() {
|
||||
return JSON.parse(defaultManifestJson);
|
||||
}
|
||||
exports.initDefaultManifestJson = initDefaultManifestJson;
|
||||
const defaultManifestJson = `{
|
||||
"@platforms": [
|
||||
"android",
|
||||
"iPhone",
|
||||
"iPad"
|
||||
],
|
||||
"id": "__WEAPP_ID",
|
||||
"name": "__WEAPP_NAME",
|
||||
"version": {
|
||||
"name": "1.0",
|
||||
"code": ""
|
||||
},
|
||||
"description": "",
|
||||
"developer": {
|
||||
"name": "",
|
||||
"email": "",
|
||||
"url": ""
|
||||
},
|
||||
"permissions": {},
|
||||
"plus": {
|
||||
"useragent": {
|
||||
"value": "",
|
||||
"concatenate": true
|
||||
},
|
||||
"splashscreen": {
|
||||
"target":"id:1",
|
||||
"autoclose": true,
|
||||
"waiting": true,
|
||||
"alwaysShowBeforeRender":true
|
||||
},
|
||||
"popGesture": "close",
|
||||
"launchwebview": {}
|
||||
},
|
||||
"app-harmony": {
|
||||
"useragent": {
|
||||
"value": "",
|
||||
"concatenate": true
|
||||
}
|
||||
}
|
||||
}`;
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export declare function getAppRenderer(manifestJson: Record<string, any>): "" | "native";
|
||||
export declare function getAppCodeSpliting(manifestJson: Record<string, any>): boolean;
|
||||
export declare function getAppStyleIsolation(manifestJson: Record<string, any>): 'apply-shared' | 'isolated' | 'shared';
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getAppStyleIsolation = exports.getAppCodeSpliting = exports.getAppRenderer = void 0;
|
||||
function getAppRenderer(manifestJson) {
|
||||
const platformOptions = manifestJson['app-plus'];
|
||||
if (platformOptions && platformOptions.renderer === 'native') {
|
||||
return 'native';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
exports.getAppRenderer = getAppRenderer;
|
||||
function getAppCodeSpliting(manifestJson) {
|
||||
if (manifestJson['app-plus']?.optimization?.codeSpliting === true) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.getAppCodeSpliting = getAppCodeSpliting;
|
||||
function getAppStyleIsolation(manifestJson) {
|
||||
return (manifestJson['app-plus']?.optimization?.styleIsolation ?? 'apply-shared');
|
||||
}
|
||||
exports.getAppStyleIsolation = getAppStyleIsolation;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initI18n(manifestJson: Record<string, any>): Record<string, any>;
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initI18n = void 0;
|
||||
const uni_i18n_1 = require("@dcloudio/uni-i18n");
|
||||
const i18n_1 = require("../../../i18n");
|
||||
function initI18n(manifestJson) {
|
||||
const i18nOptions = (0, i18n_1.initI18nOptions)(process.env.UNI_PLATFORM, process.env.UNI_INPUT_DIR, true);
|
||||
if (i18nOptions) {
|
||||
manifestJson = JSON.parse((0, uni_i18n_1.compileI18nJsonStr)(JSON.stringify(manifestJson), i18nOptions));
|
||||
manifestJson.fallbackLocale = i18nOptions.locale;
|
||||
}
|
||||
return manifestJson;
|
||||
}
|
||||
exports.initI18n = initI18n;
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export declare function normalizeAppManifestJson(userManifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): Record<string, any>;
|
||||
export * from './env';
|
||||
export { APP_CONFUSION_FILENAME, isConfusionFile, hasConfusionFile, } from './confusion';
|
||||
export { getNVueCompiler, getNVueStyleCompiler, getNVueFlexDirection, } from './nvue';
|
||||
export { parseArguments } from './arguments';
|
||||
Generated
Vendored
+63
@@ -0,0 +1,63 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseArguments = exports.getNVueFlexDirection = exports.getNVueStyleCompiler = exports.getNVueCompiler = exports.hasConfusionFile = exports.isConfusionFile = exports.APP_CONFUSION_FILENAME = exports.normalizeAppManifestJson = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const merge_1 = require("./merge");
|
||||
const defaultManifestJson_1 = require("./defaultManifestJson");
|
||||
const statusbar_1 = require("./statusbar");
|
||||
const plus_1 = require("./plus");
|
||||
const nvue_1 = require("./nvue");
|
||||
const arguments_1 = require("./arguments");
|
||||
const safearea_1 = require("./safearea");
|
||||
const splashscreen_1 = require("./splashscreen");
|
||||
const confusion_1 = require("./confusion");
|
||||
const uniApp_1 = require("./uniApp");
|
||||
const launchwebview_1 = require("./launchwebview");
|
||||
const checksystemwebview_1 = require("./checksystemwebview");
|
||||
const tabBar_1 = require("./tabBar");
|
||||
const i18n_1 = require("./i18n");
|
||||
const theme_1 = require("../../theme");
|
||||
function normalizeAppManifestJson(userManifestJson, pagesJson) {
|
||||
const manifestJson = (0, merge_1.initRecursiveMerge)((0, defaultManifestJson_1.initDefaultManifestJson)(), userManifestJson);
|
||||
const { pages, globalStyle, tabBar } = (0, theme_1.initTheme)(manifestJson, pagesJson);
|
||||
(0, shared_1.extend)(pagesJson, JSON.parse(JSON.stringify({ pages, globalStyle, tabBar })));
|
||||
(0, statusbar_1.initAppStatusbar)(manifestJson, pagesJson);
|
||||
(0, arguments_1.initArguments)(manifestJson, pagesJson);
|
||||
(0, plus_1.initPlus)(manifestJson, pagesJson);
|
||||
(0, nvue_1.initNVue)(manifestJson, pagesJson);
|
||||
(0, safearea_1.initSafearea)(manifestJson, pagesJson);
|
||||
(0, splashscreen_1.initSplashscreen)(manifestJson, userManifestJson);
|
||||
(0, confusion_1.initConfusion)(manifestJson);
|
||||
(0, uniApp_1.initUniApp)(manifestJson);
|
||||
// 依赖 initArguments 先执行
|
||||
(0, tabBar_1.initTabBar)((0, launchwebview_1.initLaunchwebview)(manifestJson, pagesJson), manifestJson, pagesJson);
|
||||
// 依赖 initUniApp 先执行
|
||||
(0, checksystemwebview_1.initCheckSystemWebview)(manifestJson);
|
||||
return (0, i18n_1.initI18n)(manifestJson);
|
||||
}
|
||||
exports.normalizeAppManifestJson = normalizeAppManifestJson;
|
||||
__exportStar(require("./env"), exports);
|
||||
var confusion_2 = require("./confusion");
|
||||
Object.defineProperty(exports, "APP_CONFUSION_FILENAME", { enumerable: true, get: function () { return confusion_2.APP_CONFUSION_FILENAME; } });
|
||||
Object.defineProperty(exports, "isConfusionFile", { enumerable: true, get: function () { return confusion_2.isConfusionFile; } });
|
||||
Object.defineProperty(exports, "hasConfusionFile", { enumerable: true, get: function () { return confusion_2.hasConfusionFile; } });
|
||||
var nvue_2 = require("./nvue");
|
||||
Object.defineProperty(exports, "getNVueCompiler", { enumerable: true, get: function () { return nvue_2.getNVueCompiler; } });
|
||||
Object.defineProperty(exports, "getNVueStyleCompiler", { enumerable: true, get: function () { return nvue_2.getNVueStyleCompiler; } });
|
||||
Object.defineProperty(exports, "getNVueFlexDirection", { enumerable: true, get: function () { return nvue_2.getNVueFlexDirection; } });
|
||||
var arguments_2 = require("./arguments");
|
||||
Object.defineProperty(exports, "parseArguments", { enumerable: true, get: function () { return arguments_2.parseArguments; } });
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initLaunchwebview(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): string;
|
||||
Generated
Vendored
+53
@@ -0,0 +1,53 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initLaunchwebview = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
function initLaunchwebview(manifestJson, pagesJson) {
|
||||
let entryPagePath = pagesJson.pages[0].path;
|
||||
// 依赖前置执行initArguments
|
||||
if (manifestJson.plus.arguments) {
|
||||
try {
|
||||
const args = JSON.parse(manifestJson.plus.arguments);
|
||||
if (args.path) {
|
||||
entryPagePath = args.path;
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
if (manifestJson.plus.useragent.concatenate) {
|
||||
if (manifestJson.plus.useragent.value) {
|
||||
manifestJson.plus.useragent.value = [
|
||||
'uni-app',
|
||||
manifestJson.plus.useragent.value,
|
||||
].join(' ');
|
||||
}
|
||||
else {
|
||||
manifestJson.plus.useragent.value = 'uni-app';
|
||||
}
|
||||
}
|
||||
if (manifestJson['app-harmony'].useragent.concatenate) {
|
||||
if (manifestJson['app-harmony'].useragent.value) {
|
||||
manifestJson['app-harmony'].useragent.value = [
|
||||
'uni-app',
|
||||
manifestJson['app-harmony'].useragent.value,
|
||||
].join(' ');
|
||||
}
|
||||
else {
|
||||
manifestJson['app-harmony'].useragent.value = 'uni-app';
|
||||
}
|
||||
}
|
||||
(0, shared_1.extend)(manifestJson.plus.launchwebview, {
|
||||
id: '1',
|
||||
kernel: 'WKWebview',
|
||||
});
|
||||
// 首页为nvue
|
||||
const entryPage = pagesJson.pages.find((p) => p.path === entryPagePath);
|
||||
if (entryPage?.style.isNVue) {
|
||||
manifestJson.plus.launchwebview.uniNView = { path: entryPagePath + '.js' };
|
||||
}
|
||||
else {
|
||||
manifestJson.launch_path = '__uniappview.html';
|
||||
}
|
||||
return entryPagePath;
|
||||
}
|
||||
exports.initLaunchwebview = initLaunchwebview;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initRecursiveMerge(manifestJson: Record<string, any>, userManifestJson: Record<string, any>): Record<string, any>;
|
||||
Generated
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initRecursiveMerge = void 0;
|
||||
const merge_1 = require("merge");
|
||||
function initRecursiveMerge(manifestJson, userManifestJson) {
|
||||
const platformConfig = {
|
||||
plus: userManifestJson['app-plus'],
|
||||
};
|
||||
platformConfig['app-harmony'] = userManifestJson['app-harmony'];
|
||||
return (0, merge_1.recursive)(true, manifestJson, {
|
||||
id: userManifestJson.appid || '',
|
||||
name: userManifestJson.name || '',
|
||||
description: userManifestJson.description || '',
|
||||
version: {
|
||||
name: userManifestJson.versionName,
|
||||
code: userManifestJson.versionCode,
|
||||
},
|
||||
locale: userManifestJson.locale,
|
||||
uniStatistics: userManifestJson.uniStatistics,
|
||||
}, platformConfig);
|
||||
}
|
||||
exports.initRecursiveMerge = initRecursiveMerge;
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
export declare function initNVue(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): void;
|
||||
export declare function getNVueCompiler(manifestJson: Record<string, any>): "uni-app" | "vue" | "weex" | "vite";
|
||||
export declare function getNVueStyleCompiler(manifestJson: Record<string, any>): "uni-app" | "weex";
|
||||
export declare function getNVueFlexDirection(manifestJson: Record<string, any>): "column" | "row" | "row-reverse" | "column-reverse";
|
||||
Generated
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getNVueFlexDirection = exports.getNVueStyleCompiler = exports.getNVueCompiler = exports.initNVue = void 0;
|
||||
function initNVue(manifestJson, pagesJson) { }
|
||||
exports.initNVue = initNVue;
|
||||
function getNVueCompiler(manifestJson) {
|
||||
const platformOptions = manifestJson['app-plus'];
|
||||
if (platformOptions) {
|
||||
const { nvueCompiler } = platformOptions;
|
||||
if (nvueCompiler === 'weex') {
|
||||
return 'weex';
|
||||
}
|
||||
if (nvueCompiler === 'vue') {
|
||||
return 'vue';
|
||||
}
|
||||
if (nvueCompiler === 'vite') {
|
||||
return 'vite';
|
||||
}
|
||||
}
|
||||
return 'uni-app';
|
||||
}
|
||||
exports.getNVueCompiler = getNVueCompiler;
|
||||
function getNVueStyleCompiler(manifestJson) {
|
||||
const platformOptions = manifestJson['app-plus'];
|
||||
if (platformOptions && platformOptions.nvueStyleCompiler === 'uni-app') {
|
||||
return 'uni-app';
|
||||
}
|
||||
return 'weex';
|
||||
}
|
||||
exports.getNVueStyleCompiler = getNVueStyleCompiler;
|
||||
const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse'];
|
||||
function getNVueFlexDirection(manifestJson) {
|
||||
let flexDir = 'column';
|
||||
const appPlusJson = manifestJson['app-plus'] || manifestJson['plus'];
|
||||
if (appPlusJson?.nvue?.['flex-direction'] &&
|
||||
flexDirs.includes(appPlusJson?.nvue?.['flex-direction'])) {
|
||||
flexDir = appPlusJson.nvue['flex-direction'];
|
||||
}
|
||||
return flexDir;
|
||||
}
|
||||
exports.getNVueFlexDirection = getNVueFlexDirection;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initPlus(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): void;
|
||||
Generated
Vendored
+131
@@ -0,0 +1,131 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initPlus = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const merge_1 = require("merge");
|
||||
const wxPageOrientationMapping = {
|
||||
auto: [
|
||||
'portrait-primary',
|
||||
'portrait-secondary',
|
||||
'landscape-primary',
|
||||
'landscape-secondary',
|
||||
],
|
||||
portrait: ['portrait-primary', 'portrait-secondary'],
|
||||
landscape: ['landscape-primary', 'landscape-secondary'],
|
||||
};
|
||||
function initPlus(manifestJson, pagesJson) {
|
||||
initUniStatistics(manifestJson);
|
||||
// 转换为老版本配置
|
||||
if (manifestJson.plus.modules) {
|
||||
manifestJson.permissions = manifestJson.plus.modules;
|
||||
delete manifestJson.plus.modules;
|
||||
}
|
||||
const distribute = manifestJson.plus.distribute;
|
||||
if (distribute) {
|
||||
if (distribute.android) {
|
||||
manifestJson.plus.distribute.google = distribute.android;
|
||||
delete manifestJson.plus.distribute.android;
|
||||
}
|
||||
if (distribute.ios) {
|
||||
manifestJson.plus.distribute.apple = distribute.ios;
|
||||
delete manifestJson.plus.distribute.ios;
|
||||
}
|
||||
if (distribute.sdkConfigs) {
|
||||
manifestJson.plus.distribute.plugins = distribute.sdkConfigs;
|
||||
delete manifestJson.plus.distribute.sdkConfigs;
|
||||
}
|
||||
if (manifestJson.plus.darkmode) {
|
||||
if (!(distribute.google || (distribute.google = {})).defaultNightMode) {
|
||||
distribute.google.defaultNightMode = 'auto';
|
||||
}
|
||||
if (!(distribute.apple || (distribute.apple = {})).UIUserInterfaceStyle) {
|
||||
distribute.apple.UIUserInterfaceStyle = 'Automatic';
|
||||
}
|
||||
}
|
||||
}
|
||||
// 屏幕启动方向
|
||||
if (manifestJson.plus.screenOrientation) {
|
||||
// app平台优先使用 manifest 配置
|
||||
manifestJson.screenOrientation = manifestJson.plus.screenOrientation;
|
||||
delete manifestJson.plus.screenOrientation;
|
||||
}
|
||||
else if (pagesJson.globalStyle?.pageOrientation) {
|
||||
// 兼容微信小程序
|
||||
const pageOrientationValue = wxPageOrientationMapping[pagesJson.globalStyle
|
||||
.pageOrientation];
|
||||
if (pageOrientationValue) {
|
||||
manifestJson.screenOrientation = pageOrientationValue;
|
||||
}
|
||||
}
|
||||
// 全屏配置
|
||||
manifestJson.fullscreen = manifestJson.plus.fullscreen;
|
||||
// 地图坐标系
|
||||
if (manifestJson.permissions && manifestJson.permissions.Maps) {
|
||||
manifestJson.permissions.Maps.coordType = 'gcj02';
|
||||
}
|
||||
if (!manifestJson.permissions) {
|
||||
manifestJson.permissions = {};
|
||||
}
|
||||
manifestJson.permissions.UniNView = {
|
||||
description: 'UniNView原生渲染',
|
||||
};
|
||||
// 允许内联播放视频
|
||||
manifestJson.plus.allowsInlineMediaPlayback = true;
|
||||
if (!manifestJson.plus.distribute) {
|
||||
manifestJson.plus.distribute = {
|
||||
plugins: {},
|
||||
};
|
||||
}
|
||||
if (!manifestJson.plus.distribute.plugins) {
|
||||
manifestJson.plus.distribute.plugins = {};
|
||||
}
|
||||
// 录音支持 mp3
|
||||
manifestJson.plus.distribute.plugins.audio = {
|
||||
mp3: {
|
||||
description: 'Android平台录音支持MP3格式文件',
|
||||
},
|
||||
};
|
||||
// 有效值为 close,none
|
||||
if (!['close', 'none'].includes(manifestJson.plus.popGesture)) {
|
||||
manifestJson.plus.popGesture = 'close';
|
||||
}
|
||||
}
|
||||
exports.initPlus = initPlus;
|
||||
function initUniStatistics(manifestJson) {
|
||||
// 根节点配置了统计
|
||||
if (manifestJson.uniStatistics) {
|
||||
manifestJson.plus.uniStatistics = (0, merge_1.recursive)(true, manifestJson.uniStatistics, manifestJson.plus.uniStatistics);
|
||||
manifestJson['app-harmony'].uniStatistics = (0, merge_1.recursive)(true, manifestJson.uniStatistics, manifestJson['app-harmony'].uniStatistics);
|
||||
delete manifestJson.uniStatistics;
|
||||
}
|
||||
if (!process.env.UNI_CLOUD_PROVIDER) {
|
||||
return;
|
||||
}
|
||||
let spaces = [];
|
||||
try {
|
||||
spaces = JSON.parse(process.env.UNI_CLOUD_PROVIDER);
|
||||
}
|
||||
catch (e) { }
|
||||
if (!(0, shared_1.isArray)(spaces) || !spaces.length) {
|
||||
return;
|
||||
}
|
||||
const space = spaces[0];
|
||||
if (!space) {
|
||||
return;
|
||||
}
|
||||
const uniStatistics = manifestJson.plus?.uniStatistics;
|
||||
if (!uniStatistics) {
|
||||
return;
|
||||
}
|
||||
if (uniStatistics.version === 2 || uniStatistics.version === '2') {
|
||||
if (uniStatistics.uniCloud && uniStatistics.uniCloud.spaceId) {
|
||||
return;
|
||||
}
|
||||
uniStatistics.uniCloud = {
|
||||
provider: space.provider,
|
||||
spaceId: space.spaceId,
|
||||
clientSecret: space.clientSecret,
|
||||
endpoint: space.endpoint,
|
||||
};
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initSafearea(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): void;
|
||||
Generated
Vendored
+35
@@ -0,0 +1,35 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initSafearea = void 0;
|
||||
function initSafearea(manifestJson, pagesJson) {
|
||||
if (pagesJson.tabBar?.list?.length) {
|
||||
// 安全区配置 仅包含 tabBar 的时候才配置
|
||||
if (!manifestJson.plus.safearea) {
|
||||
manifestJson.plus.safearea = {
|
||||
background: pagesJson.tabBar.backgroundColor || '#FFFFFF',
|
||||
bottom: {
|
||||
offset: 'auto',
|
||||
},
|
||||
};
|
||||
}
|
||||
if (!manifestJson['app-harmony'].safearea) {
|
||||
manifestJson['app-harmony'].safearea = {
|
||||
background: pagesJson.tabBar.backgroundColor || '#FFFFFF',
|
||||
bottom: {
|
||||
offset: 'auto',
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!manifestJson.plus.launchwebview) {
|
||||
manifestJson.plus.launchwebview = {
|
||||
render: 'always',
|
||||
};
|
||||
}
|
||||
else if (!manifestJson.plus.launchwebview.render) {
|
||||
manifestJson.plus.launchwebview.render = 'always';
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.initSafearea = initSafearea;
|
||||
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
export declare function initSplashscreen(manifestJson: Record<string, any>, userManifestJson: Record<string, any>): void;
|
||||
export declare function getSplashscreen(manifestJson: Record<string, any>): {
|
||||
autoclose: boolean;
|
||||
alwaysShowBeforeRender: boolean;
|
||||
};
|
||||
Generated
Vendored
+43
@@ -0,0 +1,43 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getSplashscreen = exports.initSplashscreen = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
function initSplashscreen(manifestJson, userManifestJson) {
|
||||
if (!manifestJson.plus.splashscreen) {
|
||||
return;
|
||||
}
|
||||
// 强制白屏检测
|
||||
const splashscreenOptions = userManifestJson['app-plus'] && userManifestJson['app-plus'].splashscreen;
|
||||
const hasAlwaysShowBeforeRender = splashscreenOptions && (0, shared_1.hasOwn)(splashscreenOptions, 'alwaysShowBeforeRender');
|
||||
if (!hasAlwaysShowBeforeRender &&
|
||||
manifestJson.plus.splashscreen.autoclose === false) {
|
||||
// 兼容旧版本仅配置了 autoclose 为 false
|
||||
manifestJson.plus.splashscreen.alwaysShowBeforeRender = false;
|
||||
}
|
||||
if (manifestJson.plus.splashscreen.alwaysShowBeforeRender) {
|
||||
// 白屏检测
|
||||
if (!manifestJson.plus.splashscreen.target) {
|
||||
manifestJson.plus.splashscreen.target = 'id:1';
|
||||
}
|
||||
manifestJson.plus.splashscreen.autoclose = true;
|
||||
manifestJson.plus.splashscreen.delay = 0;
|
||||
}
|
||||
else {
|
||||
// 不启用白屏检测
|
||||
delete manifestJson.plus.splashscreen.target;
|
||||
if (manifestJson.plus.splashscreen.autoclose) {
|
||||
// 启用 uni-app 框架关闭 splash
|
||||
manifestJson.plus.splashscreen.autoclose = false; // 原 5+ autoclose 改为 false
|
||||
}
|
||||
}
|
||||
delete manifestJson.plus.splashscreen.alwaysShowBeforeRender;
|
||||
}
|
||||
exports.initSplashscreen = initSplashscreen;
|
||||
function getSplashscreen(manifestJson) {
|
||||
const splashscreenOptions = manifestJson['app-plus']?.splashscreen || {};
|
||||
return {
|
||||
autoclose: splashscreenOptions.autoclose !== false,
|
||||
alwaysShowBeforeRender: splashscreenOptions.alwaysShowBeforeRender !== false,
|
||||
};
|
||||
}
|
||||
exports.getSplashscreen = getSplashscreen;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initAppStatusbar(manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): Record<string, any>;
|
||||
Generated
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initAppStatusbar = void 0;
|
||||
function initAppStatusbar(manifestJson, pagesJson) {
|
||||
const titleColor = pagesJson.pages[0].style.navigationBar.titleColor ||
|
||||
pagesJson.globalStyle.navigationBar.titleColor ||
|
||||
'#000000';
|
||||
const backgroundColor = pagesJson.globalStyle.navigationBar.backgroundColor || '#000000';
|
||||
manifestJson.plus.statusbar = {
|
||||
immersed: 'supportedDevice',
|
||||
style: titleColor === '#ffffff' ? 'light' : 'dark',
|
||||
background: backgroundColor,
|
||||
};
|
||||
return manifestJson;
|
||||
}
|
||||
exports.initAppStatusbar = initAppStatusbar;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initTabBar(entryPagePath: string, manifestJson: Record<string, any>, pagesJson: UniApp.PagesJson): void;
|
||||
Generated
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initTabBar = void 0;
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
function initTabBar(entryPagePath, manifestJson, pagesJson) {
|
||||
if (!pagesJson.tabBar?.list?.length) {
|
||||
return;
|
||||
}
|
||||
const tabBar = JSON.parse(JSON.stringify(pagesJson.tabBar));
|
||||
tabBar.borderStyle = (0, uni_shared_1.normalizeTabBarStyles)(tabBar.borderStyle);
|
||||
if (!tabBar.selectedColor) {
|
||||
tabBar.selectedColor = uni_shared_1.SELECTED_COLOR;
|
||||
}
|
||||
tabBar.height = `${parseFloat(tabBar.height) || uni_shared_1.TABBAR_HEIGHT}px`;
|
||||
// 首页是 tabBar 页面
|
||||
const item = tabBar.list.find((page) => page.pagePath === entryPagePath);
|
||||
if (item) {
|
||||
;
|
||||
tabBar.child = ['lauchwebview'];
|
||||
tabBar.selected = tabBar.list.indexOf(item);
|
||||
}
|
||||
manifestJson.plus.tabBar = tabBar;
|
||||
}
|
||||
exports.initTabBar = initTabBar;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function initUniApp(manifestJson: Record<string, any>): void;
|
||||
Generated
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.initUniApp = void 0;
|
||||
const nvue_1 = require("./nvue");
|
||||
function initUniApp(manifestJson) {
|
||||
manifestJson.plus['uni-app'] = {
|
||||
control: 'uni-v3',
|
||||
vueVersion: '3',
|
||||
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
||||
nvueCompiler: (0, nvue_1.getNVueCompiler)(manifestJson),
|
||||
renderer: 'auto',
|
||||
nvue: {
|
||||
'flex-direction': (0, nvue_1.getNVueFlexDirection)(manifestJson),
|
||||
},
|
||||
nvueLaunchMode: manifestJson.plus.nvueLaunchMode === 'fast' ? 'fast' : 'normal',
|
||||
};
|
||||
delete manifestJson.plus.nvueLaunchMode;
|
||||
}
|
||||
exports.initUniApp = initUniApp;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export declare const arrayBufferCode = "\nif (typeof uni !== 'undefined' && uni && uni.requireGlobal) {\n const global = uni.requireGlobal()\n ArrayBuffer = global.ArrayBuffer\n Int8Array = global.Int8Array\n Uint8Array = global.Uint8Array\n Uint8ClampedArray = global.Uint8ClampedArray\n Int16Array = global.Int16Array\n Uint16Array = global.Uint16Array\n Int32Array = global.Int32Array\n Uint32Array = global.Uint32Array\n Float32Array = global.Float32Array\n Float64Array = global.Float64Array\n BigInt64Array = global.BigInt64Array\n BigUint64Array = global.BigUint64Array\n};\n";
|
||||
export declare const polyfillCode = "\nif (typeof Promise !== 'undefined' && !Promise.prototype.finally) {\n Promise.prototype.finally = function(callback) {\n const promise = this.constructor\n return this.then(\n value => promise.resolve(callback()).then(() => value),\n reason => promise.resolve(callback()).then(() => {\n throw reason\n })\n )\n }\n};\n\nif (typeof uni !== 'undefined' && uni && uni.requireGlobal) {\n const global = uni.requireGlobal()\n ArrayBuffer = global.ArrayBuffer\n Int8Array = global.Int8Array\n Uint8Array = global.Uint8Array\n Uint8ClampedArray = global.Uint8ClampedArray\n Int16Array = global.Int16Array\n Uint16Array = global.Uint16Array\n Int32Array = global.Int32Array\n Uint32Array = global.Uint32Array\n Float32Array = global.Float32Array\n Float64Array = global.Float64Array\n BigInt64Array = global.BigInt64Array\n BigUint64Array = global.BigUint64Array\n};\n\n";
|
||||
export declare const restoreGlobalCode = "\nif(uni.restoreGlobal){\n uni.restoreGlobal(Vue,weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)\n}\n";
|
||||
export declare const globalCode: string;
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.globalCode = exports.restoreGlobalCode = exports.polyfillCode = exports.arrayBufferCode = void 0;
|
||||
exports.arrayBufferCode = `
|
||||
if (typeof uni !== 'undefined' && uni && uni.requireGlobal) {
|
||||
const global = uni.requireGlobal()
|
||||
ArrayBuffer = global.ArrayBuffer
|
||||
Int8Array = global.Int8Array
|
||||
Uint8Array = global.Uint8Array
|
||||
Uint8ClampedArray = global.Uint8ClampedArray
|
||||
Int16Array = global.Int16Array
|
||||
Uint16Array = global.Uint16Array
|
||||
Int32Array = global.Int32Array
|
||||
Uint32Array = global.Uint32Array
|
||||
Float32Array = global.Float32Array
|
||||
Float64Array = global.Float64Array
|
||||
BigInt64Array = global.BigInt64Array
|
||||
BigUint64Array = global.BigUint64Array
|
||||
};
|
||||
`;
|
||||
exports.polyfillCode = `
|
||||
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
|
||||
Promise.prototype.finally = function(callback) {
|
||||
const promise = this.constructor
|
||||
return this.then(
|
||||
value => promise.resolve(callback()).then(() => value),
|
||||
reason => promise.resolve(callback()).then(() => {
|
||||
throw reason
|
||||
})
|
||||
)
|
||||
}
|
||||
};
|
||||
${exports.arrayBufferCode}
|
||||
`;
|
||||
exports.restoreGlobalCode = `
|
||||
if(uni.restoreGlobal){
|
||||
uni.restoreGlobal(Vue,weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
|
||||
}
|
||||
`;
|
||||
const GLOBALS = [
|
||||
'global',
|
||||
'window',
|
||||
'document',
|
||||
'frames',
|
||||
'self',
|
||||
'location',
|
||||
'navigator',
|
||||
'localStorage',
|
||||
'history',
|
||||
'Caches',
|
||||
'screen',
|
||||
'alert',
|
||||
'confirm',
|
||||
'prompt',
|
||||
'fetch',
|
||||
'XMLHttpRequest',
|
||||
'WebSocket',
|
||||
'webkit',
|
||||
'print',
|
||||
];
|
||||
exports.globalCode = GLOBALS.map((g) => `${g}:u`).join(',');
|
||||
Generated
Vendored
+2
@@ -0,0 +1,2 @@
|
||||
export declare function definePageCode(pagesJson: Record<string, any>, platform?: UniApp.PLATFORM): string;
|
||||
export declare function defineNVuePageCode(pagesJson: Record<string, any>): string;
|
||||
Generated
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.defineNVuePageCode = exports.definePageCode = void 0;
|
||||
const utils_1 = require("../../../utils");
|
||||
function definePageCode(pagesJson, platform = 'app') {
|
||||
const importPagesCode = [];
|
||||
const definePagesCode = [];
|
||||
pagesJson.pages.forEach((page) => {
|
||||
if (platform === 'app' && page.style.isNVue) {
|
||||
return;
|
||||
}
|
||||
const pagePath = page.path;
|
||||
const pageIdentifier = (0, utils_1.normalizeIdentifier)(pagePath);
|
||||
const pagePathWithExtname = (0, utils_1.normalizePagePath)(pagePath, platform);
|
||||
if (pagePathWithExtname) {
|
||||
if (process.env.UNI_APP_CODE_SPLITING) {
|
||||
// 拆分页面
|
||||
importPagesCode.push(`const ${pageIdentifier} = ()=>import('./${pagePathWithExtname}')`);
|
||||
}
|
||||
else {
|
||||
importPagesCode.push(`import ${pageIdentifier} from './${pagePathWithExtname}'`);
|
||||
}
|
||||
definePagesCode.push(`__definePage('${pagePath}',${pageIdentifier})`);
|
||||
}
|
||||
});
|
||||
return importPagesCode.join('\n') + '\n' + definePagesCode.join('\n');
|
||||
}
|
||||
exports.definePageCode = definePageCode;
|
||||
function defineNVuePageCode(pagesJson) {
|
||||
const importNVuePagesCode = [];
|
||||
pagesJson.pages.forEach((page) => {
|
||||
if (!page.style.isNVue) {
|
||||
return;
|
||||
}
|
||||
const pagePathWithExtname = (0, utils_1.normalizePagePath)(page.path, 'app');
|
||||
if (pagePathWithExtname) {
|
||||
importNVuePagesCode.push(`import('./${pagePathWithExtname}').then((res)=>{res.length})`);
|
||||
}
|
||||
});
|
||||
return importNVuePagesCode.join('\n');
|
||||
}
|
||||
exports.defineNVuePageCode = defineNVuePageCode;
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
export declare function normalizeAppPagesJson(pagesJson: Record<string, any>, platform?: UniApp.PLATFORM): string;
|
||||
export declare function normalizeAppNVuePagesJson(pagesJson: Record<string, any>): string;
|
||||
export declare function normalizeAppConfigService(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): string;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizeAppConfigService = exports.normalizeAppNVuePagesJson = exports.normalizeAppPagesJson = void 0;
|
||||
const code_1 = require("./code");
|
||||
const definePage_1 = require("./definePage");
|
||||
const uniConfig_1 = require("./uniConfig");
|
||||
const uniRoutes_1 = require("./uniRoutes");
|
||||
function normalizeAppPagesJson(pagesJson, platform = 'app') {
|
||||
return (0, definePage_1.definePageCode)(pagesJson, platform);
|
||||
}
|
||||
exports.normalizeAppPagesJson = normalizeAppPagesJson;
|
||||
function normalizeAppNVuePagesJson(pagesJson) {
|
||||
return (0, definePage_1.defineNVuePageCode)(pagesJson);
|
||||
}
|
||||
exports.normalizeAppNVuePagesJson = normalizeAppNVuePagesJson;
|
||||
function normalizeAppConfigService(pagesJson, manifestJson) {
|
||||
return `
|
||||
;(function(){
|
||||
let u=void 0,isReady=false,onReadyCallbacks=[],isServiceReady=false,onServiceReadyCallbacks=[];
|
||||
const __uniConfig = ${(0, uniConfig_1.normalizeAppUniConfig)(pagesJson, manifestJson)};
|
||||
const __uniRoutes = ${(0, uniRoutes_1.normalizeAppUniRoutes)(pagesJson)}.map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute));
|
||||
__uniConfig.styles=${process.env.UNI_NVUE_APP_STYLES || '[]'};//styles
|
||||
__uniConfig.onReady=function(callback){if(__uniConfig.ready){callback()}else{onReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"ready",{get:function(){return isReady},set:function(val){isReady=val;if(!isReady){return}const callbacks=onReadyCallbacks.slice(0);onReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
__uniConfig.onServiceReady=function(callback){if(__uniConfig.serviceReady){callback()}else{onServiceReadyCallbacks.push(callback)}};Object.defineProperty(__uniConfig,"serviceReady",{get:function(){return isServiceReady},set:function(val){isServiceReady=val;if(!isServiceReady){return}const callbacks=onServiceReadyCallbacks.slice(0);onServiceReadyCallbacks.length=0;callbacks.forEach(function(callback){callback()})}});
|
||||
service.register("uni-app-config",{create(a,b,c){if(!__uniConfig.viewport){var d=b.weex.config.env.scale,e=b.weex.config.env.deviceWidth,f=Math.ceil(e/d);Object.assign(__uniConfig,{viewport:f,defaultFontSize:16})}return{instance:{__uniConfig:__uniConfig,__uniRoutes:__uniRoutes,${code_1.globalCode}}}}});
|
||||
})();
|
||||
`;
|
||||
}
|
||||
exports.normalizeAppConfigService = normalizeAppConfigService;
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
export declare function normalizeAppUniConfig(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): string;
|
||||
export declare function parseEntryPagePath(pagesJson: UniApp.PagesJson): {
|
||||
entryPagePath: string;
|
||||
entryPageQuery: string;
|
||||
realEntryPagePath: string;
|
||||
};
|
||||
Generated
Vendored
+75
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseEntryPagePath = exports.normalizeAppUniConfig = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const i18n_1 = require("../../../i18n");
|
||||
const manifest_1 = require("../../manifest");
|
||||
const manifest_2 = require("../manifest");
|
||||
const arguments_1 = require("../manifest/arguments");
|
||||
const splashscreen_1 = require("../manifest/splashscreen");
|
||||
const theme_1 = require("../../theme");
|
||||
function normalizeAppUniConfig(pagesJson, manifestJson) {
|
||||
const { autoclose, alwaysShowBeforeRender } = (0, splashscreen_1.getSplashscreen)(manifestJson);
|
||||
const platformConfig = (0, manifest_1.getPlatformManifestJsonOnce)();
|
||||
const config = {
|
||||
pages: [],
|
||||
globalStyle: pagesJson.globalStyle,
|
||||
nvue: {
|
||||
compiler: (0, manifest_2.getNVueCompiler)(manifestJson),
|
||||
styleCompiler: (0, manifest_2.getNVueStyleCompiler)(manifestJson),
|
||||
'flex-direction': (0, manifest_2.getNVueFlexDirection)(manifestJson),
|
||||
},
|
||||
renderer: manifestJson['app-plus']?.renderer === 'native' ? 'native' : 'auto',
|
||||
appname: manifestJson.name || '',
|
||||
splashscreen: {
|
||||
alwaysShowBeforeRender,
|
||||
autoclose,
|
||||
},
|
||||
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
||||
...parseEntryPagePath(pagesJson),
|
||||
networkTimeout: (0, manifest_1.normalizeNetworkTimeout)(manifestJson.networkTimeout),
|
||||
tabBar: pagesJson.tabBar,
|
||||
fallbackLocale: manifestJson.fallbackLocale,
|
||||
locales: (0, i18n_1.initLocales)(path_1.default.join(process.env.UNI_INPUT_DIR, 'locale')),
|
||||
darkmode: platformConfig.darkmode || false,
|
||||
themeConfig: (0, theme_1.normalizeThemeConfigOnce)(platformConfig),
|
||||
// @ts-expect-error
|
||||
qqMapKey: platformConfig?.distribute?.sdkConfigs?.maps?.tencent?.key,
|
||||
};
|
||||
// TODO 待支持分包
|
||||
return JSON.stringify(config);
|
||||
}
|
||||
exports.normalizeAppUniConfig = normalizeAppUniConfig;
|
||||
function parseEntryPagePath(pagesJson) {
|
||||
const res = {
|
||||
entryPagePath: '',
|
||||
entryPageQuery: '',
|
||||
realEntryPagePath: '',
|
||||
};
|
||||
if (!pagesJson.pages.length) {
|
||||
return res;
|
||||
}
|
||||
res.entryPagePath = pagesJson.pages[0].path;
|
||||
const argsJsonStr = (0, arguments_1.parseArguments)(pagesJson);
|
||||
if (argsJsonStr) {
|
||||
try {
|
||||
const args = JSON.parse(argsJsonStr);
|
||||
const entryPagePath = args.path || args.pathName;
|
||||
const realEntryPagePath = res.entryPagePath;
|
||||
if (entryPagePath && realEntryPagePath !== entryPagePath) {
|
||||
res.entryPagePath = entryPagePath;
|
||||
res.entryPageQuery = args.query ? '?' + args.query : '';
|
||||
// non tabBar page
|
||||
if (!(pagesJson.tabBar?.list || []).find((page) => page.pagePath === entryPagePath)) {
|
||||
res.realEntryPagePath = realEntryPagePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (e) { }
|
||||
}
|
||||
return res;
|
||||
}
|
||||
exports.parseEntryPagePath = parseEntryPagePath;
|
||||
Generated
Vendored
+1
@@ -0,0 +1 @@
|
||||
export declare function normalizeAppUniRoutes(pagesJson: UniApp.PagesJson): string;
|
||||
Generated
Vendored
+8
@@ -0,0 +1,8 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizeAppUniRoutes = void 0;
|
||||
const pages_1 = require("../../pages");
|
||||
function normalizeAppUniRoutes(pagesJson) {
|
||||
return JSON.stringify((0, pages_1.normalizePagesRoute)(pagesJson));
|
||||
}
|
||||
exports.normalizeAppUniRoutes = normalizeAppUniRoutes;
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
export * from './mp';
|
||||
export * from './app';
|
||||
export * from './json';
|
||||
export * from './pages';
|
||||
export * from './manifest';
|
||||
export * from './theme';
|
||||
export { normalizeUniAppXAppPagesJson, normalizeUniAppXAppConfig, checkPagesJson, parseUniXFlexDirection, parseUniXSplashScreen, parseUniXUniStatistics, } from './uni-x';
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseUniXUniStatistics = exports.parseUniXSplashScreen = exports.parseUniXFlexDirection = exports.checkPagesJson = exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = void 0;
|
||||
__exportStar(require("./mp"), exports);
|
||||
__exportStar(require("./app"), exports);
|
||||
__exportStar(require("./json"), exports);
|
||||
__exportStar(require("./pages"), exports);
|
||||
__exportStar(require("./manifest"), exports);
|
||||
__exportStar(require("./theme"), exports);
|
||||
var uni_x_1 = require("./uni-x");
|
||||
Object.defineProperty(exports, "normalizeUniAppXAppPagesJson", { enumerable: true, get: function () { return uni_x_1.normalizeUniAppXAppPagesJson; } });
|
||||
Object.defineProperty(exports, "normalizeUniAppXAppConfig", { enumerable: true, get: function () { return uni_x_1.normalizeUniAppXAppConfig; } });
|
||||
Object.defineProperty(exports, "checkPagesJson", { enumerable: true, get: function () { return uni_x_1.checkPagesJson; } });
|
||||
Object.defineProperty(exports, "parseUniXFlexDirection", { enumerable: true, get: function () { return uni_x_1.parseUniXFlexDirection; } });
|
||||
Object.defineProperty(exports, "parseUniXSplashScreen", { enumerable: true, get: function () { return uni_x_1.parseUniXSplashScreen; } });
|
||||
Object.defineProperty(exports, "parseUniXUniStatistics", { enumerable: true, get: function () { return uni_x_1.parseUniXUniStatistics; } });
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function parseJson(jsonStr: string, shouldPre: boolean | undefined, filename: string): any;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseJson = void 0;
|
||||
const jsonc_parser_1 = require("jsonc-parser");
|
||||
const preprocess_1 = require("../preprocess");
|
||||
function parseJson(jsonStr, shouldPre = false, filename) {
|
||||
return (0, jsonc_parser_1.parse)(shouldPre
|
||||
? process.env.UNI_APP_X === 'true'
|
||||
? (0, preprocess_1.preUVueJson)(jsonStr, filename)
|
||||
: (0, preprocess_1.preJson)(jsonStr, filename)
|
||||
: jsonStr);
|
||||
}
|
||||
exports.parseJson = parseJson;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
export declare const parseManifestJson: (inputDir: string) => any;
|
||||
export declare const parseManifestJsonOnce: (inputDir: string) => any;
|
||||
export declare const parseRpx2UnitOnce: (inputDir: string, platform?: UniApp.PLATFORM) => any;
|
||||
interface CompilerCompatConfig {
|
||||
MODE?: 2 | 3;
|
||||
}
|
||||
declare function parseCompatConfig(_inputDir: string): CompilerCompatConfig;
|
||||
export declare const parseCompatConfigOnce: typeof parseCompatConfig;
|
||||
declare const defaultNetworkTimeout: {
|
||||
request: number;
|
||||
connectSocket: number;
|
||||
uploadFile: number;
|
||||
downloadFile: number;
|
||||
};
|
||||
export declare function normalizeNetworkTimeout(networkTimeout?: Partial<typeof defaultNetworkTimeout>): {
|
||||
request: number;
|
||||
connectSocket: number;
|
||||
uploadFile: number;
|
||||
downloadFile: number;
|
||||
};
|
||||
export declare function getUniStatistics(inputDir: string, platform: UniApp.PLATFORM): any;
|
||||
export declare function isEnableUniPushV1(inputDir: string, platform: UniApp.PLATFORM): boolean;
|
||||
export declare function isEnableUniPushV2(inputDir: string, platform: UniApp.PLATFORM): boolean;
|
||||
export declare function isEnableSecureNetwork(inputDir: string, platform: UniApp.PLATFORM): boolean;
|
||||
export declare function hasPushModule(inputDir: string): boolean;
|
||||
export declare function isUniPushOffline(inputDir: string): boolean;
|
||||
export declare function getRouterOptions(manifestJson: Record<string, any>): {
|
||||
mode?: 'history' | 'hash';
|
||||
base?: string;
|
||||
};
|
||||
export declare function isEnableTreeShaking(manifestJson: Record<string, any>): boolean;
|
||||
export declare function getDevServerOptions(manifestJson: Record<string, any>): any;
|
||||
export declare function getPlatformManifestJson(manifestJson: any, platform?: UniApp.PLATFORM): any;
|
||||
export declare function getPlatformManifestJsonOnce(): any;
|
||||
export declare function validateThemeValue(value: string): boolean;
|
||||
export {};
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.validateThemeValue = exports.getPlatformManifestJsonOnce = exports.getPlatformManifestJson = exports.getDevServerOptions = exports.isEnableTreeShaking = exports.getRouterOptions = exports.isUniPushOffline = exports.hasPushModule = exports.isEnableSecureNetwork = exports.isEnableUniPushV2 = exports.isEnableUniPushV1 = exports.getUniStatistics = exports.normalizeNetworkTimeout = exports.parseCompatConfigOnce = exports.parseRpx2UnitOnce = exports.parseManifestJsonOnce = exports.parseManifestJson = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const json_1 = require("./json");
|
||||
const utils_1 = require("../utils");
|
||||
const parseManifestJson = (inputDir) => {
|
||||
const manifestFilename = path_1.default.join(inputDir, 'manifest.json');
|
||||
if (!fs_1.default.existsSync(manifestFilename)) {
|
||||
if (!(0, utils_1.isNormalCompileTarget)()) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
return (0, json_1.parseJson)(fs_1.default.readFileSync(manifestFilename, 'utf8'), false, manifestFilename);
|
||||
};
|
||||
exports.parseManifestJson = parseManifestJson;
|
||||
exports.parseManifestJsonOnce = (0, uni_shared_1.once)(exports.parseManifestJson);
|
||||
exports.parseRpx2UnitOnce = (0, uni_shared_1.once)((inputDir, platform = 'h5') => {
|
||||
const rpx2unit = platform === 'h5' || platform === 'app' || platform === 'app-harmony'
|
||||
? uni_shared_1.defaultRpx2Unit
|
||||
: uni_shared_1.defaultMiniProgramRpx2Unit;
|
||||
const manifestJson = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
let platformOptions = getPlatformManifestJson(manifestJson, platform);
|
||||
if (platformOptions && platformOptions.rpx) {
|
||||
return (0, shared_1.extend)({}, rpx2unit, platformOptions);
|
||||
}
|
||||
return (0, shared_1.extend)({}, rpx2unit);
|
||||
});
|
||||
function parseCompatConfig(_inputDir) {
|
||||
// 不支持 mode:2
|
||||
return { MODE: 3 }; //parseManifestJsonOnce(inputDir).compatConfig || {}
|
||||
}
|
||||
exports.parseCompatConfigOnce = (0, uni_shared_1.once)(parseCompatConfig);
|
||||
const defaultNetworkTimeout = {
|
||||
request: 60000,
|
||||
connectSocket: 60000,
|
||||
uploadFile: 60000,
|
||||
downloadFile: 60000,
|
||||
};
|
||||
function normalizeNetworkTimeout(networkTimeout) {
|
||||
return {
|
||||
...defaultNetworkTimeout,
|
||||
...networkTimeout,
|
||||
};
|
||||
}
|
||||
exports.normalizeNetworkTimeout = normalizeNetworkTimeout;
|
||||
function getUniStatistics(inputDir, platform) {
|
||||
const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
let platformManifest = getPlatformManifestJson(manifest, platform);
|
||||
return (0, shared_1.extend)({}, manifest.uniStatistics, platformManifest && platformManifest.uniStatistics);
|
||||
}
|
||||
exports.getUniStatistics = getUniStatistics;
|
||||
function isEnableUniPushV1(inputDir, platform) {
|
||||
if (isEnableUniPushV2(inputDir, platform)) {
|
||||
return false;
|
||||
}
|
||||
const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
if (platform === 'app') {
|
||||
const push = manifest['app-plus']?.distribute?.sdkConfigs?.push;
|
||||
if (push && (0, shared_1.hasOwn)(push, 'unipush')) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.isEnableUniPushV1 = isEnableUniPushV1;
|
||||
function isEnableUniPushV2(inputDir, platform) {
|
||||
const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
const platformManifest = getPlatformManifestJson(manifest, platform);
|
||||
if (platform === 'app') {
|
||||
return (platformManifest?.distribute?.sdkConfigs?.push?.unipush?.version == '2');
|
||||
}
|
||||
return platformManifest?.unipush?.enable === true;
|
||||
}
|
||||
exports.isEnableUniPushV2 = isEnableUniPushV2;
|
||||
function isEnableSecureNetwork(inputDir, platform) {
|
||||
const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
const platformManifest = getPlatformManifestJson(manifest, platform);
|
||||
if (platform === 'app') {
|
||||
return !!platformManifest?.modules?.SecureNetwork;
|
||||
}
|
||||
return platformManifest?.secureNetwork?.enable === true;
|
||||
}
|
||||
exports.isEnableSecureNetwork = isEnableSecureNetwork;
|
||||
function hasPushModule(inputDir) {
|
||||
const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
return !!manifest['app-plus']?.modules?.Push;
|
||||
}
|
||||
exports.hasPushModule = hasPushModule;
|
||||
function isUniPushOffline(inputDir) {
|
||||
const manifest = (0, exports.parseManifestJsonOnce)(inputDir);
|
||||
return (manifest['app-plus']?.distribute?.sdkConfigs?.push?.unipush?.offline ===
|
||||
true);
|
||||
}
|
||||
exports.isUniPushOffline = isUniPushOffline;
|
||||
function getRouterOptions(manifestJson) {
|
||||
return (0, shared_1.extend)({}, getPlatformManifestJson(manifestJson, 'h5')?.router);
|
||||
}
|
||||
exports.getRouterOptions = getRouterOptions;
|
||||
function isEnableTreeShaking(manifestJson) {
|
||||
// 自动化测试时,一定不摇树
|
||||
if (process.env.UNI_AUTOMATOR_WS_ENDPOINT) {
|
||||
return false;
|
||||
}
|
||||
const platformManifest = getPlatformManifestJson(manifestJson, 'h5');
|
||||
return platformManifest?.optimization?.treeShaking?.enable !== false;
|
||||
}
|
||||
exports.isEnableTreeShaking = isEnableTreeShaking;
|
||||
function getDevServerOptions(manifestJson) {
|
||||
const platformManifest = getPlatformManifestJson(manifestJson, 'h5');
|
||||
return (0, shared_1.extend)({}, platformManifest?.devServer);
|
||||
}
|
||||
exports.getDevServerOptions = getDevServerOptions;
|
||||
function getPlatformManifestJson(manifestJson, platform) {
|
||||
if (!platform) {
|
||||
platform = process.env.UNI_PLATFORM;
|
||||
}
|
||||
if (platform === 'app') {
|
||||
return manifestJson['app-plus'] || manifestJson['plus'] || {};
|
||||
}
|
||||
if (platform === 'h5') {
|
||||
return manifestJson.web || manifestJson.h5 || {};
|
||||
}
|
||||
return manifestJson[platform] || {};
|
||||
}
|
||||
exports.getPlatformManifestJson = getPlatformManifestJson;
|
||||
function getPlatformManifestJsonOnce() {
|
||||
const manifestJson = !process.env.UNI_INPUT_DIR
|
||||
? {}
|
||||
: (0, exports.parseManifestJsonOnce)(process.env.UNI_INPUT_DIR);
|
||||
return getPlatformManifestJson(manifestJson);
|
||||
}
|
||||
exports.getPlatformManifestJsonOnce = getPlatformManifestJsonOnce;
|
||||
const themeValues = ['dark', 'light', 'auto'];
|
||||
function validateThemeValue(value) {
|
||||
return themeValues.indexOf(value) !== -1;
|
||||
}
|
||||
exports.validateThemeValue = validateThemeValue;
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
export * from './jsonFile';
|
||||
export { AppJson, ComponentJson, MiniProgramComponentsType } from './types';
|
||||
export { mergeMiniProgramAppJson, parseMiniProgramPagesJson } from './pages';
|
||||
export { parseMiniProgramProjectJson } from './project';
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseMiniProgramProjectJson = exports.parseMiniProgramPagesJson = exports.mergeMiniProgramAppJson = void 0;
|
||||
__exportStar(require("./jsonFile"), exports);
|
||||
var pages_1 = require("./pages");
|
||||
Object.defineProperty(exports, "mergeMiniProgramAppJson", { enumerable: true, get: function () { return pages_1.mergeMiniProgramAppJson; } });
|
||||
Object.defineProperty(exports, "parseMiniProgramPagesJson", { enumerable: true, get: function () { return pages_1.parseMiniProgramPagesJson; } });
|
||||
var project_1 = require("./project");
|
||||
Object.defineProperty(exports, "parseMiniProgramProjectJson", { enumerable: true, get: function () { return project_1.parseMiniProgramProjectJson; } });
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import type { ComponentJson, MiniProgramComponentsType, PageWindowOptions, UsingComponents } from './types';
|
||||
export declare function isMiniProgramPageFile(file: string, inputDir?: string): boolean;
|
||||
export declare function isMiniProgramPageSfcFile(file: string, inputDir?: string): boolean;
|
||||
export declare function hasJsonFile(filename: string): boolean;
|
||||
export declare function getComponentJsonFilenames(): string[];
|
||||
export declare function findJsonFile(filename: string): Record<string, any> | ComponentJson | PageWindowOptions | undefined;
|
||||
export declare function findUsingComponents(filename: string): UsingComponents | undefined;
|
||||
export declare function normalizeJsonFilename(filename: string): string;
|
||||
export declare function findChangedJsonFiles(supportGlobalUsingComponents?: boolean): Map<string, string>;
|
||||
export declare function addMiniProgramAppJson(appJson: Record<string, any>): void;
|
||||
export declare function addMiniProgramPageJson(filename: string, json: PageWindowOptions): void;
|
||||
export declare function addMiniProgramComponentJson(filename: string, json: ComponentJson): void;
|
||||
export declare function addMiniProgramUsingComponents(filename: string, json: UsingComponents): void;
|
||||
export declare function isMiniProgramUsingComponent(name: string, options: {
|
||||
filename: string;
|
||||
inputDir: string;
|
||||
componentsDir?: string;
|
||||
}): boolean;
|
||||
interface MiniProgramComponents {
|
||||
[name: string]: MiniProgramComponentsType;
|
||||
}
|
||||
export declare function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, }: {
|
||||
filename: string;
|
||||
inputDir: string;
|
||||
componentsDir?: string;
|
||||
}): MiniProgramComponents;
|
||||
/**
|
||||
* 开发者在配置usingComponents时,可以指向具体路径(不含文件后缀),也可以指向目录(指向目录时查找目录下的index.wxml/.json等)
|
||||
* 当usingComponents配置为`"demo": "/components/demo"`时,查找优先级为:
|
||||
* 1. /components/demo.wxml
|
||||
* 2. /components/demo/index.wxml
|
||||
*
|
||||
* 注意如下配置是非法的:
|
||||
* - "demo": "/components/demo.wxml"
|
||||
* - "demo": "/components/demo/"
|
||||
*
|
||||
* 注意用户的pages.json内可以配置如下三种路径:
|
||||
* - "demo": "/wxcomponents/demo"
|
||||
* - "demo": "wxcomponents/demo"
|
||||
* - [TODO 待确认] "demo": "../wxcomponents/demo"
|
||||
*/
|
||||
export declare function findUsingComponentsJson(pathInpages: string, componentsDir: string): Record<any, any>;
|
||||
export {};
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.findUsingComponentsJson = exports.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findUsingComponents = exports.findJsonFile = exports.getComponentJsonFilenames = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const utils_1 = require("../../utils");
|
||||
const resolve_1 = require("../../resolve");
|
||||
const utils_2 = require("../../vue/utils");
|
||||
let appJsonCache = {};
|
||||
const jsonFilesCache = new Map();
|
||||
const jsonPagesCache = new Map();
|
||||
const jsonComponentsCache = new Map();
|
||||
const jsonUsingComponentsCache = new Map();
|
||||
function isMiniProgramPageFile(file, inputDir) {
|
||||
if (inputDir && path_1.default.isAbsolute(file)) {
|
||||
file = (0, utils_1.normalizePath)(path_1.default.relative(inputDir, file));
|
||||
}
|
||||
return jsonPagesCache.has((0, utils_1.removeExt)(file));
|
||||
}
|
||||
exports.isMiniProgramPageFile = isMiniProgramPageFile;
|
||||
function isMiniProgramPageSfcFile(file, inputDir) {
|
||||
return (0, utils_2.isVueSfcFile)(file) && isMiniProgramPageFile(file, inputDir);
|
||||
}
|
||||
exports.isMiniProgramPageSfcFile = isMiniProgramPageSfcFile;
|
||||
function hasJsonFile(filename) {
|
||||
return (filename === 'app' ||
|
||||
jsonPagesCache.has(filename) ||
|
||||
jsonComponentsCache.has(filename));
|
||||
}
|
||||
exports.hasJsonFile = hasJsonFile;
|
||||
function getComponentJsonFilenames() {
|
||||
return [...jsonComponentsCache.keys()];
|
||||
}
|
||||
exports.getComponentJsonFilenames = getComponentJsonFilenames;
|
||||
function findJsonFile(filename) {
|
||||
if (filename === 'app') {
|
||||
return appJsonCache;
|
||||
}
|
||||
return jsonPagesCache.get(filename) || jsonComponentsCache.get(filename);
|
||||
}
|
||||
exports.findJsonFile = findJsonFile;
|
||||
function findUsingComponents(filename) {
|
||||
return jsonUsingComponentsCache.get(filename);
|
||||
}
|
||||
exports.findUsingComponents = findUsingComponents;
|
||||
function normalizeJsonFilename(filename) {
|
||||
return (0, utils_1.normalizeNodeModules)(filename);
|
||||
}
|
||||
exports.normalizeJsonFilename = normalizeJsonFilename;
|
||||
function findChangedJsonFiles(supportGlobalUsingComponents = true) {
|
||||
const changedJsonFiles = new Map();
|
||||
function findChangedFile(filename, json) {
|
||||
const newJson = JSON.parse(JSON.stringify(json));
|
||||
if (!newJson.usingComponents) {
|
||||
newJson.usingComponents = {};
|
||||
}
|
||||
(0, shared_1.extend)(newJson.usingComponents, jsonUsingComponentsCache.get(filename));
|
||||
// 格式化为相对路径,这样作为分包也可以直接运行
|
||||
// app.json mp-baidu 在 win 不支持相对路径。所有平台改用绝对路径
|
||||
if (filename !== 'app') {
|
||||
let usingComponents = newJson.usingComponents;
|
||||
// 如果小程序不支持 global 的 usingComponents
|
||||
if (!supportGlobalUsingComponents) {
|
||||
// 从取全局的 usingComponents 并补充到子组件 usingComponents 中
|
||||
const globalUsingComponents = appJsonCache?.usingComponents || {};
|
||||
const globalComponents = findUsingComponents('app') || {};
|
||||
usingComponents = {
|
||||
...globalUsingComponents,
|
||||
...globalComponents,
|
||||
...newJson.usingComponents,
|
||||
};
|
||||
}
|
||||
Object.keys(usingComponents).forEach((name) => {
|
||||
const componentFilename = usingComponents[name];
|
||||
if (componentFilename.startsWith('/')) {
|
||||
usingComponents[name] = (0, resolve_1.relativeFile)(filename, componentFilename.slice(1));
|
||||
}
|
||||
});
|
||||
newJson.usingComponents = usingComponents;
|
||||
}
|
||||
const jsonStr = JSON.stringify(newJson, null, 2);
|
||||
if (jsonFilesCache.get(filename) !== jsonStr) {
|
||||
changedJsonFiles.set(filename, jsonStr);
|
||||
jsonFilesCache.set(filename, jsonStr);
|
||||
}
|
||||
}
|
||||
function findChangedFiles(jsonsCache) {
|
||||
for (const name of jsonsCache.keys()) {
|
||||
findChangedFile(name, jsonsCache.get(name));
|
||||
}
|
||||
}
|
||||
findChangedFile('app', appJsonCache);
|
||||
findChangedFiles(jsonPagesCache);
|
||||
findChangedFiles(jsonComponentsCache);
|
||||
return changedJsonFiles;
|
||||
}
|
||||
exports.findChangedJsonFiles = findChangedJsonFiles;
|
||||
function addMiniProgramAppJson(appJson) {
|
||||
appJsonCache = appJson;
|
||||
}
|
||||
exports.addMiniProgramAppJson = addMiniProgramAppJson;
|
||||
function addMiniProgramPageJson(filename, json) {
|
||||
jsonPagesCache.set(filename, json);
|
||||
}
|
||||
exports.addMiniProgramPageJson = addMiniProgramPageJson;
|
||||
function addMiniProgramComponentJson(filename, json) {
|
||||
jsonComponentsCache.set(filename, json);
|
||||
}
|
||||
exports.addMiniProgramComponentJson = addMiniProgramComponentJson;
|
||||
function addMiniProgramUsingComponents(filename, json) {
|
||||
jsonUsingComponentsCache.set(filename, json);
|
||||
}
|
||||
exports.addMiniProgramUsingComponents = addMiniProgramUsingComponents;
|
||||
function isMiniProgramUsingComponent(name, options) {
|
||||
return !!findMiniProgramUsingComponents(options)[name];
|
||||
}
|
||||
exports.isMiniProgramUsingComponent = isMiniProgramUsingComponent;
|
||||
function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, }) {
|
||||
const globalUsingComponents = appJsonCache && appJsonCache.usingComponents;
|
||||
const miniProgramComponents = {};
|
||||
if (globalUsingComponents) {
|
||||
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(globalUsingComponents, componentsDir));
|
||||
}
|
||||
const jsonFile = findJsonFile((0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(filename, inputDir)));
|
||||
if (jsonFile) {
|
||||
if (jsonFile.usingComponents) {
|
||||
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingComponents, componentsDir));
|
||||
}
|
||||
// mp-baidu 特有
|
||||
if (jsonFile.usingSwanComponents) {
|
||||
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingSwanComponents, componentsDir));
|
||||
}
|
||||
}
|
||||
return miniProgramComponents;
|
||||
}
|
||||
exports.findMiniProgramUsingComponents = findMiniProgramUsingComponents;
|
||||
function findMiniProgramUsingComponent(usingComponents, componentsDir) {
|
||||
return Object.keys(usingComponents).reduce((res, name) => {
|
||||
const path = usingComponents[name];
|
||||
if (path.includes('plugin://')) {
|
||||
// mp-weixin & mp-alipay
|
||||
res[name] = 'plugin';
|
||||
}
|
||||
else if (path.includes('dynamicLib://')) {
|
||||
// mp-baidu
|
||||
res[name] = 'dynamicLib';
|
||||
}
|
||||
else if (path.includes('ext://')) {
|
||||
// mp-toutiao
|
||||
res[name] = 'ext';
|
||||
}
|
||||
else if (componentsDir &&
|
||||
path.includes(componentsDir + '/') &&
|
||||
findUsingComponentsJson(path, componentsDir).renderer === 'xr-frame') {
|
||||
// mp-weixin & x-frame
|
||||
res[name] = 'xr-frame';
|
||||
}
|
||||
else if (componentsDir && path.includes(componentsDir + '/')) {
|
||||
res[name] = 'component';
|
||||
}
|
||||
else if (path.startsWith('weui-miniprogram')) {
|
||||
res[name] = 'weui';
|
||||
}
|
||||
return res;
|
||||
}, {});
|
||||
}
|
||||
/**
|
||||
* 开发者在配置usingComponents时,可以指向具体路径(不含文件后缀),也可以指向目录(指向目录时查找目录下的index.wxml/.json等)
|
||||
* 当usingComponents配置为`"demo": "/components/demo"`时,查找优先级为:
|
||||
* 1. /components/demo.wxml
|
||||
* 2. /components/demo/index.wxml
|
||||
*
|
||||
* 注意如下配置是非法的:
|
||||
* - "demo": "/components/demo.wxml"
|
||||
* - "demo": "/components/demo/"
|
||||
*
|
||||
* 注意用户的pages.json内可以配置如下三种路径:
|
||||
* - "demo": "/wxcomponents/demo"
|
||||
* - "demo": "wxcomponents/demo"
|
||||
* - [TODO 待确认] "demo": "../wxcomponents/demo"
|
||||
*/
|
||||
function findUsingComponentsJson(pathInpages, componentsDir) {
|
||||
// 兼容test case
|
||||
if (!process.env.UNI_INPUT_DIR)
|
||||
return {};
|
||||
let [, dir] = pathInpages.split(componentsDir);
|
||||
if (dir === '') {
|
||||
console.warn(`${pathInpages} 路径里没有找到对应的 ${componentsDir} 目录`);
|
||||
return {};
|
||||
}
|
||||
dir = '.' + dir;
|
||||
const fulldir = path_1.default.resolve(process.env.UNI_INPUT_DIR, componentsDir, dir);
|
||||
let jsonPath = fulldir + '.json';
|
||||
if (fs_1.default.existsSync(jsonPath)) {
|
||||
return require(jsonPath);
|
||||
}
|
||||
jsonPath = path_1.default.resolve(fulldir, 'index.json');
|
||||
if (fs_1.default.existsSync(jsonPath)) {
|
||||
return require(jsonPath);
|
||||
}
|
||||
console.warn(`${pathInpages} 路径下没有找到对应的json文件`);
|
||||
return {};
|
||||
}
|
||||
exports.findUsingComponentsJson = findUsingComponentsJson;
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import type { AppJson, NetworkTimeout, PageWindowOptions } from './types';
|
||||
interface ParsePagesJsonOptions {
|
||||
debug?: boolean;
|
||||
darkmode?: boolean;
|
||||
subpackages: boolean;
|
||||
windowOptionsMap?: Record<string, string>;
|
||||
tabBarOptionsMap?: Record<string, string>;
|
||||
tabBarItemOptionsMap?: Record<string, string>;
|
||||
networkTimeout?: NetworkTimeout;
|
||||
}
|
||||
export declare function parseMiniProgramPagesJson(jsonStr: string, platform: UniApp.PLATFORM, options?: ParsePagesJsonOptions): {
|
||||
appJson: AppJson;
|
||||
pageJsons: Record<string, PageWindowOptions>;
|
||||
nvuePages: string[];
|
||||
};
|
||||
export declare function mergeMiniProgramAppJson(appJson: Record<string, any>, platformJson?: Record<string, any>, source?: Record<string, any>): void;
|
||||
export {};
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.mergeMiniProgramAppJson = exports.parseMiniProgramPagesJson = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const json_1 = require("../json");
|
||||
const pages_1 = require("../pages");
|
||||
const utils_1 = require("./utils");
|
||||
const utils_2 = require("../../utils");
|
||||
const project_1 = require("./project");
|
||||
const manifest_1 = require("../manifest");
|
||||
const theme_1 = require("../theme");
|
||||
const uni_x_1 = require("../uni-x");
|
||||
function parseMiniProgramPagesJson(jsonStr, platform, options = { subpackages: false }) {
|
||||
if (process.env.UNI_APP_X === 'true') {
|
||||
// 目前仅对x开放
|
||||
(0, uni_x_1.checkPagesJson)(jsonStr, process.env.UNI_INPUT_DIR);
|
||||
}
|
||||
return parsePagesJson(jsonStr, platform, options);
|
||||
}
|
||||
exports.parseMiniProgramPagesJson = parseMiniProgramPagesJson;
|
||||
const NON_APP_JSON_KEYS = [
|
||||
'unipush',
|
||||
'secureNetwork',
|
||||
'usingComponents',
|
||||
'optimization',
|
||||
'scopedSlotsCompiler',
|
||||
'uniStatistics',
|
||||
'mergeVirtualHostAttributes',
|
||||
'styleIsolation',
|
||||
'enableVirtualHost',
|
||||
];
|
||||
function mergeMiniProgramAppJson(appJson, platformJson = {}, source = {}) {
|
||||
Object.keys(source).forEach((key) => {
|
||||
if (!project_1.projectKeys.includes(key)) {
|
||||
project_1.projectKeys.push(key);
|
||||
}
|
||||
});
|
||||
Object.keys(platformJson).forEach((name) => {
|
||||
if (!(0, project_1.isMiniProgramProjectJsonKey)(name) &&
|
||||
!NON_APP_JSON_KEYS.includes(name)) {
|
||||
appJson[name] = platformJson[name];
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.mergeMiniProgramAppJson = mergeMiniProgramAppJson;
|
||||
function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, subpackages, windowOptionsMap, tabBarOptionsMap, tabBarItemOptionsMap, } = {
|
||||
subpackages: false,
|
||||
}) {
|
||||
let appJson = {
|
||||
pages: [],
|
||||
};
|
||||
let pageJsons = {};
|
||||
let nvuePages = [];
|
||||
// preprocess
|
||||
const pagesJson = (0, json_1.parseJson)(jsonStr, true, 'pages.json');
|
||||
if (!pagesJson) {
|
||||
throw new Error(`[vite] Error: pages.json parse failed.\n`);
|
||||
}
|
||||
function addPageJson(pagePath, style) {
|
||||
const filename = path_1.default.join(process.env.UNI_INPUT_DIR, pagePath);
|
||||
if (fs_1.default.existsSync(filename + '.nvue') &&
|
||||
!fs_1.default.existsSync(filename + '.vue')) {
|
||||
nvuePages.push(pagePath);
|
||||
}
|
||||
const windowOptions = {};
|
||||
if (platform === 'mp-baidu') {
|
||||
// 仅百度小程序需要页面配置 component:true
|
||||
// 快手小程序反而不能配置 component:true,故不能统一添加,目前硬编码处理
|
||||
windowOptions.component = true;
|
||||
}
|
||||
pageJsons[pagePath] = (0, shared_1.extend)(windowOptions, (0, utils_1.parseWindowOptions)(style, platform, windowOptionsMap));
|
||||
}
|
||||
// pages
|
||||
(0, pages_1.validatePages)(pagesJson, jsonStr);
|
||||
pagesJson.pages.forEach((page) => {
|
||||
appJson.pages.push(page.path);
|
||||
addPageJson(page.path, page.style);
|
||||
});
|
||||
// subpackages
|
||||
pagesJson.subPackages = pagesJson.subPackages || pagesJson.subpackages;
|
||||
if (pagesJson.subPackages) {
|
||||
if (subpackages) {
|
||||
appJson.subPackages = pagesJson.subPackages.map(({ root, pages, ...rest }) => {
|
||||
return (0, shared_1.extend)({
|
||||
root,
|
||||
pages: pages.map((page) => {
|
||||
addPageJson((0, utils_2.normalizePath)(path_1.default.join(root, page.path)), page.style);
|
||||
return page.path;
|
||||
}),
|
||||
}, rest);
|
||||
});
|
||||
}
|
||||
else {
|
||||
pagesJson.subPackages.forEach(({ root, pages }) => {
|
||||
pages.forEach((page) => {
|
||||
const pagePath = (0, utils_2.normalizePath)(path_1.default.join(root, page.path));
|
||||
appJson.pages.push(pagePath);
|
||||
addPageJson(pagePath, page.style);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
// window
|
||||
if (pagesJson.globalStyle) {
|
||||
const windowOptions = (0, utils_1.parseWindowOptions)(pagesJson.globalStyle, platform, windowOptionsMap);
|
||||
const { usingComponents } = windowOptions;
|
||||
if (usingComponents) {
|
||||
delete windowOptions.usingComponents;
|
||||
appJson.usingComponents = usingComponents;
|
||||
}
|
||||
else {
|
||||
delete appJson.usingComponents;
|
||||
}
|
||||
appJson.window = windowOptions;
|
||||
}
|
||||
// tabBar
|
||||
if (pagesJson.tabBar) {
|
||||
const tabBar = (0, utils_1.parseTabBar)(pagesJson.tabBar, platform, tabBarOptionsMap, tabBarItemOptionsMap);
|
||||
if (tabBar) {
|
||||
appJson.tabBar = tabBar;
|
||||
}
|
||||
}
|
||||
(0, pages_1.filterPlatformPages)(platform, pagesJson);
|
||||
['preloadRule', 'workers', 'plugins', 'entryPagePath'].forEach((name) => {
|
||||
if ((0, shared_1.hasOwn)(pagesJson, name)) {
|
||||
appJson[name] = pagesJson[name];
|
||||
}
|
||||
});
|
||||
if (debug) {
|
||||
appJson.debug = debug;
|
||||
}
|
||||
if (networkTimeout) {
|
||||
appJson.networkTimeout = networkTimeout;
|
||||
}
|
||||
const manifestJson = (0, manifest_1.getPlatformManifestJsonOnce)();
|
||||
if (!darkmode) {
|
||||
const { pages, window, tabBar } = (0, theme_1.initTheme)(manifestJson, appJson);
|
||||
(0, shared_1.extend)(appJson, JSON.parse(JSON.stringify({ pages, window, tabBar })));
|
||||
delete appJson.darkmode;
|
||||
delete appJson.themeLocation;
|
||||
pageJsons = (0, theme_1.initTheme)(manifestJson, pageJsons);
|
||||
}
|
||||
else {
|
||||
const themeLocation = manifestJson.themeLocation || 'theme.json';
|
||||
if ((0, theme_1.hasThemeJson)(path_1.default.join(process.env.UNI_INPUT_DIR, themeLocation)))
|
||||
appJson.themeLocation = themeLocation;
|
||||
}
|
||||
return {
|
||||
appJson,
|
||||
pageJsons,
|
||||
nvuePages,
|
||||
};
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
interface ParseMiniProgramProjectJsonOptions {
|
||||
template: Record<string, any>;
|
||||
pagesJson: UniApp.PagesJson;
|
||||
}
|
||||
interface ProjectConfig {
|
||||
appid: string;
|
||||
projectname: string;
|
||||
condition?: {
|
||||
miniprogram?: UniApp.PagesJson['condition'];
|
||||
};
|
||||
}
|
||||
export declare const projectKeys: string[];
|
||||
export declare function isMiniProgramProjectJsonKey(name: string): boolean;
|
||||
export declare function parseMiniProgramProjectJson(jsonStr: string, platform: UniApp.PLATFORM, { template, pagesJson }: ParseMiniProgramProjectJsonOptions): ProjectConfig;
|
||||
export {};
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseMiniProgramProjectJson = exports.isMiniProgramProjectJsonKey = exports.projectKeys = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const merge_1 = require("merge");
|
||||
const json_1 = require("../json");
|
||||
exports.projectKeys = [
|
||||
'appid',
|
||||
'setting',
|
||||
'miniprogramRoot',
|
||||
'cloudfunctionRoot',
|
||||
'qcloudRoot',
|
||||
'pluginRoot',
|
||||
'compileType',
|
||||
'libVersion',
|
||||
'projectname',
|
||||
'packOptions',
|
||||
'debugOptions',
|
||||
'scripts',
|
||||
'cloudbaseRoot',
|
||||
];
|
||||
function isMiniProgramProjectJsonKey(name) {
|
||||
return exports.projectKeys.includes(name);
|
||||
}
|
||||
exports.isMiniProgramProjectJsonKey = isMiniProgramProjectJsonKey;
|
||||
function parseMiniProgramProjectJson(jsonStr, platform, { template, pagesJson }) {
|
||||
const projectJson = JSON.parse(JSON.stringify(template));
|
||||
const manifestJson = (0, json_1.parseJson)(jsonStr, false, '');
|
||||
if (manifestJson) {
|
||||
projectJson.projectname = manifestJson.name;
|
||||
// 用户的平台配置
|
||||
const platformConfig = manifestJson[platform];
|
||||
if (platformConfig) {
|
||||
const setProjectJson = (name) => {
|
||||
if ((0, shared_1.hasOwn)(platformConfig, name)) {
|
||||
if ((0, shared_1.isPlainObject)(platformConfig[name]) &&
|
||||
(0, shared_1.isPlainObject)(projectJson[name])) {
|
||||
;
|
||||
projectJson[name] = (0, merge_1.recursive)(true, projectJson[name], platformConfig[name]);
|
||||
}
|
||||
else {
|
||||
;
|
||||
projectJson[name] = platformConfig[name];
|
||||
}
|
||||
}
|
||||
};
|
||||
// 读取 template 中的配置
|
||||
Object.keys(template).forEach((name) => {
|
||||
if (!exports.projectKeys.includes(name)) {
|
||||
exports.projectKeys.push(name);
|
||||
}
|
||||
});
|
||||
// common mp config
|
||||
exports.projectKeys.forEach((name) => {
|
||||
setProjectJson(name);
|
||||
});
|
||||
// 使用了微信小程序手势系统,自动开启 ES6=>ES5
|
||||
platform === 'mp-weixin' &&
|
||||
weixinSkyline(platformConfig) &&
|
||||
openES62ES5(projectJson);
|
||||
}
|
||||
}
|
||||
// 其实仅开发期间 condition 生效即可,暂不做判断
|
||||
const miniprogram = parseMiniProgramCondition(pagesJson);
|
||||
if (miniprogram) {
|
||||
if (!projectJson.condition) {
|
||||
projectJson.condition = {};
|
||||
}
|
||||
projectJson.condition.miniprogram = miniprogram;
|
||||
}
|
||||
// appid
|
||||
if (!projectJson.appid) {
|
||||
projectJson.appid = 'touristappid';
|
||||
}
|
||||
return projectJson;
|
||||
}
|
||||
exports.parseMiniProgramProjectJson = parseMiniProgramProjectJson;
|
||||
function weixinSkyline(config) {
|
||||
return (config.renderer === 'skyline' &&
|
||||
config.lazyCodeLoading === 'requiredComponents');
|
||||
}
|
||||
function openES62ES5(config) {
|
||||
if (!config.setting) {
|
||||
config.setting = {};
|
||||
}
|
||||
if (!config.setting.es6) {
|
||||
config.setting.es6 = true;
|
||||
}
|
||||
}
|
||||
function parseMiniProgramCondition(pagesJson) {
|
||||
const launchPagePath = process.env.UNI_CLI_LAUNCH_PAGE_PATH || '';
|
||||
if (launchPagePath) {
|
||||
return {
|
||||
current: 0,
|
||||
list: [
|
||||
{
|
||||
id: 0,
|
||||
name: launchPagePath, // 模式名称
|
||||
pathName: launchPagePath, // 启动页面,必选
|
||||
query: process.env.UNI_CLI_LAUNCH_PAGE_QUERY || '', // 启动参数,在页面的onLoad函数里面得到。
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
const condition = pagesJson.condition;
|
||||
if (!condition || !(0, shared_1.isArray)(condition.list) || !condition.list.length) {
|
||||
return;
|
||||
}
|
||||
condition.list.forEach(function (item, index) {
|
||||
item.id = item.id || index;
|
||||
if (item.path) {
|
||||
item.pathName = item.path;
|
||||
delete item.path;
|
||||
}
|
||||
});
|
||||
return condition;
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
export interface ComponentJson {
|
||||
component: true;
|
||||
usingComponents?: UsingComponents;
|
||||
usingSwanComponents?: UsingComponents;
|
||||
styleIsolation?: 'apply-shared' | 'shared' | 'isolated';
|
||||
}
|
||||
interface ShareWindowOptions {
|
||||
navigationBarBackgroundColor?: string;
|
||||
navigationBarTextStyle?: 'white' | 'black';
|
||||
navigationBarTitleText?: string;
|
||||
navigationStyle?: 'default' | 'custom';
|
||||
backgroundColor?: string;
|
||||
backgroundTextStyle?: 'dark' | 'light';
|
||||
backgroundColorTop?: string;
|
||||
backgroundColorBottom?: string;
|
||||
enablePullDownRefresh?: boolean;
|
||||
onReachBottomDistance?: number;
|
||||
pageOrientation?: 'portrait' | 'landscape' | 'auto';
|
||||
}
|
||||
type Style = 'v2' | string;
|
||||
type RestartStrategy = 'homePage' | 'homePageAndLatestPage' | string;
|
||||
export interface PageWindowOptions extends ShareWindowOptions {
|
||||
component?: true;
|
||||
disableScroll?: boolean;
|
||||
usingComponents?: UsingComponents;
|
||||
usingSwanComponents?: UsingComponents;
|
||||
initialRenderingCache?: 'static' | string;
|
||||
style?: Style;
|
||||
singlePage?: SinglePage;
|
||||
restartStrategy?: RestartStrategy;
|
||||
}
|
||||
export interface AppWindowOptions extends ShareWindowOptions {
|
||||
visualEffectInBackground?: 'none' | 'hidden';
|
||||
}
|
||||
interface SubPackage {
|
||||
name?: string;
|
||||
root: string;
|
||||
pages: string[];
|
||||
independent?: boolean;
|
||||
}
|
||||
interface TabBarItem {
|
||||
pagePath: string;
|
||||
text: string;
|
||||
iconPath?: string;
|
||||
selectedIconPath?: string;
|
||||
}
|
||||
export interface TabBar {
|
||||
color: string;
|
||||
selectedColor: string;
|
||||
backgroundColor: string;
|
||||
borderStyle?: 'black' | 'white';
|
||||
list: TabBarItem[];
|
||||
position?: 'bottom' | 'top';
|
||||
custom?: boolean;
|
||||
}
|
||||
export interface NetworkTimeout {
|
||||
request?: number;
|
||||
requeconnectSocketst?: number;
|
||||
uploadFile?: number;
|
||||
downloadFile?: number;
|
||||
}
|
||||
interface Plugins {
|
||||
[name: string]: {
|
||||
version: string;
|
||||
provider: string;
|
||||
};
|
||||
}
|
||||
interface PreloadRule {
|
||||
[name: string]: {
|
||||
network: 'wifi' | 'all';
|
||||
packages: string[];
|
||||
};
|
||||
}
|
||||
export interface UsingComponents {
|
||||
[name: string]: string;
|
||||
}
|
||||
interface Permission {
|
||||
[name: string]: {
|
||||
desc: string;
|
||||
};
|
||||
}
|
||||
interface UseExtendedLib {
|
||||
kbone: boolean;
|
||||
weui: boolean;
|
||||
}
|
||||
interface EntranceDeclare {
|
||||
locationMessage: {
|
||||
path: string;
|
||||
query: string;
|
||||
};
|
||||
}
|
||||
interface SinglePage {
|
||||
navigationBarFit?: 'squeezed' | 'float';
|
||||
}
|
||||
export interface AppJson {
|
||||
entryPagePath?: string;
|
||||
pages: string[];
|
||||
window?: AppWindowOptions;
|
||||
tabBar?: TabBar;
|
||||
networkTimeout?: NetworkTimeout;
|
||||
debug?: boolean;
|
||||
functionalPages?: boolean;
|
||||
subPackages?: SubPackage[];
|
||||
workers?: string;
|
||||
requiredBackgroundModes?: string[];
|
||||
plugins?: Plugins;
|
||||
preloadRule?: PreloadRule;
|
||||
resizable?: boolean;
|
||||
usingComponents?: UsingComponents;
|
||||
permission?: Permission;
|
||||
sitemapLocation?: string;
|
||||
style?: Style;
|
||||
useExtendedLib?: UseExtendedLib;
|
||||
entranceDeclare?: EntranceDeclare;
|
||||
darkmode?: boolean;
|
||||
themeLocation?: string;
|
||||
lazyCodeLoading?: 'requiredComponents' | string;
|
||||
singlePage?: SinglePage;
|
||||
restartStrategy?: RestartStrategy;
|
||||
[name: string]: unknown;
|
||||
}
|
||||
export type MiniProgramComponentsType = 'plugin' | 'component' | 'dynamicLib' | 'ext' | 'xr-frame' | 'weui';
|
||||
export {};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import type { AppWindowOptions, PageWindowOptions, TabBar } from './types';
|
||||
export declare function parseWindowOptions(style: UniApp.PagesJsonPageStyle, platform: UniApp.PLATFORM, windowOptionsMap?: Record<string, string>): PageWindowOptions | AppWindowOptions;
|
||||
export declare function parseTabBar(tabBar: UniApp.TabBarOptions, platform: UniApp.PLATFORM, tabBarOptionsMap?: Record<string, string>, tabBarItemOptionsMap?: Record<string, string>): TabBar;
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseTabBar = exports.parseWindowOptions = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const pages_1 = require("../pages");
|
||||
function trimJson(json) {
|
||||
delete json.maxWidth;
|
||||
delete json.topWindow;
|
||||
delete json.leftWindow;
|
||||
delete json.rightWindow;
|
||||
if (json.tabBar) {
|
||||
delete json.tabBar.matchMedia;
|
||||
}
|
||||
return json;
|
||||
}
|
||||
function convert(to, from, map) {
|
||||
Object.keys(map).forEach((key) => {
|
||||
if ((0, shared_1.hasOwn)(from, map[key])) {
|
||||
to[key] = from[map[key]];
|
||||
}
|
||||
});
|
||||
return to;
|
||||
}
|
||||
function parseWindowOptions(style, platform, windowOptionsMap) {
|
||||
if (!style) {
|
||||
return {};
|
||||
}
|
||||
const platformStyle = style[platform] || {};
|
||||
(0, pages_1.removePlatformStyle)(trimJson(style));
|
||||
const res = {};
|
||||
if (windowOptionsMap) {
|
||||
return (0, shared_1.extend)(convert(res, style, windowOptionsMap), platformStyle);
|
||||
}
|
||||
return (0, shared_1.extend)(res, style, platformStyle);
|
||||
}
|
||||
exports.parseWindowOptions = parseWindowOptions;
|
||||
function trimTabBarJson(tabBar) {
|
||||
;
|
||||
[
|
||||
'fontSize',
|
||||
'height',
|
||||
'iconWidth',
|
||||
'midButton',
|
||||
'selectedIndex',
|
||||
'spacing',
|
||||
].forEach((name) => {
|
||||
delete tabBar[name];
|
||||
});
|
||||
return tabBar;
|
||||
}
|
||||
function parseTabBar(tabBar, platform, tabBarOptionsMap, tabBarItemOptionsMap) {
|
||||
const platformStyle = tabBar[platform] || {};
|
||||
(0, pages_1.removePlatformStyle)(trimTabBarJson(tabBar));
|
||||
const res = {};
|
||||
if (tabBarOptionsMap) {
|
||||
if (tabBarItemOptionsMap && tabBar.list) {
|
||||
tabBar.list = tabBar.list.map((item) => {
|
||||
return convert({}, item, tabBarItemOptionsMap);
|
||||
});
|
||||
}
|
||||
convert(res, tabBar, tabBarOptionsMap);
|
||||
return (0, shared_1.extend)(res, platformStyle);
|
||||
}
|
||||
return (0, shared_1.extend)(res, tabBar, platformStyle);
|
||||
}
|
||||
exports.parseTabBar = parseTabBar;
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
export declare function isUniPageFile(file: string, inputDir?: string): boolean;
|
||||
export declare function isUniPageSetupAndUts(file: string): boolean;
|
||||
export declare function isUniPageSetupAndTs(file: string): boolean;
|
||||
export declare function isUniPageSfcFile(file: string, inputDir?: string): boolean;
|
||||
/**
|
||||
* 小程序平台慎用,因为该解析不支持 subpackages
|
||||
* @param inputDir
|
||||
* @param platform
|
||||
* @param normalize
|
||||
* @returns
|
||||
*/
|
||||
export declare const parsePagesJson: (inputDir: string, platform: UniApp.PLATFORM, normalize?: boolean) => UniApp.PagesJson;
|
||||
/**
|
||||
* 该方法解析出来的是不支持 subpackages,会被合并入 pages
|
||||
*/
|
||||
export declare const parsePagesJsonOnce: (inputDir: string, platform: UniApp.PLATFORM, normalize?: boolean) => UniApp.PagesJson;
|
||||
/**
|
||||
* 目前 App 和 H5 使用了该方法
|
||||
* @param jsonStr
|
||||
* @param platform
|
||||
* @param param2
|
||||
* @returns
|
||||
*/
|
||||
export declare function normalizePagesJson(jsonStr: string, platform: UniApp.PLATFORM, { subpackages, }?: {
|
||||
subpackages: boolean;
|
||||
}): UniApp.PagesJson;
|
||||
export declare function validatePages(pagesJson: Record<string, any>, jsonStr: string): void;
|
||||
export declare function removePlatformStyle(pageStyle: Record<string, any>): Record<string, any>;
|
||||
export declare function normalizePagesRoute(pagesJson: UniApp.PagesJson): UniApp.UniRoute[];
|
||||
declare function parseSubpackagesRoot(inputDir: string, platform: UniApp.PLATFORM): string[];
|
||||
export declare const parseSubpackagesRootOnce: typeof parseSubpackagesRoot;
|
||||
export declare function filterPlatformPages(platform: UniApp.PLATFORM, pagesJson: UniApp.PagesJson): void;
|
||||
export {};
|
||||
+533
@@ -0,0 +1,533 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.filterPlatformPages = exports.parseSubpackagesRootOnce = exports.normalizePagesRoute = exports.removePlatformStyle = exports.validatePages = exports.normalizePagesJson = exports.parsePagesJsonOnce = exports.parsePagesJson = exports.isUniPageSfcFile = exports.isUniPageSetupAndTs = exports.isUniPageSetupAndUts = exports.isUniPageFile = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const utils_1 = require("../utils");
|
||||
const json_1 = require("./json");
|
||||
const utils_2 = require("../vue/utils");
|
||||
const vite_1 = require("../vite");
|
||||
const constants_1 = require("../constants");
|
||||
const theme_1 = require("./theme");
|
||||
const manifest_1 = require("./manifest");
|
||||
const pagesCacheSet = new Set();
|
||||
function isUniPageFile(file, inputDir = process.env.UNI_INPUT_DIR) {
|
||||
if (inputDir && path_1.default.isAbsolute(file)) {
|
||||
file = (0, utils_1.normalizePath)(path_1.default.relative(inputDir, file));
|
||||
}
|
||||
return pagesCacheSet.has((0, utils_1.removeExt)(file));
|
||||
}
|
||||
exports.isUniPageFile = isUniPageFile;
|
||||
function isUniPageSetupAndUts(file) {
|
||||
const { filename, query } = (0, vite_1.parseVueRequest)(file);
|
||||
return !!(query.vue &&
|
||||
query.setup &&
|
||||
(0, shared_1.hasOwn)(query, 'lang.uts') &&
|
||||
constants_1.EXTNAME_VUE_RE.test(filename));
|
||||
}
|
||||
exports.isUniPageSetupAndUts = isUniPageSetupAndUts;
|
||||
function isUniPageSetupAndTs(file) {
|
||||
const { filename, query } = (0, vite_1.parseVueRequest)(file);
|
||||
return !!(query.vue &&
|
||||
query.setup &&
|
||||
(0, shared_1.hasOwn)(query, 'lang.ts') &&
|
||||
constants_1.EXTNAME_VUE_RE.test(filename));
|
||||
}
|
||||
exports.isUniPageSetupAndTs = isUniPageSetupAndTs;
|
||||
function isUniPageSfcFile(file, inputDir = process.env.UNI_INPUT_DIR) {
|
||||
return (0, utils_2.isVueSfcFile)(file) && isUniPageFile(file, inputDir);
|
||||
}
|
||||
exports.isUniPageSfcFile = isUniPageSfcFile;
|
||||
/**
|
||||
* 小程序平台慎用,因为该解析不支持 subpackages
|
||||
* @param inputDir
|
||||
* @param platform
|
||||
* @param normalize
|
||||
* @returns
|
||||
*/
|
||||
const parsePagesJson = (inputDir, platform, normalize = true) => {
|
||||
const pagesFilename = path_1.default.join(inputDir, 'pages.json');
|
||||
if (!fs_1.default.existsSync(pagesFilename)) {
|
||||
if (!(0, utils_1.isNormalCompileTarget)()) {
|
||||
return {
|
||||
pages: [],
|
||||
globalStyle: { navigationBar: {} },
|
||||
};
|
||||
}
|
||||
}
|
||||
const jsonStr = fs_1.default.readFileSync(pagesFilename, 'utf8');
|
||||
if (normalize) {
|
||||
return normalizePagesJson(jsonStr, platform);
|
||||
}
|
||||
return (0, json_1.parseJson)(jsonStr, true, pagesFilename);
|
||||
};
|
||||
exports.parsePagesJson = parsePagesJson;
|
||||
/**
|
||||
* 该方法解析出来的是不支持 subpackages,会被合并入 pages
|
||||
*/
|
||||
exports.parsePagesJsonOnce = (0, uni_shared_1.once)(exports.parsePagesJson);
|
||||
/**
|
||||
* 目前 App 和 H5 使用了该方法
|
||||
* @param jsonStr
|
||||
* @param platform
|
||||
* @param param2
|
||||
* @returns
|
||||
*/
|
||||
function normalizePagesJson(jsonStr, platform, { subpackages, } = { subpackages: false }) {
|
||||
let pagesJson = {
|
||||
pages: [],
|
||||
globalStyle: {
|
||||
navigationBar: {},
|
||||
},
|
||||
};
|
||||
// preprocess
|
||||
try {
|
||||
pagesJson = (0, json_1.parseJson)(jsonStr, true, 'pages.json');
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
|
||||
}
|
||||
// pages
|
||||
validatePages(pagesJson, jsonStr);
|
||||
pagesJson.subPackages = pagesJson.subPackages || pagesJson.subpackages;
|
||||
delete pagesJson.subpackages;
|
||||
// subpackages
|
||||
if (pagesJson.subPackages) {
|
||||
if (subpackages) {
|
||||
pagesJson.subPackages.forEach(({ pages }) => {
|
||||
pages && normalizePages(pages, platform);
|
||||
});
|
||||
}
|
||||
else {
|
||||
pagesJson.pages.push(...normalizeSubpackages(pagesJson.subPackages));
|
||||
delete pagesJson.subPackages;
|
||||
}
|
||||
}
|
||||
else {
|
||||
delete pagesJson.subPackages;
|
||||
}
|
||||
// pageStyle
|
||||
normalizePages(pagesJson.pages, platform);
|
||||
// globalStyle
|
||||
pagesJson.globalStyle = normalizePageStyle(null, pagesJson.globalStyle, platform);
|
||||
// tabBar
|
||||
if (pagesJson.tabBar) {
|
||||
const tabBar = normalizeTabBar(pagesJson.tabBar, platform);
|
||||
if (tabBar) {
|
||||
pagesJson.tabBar = tabBar;
|
||||
}
|
||||
else {
|
||||
delete pagesJson.tabBar;
|
||||
}
|
||||
}
|
||||
// 过滤平台page
|
||||
filterPlatformPages(platform, pagesJson);
|
||||
// 缓存页面列表
|
||||
pagesCacheSet.clear();
|
||||
pagesJson.pages.forEach((page) => pagesCacheSet.add(page.path));
|
||||
const manifestJsonPlatform = (0, manifest_1.getPlatformManifestJsonOnce)();
|
||||
if (!manifestJsonPlatform.darkmode) {
|
||||
const { pages, globalStyle, tabBar } = (0, theme_1.initTheme)(manifestJsonPlatform, pagesJson);
|
||||
(0, shared_1.extend)(pagesJson, { pages, globalStyle, tabBar });
|
||||
}
|
||||
return pagesJson;
|
||||
}
|
||||
exports.normalizePagesJson = normalizePagesJson;
|
||||
function validatePages(pagesJson, jsonStr) {
|
||||
if (!(0, shared_1.isArray)(pagesJson.pages)) {
|
||||
pagesJson.pages = [];
|
||||
console.error(`[uni-app] Error: pages.json->pages parse failed.`);
|
||||
process.exit(0);
|
||||
}
|
||||
else if (!pagesJson.pages.length) {
|
||||
console.error(`[uni-app] Error: pages.json->pages must contain at least 1 page.`);
|
||||
process.exit(0);
|
||||
}
|
||||
else {
|
||||
const pages = [];
|
||||
pagesJson.pages.forEach((page) => {
|
||||
if (pages.indexOf(page.path) !== -1) {
|
||||
console.error(`[uni-app] Error: pages.json->${page.path} duplication.`);
|
||||
process.exit(0);
|
||||
}
|
||||
pages.push(page.path);
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.validatePages = validatePages;
|
||||
function normalizePages(pages, platform) {
|
||||
pages.forEach((page) => {
|
||||
page.style = normalizePageStyle(page.path, page.style, platform);
|
||||
if (platform === 'app-harmony') {
|
||||
// 鸿蒙下强制 isNVue 为 false,增加额外的 isNVueStyle 来标记样式处理
|
||||
// 因为已有的代码里太多根据 isNVue 来处理的逻辑,这些逻辑在鸿蒙都不适用
|
||||
// 鸿蒙仅需要将 nvue 当做 vue,并补充 css 即可
|
||||
if (page.style.isNVue) {
|
||||
page.style.isNVue = false;
|
||||
page.style.isNVueStyle = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (platform !== 'app') {
|
||||
return;
|
||||
}
|
||||
const subNVuePages = [];
|
||||
// subNVues
|
||||
pages.forEach(({ style: { subNVues } }) => {
|
||||
if (!(0, shared_1.isArray)(subNVues)) {
|
||||
return;
|
||||
}
|
||||
subNVues.forEach((subNVue) => {
|
||||
if (subNVue && subNVue.path) {
|
||||
subNVuePages.push({
|
||||
path: subNVue.path,
|
||||
style: { isSubNVue: true, isNVue: true, navigationBar: {} },
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
if (subNVuePages.length) {
|
||||
pages.push(...subNVuePages);
|
||||
}
|
||||
}
|
||||
function normalizeSubpackages(subpackages) {
|
||||
const pages = [];
|
||||
if ((0, shared_1.isArray)(subpackages)) {
|
||||
subpackages.forEach(({ root, pages: subPages }) => {
|
||||
if (root && subPages.length) {
|
||||
subPages.forEach((subPage) => {
|
||||
subPage.path = (0, utils_1.normalizePath)(path_1.default.join(root, subPage.path));
|
||||
subPage.style = normalizeSubpackageSubNVues(root, subPage.style);
|
||||
pages.push(subPage);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
function normalizeSubpackageSubNVues(root, style = { navigationBar: {} }) {
|
||||
const platformStyle = style['app'] || style['app-plus'];
|
||||
if (!platformStyle) {
|
||||
return style;
|
||||
}
|
||||
if ((0, shared_1.isArray)(platformStyle.subNVues)) {
|
||||
platformStyle.subNVues.forEach((subNVue) => {
|
||||
if (subNVue.path) {
|
||||
subNVue.path = (0, utils_1.normalizePath)(path_1.default.join(root, subNVue.path));
|
||||
}
|
||||
});
|
||||
}
|
||||
return style;
|
||||
}
|
||||
function normalizePageStyle(pagePath, pageStyle, platform) {
|
||||
let isNVue = false;
|
||||
if (process.env.UNI_APP_X === 'true') {
|
||||
isNVue = undefined;
|
||||
}
|
||||
else {
|
||||
const hasNVue = pagePath &&
|
||||
process.env.UNI_INPUT_DIR &&
|
||||
fs_1.default.existsSync(path_1.default.join(process.env.UNI_INPUT_DIR, pagePath + '.nvue'))
|
||||
? true
|
||||
: undefined;
|
||||
if (hasNVue) {
|
||||
const hasVue = fs_1.default.existsSync(path_1.default.join(process.env.UNI_INPUT_DIR, pagePath + '.vue'));
|
||||
if (hasVue) {
|
||||
if (platform === 'app') {
|
||||
if (process.env.UNI_NVUE_COMPILER !== 'vue') {
|
||||
isNVue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
isNVue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pageStyle) {
|
||||
if (platform === 'h5') {
|
||||
(0, shared_1.extend)(pageStyle, pageStyle['app'] || pageStyle['app-plus'], pageStyle['web'] || pageStyle['h5']);
|
||||
}
|
||||
else if (platform === 'app') {
|
||||
(0, shared_1.extend)(pageStyle, pageStyle['app'] || pageStyle['app-plus']);
|
||||
}
|
||||
else {
|
||||
(0, shared_1.extend)(pageStyle, pageStyle[platform]);
|
||||
}
|
||||
if (['h5', 'app', 'app-harmony'].includes(platform)) {
|
||||
pageStyle.navigationBar = normalizeNavigationBar(pageStyle);
|
||||
if (isEnablePullDownRefresh(pageStyle)) {
|
||||
pageStyle.enablePullDownRefresh = true;
|
||||
pageStyle.pullToRefresh = normalizePullToRefresh(pageStyle);
|
||||
}
|
||||
if (platform === 'app') {
|
||||
pageStyle.disableSwipeBack === true
|
||||
? (pageStyle.popGesture = 'none')
|
||||
: delete pageStyle.popGesture;
|
||||
delete pageStyle.disableSwipeBack;
|
||||
}
|
||||
}
|
||||
pageStyle.isNVue = isNVue;
|
||||
removePlatformStyle(pageStyle);
|
||||
return pageStyle;
|
||||
}
|
||||
return { navigationBar: {}, isNVue };
|
||||
}
|
||||
const navigationBarMaps = {
|
||||
navigationBarBackgroundColor: 'backgroundColor',
|
||||
navigationBarTextStyle: 'textStyle',
|
||||
navigationBarTitleText: 'titleText',
|
||||
navigationStyle: 'style',
|
||||
titleImage: 'titleImage',
|
||||
titlePenetrate: 'titlePenetrate',
|
||||
transparentTitle: 'transparentTitle',
|
||||
};
|
||||
function normalizeNavigationBar(pageStyle) {
|
||||
const navigationBar = Object.create(null);
|
||||
Object.keys(navigationBarMaps).forEach((name) => {
|
||||
if ((0, shared_1.hasOwn)(pageStyle, name)) {
|
||||
navigationBar[navigationBarMaps[name]] =
|
||||
pageStyle[name];
|
||||
delete pageStyle[name];
|
||||
}
|
||||
});
|
||||
navigationBar.type = navigationBar.type || 'default';
|
||||
const { titleNView } = pageStyle;
|
||||
if ((0, shared_1.isPlainObject)(titleNView)) {
|
||||
(0, shared_1.extend)(navigationBar, titleNView);
|
||||
delete pageStyle.titleNView;
|
||||
}
|
||||
else if (titleNView === false) {
|
||||
navigationBar.style = 'custom';
|
||||
}
|
||||
if ((0, shared_1.hasOwn)(navigationBar, 'transparentTitle')) {
|
||||
const transparentTitle = navigationBar.transparentTitle;
|
||||
if (transparentTitle === 'always') {
|
||||
navigationBar.style = 'custom';
|
||||
navigationBar.type = 'float';
|
||||
}
|
||||
else if (transparentTitle === 'auto') {
|
||||
navigationBar.type = 'transparent';
|
||||
}
|
||||
else {
|
||||
navigationBar.type = 'default';
|
||||
}
|
||||
delete navigationBar.transparentTitle;
|
||||
}
|
||||
if (navigationBar.titleImage && navigationBar.titleText) {
|
||||
delete navigationBar.titleText;
|
||||
}
|
||||
if (!navigationBar.titleColor && (0, shared_1.hasOwn)(navigationBar, 'textStyle')) {
|
||||
const textStyle = navigationBar.textStyle;
|
||||
if (constants_1.TEXT_STYLE.includes(textStyle)) {
|
||||
navigationBar.titleColor = (0, uni_shared_1.normalizeTitleColor)(textStyle);
|
||||
}
|
||||
else {
|
||||
navigationBar.titleColor = navigationBar.textStyle;
|
||||
}
|
||||
delete navigationBar.textStyle;
|
||||
}
|
||||
if (pageStyle.navigationBarShadow &&
|
||||
pageStyle.navigationBarShadow.colorType) {
|
||||
navigationBar.shadowColorType = pageStyle.navigationBarShadow.colorType;
|
||||
delete pageStyle.navigationBarShadow;
|
||||
}
|
||||
const parsedNavigationBar = (0, theme_1.initTheme)((0, manifest_1.getPlatformManifestJsonOnce)(), navigationBar);
|
||||
if ((0, shared_1.isArray)(navigationBar.buttons)) {
|
||||
navigationBar.buttons = navigationBar.buttons.map((btn) => normalizeNavigationBarButton(btn, navigationBar.type, parsedNavigationBar.titleColor));
|
||||
}
|
||||
if ((0, shared_1.isPlainObject)(navigationBar.searchInput)) {
|
||||
navigationBar.searchInput = normalizeNavigationBarSearchInput(navigationBar.searchInput);
|
||||
}
|
||||
if (navigationBar.type === 'transparent') {
|
||||
navigationBar.coverage = navigationBar.coverage || '132px';
|
||||
}
|
||||
return navigationBar;
|
||||
}
|
||||
function normalizeNavigationBarButton(btn, type, titleColor) {
|
||||
btn.color = btn.color || titleColor;
|
||||
if (!btn.fontSize) {
|
||||
btn.fontSize =
|
||||
type === 'transparent' || (btn.text && /\\u/.test(btn.text))
|
||||
? '22px'
|
||||
: '27px';
|
||||
}
|
||||
else if (/\d$/.test(btn.fontSize)) {
|
||||
btn.fontSize += 'px';
|
||||
}
|
||||
btn.text = btn.text || '';
|
||||
return btn;
|
||||
}
|
||||
function normalizeNavigationBarSearchInput(searchInput) {
|
||||
return (0, shared_1.extend)({
|
||||
autoFocus: false,
|
||||
align: 'center',
|
||||
color: '#000',
|
||||
backgroundColor: 'rgba(255,255,255,0.5)',
|
||||
borderRadius: '0px',
|
||||
placeholder: '',
|
||||
placeholderColor: '#CCCCCC',
|
||||
disabled: false,
|
||||
}, searchInput);
|
||||
}
|
||||
const DEFAULT_TAB_BAR = {
|
||||
position: 'bottom',
|
||||
color: '#999',
|
||||
selectedColor: '#007aff',
|
||||
borderStyle: 'black',
|
||||
blurEffect: 'none',
|
||||
fontSize: '10px',
|
||||
iconWidth: '24px',
|
||||
spacing: '3px',
|
||||
height: uni_shared_1.TABBAR_HEIGHT + 'px',
|
||||
list: [],
|
||||
};
|
||||
function normalizeTabBar(tabBar, platform) {
|
||||
const { midButton } = tabBar;
|
||||
tabBar = (0, shared_1.extend)({}, DEFAULT_TAB_BAR, tabBar);
|
||||
tabBar.list.forEach((item) => {
|
||||
if (item.iconPath) {
|
||||
item.iconPath = normalizeFilepath(item.iconPath);
|
||||
}
|
||||
if (item.selectedIconPath) {
|
||||
item.selectedIconPath = normalizeFilepath(item.selectedIconPath);
|
||||
}
|
||||
});
|
||||
if (midButton && midButton.backgroundImage) {
|
||||
midButton.backgroundImage = normalizeFilepath(midButton.backgroundImage);
|
||||
}
|
||||
tabBar.selectedIndex = 0;
|
||||
tabBar.shown = true;
|
||||
return tabBar;
|
||||
}
|
||||
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
|
||||
const DATA_RE = /^data:.*,.*/;
|
||||
function normalizeFilepath(filepath) {
|
||||
const themeConfig = (0, theme_1.normalizeThemeConfigOnce)()['light'] || {};
|
||||
if (themeConfig[filepath.replace('@', '')])
|
||||
return filepath;
|
||||
if (!(SCHEME_RE.test(filepath) || DATA_RE.test(filepath)) &&
|
||||
filepath.indexOf('/') !== 0) {
|
||||
return (0, uni_shared_1.addLeadingSlash)(filepath);
|
||||
}
|
||||
return filepath;
|
||||
}
|
||||
const platforms = ['h5', 'app', 'mp-', 'quickapp', 'web'];
|
||||
function removePlatformStyle(pageStyle) {
|
||||
Object.keys(pageStyle).forEach((name) => {
|
||||
if (platforms.find((prefix) => name.startsWith(prefix))) {
|
||||
delete pageStyle[name];
|
||||
}
|
||||
});
|
||||
return pageStyle;
|
||||
}
|
||||
exports.removePlatformStyle = removePlatformStyle;
|
||||
function normalizePagesRoute(pagesJson) {
|
||||
const firstPagePath = pagesJson.pages[0].path;
|
||||
const tabBarList = (pagesJson.tabBar && pagesJson.tabBar.list) || [];
|
||||
return pagesJson.pages.map((pageOptions) => {
|
||||
const pagePath = pageOptions.path;
|
||||
const isEntry = firstPagePath === pagePath ? true : undefined;
|
||||
const tabBarIndex = tabBarList.findIndex((tabBarPage) => tabBarPage.pagePath === pagePath);
|
||||
const isTabBar = tabBarIndex !== -1 ? true : undefined;
|
||||
let windowTop = 0;
|
||||
const meta = (0, shared_1.extend)({
|
||||
isQuit: isEntry || isTabBar ? true : undefined,
|
||||
isEntry: isEntry || undefined,
|
||||
isTabBar: isTabBar || undefined,
|
||||
tabBarIndex: isTabBar ? tabBarIndex : undefined,
|
||||
windowTop: windowTop || undefined,
|
||||
}, pageOptions.style);
|
||||
return {
|
||||
path: pageOptions.path,
|
||||
meta,
|
||||
};
|
||||
});
|
||||
}
|
||||
exports.normalizePagesRoute = normalizePagesRoute;
|
||||
function isEnablePullDownRefresh(pageStyle) {
|
||||
return pageStyle.enablePullDownRefresh || pageStyle.pullToRefresh?.support;
|
||||
}
|
||||
function normalizePullToRefresh(pageStyle) {
|
||||
return pageStyle.pullToRefresh;
|
||||
}
|
||||
function parseSubpackagesRoot(inputDir, platform) {
|
||||
const pagesJson = (0, exports.parsePagesJson)(inputDir, platform, false);
|
||||
const subpackages = pagesJson.subPackages || pagesJson.subpackages;
|
||||
const roots = [];
|
||||
if ((0, shared_1.isArray)(subpackages)) {
|
||||
subpackages.forEach(({ root }) => {
|
||||
if (root) {
|
||||
roots.push(root);
|
||||
}
|
||||
});
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
exports.parseSubpackagesRootOnce = (0, uni_shared_1.once)(parseSubpackagesRoot);
|
||||
let isInvalidPagesWarned = false;
|
||||
function filterPlatformPages(platform, pagesJson) {
|
||||
const invalidPages = [];
|
||||
pagesJson.pages = pagesJson.pages.filter(({ path }) => {
|
||||
if (isPlatformPage(platform, path)) {
|
||||
return true;
|
||||
}
|
||||
invalidPages.push(path);
|
||||
return false;
|
||||
});
|
||||
if (pagesJson.subPackages) {
|
||||
pagesJson.subPackages.forEach((subPackage) => {
|
||||
if (subPackage.pages) {
|
||||
subPackage.pages = subPackage.pages.filter(({ path }) => {
|
||||
const pagePath = subPackage.root + '/' + path;
|
||||
if (isPlatformPage(platform, pagePath)) {
|
||||
return true;
|
||||
}
|
||||
invalidPages.push(pagePath);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (pagesJson.subpackages) {
|
||||
pagesJson.subpackages.forEach((subPackage) => {
|
||||
if (subPackage.pages) {
|
||||
subPackage.pages = subPackage.pages.filter(({ path }) => {
|
||||
const pagePath = subPackage.root + '/' + path;
|
||||
if (isPlatformPage(platform, pagePath)) {
|
||||
return true;
|
||||
}
|
||||
invalidPages.push(pagePath);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
// 目前仅启动的时候警告一次,该方法可能会被调用很多次
|
||||
if (invalidPages.length) {
|
||||
if (!isInvalidPagesWarned) {
|
||||
isInvalidPagesWarned = true;
|
||||
console.log(`已忽略页面:${invalidPages.join('、')}。详见:https://uniapp.dcloud.net.cn/tutorial/platform.html#platforms`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.filterPlatformPages = filterPlatformPages;
|
||||
function isPlatformPage(platform, pagePath) {
|
||||
if (pagePath.startsWith('platforms/')) {
|
||||
if (platform === 'app' || platform === 'app-plus') {
|
||||
return (pagePath.startsWith('platforms/app/') ||
|
||||
pagePath.startsWith('platforms/app-plus/'));
|
||||
}
|
||||
else if (platform === 'h5' || platform === 'web') {
|
||||
return (pagePath.startsWith('platforms/h5/') ||
|
||||
pagePath.startsWith('platforms/web/'));
|
||||
}
|
||||
return pagePath.startsWith('platforms/' + platform + '/');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
export declare function hasThemeJson(themeLocation: string): boolean;
|
||||
export declare const parseThemeJson: (themeLocation?: string) => UniApp.ThemeJson;
|
||||
export declare const normalizeThemeConfigOnce: (manifestJsonPlatform?: Record<string, any>) => UniApp.ThemeJson;
|
||||
export declare function initTheme<T extends object>(manifestJson: Record<string, any>, pagesJson: T): T;
|
||||
export declare class ThemeSassParser {
|
||||
_index: number;
|
||||
_input: string;
|
||||
_theme: Record<string, Record<string, any>>;
|
||||
constructor();
|
||||
parse(input: string): Record<string, Record<string, any>>;
|
||||
parseVariable(): void;
|
||||
parseVariableValue(): any;
|
||||
parseFunction(): void | string[];
|
||||
skipOtherValue(): void;
|
||||
parseString(): string;
|
||||
pushThemeValue(key: string, valuePair: string[]): void;
|
||||
consume(expected: string): void;
|
||||
get currentChar(): string;
|
||||
skipWhiteSpaceAndComments(): void;
|
||||
skipComment(): void;
|
||||
skipWhiteSpace(): void;
|
||||
isspace(str: string): boolean;
|
||||
}
|
||||
+276
@@ -0,0 +1,276 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.ThemeSassParser = exports.initTheme = exports.normalizeThemeConfigOnce = exports.parseThemeJson = exports.hasThemeJson = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const json_1 = require("./json");
|
||||
const uni_shared_1 = require("@dcloudio/uni-shared");
|
||||
const manifest_1 = require("./manifest");
|
||||
function hasThemeJson(themeLocation) {
|
||||
if (!fs_1.default.existsSync(themeLocation)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.hasThemeJson = hasThemeJson;
|
||||
const parseThemeJson = (themeLocation = 'theme.json') => {
|
||||
if (!themeLocation || !process.env.UNI_INPUT_DIR) {
|
||||
return {};
|
||||
}
|
||||
themeLocation = path_1.default.join(process.env.UNI_INPUT_DIR, themeLocation);
|
||||
if (!hasThemeJson(themeLocation)) {
|
||||
return {};
|
||||
}
|
||||
const jsonStr = fs_1.default.readFileSync(themeLocation, 'utf8');
|
||||
return (0, json_1.parseJson)(jsonStr, true, themeLocation);
|
||||
};
|
||||
exports.parseThemeJson = parseThemeJson;
|
||||
const SCHEME_RE = /^([a-z-]+:)?\/\//i;
|
||||
const DATA_RE = /^data:.*,.*/;
|
||||
function normalizeFilepath(filepath) {
|
||||
if (!(SCHEME_RE.test(filepath) || DATA_RE.test(filepath)) &&
|
||||
filepath.indexOf('/') !== 0) {
|
||||
return (0, uni_shared_1.addLeadingSlash)(filepath);
|
||||
}
|
||||
return filepath;
|
||||
}
|
||||
const parseThemeJsonIconPath = (themeConfig, curPathThemeJsonKey) => {
|
||||
if (themeConfig.light?.[curPathThemeJsonKey]) {
|
||||
themeConfig.light[curPathThemeJsonKey] = normalizeFilepath(themeConfig.light[curPathThemeJsonKey]);
|
||||
}
|
||||
if (themeConfig.dark?.[curPathThemeJsonKey]) {
|
||||
themeConfig.dark[curPathThemeJsonKey] = normalizeFilepath(themeConfig.dark[curPathThemeJsonKey]);
|
||||
}
|
||||
};
|
||||
function normalizeUniConfigThemeJsonIconPath(themeConfig, pagesJson) {
|
||||
// 处理 tabbar 下 list -> item -> iconPath、selectedIconPath; midButton -> backgroundImage 路径 / 不开头的情况
|
||||
const tabBar = pagesJson.tabBar;
|
||||
if (tabBar && tabBar.list && tabBar.list.length) {
|
||||
tabBar.list.forEach((item) => {
|
||||
if (item.iconPath && item.iconPath.indexOf('@') === 0) {
|
||||
parseThemeJsonIconPath(themeConfig, item.iconPath.replace(/^@/, ''));
|
||||
}
|
||||
if (item.selectedIconPath && item.selectedIconPath.indexOf('@') === 0) {
|
||||
parseThemeJsonIconPath(themeConfig, item.selectedIconPath.replace(/^@/, ''));
|
||||
}
|
||||
});
|
||||
const midButtonBackgroundImage = tabBar.midButton?.backgroundImage;
|
||||
if (midButtonBackgroundImage &&
|
||||
midButtonBackgroundImage.indexOf('@') === 0) {
|
||||
parseThemeJsonIconPath(themeConfig, midButtonBackgroundImage.replace(/^@/, ''));
|
||||
}
|
||||
}
|
||||
return themeConfig;
|
||||
}
|
||||
const getPagesJson = (inputDir) => {
|
||||
const pagesFilename = path_1.default.join(inputDir, 'pages.json');
|
||||
if (!fs_1.default.existsSync(pagesFilename)) {
|
||||
return {
|
||||
pages: [],
|
||||
globalStyle: { navigationBar: {} },
|
||||
};
|
||||
}
|
||||
const jsonStr = fs_1.default.readFileSync(pagesFilename, 'utf8');
|
||||
return (0, json_1.parseJson)(jsonStr, true, pagesFilename);
|
||||
};
|
||||
exports.normalizeThemeConfigOnce = (0, uni_shared_1.once)((manifestJsonPlatform = {}) => {
|
||||
const themeConfig = (0, exports.parseThemeJson)(manifestJsonPlatform.themeLocation);
|
||||
if (process.env.UNI_INPUT_DIR) {
|
||||
normalizeUniConfigThemeJsonIconPath(themeConfig, getPagesJson(process.env.UNI_INPUT_DIR));
|
||||
}
|
||||
return themeConfig;
|
||||
});
|
||||
function initTheme(manifestJson, pagesJson) {
|
||||
const platform = process.env.UNI_PLATFORM === 'app' ? 'app-plus' : process.env.UNI_PLATFORM;
|
||||
const manifestPlatform = (0, manifest_1.getPlatformManifestJson)(manifestJson, platform) || {};
|
||||
const themeConfig = (0, exports.normalizeThemeConfigOnce)(manifestPlatform);
|
||||
return (0, uni_shared_1.normalizeStyles)(pagesJson, themeConfig);
|
||||
}
|
||||
exports.initTheme = initTheme;
|
||||
// TODO
|
||||
class ThemeSassParser {
|
||||
constructor() {
|
||||
this._index = 0;
|
||||
this._input = '';
|
||||
this._theme = {};
|
||||
}
|
||||
parse(input) {
|
||||
this._index = 0;
|
||||
this._input = input;
|
||||
this._theme = {};
|
||||
this._theme['light'] = {};
|
||||
this._theme['dark'] = {};
|
||||
this.parseVariable();
|
||||
return this._theme;
|
||||
}
|
||||
parseVariable() {
|
||||
this.skipWhiteSpaceAndComments();
|
||||
this.consume('$');
|
||||
this.skipWhiteSpaceAndComments();
|
||||
let key = this.parseString();
|
||||
this.skipWhiteSpaceAndComments();
|
||||
this.consume(':');
|
||||
this.skipWhiteSpace();
|
||||
const value = this.parseVariableValue();
|
||||
if (Array.isArray(value)) {
|
||||
this.pushThemeValue(key, value);
|
||||
}
|
||||
this.consume(';');
|
||||
this.skipWhiteSpaceAndComments();
|
||||
if (this._index < this._input.length) {
|
||||
this.parseVariable();
|
||||
}
|
||||
}
|
||||
parseVariableValue() {
|
||||
switch (this.currentChar) {
|
||||
case 'l':
|
||||
return this.parseFunction();
|
||||
default:
|
||||
return this.skipOtherValue();
|
||||
}
|
||||
}
|
||||
parseFunction() {
|
||||
let functionName = '';
|
||||
while (this.currentChar != '(') {
|
||||
functionName += this.currentChar;
|
||||
if (this._index + 1 < this._input.length) {
|
||||
++this._index;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (functionName != 'light-dark') {
|
||||
return this.skipOtherValue();
|
||||
}
|
||||
let valuePair = new Array(2);
|
||||
valuePair[0] = '';
|
||||
valuePair[1] = '';
|
||||
this.consume('(');
|
||||
let index = 0;
|
||||
// TODO rgb?
|
||||
while (this.currentChar != ')') {
|
||||
valuePair[index] += this.currentChar;
|
||||
if (this.currentChar === ',') {
|
||||
index++;
|
||||
}
|
||||
++this._index;
|
||||
}
|
||||
this.consume(')');
|
||||
valuePair[0] = valuePair[0].trim();
|
||||
valuePair[1] = valuePair[1].trim();
|
||||
return valuePair;
|
||||
}
|
||||
skipOtherValue() {
|
||||
while (this.currentChar != ';') {
|
||||
if (this._index + 1 < this._input.length) {
|
||||
++this._index;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
parseString() {
|
||||
let str = '';
|
||||
while (this.currentChar != ':') {
|
||||
if (this.currentChar == '\\') {
|
||||
str += this.currentChar;
|
||||
if (this._index + 1 < this._input.length) {
|
||||
str += this._input[++this._index];
|
||||
}
|
||||
}
|
||||
str += this.currentChar;
|
||||
if (this._index + 1 < this._input.length) {
|
||||
++this._index;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
pushThemeValue(key, valuePair) {
|
||||
this._theme['light'][key] = valuePair[0];
|
||||
this._theme['dark'][key] = valuePair[1];
|
||||
}
|
||||
consume(expected) {
|
||||
if (this.currentChar != expected) {
|
||||
throw new Error('Unexpected character ' +
|
||||
expected +
|
||||
' index=' +
|
||||
this._index +
|
||||
' ' +
|
||||
this.currentChar);
|
||||
}
|
||||
++this._index;
|
||||
}
|
||||
get currentChar() {
|
||||
if (this._index >= this._input.length) {
|
||||
throw new Error('Unexpected end of input');
|
||||
}
|
||||
return this._input[this._index];
|
||||
}
|
||||
skipWhiteSpaceAndComments() {
|
||||
while (this._index < this._input.length) {
|
||||
const c = this._input[this._index];
|
||||
if (this.isspace(c)) {
|
||||
++this._index;
|
||||
}
|
||||
else if (c == '/') {
|
||||
this.skipComment();
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
skipComment() {
|
||||
if (this.currentChar != '/') {
|
||||
return;
|
||||
}
|
||||
this.consume('/');
|
||||
let nextChar = this.currentChar;
|
||||
if (nextChar == '/') {
|
||||
// Single line comment
|
||||
while (
|
||||
// @ts-expect-error
|
||||
this.currentChar !== '\n' &&
|
||||
this._index < this._input.length - 1) {
|
||||
++this._index;
|
||||
}
|
||||
this.skipWhiteSpace();
|
||||
}
|
||||
else if (nextChar === '*') {
|
||||
// Multi-line comment
|
||||
while (true) {
|
||||
if (this._index + 1 >= this._input.length) {
|
||||
throw new Error('Unterminated multi-line comment');
|
||||
}
|
||||
++this._index;
|
||||
// @ts-expect-error
|
||||
if (this.currentChar === '*' && this._input[this._index + 1] === '/') {
|
||||
this._index += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.skipWhiteSpace();
|
||||
}
|
||||
else {
|
||||
throw new Error('Invalid comment');
|
||||
}
|
||||
}
|
||||
skipWhiteSpace() {
|
||||
while (this._index < this._input.length &&
|
||||
this.isspace(this._input[this._index])) {
|
||||
++this._index;
|
||||
}
|
||||
}
|
||||
isspace(str) {
|
||||
return str == ' ' || str == '\n' || str == '\r' || str == "'";
|
||||
}
|
||||
}
|
||||
exports.ThemeSassParser = ThemeSassParser;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
export * from './manifest';
|
||||
export declare function checkPagesJson(jsonStr: string, inputDir: string): boolean;
|
||||
export declare function normalizeUniAppXAppPagesJson(jsonStr: string): UniApp.PagesJson;
|
||||
/**
|
||||
* TODO 应该闭包,通过globalThis赋值?
|
||||
* @param pagesJson
|
||||
* @param manifestJson
|
||||
* @returns
|
||||
*/
|
||||
export declare function normalizeUniAppXAppConfig(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): string;
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizeUniAppXAppConfig = exports.normalizeUniAppXAppPagesJson = exports.checkPagesJson = void 0;
|
||||
const fs_1 = __importDefault(require("fs"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const shared_1 = require("@vue/shared");
|
||||
const jsonc_parser_1 = require("jsonc-parser");
|
||||
const json_1 = require("../json");
|
||||
const pages_1 = require("../pages");
|
||||
const utils_1 = require("../../utils");
|
||||
const uniRoutes_1 = require("../app/pages/uniRoutes");
|
||||
const uniConfig_1 = require("./uniConfig");
|
||||
const utils_2 = require("../../vite/plugins/vitejs/utils");
|
||||
const preprocess_1 = require("../../preprocess");
|
||||
__exportStar(require("./manifest"), exports);
|
||||
function checkPagesJson(jsonStr, inputDir) {
|
||||
if (!inputDir) {
|
||||
return false;
|
||||
}
|
||||
const errors = [];
|
||||
const root = (0, jsonc_parser_1.parseTree)(jsonStr, errors);
|
||||
if (!root) {
|
||||
if (errors.length) {
|
||||
for (const error of errors) {
|
||||
const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, error.offset);
|
||||
throw {
|
||||
name: 'SyntaxError',
|
||||
code: error.error,
|
||||
message: (0, jsonc_parser_1.printParseErrorCode)(error.error),
|
||||
loc: {
|
||||
start: { line, column },
|
||||
},
|
||||
offsetStart: error.offset,
|
||||
offsetEnd: error.offset + error.length,
|
||||
};
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
const pagePathNodes = walkNodes(findRootNode(root, ['pages']));
|
||||
findRootNode(root, ['subPackages', 'subpackages']).forEach((node) => {
|
||||
const subPackageRoot = findSubPackageRoot(node);
|
||||
if (subPackageRoot) {
|
||||
findRootNode(node, ['pages']).forEach((subNode) => {
|
||||
walkNodes(subNode.children ?? []).forEach((node) => {
|
||||
pagePathNodes.push({
|
||||
...node,
|
||||
value: (0, utils_1.normalizePath)(path_1.default.join(subPackageRoot, node.value)),
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
if (pagePathNodes.length) {
|
||||
for (const node of pagePathNodes) {
|
||||
const pagePath = node.value ?? '';
|
||||
if (pageExistsWithCaseSync(path_1.default.join(inputDir, pagePath))) {
|
||||
continue;
|
||||
}
|
||||
const { line, column } = (0, utils_2.offsetToLineColumn)(jsonStr, node.offset);
|
||||
throw {
|
||||
name: 'CompilerError',
|
||||
code: 'CompilerError',
|
||||
message: `The page path "${pagePath}" does not exist`,
|
||||
loc: {
|
||||
start: { line, column },
|
||||
},
|
||||
offsetStart: node.offset,
|
||||
offsetEnd: node.offset + node.length,
|
||||
};
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
exports.checkPagesJson = checkPagesJson;
|
||||
function pageExistsWithCaseSync(pagePath) {
|
||||
try {
|
||||
const files = fs_1.default.readdirSync(path_1.default.dirname(pagePath));
|
||||
const basename = path_1.default.basename(pagePath);
|
||||
const uvuePage = basename + '.uvue';
|
||||
const vuePage = basename + '.vue';
|
||||
return files.some((file) => file === uvuePage || file === vuePage);
|
||||
}
|
||||
catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function findSubPackageRoot(node) {
|
||||
const child = node.children?.find((child) => child.type === 'property' &&
|
||||
child.children &&
|
||||
child.children.find((child) => child.type === 'string' && child.value === 'root'));
|
||||
if (child && child.children?.length === 2) {
|
||||
return child.children[1].value;
|
||||
}
|
||||
return '';
|
||||
}
|
||||
function findRootNode(node, property) {
|
||||
const { type, children } = node;
|
||||
if (type === 'object' && children) {
|
||||
const child = children.find((child) => child.type === 'property' &&
|
||||
child.children &&
|
||||
child.children.find((child) => child.type === 'string' && property.includes(child.value)));
|
||||
if (child) {
|
||||
const node = child.children.find((child) => child.type === 'array');
|
||||
return node?.children ?? [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
function walkNodes(node) {
|
||||
const pagePathNodes = [];
|
||||
node.forEach((node) => walkNode(node, pagePathNodes));
|
||||
return pagePathNodes;
|
||||
}
|
||||
function walkNode(node, pagePathNodes) {
|
||||
const { type, children } = node;
|
||||
if (type === 'property' && children && children.length === 2) {
|
||||
const maybePagePathNode = children[0];
|
||||
const maybePagePathValueNode = children[1];
|
||||
if (maybePagePathNode.type === 'string' &&
|
||||
maybePagePathNode.value === 'path' &&
|
||||
maybePagePathValueNode.type === 'string' &&
|
||||
(0, shared_1.isString)(maybePagePathValueNode.value)) {
|
||||
pagePathNodes.push(maybePagePathValueNode);
|
||||
}
|
||||
}
|
||||
if (children) {
|
||||
children.forEach((node) => walkNode(node, pagePathNodes));
|
||||
}
|
||||
}
|
||||
function normalizeUniAppXAppPagesJson(jsonStr) {
|
||||
// 先条件编译
|
||||
jsonStr = (0, preprocess_1.preUVueJson)(jsonStr, 'pages.json');
|
||||
checkPagesJson(jsonStr, process.env.UNI_INPUT_DIR);
|
||||
const pagesJson = {
|
||||
pages: [],
|
||||
globalStyle: {},
|
||||
};
|
||||
let userPagesJson = {
|
||||
pages: [],
|
||||
globalStyle: {},
|
||||
};
|
||||
try {
|
||||
// 此处不需要条件编译了
|
||||
userPagesJson = (0, json_1.parseJson)(jsonStr, false, 'pages.json');
|
||||
}
|
||||
catch (e) {
|
||||
console.error(`[vite] Error: pages.json parse failed.\n`, jsonStr, e);
|
||||
}
|
||||
// pages
|
||||
(0, pages_1.validatePages)(userPagesJson, jsonStr);
|
||||
userPagesJson.subPackages =
|
||||
userPagesJson.subPackages || userPagesJson.subpackages;
|
||||
// subPackages
|
||||
if (userPagesJson.subPackages) {
|
||||
userPagesJson.pages.push(...normalizeSubPackages(userPagesJson.subPackages));
|
||||
}
|
||||
pagesJson.pages = userPagesJson.pages;
|
||||
// pageStyle
|
||||
normalizePages(pagesJson.pages);
|
||||
// globalStyle
|
||||
pagesJson.globalStyle = normalizePageStyle(userPagesJson.globalStyle);
|
||||
// tabBar
|
||||
if (userPagesJson.tabBar) {
|
||||
pagesJson.tabBar = userPagesJson.tabBar;
|
||||
}
|
||||
// condition
|
||||
if (userPagesJson.condition) {
|
||||
pagesJson.condition = userPagesJson.condition;
|
||||
}
|
||||
// uniIdRouter
|
||||
if (userPagesJson.uniIdRouter) {
|
||||
pagesJson.uniIdRouter = userPagesJson.uniIdRouter;
|
||||
}
|
||||
// 是否应该用 process.env.UNI_UTS_PLATFORM
|
||||
(0, pages_1.filterPlatformPages)(process.env.UNI_PLATFORM, pagesJson);
|
||||
return pagesJson;
|
||||
}
|
||||
exports.normalizeUniAppXAppPagesJson = normalizeUniAppXAppPagesJson;
|
||||
function normalizeSubPackages(subPackages) {
|
||||
const pages = [];
|
||||
if ((0, shared_1.isArray)(subPackages)) {
|
||||
subPackages.forEach(({ root, pages: subPages }) => {
|
||||
if (root && subPages.length) {
|
||||
subPages.forEach((subPage) => {
|
||||
subPage.path = (0, utils_1.normalizePath)(path_1.default.join(root, subPage.path));
|
||||
subPage.style = subPage.style;
|
||||
pages.push(subPage);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return pages;
|
||||
}
|
||||
function normalizePages(pages) {
|
||||
pages.forEach((page) => {
|
||||
page.style = normalizePageStyle(page.style);
|
||||
});
|
||||
}
|
||||
function normalizePageStyle(pageStyle) {
|
||||
if (pageStyle) {
|
||||
(0, shared_1.extend)(pageStyle, pageStyle['app']);
|
||||
(0, pages_1.removePlatformStyle)(pageStyle);
|
||||
return pageStyle;
|
||||
}
|
||||
return {};
|
||||
}
|
||||
/**
|
||||
* TODO 应该闭包,通过globalThis赋值?
|
||||
* @param pagesJson
|
||||
* @param manifestJson
|
||||
* @returns
|
||||
*/
|
||||
function normalizeUniAppXAppConfig(pagesJson, manifestJson) {
|
||||
const uniConfig = (0, uniConfig_1.normalizeAppXUniConfig)(pagesJson, manifestJson);
|
||||
const tabBar = uniConfig.tabBar;
|
||||
delete uniConfig.tabBar;
|
||||
let appConfigJs = `const __uniConfig = ${JSON.stringify(uniConfig)};
|
||||
__uniConfig.getTabBarConfig = () => {return ${tabBar ? JSON.stringify(tabBar) : 'undefined'}};
|
||||
__uniConfig.tabBar = __uniConfig.getTabBarConfig();
|
||||
const __uniRoutes = ${(0, uniRoutes_1.normalizeAppUniRoutes)(pagesJson)}.map(uniRoute=>(uniRoute.meta.route=uniRoute.path,__uniConfig.pages.push(uniRoute.path),uniRoute.path='/'+uniRoute.path,uniRoute)).concat(typeof __uniSystemRoutes !== 'undefined' ? __uniSystemRoutes : []);
|
||||
|
||||
`;
|
||||
if (process.env.UNI_UTS_PLATFORM === 'app-harmony') {
|
||||
appConfigJs += `globalThis.__uniConfig = __uniConfig;
|
||||
globalThis.__uniRoutes = __uniRoutes;`;
|
||||
}
|
||||
return appConfigJs;
|
||||
}
|
||||
exports.normalizeUniAppXAppConfig = normalizeUniAppXAppConfig;
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
export declare function parseUniXFlexDirection(manifestJson: Record<string, any>): any;
|
||||
export declare function parseUniXSplashScreen(manifestJson: Record<string, any>): false | object;
|
||||
export declare function parseUniXUniStatistics(manifestJson: Record<string, any>): false | object;
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.parseUniXUniStatistics = exports.parseUniXSplashScreen = exports.parseUniXFlexDirection = void 0;
|
||||
const shared_1 = require("@vue/shared");
|
||||
const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse'];
|
||||
function parseUniXFlexDirection(manifestJson) {
|
||||
const flexDir = manifestJson?.['uni-app-x']?.['flex-direction'];
|
||||
if (flexDir && flexDirs.includes(flexDir)) {
|
||||
return flexDir;
|
||||
}
|
||||
return 'column';
|
||||
}
|
||||
exports.parseUniXFlexDirection = parseUniXFlexDirection;
|
||||
function parseUniXSplashScreen(manifestJson) {
|
||||
const splashScreen = manifestJson?.['app']?.['splashScreen'];
|
||||
if ((0, shared_1.isPlainObject)(splashScreen)) {
|
||||
return splashScreen;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.parseUniXSplashScreen = parseUniXSplashScreen;
|
||||
function parseUniXUniStatistics(manifestJson) {
|
||||
const uniStatistics = manifestJson?.['app']?.['uniStatistics'];
|
||||
if ((0, shared_1.isPlainObject)(uniStatistics)) {
|
||||
return uniStatistics;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
exports.parseUniXUniStatistics = parseUniXUniStatistics;
|
||||
Generated
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
interface AppXUniConfig {
|
||||
pages: unknown[];
|
||||
globalStyle: unknown;
|
||||
appname: string;
|
||||
compilerVersion: string;
|
||||
fallbackLocale: unknown;
|
||||
tabBar: unknown;
|
||||
entryPagePath: string;
|
||||
entryPageQuery?: string;
|
||||
conditionUrl?: string;
|
||||
realEntryPagePath?: string;
|
||||
themeConfig?: unknown;
|
||||
}
|
||||
export declare function normalizeAppXUniConfig(pagesJson: UniApp.PagesJson, manifestJson: Record<string, any>): AppXUniConfig;
|
||||
export {};
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.normalizeAppXUniConfig = void 0;
|
||||
const uniConfig_1 = require("../app/pages/uniConfig");
|
||||
// app-config.js 内容
|
||||
function normalizeAppXUniConfig(pagesJson, manifestJson) {
|
||||
const config = {
|
||||
pages: [],
|
||||
globalStyle: pagesJson.globalStyle,
|
||||
appname: manifestJson.name || '',
|
||||
compilerVersion: process.env.UNI_COMPILER_VERSION,
|
||||
...(0, uniConfig_1.parseEntryPagePath)(pagesJson),
|
||||
tabBar: pagesJson.tabBar,
|
||||
fallbackLocale: manifestJson.fallbackLocale,
|
||||
};
|
||||
if (config.realEntryPagePath) {
|
||||
config.conditionUrl = config.entryPagePath;
|
||||
config.entryPagePath = config.realEntryPagePath;
|
||||
}
|
||||
// darkmode
|
||||
if (pagesJson.themeConfig) {
|
||||
config.themeConfig = pagesJson.themeConfig;
|
||||
}
|
||||
// TODO 待支持分包
|
||||
return config;
|
||||
}
|
||||
exports.normalizeAppXUniConfig = normalizeAppXUniConfig;
|
||||
Reference in New Issue
Block a user