@plugin-light/shared 1.0.0 → 1.0.2
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.
- package/README.md +6 -2
- package/lib/config/index.d.ts +4 -0
- package/lib/cross-game-style/config.d.ts +1 -0
- package/lib/cross-game-style/types.d.ts +10 -0
- package/lib/index.js +63 -28
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,7 +11,11 @@
|
|
|
11
11
|
|
|
12
12
|
除 `t-comm` 外,`plugin-light-shared` 是整个工具库中最底层的依赖。
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## 1. 作者
|
|
15
|
+
|
|
16
|
+
**novlan1**
|
|
17
|
+
|
|
18
|
+
## 2. 如何使用
|
|
15
19
|
|
|
16
20
|
安装
|
|
17
21
|
|
|
@@ -27,6 +31,6 @@ import { getDeps } from '@plugin-light/shared';
|
|
|
27
31
|
getDeps(__dirname);
|
|
28
32
|
```
|
|
29
33
|
|
|
30
|
-
## 更新日志
|
|
34
|
+
## 3. 更新日志
|
|
31
35
|
|
|
32
36
|
[点此查看](./CHANGELOG.md)
|
package/lib/config/index.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ export declare const PLATFORM_MAP: {
|
|
|
2
2
|
readonly MP_WX: "mp-weixin";
|
|
3
3
|
readonly MP_QQ: "mp-qq";
|
|
4
4
|
readonly MP_ALIPAY: "mp-alipay";
|
|
5
|
+
readonly MP_BAIDU: "mp-baidu";
|
|
6
|
+
readonly MP_TOUTIAO: "mp-toutiao";
|
|
7
|
+
readonly MP_KUAISHOU: "mp-kuaishou";
|
|
8
|
+
readonly MP_XHS: "mp-xhs";
|
|
5
9
|
readonly MP_JD: "mp-jd";
|
|
6
10
|
readonly H5: "h5";
|
|
7
11
|
};
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export type ICrossGameStyleOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* 要替换的样式文件名,不含后缀,默认空,即从项目的 config.js 中获取
|
|
4
|
+
*/
|
|
2
5
|
styleName?: string | Array<string>;
|
|
6
|
+
/**
|
|
7
|
+
* 处理的平台,默认全部,即 ['ALL']
|
|
8
|
+
*/
|
|
3
9
|
platforms?: Array<string>;
|
|
10
|
+
/**
|
|
11
|
+
* 要查找的文件后缀,默认 ['scss', 'less']
|
|
12
|
+
*/
|
|
13
|
+
extList?: Array<string>;
|
|
4
14
|
};
|
package/lib/index.js
CHANGED
|
@@ -58,6 +58,10 @@ const PLATFORM_MAP = {
|
|
|
58
58
|
MP_WX: 'mp-weixin',
|
|
59
59
|
MP_QQ: 'mp-qq',
|
|
60
60
|
MP_ALIPAY: 'mp-alipay',
|
|
61
|
+
MP_BAIDU: 'mp-baidu',
|
|
62
|
+
MP_TOUTIAO: 'mp-toutiao',
|
|
63
|
+
MP_KUAISHOU: 'mp-kuaishou',
|
|
64
|
+
MP_XHS: 'mp-xhs',
|
|
61
65
|
MP_JD: 'mp-jd',
|
|
62
66
|
H5: 'h5',
|
|
63
67
|
};
|
|
@@ -248,6 +252,7 @@ const DEFAULT_KEYS = [
|
|
|
248
252
|
'MP_WEIXIN',
|
|
249
253
|
'MP_KUAISHOU',
|
|
250
254
|
'MP_JD',
|
|
255
|
+
'MP_XHS',
|
|
251
256
|
'QUICKAPP_NATIVE',
|
|
252
257
|
'QUICKAPP_WEBVIEW',
|
|
253
258
|
'QUICKAPP_WEBVIEW_HUAWEI',
|
|
@@ -409,6 +414,27 @@ function getSubProjectName() {
|
|
|
409
414
|
return name;
|
|
410
415
|
}
|
|
411
416
|
|
|
417
|
+
function updateManifestCore(_a) {
|
|
418
|
+
var path = _a.path,
|
|
419
|
+
value = _a.value,
|
|
420
|
+
manifest = _a.manifest;
|
|
421
|
+
var arr = path.split('.');
|
|
422
|
+
var len = arr.length;
|
|
423
|
+
var lastItem = arr[len - 1];
|
|
424
|
+
var i = 0;
|
|
425
|
+
var manifestArr = manifest.split(/\n/);
|
|
426
|
+
for (var index = 0; index < manifestArr.length; index++) {
|
|
427
|
+
var item = manifestArr[index];
|
|
428
|
+
if (new RegExp("\"".concat(arr[i], "\"")).test(item)) i = i + 1;
|
|
429
|
+
if (i === len) {
|
|
430
|
+
var hasComma = /,/.test(item);
|
|
431
|
+
manifestArr[index] = item.replace(new RegExp("\"".concat(lastItem, "\"[\\s\\S]*:[\\s\\S]*")), "\"".concat(lastItem, "\": ").concat(value).concat(hasComma ? ',' : ''));
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return manifestArr.join('\n');
|
|
436
|
+
}
|
|
437
|
+
|
|
412
438
|
// 读取 manifest.json ,修改后重新写入
|
|
413
439
|
const manifestPath = `${process.env.UNI_INPUT_DIR}/manifest.json`;
|
|
414
440
|
let originManifest = '';
|
|
@@ -418,26 +444,12 @@ try {
|
|
|
418
444
|
catch (err) {
|
|
419
445
|
}
|
|
420
446
|
let Manifest = originManifest;
|
|
421
|
-
function replaceManifest(path, value) {
|
|
422
|
-
const arr = path.split('.');
|
|
423
|
-
const len = arr.length;
|
|
424
|
-
const lastItem = arr[len - 1];
|
|
425
|
-
let i = 0;
|
|
426
|
-
const ManifestArr = Manifest.split(/\n/);
|
|
427
|
-
for (let index = 0; index < ManifestArr.length; index++) {
|
|
428
|
-
const item = ManifestArr[index];
|
|
429
|
-
if (new RegExp(`"${arr[i]}"`).test(item))
|
|
430
|
-
i = i + 1;
|
|
431
|
-
if (i === len) {
|
|
432
|
-
const hasComma = /,/.test(item);
|
|
433
|
-
ManifestArr[index] = item.replace(new RegExp(`"${lastItem}"[\\s\\S]*:[\\s\\S]*`), `"${lastItem}": ${value}${hasComma ? ',' : ''}`);
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
Manifest = ManifestArr.join('\n');
|
|
438
|
-
}
|
|
439
447
|
function updateManifest(path, value) {
|
|
440
|
-
|
|
448
|
+
Manifest = updateManifestCore({
|
|
449
|
+
path,
|
|
450
|
+
value,
|
|
451
|
+
manifest: Manifest,
|
|
452
|
+
});
|
|
441
453
|
fs__namespace.writeFileSync(manifestPath, Manifest, {
|
|
442
454
|
flag: 'w',
|
|
443
455
|
});
|
|
@@ -488,6 +500,10 @@ const isQuickappUnion = () => getPlatform() === 'quickapp-webview-union';
|
|
|
488
500
|
const isQuickappHuawei = () => getPlatform() === 'quickapp-webview-huawei';
|
|
489
501
|
|
|
490
502
|
const TIP_STYLE_NAME = '@TIP_STYLE_NAME';
|
|
503
|
+
const DEFAULT_EXT_LIST = [
|
|
504
|
+
'scss',
|
|
505
|
+
'less',
|
|
506
|
+
];
|
|
491
507
|
|
|
492
508
|
function getAppDir() {
|
|
493
509
|
if (process.env.VUE_APP_DIR) {
|
|
@@ -523,10 +539,20 @@ function tryRemoveImport(source, removeImport = false) {
|
|
|
523
539
|
}
|
|
524
540
|
return res;
|
|
525
541
|
}
|
|
542
|
+
function findValidFile(fileName, extList) {
|
|
543
|
+
for (const ext of extList) {
|
|
544
|
+
const file = `${fileName}.${ext}`;
|
|
545
|
+
if (fs__namespace.existsSync(file)) {
|
|
546
|
+
return [ext, file];
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
return [];
|
|
550
|
+
}
|
|
526
551
|
function crossGameStyle({ source, options, dir, removeImport = false, }) {
|
|
527
552
|
if (!source.includes(TIP_STYLE_NAME)) {
|
|
528
553
|
return source;
|
|
529
554
|
}
|
|
555
|
+
const extList = options?.extList || DEFAULT_EXT_LIST;
|
|
530
556
|
let styleName = '';
|
|
531
557
|
// 使用 env.local 的样式 VUE_APP_DIR = module/ingame-nba,即为 nba
|
|
532
558
|
if (options?.styleName) {
|
|
@@ -554,11 +580,12 @@ function crossGameStyle({ source, options, dir, removeImport = false, }) {
|
|
|
554
580
|
}
|
|
555
581
|
styleName = styleName[0] || '';
|
|
556
582
|
}
|
|
557
|
-
const cssPath = `./css/${styleName}
|
|
558
|
-
const cssAbsolutePath = `${dir}/css/${styleName}
|
|
559
|
-
const
|
|
560
|
-
if (
|
|
561
|
-
|
|
583
|
+
const cssPath = `./css/${styleName}`;
|
|
584
|
+
const cssAbsolutePath = `${dir}/css/${styleName}`;
|
|
585
|
+
const found = findValidFile(cssAbsolutePath, extList);
|
|
586
|
+
if (found.length) {
|
|
587
|
+
const [ext] = found;
|
|
588
|
+
return source.replace(TIP_STYLE_NAME, `${cssPath}.${ext}`);
|
|
562
589
|
}
|
|
563
590
|
return tryRemoveImport(source, removeImport);
|
|
564
591
|
}
|
|
@@ -635,18 +662,26 @@ function getMpVersionCode() {
|
|
|
635
662
|
return `
|
|
636
663
|
var uni = (typeof wx !== 'undefined' && wx)
|
|
637
664
|
|| (typeof qq !== 'undefined' && qq)
|
|
665
|
+
|| (typeof swan !== 'undefined' && swan)
|
|
638
666
|
|| (typeof jd !== 'undefined' && jd)
|
|
667
|
+
|| (typeof tt !== 'undefined' && tt)
|
|
668
|
+
|| (typeof kuaishou !== 'undefined' && kuaishou)
|
|
669
|
+
|| (typeof xhs !== 'undefined' && xhs)
|
|
639
670
|
|| (typeof my !== 'undefined' && my);
|
|
640
671
|
|
|
641
672
|
var miniProgram = (uni.getAccountInfoSync && uni.getAccountInfoSync().miniProgram) || {};
|
|
642
|
-
var
|
|
673
|
+
var { envVersion = '', version = '' } = miniProgram;
|
|
674
|
+
function getSystemInfo() {
|
|
675
|
+
return (uni.getSystemInfoSync && uni.getSystemInfoSync()) || {};
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
var { pixelRatio } = (uni.getWindowInfo && uni.getWindowInfo()) || getSystemInfo();
|
|
679
|
+
var { brand, model, pixelRatio } = (uni.getDeviceInfo && uni.getDeviceInfo()) || getSystemInfo();
|
|
643
680
|
var envVersionMap = {
|
|
644
681
|
develop: '开发版',
|
|
645
682
|
trial: '体验版',
|
|
646
683
|
release: '正式版'
|
|
647
|
-
}
|
|
648
|
-
var { envVersion = '', version = '' } = miniProgram;
|
|
649
|
-
var { brand, model, pixelRatio } = systemInfo;
|
|
684
|
+
};
|
|
650
685
|
var versionDesc = \`\${envVersion}(\${envVersionMap[envVersion] || ''})\`;
|
|
651
686
|
|
|
652
687
|
console.info('[system]', '');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plugin-light/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"homepage": "https://novlan1.github.io/docs/plugin-light/zh/plugin-light-shared.html",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/novlan1/plugin-light/issues"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"lib/"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"t-comm": "^
|
|
19
|
+
"t-comm": "^3.0.3"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "rm -rf lib && rollup -c",
|