2025/2/8第一次更新

This commit is contained in:
爱吃咸鱼小猫咪
2025-02-08 18:50:38 +08:00
commit d7af560866
26519 changed files with 5046029 additions and 0 deletions
+4
View File
@@ -0,0 +1,4 @@
export * from './jsonFile';
export { AppJson, ComponentJson, MiniProgramComponentsType } from './types';
export { mergeMiniProgramAppJson, parseMiniProgramPagesJson } from './pages';
export { parseMiniProgramProjectJson } from './project';
+23
View File
@@ -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; } });
+28
View File
@@ -0,0 +1,28 @@
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;
export declare function findUsingComponentsJson(pathInpages: string, componentsDir: string): Record<any, any>;
export {};
+191
View File
@@ -0,0 +1,191 @@
"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';
}
return res;
}, {});
}
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 filename = path_1.default.parse(pathInpages).name + '.json';
let jsonPath = path_1.default.resolve(fulldir, filename);
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
View File
@@ -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 {};
+157
View File
@@ -0,0 +1,157 @@
"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',
];
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);
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
View File
@@ -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
View File
@@ -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);
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
View File
@@ -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';
export {};
+2
View File
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+3
View File
@@ -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
View File
@@ -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;