@plugin-light/shared 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +19 -0
  2. package/lib/bundle-analyze.d.ts +2 -0
  3. package/lib/config-project.d.ts +10 -0
  4. package/lib/config.d.ts +25 -0
  5. package/lib/context.d.ts +1 -0
  6. package/lib/core/cross-game-style/config.d.ts +1 -0
  7. package/lib/core/cross-game-style/cross-game-style.d.ts +7 -0
  8. package/lib/core/cross-game-style/index.d.ts +2 -0
  9. package/lib/core/cross-game-style/style-name.d.ts +1 -0
  10. package/lib/core/cross-game-style/types.d.ts +4 -0
  11. package/lib/core/gen-version/gen-version.d.ts +11 -0
  12. package/lib/core/gen-version/index.d.ts +2 -0
  13. package/lib/core/gen-version/types.d.ts +5 -0
  14. package/lib/core/ifdef/index.d.ts +1 -0
  15. package/lib/core/ifdef/types.d.ts +5 -0
  16. package/lib/core/index.d.ts +6 -0
  17. package/lib/core/inject-dynamic-style/helper.d.ts +9 -0
  18. package/lib/core/inject-dynamic-style/index.d.ts +2 -0
  19. package/lib/core/inject-dynamic-style/types.d.ts +4 -0
  20. package/lib/core/replace-vue-directive/index.d.ts +1 -0
  21. package/lib/core/replace-vue-directive/replace-vue-directive.d.ts +1 -0
  22. package/lib/core/v-lazy/index.d.ts +2 -0
  23. package/lib/core/v-lazy/types.d.ts +3 -0
  24. package/lib/core/v-lazy/v-lazy.d.ts +2 -0
  25. package/lib/deps.d.ts +1 -0
  26. package/lib/find-dependencies.d.ts +1 -0
  27. package/lib/h5.d.ts +1 -0
  28. package/lib/helper.d.ts +9 -0
  29. package/lib/index.d.ts +15 -0
  30. package/lib/index.js +766 -0
  31. package/lib/loader-file.d.ts +2 -0
  32. package/lib/loader-log.d.ts +2 -0
  33. package/lib/project-name.d.ts +2 -0
  34. package/lib/replace-manifest.d.ts +2 -0
  35. package/lib/root.d.ts +1 -0
  36. package/lib/sub-project.d.ts +5 -0
  37. package/package.json +26 -0
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ ## 公共包
2
+
3
+ 除 `t-comm` 外,`plugin-light` 中最底层的依赖,业务无需使用。
4
+
5
+ ### 如何使用
6
+
7
+ 安装
8
+
9
+ ```bash
10
+ pnpm add plugin-light-shared -D
11
+ ```
12
+
13
+ 使用
14
+
15
+ ```js
16
+ import { getDeps } from 'plugin-light-shared';
17
+
18
+ getDeps(__dirname);
19
+ ```
@@ -0,0 +1,2 @@
1
+ export declare function checkBundleAnalyze(): boolean;
2
+ export declare function checkDebugMode(): boolean;
@@ -0,0 +1,10 @@
1
+ export declare const DEFAULT_TRANSPILE_DEPENDENCIES: string[];
2
+ export declare const DEFAULT_ADAPTER_DIRS: string[];
3
+ export declare const AEGIS_EXTERNAL_SCRIPT_LINK = "https://image-1251917893.file.myqcloud.com/igame/npm/aegis-web/aegis.min.js";
4
+ export declare const UNI_SIMPLE_ROUTER_SCRIPT_LINK = "https://image-1251917893.file.myqcloud.com/igame/npm/uni-simple-router/uni-simple-router-2.0.8-beta-4.js";
5
+ export declare const EXTERNAL_LINK_MAP: {
6
+ AXIOS: string;
7
+ VUE_LAZY_LOAD: string;
8
+ AEGIS_WEB: string;
9
+ UNI_SIMPLE_ROUTER: string;
10
+ };
@@ -0,0 +1,25 @@
1
+ export declare const PLATFORM_MAP: {
2
+ readonly MP_WX: "mp-weixin";
3
+ readonly MP_QQ: "mp-qq";
4
+ readonly MP_ALIPAY: "mp-alipay";
5
+ readonly H5: "h5";
6
+ };
7
+ export declare const ALL_PLATFORM = "ALL";
8
+ export declare const PLATFORMS_MP: ("mp-weixin" | "mp-qq")[];
9
+ export declare const PLATFORMS_ALL: ("mp-weixin" | "mp-qq" | "h5")[];
10
+ export declare const HTML_MAP: {
11
+ readonly MP_WX: ".wxml";
12
+ readonly MP_QQ: ".qml";
13
+ readonly MP_ALIPAY: ".axml";
14
+ readonly MP_JD: ".jxml";
15
+ };
16
+ export declare const CSS_MAP: {
17
+ readonly MP_WX: ".wxss";
18
+ readonly MP_QQ: ".qss";
19
+ readonly MP_ALIPAY: ".acss";
20
+ readonly MP_JD: ".jxss";
21
+ };
22
+ export declare const CSS_POSTFIX_MAP: any;
23
+ export declare const CDN_MAP: {
24
+ UNI_SIMPLE_ROUTER: string;
25
+ };
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_CONTEXT_OBJECT: {};
@@ -0,0 +1 @@
1
+ export declare const TIP_STYLE_NAME = "@TIP_STYLE_NAME";
@@ -0,0 +1,7 @@
1
+ import type { ICrossGameStyleOptions } from './types';
2
+ export declare function crossGameStyle({ source, options, dir, removeImport, }: {
3
+ source: string;
4
+ options?: ICrossGameStyleOptions;
5
+ dir: string;
6
+ removeImport?: boolean;
7
+ }): string;
@@ -0,0 +1,2 @@
1
+ export { crossGameStyle } from './cross-game-style';
2
+ export type { ICrossGameStyleOptions } from './types';
@@ -0,0 +1 @@
1
+ export declare function getStyleName(): string;
@@ -0,0 +1,4 @@
1
+ export type ICrossGameStyleOptions = {
2
+ styleName?: string | Array<string>;
3
+ platforms?: Array<string>;
4
+ };
@@ -0,0 +1,11 @@
1
+ import type { IGenVersionOptions } from './types';
2
+ export declare function getVersionCode(versionName?: string): string;
3
+ export declare function getCommitCode(versionName?: string): string;
4
+ export declare function getMpVersionCode(): string;
5
+ export declare function getMpInsertCode(): string;
6
+ export declare function getGenVersionPluginOptions(options: IGenVersionOptions): {
7
+ buildName: string;
8
+ commitName: string;
9
+ delay: number;
10
+ };
11
+ export declare function getWebInsertCode(options: IGenVersionOptions): string;
@@ -0,0 +1,2 @@
1
+ export { getVersionCode, getCommitCode, getMpVersionCode, getMpInsertCode, getGenVersionPluginOptions, getWebInsertCode, } from './gen-version';
2
+ export type { IGenVersionOptions, } from './types';
@@ -0,0 +1,5 @@
1
+ export type IGenVersionOptions = {
2
+ buildName?: string;
3
+ commitName?: string;
4
+ delay?: number;
5
+ };
@@ -0,0 +1 @@
1
+ export type { IIfdefOptions } from './types';
@@ -0,0 +1,5 @@
1
+ export type IIfdefOptions = {
2
+ context?: Record<string, boolean>;
3
+ log?: boolean;
4
+ type: Array<string>;
5
+ };
@@ -0,0 +1,6 @@
1
+ export * from './cross-game-style';
2
+ export * from './gen-version';
3
+ export * from './ifdef';
4
+ export * from './inject-dynamic-style';
5
+ export * from './replace-vue-directive';
6
+ export * from './v-lazy';
@@ -0,0 +1,9 @@
1
+ export declare const BASE_SCSS = "base.scss";
2
+ export declare function getStyleList(dir: string): string[];
3
+ export declare function genInjectContent({ styleList, componentName, topElement, dir, }: {
4
+ styleList: Array<string>;
5
+ componentName: string;
6
+ topElement: string;
7
+ dir?: string;
8
+ }): string;
9
+ export declare function getComponentName(dir: string): string;
@@ -0,0 +1,2 @@
1
+ export { BASE_SCSS, getStyleList, genInjectContent, getComponentName } from './helper';
2
+ export type { IInjectDynamicStyleWebOptions } from './types';
@@ -0,0 +1,4 @@
1
+ export type IInjectDynamicStyleWebOptions = {
2
+ topElement?: string;
3
+ platforms?: Array<string>;
4
+ };
@@ -0,0 +1 @@
1
+ export { replaceDirective } from './replace-vue-directive';
@@ -0,0 +1 @@
1
+ export declare function replaceDirective(source: string, list: Array<string>): string;
@@ -0,0 +1,2 @@
1
+ export { vLazyCore } from './v-lazy';
2
+ export type { IVLazyOptions } from './types';
@@ -0,0 +1,3 @@
1
+ export type IVLazyOptions = {
2
+ urlHandler?: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ import type { IVLazyOptions } from './types';
2
+ export declare function vLazyCore(source: string, options?: IVLazyOptions): string;
package/lib/deps.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function getDeps(dir: string): string[];
@@ -0,0 +1 @@
1
+ export declare function findDependencies(content: string): string[];
package/lib/h5.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function checkH5(): boolean;
@@ -0,0 +1,9 @@
1
+ export declare const ROOT_NAME = "MAIN";
2
+ export declare function saveJsonToLog(content: any, file: string, needLog?: boolean): void;
3
+ export declare function createLogDir(): void;
4
+ export declare const normalizePath: (path: string) => string;
5
+ export declare function updateAssetSource(assets: Record<string, any>, key: string, source: string): void;
6
+ export declare function removeFirstSlash(key: string): string;
7
+ export declare function parseSetDeps(deps: Record<string, any>): Record<string, any>;
8
+ export declare function getRelativePath(filePath: string): string;
9
+ export declare function getUniCliCache(key?: string): any;
package/lib/index.d.ts ADDED
@@ -0,0 +1,15 @@
1
+ export * from './core';
2
+ export { checkBundleAnalyze, checkDebugMode, } from './bundle-analyze';
3
+ export { PLATFORM_MAP, ALL_PLATFORM, PLATFORMS_ALL, PLATFORMS_MP, HTML_MAP, CSS_MAP, CSS_POSTFIX_MAP, CDN_MAP, } from './config';
4
+ export { DEFAULT_TRANSPILE_DEPENDENCIES, DEFAULT_ADAPTER_DIRS, AEGIS_EXTERNAL_SCRIPT_LINK, UNI_SIMPLE_ROUTER_SCRIPT_LINK, EXTERNAL_LINK_MAP, } from './config-project';
5
+ export { ROOT_NAME, saveJsonToLog, createLogDir, normalizePath, updateAssetSource, removeFirstSlash, parseSetDeps, getRelativePath, getUniCliCache, } from './helper';
6
+ export { DEFAULT_CONTEXT_OBJECT, } from './context';
7
+ export { getDeps, } from './deps';
8
+ export { findDependencies, } from './find-dependencies';
9
+ export { checkH5, } from './h5';
10
+ export { getLoaderFile, getLoaderProdFile, } from './loader-file';
11
+ export { saveLoaderLog, recordLoaderLog, } from './loader-log';
12
+ export { getProjectName, getSubProjectName, } from './project-name';
13
+ export { updateManifest, revertManifest, } from './replace-manifest';
14
+ export { getRootDir, } from './root';
15
+ export { getSubProjectConfig, getSubProjectRoot, } from './sub-project';
package/lib/index.js ADDED
@@ -0,0 +1,766 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var fs = require('fs');
6
+ var path = require('path');
7
+ var tComm = require('t-comm');
8
+
9
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
10
+
11
+ function _interopNamespace(e) {
12
+ if (e && e.__esModule) return e;
13
+ var n = Object.create(null);
14
+ if (e) {
15
+ Object.keys(e).forEach(function (k) {
16
+ if (k !== 'default') {
17
+ var d = Object.getOwnPropertyDescriptor(e, k);
18
+ Object.defineProperty(n, k, d.get ? d : {
19
+ enumerable: true,
20
+ get: function () { return e[k]; }
21
+ });
22
+ }
23
+ });
24
+ }
25
+ n["default"] = e;
26
+ return Object.freeze(n);
27
+ }
28
+
29
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
30
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
31
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
32
+
33
+ function getRootDir() {
34
+ return process.cwd();
35
+ }
36
+
37
+ function getAppDir() {
38
+ if (process.env.VUE_APP_DIR) {
39
+ return process.env.VUE_APP_DIR;
40
+ }
41
+ if (process.env.UNI_INPUT_DIR) {
42
+ return process.env.UNI_INPUT_DIR;
43
+ }
44
+ const dir = tComm.readEnvVariable('VUE_APP_DIR', path__namespace.join(getRootDir(), '.env.local'));
45
+ if (dir) {
46
+ return dir;
47
+ }
48
+ return '';
49
+ }
50
+ function getStyleName() {
51
+ const configPath = path__namespace.resolve(getRootDir(), 'src', getAppDir(), 'config.js');
52
+ let config = { styleName: '' };
53
+ if (fs__namespace.existsSync(configPath)) {
54
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
55
+ config = require(configPath);
56
+ }
57
+ const { styleName } = config;
58
+ return styleName;
59
+ }
60
+
61
+ const TIP_STYLE_NAME = '@TIP_STYLE_NAME';
62
+
63
+ function tryRemoveImport(source, removeImport = false) {
64
+ let res = source;
65
+ if (removeImport) {
66
+ res = res.replace(`src="${TIP_STYLE_NAME}"`, '').replace(`src='${TIP_STYLE_NAME}'`, '');
67
+ }
68
+ else {
69
+ res = res.replace(TIP_STYLE_NAME, '');
70
+ }
71
+ return res;
72
+ }
73
+ function crossGameStyle({ source, options, dir, removeImport = false, }) {
74
+ if (!source.includes(TIP_STYLE_NAME)) {
75
+ return source;
76
+ }
77
+ let styleName = '';
78
+ // 使用 env.local 的样式 VUE_APP_DIR = module/ingame-nba,即为 nba
79
+ if (options?.styleName) {
80
+ styleName = options.styleName;
81
+ }
82
+ else if (getStyleName()) {
83
+ styleName = getStyleName();
84
+ }
85
+ if (Array.isArray(styleName)) {
86
+ if (styleName.length > 1) {
87
+ styleName = styleName.filter((item) => {
88
+ const cssAbsolutePath = `${dir}/css/${item}.scss`;
89
+ return fs__namespace.existsSync(cssAbsolutePath);
90
+ });
91
+ if (styleName.length > 1) {
92
+ const styleTags = styleName
93
+ .filter((item) => {
94
+ const cssAbsolutePath = `${dir}/css/${item}.scss`;
95
+ return removeImport ? fs__namespace.existsSync(cssAbsolutePath) : true;
96
+ })
97
+ .map(item => `.${item} {@import './css/${item}.scss';}`);
98
+ const res = tryRemoveImport(source, removeImport);
99
+ return res.replace(/<\/style>/, `</style>${['<style scoped lang="scss">', ...styleTags, '</style>'].join('')}`);
100
+ }
101
+ }
102
+ styleName = styleName[0] || '';
103
+ }
104
+ const cssPath = `./css/${styleName}.scss`;
105
+ const cssAbsolutePath = `${dir}/css/${styleName}.scss`;
106
+ const exist = fs__namespace.existsSync(cssAbsolutePath);
107
+ if (exist) {
108
+ return source.replace(TIP_STYLE_NAME, cssPath);
109
+ }
110
+ return tryRemoveImport(source, removeImport);
111
+ }
112
+
113
+ function parseQuote(str = '') {
114
+ return str.replace(/'/g, '"');
115
+ }
116
+ function getVersionCode(versionName) {
117
+ let author = '';
118
+ let branch = '';
119
+ try {
120
+ author = tComm.getGitAuthor(false) || '';
121
+ branch = tComm.getGitCurBranch() || '';
122
+ }
123
+ catch (err) { }
124
+ const versionInfo = {
125
+ time: tComm.timeStampFormat(Date.now(), 'yyyy-MM-dd hh:mm:ss'),
126
+ author,
127
+ branch,
128
+ netEnv: process.env.NET_ENV || '',
129
+ };
130
+ let code = '';
131
+ if (versionName) {
132
+ code = `
133
+ window.${versionName} = {
134
+ time: '${versionInfo.time}',
135
+ author: '${versionInfo.author}',
136
+ branch: '${versionInfo.branch}',
137
+ netEnv: '${versionInfo.netEnv}',
138
+ }
139
+ `;
140
+ return code;
141
+ }
142
+ code = `
143
+ console.info('[system]', '');
144
+ console.info('[system]', 'Build Time: ${versionInfo.time || ''}');
145
+ console.info('[system]', 'Build Author: ${versionInfo.author || ''}');
146
+ console.info('[system]', 'Build Branch: ${versionInfo.branch || ''}');
147
+ console.info('[system]', 'Build Net Env: ${versionInfo.netEnv || ''}');
148
+ `;
149
+ return code;
150
+ }
151
+ function getCommitCode(versionName) {
152
+ let commitInfo = {};
153
+ try {
154
+ commitInfo = tComm.getGitCommitInfo();
155
+ }
156
+ catch (err) { }
157
+ if (commitInfo.timeStamp) {
158
+ commitInfo.date = tComm.timeStampFormat(commitInfo.timeStamp, 'yyyy-MM-dd hh:mm:ss');
159
+ }
160
+ let code = '';
161
+ if (versionName) {
162
+ code = `
163
+ window.${versionName} = {
164
+ message: '${commitInfo.message}',
165
+ author: '${commitInfo.author}',
166
+ date: '${commitInfo.date}',
167
+ hash: '${commitInfo.hash}',
168
+ }
169
+ `;
170
+ return code;
171
+ }
172
+ code = `
173
+ console.info('[system]', '');
174
+ console.info('[system]', 'Last Commit Message: ${parseQuote(commitInfo.message) || ''}');
175
+ console.info('[system]', 'Last Commit Author: ${commitInfo.author || ''}');
176
+ console.info('[system]', 'Last Commit Time: ${commitInfo.date || ''}');
177
+ console.info('[system]', 'Last Commit Hash: ${commitInfo.hash || ''}');
178
+ `;
179
+ return code;
180
+ }
181
+ function getMpVersionCode() {
182
+ return `
183
+ var uni = (typeof wx !== 'undefined' && wx)
184
+ || (typeof qq !== 'undefined' && qq)
185
+ || (typeof jd !== 'undefined' && jd)
186
+ || (typeof my !== 'undefined' && my);
187
+
188
+ var miniProgram = uni.getAccountInfoSync().miniProgram || {};
189
+ var systemInfo = uni.getSystemInfoSync() || {};
190
+ var envVersionMap = {
191
+ develop: '开发版',
192
+ trial: '体验版',
193
+ release: '正式版'
194
+ }
195
+ var { envVersion = '', version = '' } = miniProgram;
196
+ var { brand, model, pixelRatio } = systemInfo;
197
+ var versionDesc = \`\${envVersion}(\${envVersionMap[envVersion] || ''})\`;
198
+
199
+ console.info('[system]', '');
200
+ console.info('[system]', \`Env Version:\${envVersion ? versionDesc : ''}\`);
201
+ console.info('[system]', \`Version:\${version}\`);
202
+
203
+ console.info('[system]', '');
204
+ console.info('[system]', \`Brand:\${brand}, \${model}\`);
205
+ console.info('[system]', \`PixelRatio:\${pixelRatio}\`);
206
+ `;
207
+ }
208
+ function getMpInsertCode() {
209
+ const insertCode = `
210
+ try {
211
+ setTimeout(() => {
212
+ ${getVersionCode()}
213
+ ${getCommitCode()}
214
+ ${getMpVersionCode()}
215
+ }, 2000);
216
+ } catch(err) {}
217
+ `;
218
+ return insertCode;
219
+ }
220
+ function getGenVersionPluginOptions(options) {
221
+ const buildName = options?.buildName || '';
222
+ const commitName = options?.commitName || '';
223
+ const delay = options?.delay === undefined ? 10 : options?.delay;
224
+ return {
225
+ buildName,
226
+ commitName,
227
+ delay,
228
+ };
229
+ }
230
+ function getWebInsertCode(options) {
231
+ const { buildName, commitName, delay } = getGenVersionPluginOptions(options || {});
232
+ return `
233
+ <script>
234
+ try {
235
+ setTimeout(() => {
236
+ ${getVersionCode(buildName)}
237
+ ${getCommitCode(commitName)}
238
+ }, ${delay});
239
+ } catch(err) {}
240
+ </script>
241
+ `;
242
+ }
243
+
244
+ const BASE_SCSS = 'base.scss';
245
+ function getStyleList(dir) {
246
+ const cssList = fs__namespace.readdirSync(dir);
247
+ const filtered = cssList
248
+ .filter(item => item.endsWith('scss') && !item.startsWith(BASE_SCSS))
249
+ .map(item => item.replace(/\.scss$/, ''));
250
+ return filtered;
251
+ }
252
+ function genInjectContent({ styleList, componentName, topElement, dir = '', }) {
253
+ const styleStr = styleList.map((item) => `
254
+ &--type-${item} {
255
+ @import './${dir}${item}.scss';
256
+ }`).join('\n');
257
+ return `
258
+ ${topElement}.${componentName} {
259
+ ${styleStr}
260
+ }
261
+ `;
262
+ }
263
+ function getComponentName(dir) {
264
+ const tPath = tComm.normalizePath(dir);
265
+ const reg = /\/([^/]+)\/css/;
266
+ const match = tPath.match(reg);
267
+ return match?.[1] || '';
268
+ }
269
+
270
+ function replaceDirective(source, list) {
271
+ if (!list.length)
272
+ return source;
273
+ const reg = new RegExp(`(?<=<[^<]+)v-${list.join('|')}=?[^\\s]*`, 'g');
274
+ const newSource = source.replace(reg, '');
275
+ return newSource;
276
+ }
277
+
278
+ const htmlReg = /(?<=<template>)([\s\S]+)(?=<\/template>)/;
279
+ const imgReg = /(<img[\s\S]+?)v-lazy=(?:"|')(.*?)(?:"|')([\s\S]*?>)/g;
280
+ const sizeReg = /(?<=[\s\n]+(?:data-)?)size=(?:"|')(\d+)(?:"|')/;
281
+ const widthReg = /(?<=[\s\n]+(?:data-)?)width=(?:"|')(\d+)(?:"|')/;
282
+ const heightReg = /(?<=[\s\n]+(?:data-)?)height=(?:"|')(\d+)(?:"|')/;
283
+ function vLazyCore(source, options) {
284
+ const { urlHandler } = options || {};
285
+ let html = '';
286
+ const match = source.match(htmlReg);
287
+ if (match?.[1]) {
288
+ html = match[1];
289
+ }
290
+ if (!html)
291
+ return source;
292
+ if (!html.match(imgReg))
293
+ return source;
294
+ const newHtml = handleImg(html, urlHandler);
295
+ const newSource = source.replace(htmlReg, () => newHtml);
296
+ return newSource;
297
+ }
298
+ function getSize(pre, post, reg) {
299
+ let size = '';
300
+ const preMatch = pre.match(reg);
301
+ const postMatch = post.match(reg);
302
+ if (preMatch?.[1]) {
303
+ size = preMatch[1];
304
+ }
305
+ else if (postMatch?.[1]) {
306
+ size = postMatch[1];
307
+ }
308
+ return size;
309
+ }
310
+ function getImgSrc({ urlHandler, src, size, width, height, }) {
311
+ let srcStr = src;
312
+ if (!urlHandler) {
313
+ return src;
314
+ }
315
+ if (width && height) {
316
+ srcStr = `${urlHandler}(${src}, ${width}, ${height})`;
317
+ }
318
+ else if (size) {
319
+ srcStr = `${urlHandler}(${src}, ${size}, ${size})`;
320
+ }
321
+ else {
322
+ srcStr = `${urlHandler}(${src})`;
323
+ }
324
+ return srcStr;
325
+ }
326
+ function handleImg(str = '', urlHandler = '') {
327
+ const res = str.replace(imgReg, (...args) => {
328
+ const { 1: pre, 2: src, 3: post } = args;
329
+ const size = getSize(pre, post, sizeReg);
330
+ const width = getSize(pre, post, widthReg);
331
+ const height = getSize(pre, post, heightReg);
332
+ const srcStr = getImgSrc({
333
+ urlHandler,
334
+ src,
335
+ size,
336
+ width,
337
+ height,
338
+ });
339
+ const innerRes = `${pre} :src="${srcStr}" lazy-load ${post}`;
340
+ return innerRes;
341
+ });
342
+ return res;
343
+ }
344
+
345
+ function checkBundleAnalyze() {
346
+ return process.argv.includes('--bundleAnalyzer')
347
+ || !!process.env.npm_config_report;
348
+ }
349
+ function checkDebugMode() {
350
+ return !!process.env.DEBUG_MODE;
351
+ }
352
+
353
+ const PLATFORM_MAP = {
354
+ MP_WX: 'mp-weixin',
355
+ MP_QQ: 'mp-qq',
356
+ MP_ALIPAY: 'mp-alipay',
357
+ H5: 'h5',
358
+ };
359
+ const ALL_PLATFORM = 'ALL';
360
+ const PLATFORMS_MP = [
361
+ PLATFORM_MAP.MP_WX,
362
+ PLATFORM_MAP.MP_QQ,
363
+ ];
364
+ const PLATFORMS_ALL = [
365
+ PLATFORM_MAP.MP_WX,
366
+ PLATFORM_MAP.MP_QQ,
367
+ PLATFORM_MAP.H5,
368
+ ];
369
+ const HTML_MAP = {
370
+ MP_WX: '.wxml',
371
+ MP_QQ: '.qml',
372
+ MP_ALIPAY: '.axml',
373
+ MP_JD: '.jxml',
374
+ };
375
+ const CSS_MAP = {
376
+ MP_WX: '.wxss',
377
+ MP_QQ: '.qss',
378
+ MP_ALIPAY: '.acss',
379
+ MP_JD: '.jxss',
380
+ };
381
+ const CSS_POSTFIX_MAP = Object.keys(CSS_MAP)
382
+ .reduce((acc, item) => {
383
+ acc[item] = CSS_MAP[item].slice(1);
384
+ return acc;
385
+ }, {});
386
+ const CDN_MAP = {
387
+ UNI_SIMPLE_ROUTER: 'https://image-1251917893.cos.ap-guangzhou.myqcloud.com/igame/npm/uni-simple-router/uni-simple-router%402.0.8-beta.4-1.js',
388
+ };
389
+
390
+ const DEFAULT_TRANSPILE_DEPENDENCIES = [
391
+ 'pmd-merchant-ui',
392
+ 'press-ui',
393
+ 'press-plus',
394
+ 'pmd-aegis',
395
+ 'pmd-app-info',
396
+ 'pmd-config',
397
+ 'pmd-location',
398
+ 'pmd-login',
399
+ 'pmd-network',
400
+ 'pmd-report',
401
+ 'pmd-tools',
402
+ 'pmd-types',
403
+ 'pmd-widget',
404
+ 'pmd-vue',
405
+ 'pmd-jsapi',
406
+ 'pmd-component',
407
+ 'pmd-business',
408
+ 'pmd-api',
409
+ '@zebra-ui/swiper',
410
+ // /[@\\]tencent[/\\]press-ui/,
411
+ // /[@\\]tencent[/\\]press-plus/,
412
+ // /[@\\]tencent[/\\]pmd-aegis/,
413
+ // /[@\\]tencent[/\\]pmd-app-info/,
414
+ // /[@\\]tencent[/\\]pmd-config/,
415
+ // /[@\\]tencent[/\\]pmd-location/,
416
+ // /[@\\]tencent[/\\]pmd-login/,
417
+ // /[@\\]tencent[/\\]pmd-network/,
418
+ // /[@\\]tencent[/\\]pmd-report/,
419
+ // /[@\\]tencent[/\\]pmd-tools/,
420
+ // /[@\\]tencent[/\\]pmd-widget/,
421
+ // /[@\\]tencent[/\\]pmd-vue/,
422
+ // /[@\\]tencent[/\\]pmd-jsapi/,
423
+ // /[@\\]zebra-ui[/\\]swiper/,
424
+ ];
425
+ const DEFAULT_ADAPTER_DIRS = [
426
+ 'comm',
427
+ 'common',
428
+ 'component',
429
+ 'live-component',
430
+ 'logic',
431
+ 'local-logic',
432
+ 'local-component',
433
+ 'login',
434
+ 'pages',
435
+ 'static',
436
+ 'node-modules',
437
+ ];
438
+ const AEGIS_EXTERNAL_SCRIPT_LINK = 'https://image-1251917893.file.myqcloud.com/igame/npm/aegis-web/aegis.min.js';
439
+ const UNI_SIMPLE_ROUTER_SCRIPT_LINK = 'https://image-1251917893.file.myqcloud.com/igame/npm/uni-simple-router/uni-simple-router-2.0.8-beta-4.js';
440
+ const EXTERNAL_LINK_MAP = {
441
+ AXIOS: 'https://image-1251917893.file.myqcloud.com/igame/npm/axios@0.18.0/dist/axios.min.js',
442
+ VUE_LAZY_LOAD: 'https://image-1251917893.file.myqcloud.com/igame/npm/vue-lazyload@1.3.3/vue-lazyload.js',
443
+ AEGIS_WEB: AEGIS_EXTERNAL_SCRIPT_LINK,
444
+ UNI_SIMPLE_ROUTER: UNI_SIMPLE_ROUTER_SCRIPT_LINK,
445
+ };
446
+
447
+ /* eslint-disable @typescript-eslint/no-require-imports */
448
+ const ROOT_NAME = 'MAIN';
449
+ function saveJsonToLog(content, file, needLog = true) {
450
+ if (!needLog)
451
+ return;
452
+ createLogDir();
453
+ const filePath = `./log/${file}`;
454
+ let beforeContent = [];
455
+ let newContent = [{
456
+ logTime: tComm.timeStampFormat(Date.now(), 'yyyy-MM-dd hh:mm:ss'),
457
+ data: content,
458
+ }];
459
+ if (fs__namespace.existsSync(filePath)) {
460
+ try {
461
+ beforeContent = tComm.readFileSync(filePath, true).logList || [];
462
+ }
463
+ catch (err) {
464
+ beforeContent = [];
465
+ }
466
+ }
467
+ if (beforeContent && Array.isArray(beforeContent)) {
468
+ newContent.push(...beforeContent);
469
+ }
470
+ newContent = newContent.slice(0, 10);
471
+ try {
472
+ fs__namespace.writeFile(filePath, JSON.stringify({ logList: newContent }, null, 2), {
473
+ encoding: 'utf-8',
474
+ }, () => { });
475
+ }
476
+ catch (err) {
477
+ }
478
+ }
479
+ function createLogDir() {
480
+ if (!fs__namespace.existsSync('./log')) {
481
+ fs__namespace.mkdirSync('./log');
482
+ }
483
+ }
484
+ const normalizePath = (path) => (tComm.isWindows() ? path.replace(/\\/g, '/') : path);
485
+ function updateAssetSource(assets, key, source) {
486
+ assets[key] = {
487
+ source() {
488
+ return source;
489
+ },
490
+ size() {
491
+ return source.length;
492
+ },
493
+ };
494
+ }
495
+ function removeFirstSlash(key) {
496
+ if (key.startsWith('/')) {
497
+ return key.slice(1);
498
+ }
499
+ return key;
500
+ }
501
+ function sortStringList(list) {
502
+ list.sort((a, b) => {
503
+ if (a > b)
504
+ return 1;
505
+ if (a < b)
506
+ return -1;
507
+ return 0;
508
+ });
509
+ return list;
510
+ }
511
+ function parseSetDeps(deps) {
512
+ return Object.keys(deps).reduce((acc, item) => {
513
+ acc[item] = Array.from(deps[item]);
514
+ sortStringList(acc[item]);
515
+ return acc;
516
+ }, {});
517
+ }
518
+ function getRelativePath(filePath) {
519
+ return path__namespace.relative(process.cwd(), path__namespace.resolve(filePath));
520
+ }
521
+ function getUniCliCache(key) {
522
+ const cache = require('@dcloudio/uni-cli-shared/lib/cache');
523
+ if (!key)
524
+ return cache;
525
+ return cache[key];
526
+ }
527
+
528
+ const DEFAULT_KEYS = [
529
+ 'UNI_APP_X',
530
+ 'APP',
531
+ 'APP_UVUE',
532
+ 'APP_NVUE',
533
+ 'APP_PLUS',
534
+ 'APP_PLUS_NVUE',
535
+ 'APP_VUE',
536
+ 'APP_ANDROID',
537
+ 'APP_IOS',
538
+ 'APP_HARMONY',
539
+ 'H5',
540
+ 'MP',
541
+ 'MP_360',
542
+ 'MP_ALIPAY',
543
+ 'MP_BAIDU',
544
+ 'MP_QQ',
545
+ 'MP_LARK',
546
+ 'MP_TOUTIAO',
547
+ 'MP_WEIXIN',
548
+ 'MP_KUAISHOU',
549
+ 'MP_JD',
550
+ 'QUICKAPP_NATIVE',
551
+ 'QUICKAPP_WEBVIEW',
552
+ 'QUICKAPP_WEBVIEW_HUAWEI',
553
+ 'QUICKAPP_WEBVIEW_UNION',
554
+ 'VUE2',
555
+ 'VUE3',
556
+ 'WEB',
557
+ ];
558
+ const DEFAULT_CONTEXT_OBJECT = DEFAULT_KEYS.reduce((acc, key) => ({
559
+ ...acc,
560
+ [key]: false,
561
+ }), {});
562
+
563
+ function getDeps(dir) {
564
+ const data = tComm.readFileSync(path__default["default"].resolve(dir, 'package.json'), true);
565
+ return Object.keys({
566
+ ...data.dependencies,
567
+ });
568
+ }
569
+
570
+ function getParent(path, level) {
571
+ if (!level) {
572
+ return path.parent;
573
+ }
574
+ return getParent(path.parentPath, level - 1);
575
+ }
576
+ function findDependencies(content) {
577
+ const parser = require('@babel/parser');
578
+ const traverse = require('@babel/traverse').default;
579
+ const sourceList = [];
580
+ const ast = parser.parse(content, {
581
+ // 不加这个配置,报错:SyntaxError: 'import' and 'export' may appear only with 'sourceType: "module"'
582
+ sourceType: 'module',
583
+ plugins: ['typescript'],
584
+ });
585
+ traverse(ast, {
586
+ CallExpression(path) {
587
+ if (path.node.callee.name === 'require') {
588
+ if (path.node.arguments[0].type === 'StringLiteral') {
589
+ sourceList.push(path.node.arguments[0].value);
590
+ }
591
+ if (getParent(path, 0).type === 'ExpressionStatement'
592
+ && getParent(path, 1).type === 'BlockStatement'
593
+ && getParent(path, 2).type === 'ObjectMethod'
594
+ && getParent(path, 3).type === 'ObjectExpression'
595
+ && getParent(path, 4)?.type === 'ObjectProperty'
596
+ && getParent(path, 4)?.key?.name === 'components'
597
+ && getParent(path, 5)?.type === 'ObjectExpression'
598
+ && getParent(path, 6)?.type === 'ExportDefaultDeclaration'
599
+ && path.node.arguments[0].type === 'ArrayExpression') {
600
+ sourceList.push(path.node.arguments[0].elements[0].value);
601
+ }
602
+ }
603
+ },
604
+ ImportDeclaration(path) {
605
+ sourceList.push(path.node.source.value);
606
+ },
607
+ });
608
+ return sourceList;
609
+ }
610
+
611
+ function checkH5() {
612
+ return process.env.VUE_APP_PLATFORM === 'h5';
613
+ }
614
+
615
+ const LOADER_PROD = 'loader.prod.js';
616
+ function getLoaderFile(dir = '', isProd = false) {
617
+ if (isProd) {
618
+ return path__default["default"].resolve(dir, LOADER_PROD);
619
+ }
620
+ return path__default["default"].resolve(dir, 'loader.js');
621
+ }
622
+ function getLoaderProdFile(dir = '') {
623
+ return path__default["default"].resolve(dir, LOADER_PROD);
624
+ }
625
+
626
+ const LOG_KEY = 'LOADER_LOGS';
627
+ function saveLoaderLog() {
628
+ const loaderLogs = global[LOG_KEY];
629
+ if (!loaderLogs)
630
+ return;
631
+ Object.keys(loaderLogs).forEach((file) => {
632
+ saveJsonToLog(loaderLogs[file], file);
633
+ });
634
+ }
635
+ function recordLoaderLog(file, content) {
636
+ if (!global[LOG_KEY]) {
637
+ global[LOG_KEY] = {};
638
+ }
639
+ if (!global[LOG_KEY][file]) {
640
+ global[LOG_KEY][file] = [];
641
+ }
642
+ global[LOG_KEY][file].push(content);
643
+ }
644
+
645
+ function getProjectName() {
646
+ let result = '';
647
+ try {
648
+ const json = tComm.readFileSync('package.json', true) || {};
649
+ result = json.name || '';
650
+ }
651
+ catch (err) { }
652
+ return result;
653
+ }
654
+ function getSubProjectName() {
655
+ const name = process.env.VUE_APP_DIR?.split('/')?.[1] || '';
656
+ return name;
657
+ }
658
+
659
+ // 读取 manifest.json ,修改后重新写入
660
+ const manifestPath = `${process.env.UNI_INPUT_DIR}/manifest.json`;
661
+ let originManifest = '';
662
+ try {
663
+ originManifest = fs__namespace.readFileSync(manifestPath, { encoding: 'utf-8' });
664
+ }
665
+ catch (err) {
666
+ }
667
+ let Manifest = originManifest;
668
+ function replaceManifest(path, value) {
669
+ const arr = path.split('.');
670
+ const len = arr.length;
671
+ const lastItem = arr[len - 1];
672
+ let i = 0;
673
+ const ManifestArr = Manifest.split(/\n/);
674
+ for (let index = 0; index < ManifestArr.length; index++) {
675
+ const item = ManifestArr[index];
676
+ if (new RegExp(`"${arr[i]}"`).test(item))
677
+ i = i + 1;
678
+ if (i === len) {
679
+ const hasComma = /,/.test(item);
680
+ ManifestArr[index] = item.replace(new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`), `"${lastItem}": ${value}${hasComma ? ',' : ''}`);
681
+ break;
682
+ }
683
+ }
684
+ Manifest = ManifestArr.join('\n');
685
+ }
686
+ function updateManifest(path, value) {
687
+ replaceManifest(path, value);
688
+ fs__namespace.writeFileSync(manifestPath, Manifest, {
689
+ flag: 'w',
690
+ });
691
+ }
692
+ function revertManifest() {
693
+ fs__namespace.writeFileSync(manifestPath, originManifest, {
694
+ flag: 'w',
695
+ });
696
+ }
697
+
698
+ function getSubProjectRoot({ root, appDir, }) {
699
+ let subProjectRoot = `${path__default["default"].resolve(root, `./src/${appDir}`)}/`;
700
+ if (!appDir) {
701
+ subProjectRoot = path__default["default"].resolve(root, './src/');
702
+ }
703
+ return subProjectRoot;
704
+ }
705
+ function getSubProjectConfig(subProjectRoot) {
706
+ let res = {};
707
+ try {
708
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
709
+ res = require(path__default["default"].resolve(subProjectRoot, 'config.js'));
710
+ }
711
+ catch (err) { }
712
+ return res;
713
+ }
714
+
715
+ exports.AEGIS_EXTERNAL_SCRIPT_LINK = AEGIS_EXTERNAL_SCRIPT_LINK;
716
+ exports.ALL_PLATFORM = ALL_PLATFORM;
717
+ exports.BASE_SCSS = BASE_SCSS;
718
+ exports.CDN_MAP = CDN_MAP;
719
+ exports.CSS_MAP = CSS_MAP;
720
+ exports.CSS_POSTFIX_MAP = CSS_POSTFIX_MAP;
721
+ exports.DEFAULT_ADAPTER_DIRS = DEFAULT_ADAPTER_DIRS;
722
+ exports.DEFAULT_CONTEXT_OBJECT = DEFAULT_CONTEXT_OBJECT;
723
+ exports.DEFAULT_TRANSPILE_DEPENDENCIES = DEFAULT_TRANSPILE_DEPENDENCIES;
724
+ exports.EXTERNAL_LINK_MAP = EXTERNAL_LINK_MAP;
725
+ exports.HTML_MAP = HTML_MAP;
726
+ exports.PLATFORMS_ALL = PLATFORMS_ALL;
727
+ exports.PLATFORMS_MP = PLATFORMS_MP;
728
+ exports.PLATFORM_MAP = PLATFORM_MAP;
729
+ exports.ROOT_NAME = ROOT_NAME;
730
+ exports.UNI_SIMPLE_ROUTER_SCRIPT_LINK = UNI_SIMPLE_ROUTER_SCRIPT_LINK;
731
+ exports.checkBundleAnalyze = checkBundleAnalyze;
732
+ exports.checkDebugMode = checkDebugMode;
733
+ exports.checkH5 = checkH5;
734
+ exports.createLogDir = createLogDir;
735
+ exports.crossGameStyle = crossGameStyle;
736
+ exports.findDependencies = findDependencies;
737
+ exports.genInjectContent = genInjectContent;
738
+ exports.getCommitCode = getCommitCode;
739
+ exports.getComponentName = getComponentName;
740
+ exports.getDeps = getDeps;
741
+ exports.getGenVersionPluginOptions = getGenVersionPluginOptions;
742
+ exports.getLoaderFile = getLoaderFile;
743
+ exports.getLoaderProdFile = getLoaderProdFile;
744
+ exports.getMpInsertCode = getMpInsertCode;
745
+ exports.getMpVersionCode = getMpVersionCode;
746
+ exports.getProjectName = getProjectName;
747
+ exports.getRelativePath = getRelativePath;
748
+ exports.getRootDir = getRootDir;
749
+ exports.getStyleList = getStyleList;
750
+ exports.getSubProjectConfig = getSubProjectConfig;
751
+ exports.getSubProjectName = getSubProjectName;
752
+ exports.getSubProjectRoot = getSubProjectRoot;
753
+ exports.getUniCliCache = getUniCliCache;
754
+ exports.getVersionCode = getVersionCode;
755
+ exports.getWebInsertCode = getWebInsertCode;
756
+ exports.normalizePath = normalizePath;
757
+ exports.parseSetDeps = parseSetDeps;
758
+ exports.recordLoaderLog = recordLoaderLog;
759
+ exports.removeFirstSlash = removeFirstSlash;
760
+ exports.replaceDirective = replaceDirective;
761
+ exports.revertManifest = revertManifest;
762
+ exports.saveJsonToLog = saveJsonToLog;
763
+ exports.saveLoaderLog = saveLoaderLog;
764
+ exports.updateAssetSource = updateAssetSource;
765
+ exports.updateManifest = updateManifest;
766
+ exports.vLazyCore = vLazyCore;
@@ -0,0 +1,2 @@
1
+ export declare function getLoaderFile(dir?: string, isProd?: boolean): string;
2
+ export declare function getLoaderProdFile(dir?: string): string;
@@ -0,0 +1,2 @@
1
+ export declare function saveLoaderLog(): void;
2
+ export declare function recordLoaderLog(file: string, content: any): void;
@@ -0,0 +1,2 @@
1
+ export declare function getProjectName(): string;
2
+ export declare function getSubProjectName(): string;
@@ -0,0 +1,2 @@
1
+ export declare function updateManifest(path: string, value: string): void;
2
+ export declare function revertManifest(): void;
package/lib/root.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare function getRootDir(): string;
@@ -0,0 +1,5 @@
1
+ export declare function getSubProjectRoot({ root, appDir, }: {
2
+ root: string;
3
+ appDir: string;
4
+ }): string;
5
+ export declare function getSubProjectConfig(subProjectRoot: string): Record<string, any>;
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@plugin-light/shared",
3
+ "version": "0.0.11",
4
+ "main": "./lib/index",
5
+ "files": [
6
+ "lib/"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/novlan1/uni-plugin-light"
11
+ },
12
+ "author": "guowangyang",
13
+ "homepage": "https://novlan1.github.io/uni-plugin-light/",
14
+ "bugs": {
15
+ "url": "https://github.com/novlan1/uni-plugin-light/issues"
16
+ },
17
+ "dependencies": {
18
+ "t-comm": "^1.3.104"
19
+ },
20
+ "scripts": {
21
+ "build": "rm -rf lib && rollup -c",
22
+ "changelog": "node ../../script/monorepo/changelog $PWD",
23
+ "bump": "node ../../script/monorepo/version-simple $PWD",
24
+ "release": "node ../../script/monorepo/release $PWD"
25
+ }
26
+ }