@arkxio/ark-dev-utils 0.1.6 → 0.1.8
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/.babelrc.js +11 -11
- package/LICENSE +170 -0
- package/README.md +17 -17
- package/dist/{ark-dev-utils.js → index.js} +1114 -1114
- package/dist/{ark-dev-utils.min.js → index.min.js} +1114 -1114
- package/jsconfig.json +5 -5
- package/lib/index.js +1113 -1113
- package/package.json +10 -10
- package/src/base-utils/index.js +119 -119
- package/src/check.js +102 -102
- package/src/configs/consts.js +24 -24
- package/src/configs/externalsDefault.js +25 -25
- package/src/configs/presetExternals.js +18 -18
- package/src/index.js +33 -33
- package/src/inner-utils/arr.js +8 -8
- package/src/inner-utils/index.js +124 -124
- package/src/inner-utils/obj.js +45 -45
- package/src/inner-utils/str.js +75 -75
- package/src/meta-extractor/fillAssetList.js +428 -428
- package/src/meta-extractor/index.js +84 -84
- package/src/meta-extractor/parse.js +56 -56
- package/src/meta-extractor/utils.js +141 -141
- package/src/share/createSubApp.js +72 -72
- package/src/sub-app/createLibSubApp.js +12 -12
- package/src/sub-app/createReactSubApp.js +12 -12
- package/src/sub-app/createVueSubApp.js +12 -12
- package/typings.d.ts +295 -295
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arkxio/ark-dev-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "ark dev utils",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,13 +21,6 @@
|
|
|
21
21
|
".babelrc.js",
|
|
22
22
|
"README.md"
|
|
23
23
|
],
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
|
|
26
|
-
"build:commonjs": "cross-env BUILD_ENV=commonjs rollup -c",
|
|
27
|
-
"build:es": "cross-env BUILD_ENV=es rollup -c",
|
|
28
|
-
"build:umd": "cross-env BUILD_ENV=development rollup -c",
|
|
29
|
-
"build:umd:min": "cross-env BUILD_ENV=production rollup -c"
|
|
30
|
-
},
|
|
31
24
|
"dependencies": {
|
|
32
25
|
"jsdom": ">=19.0.0"
|
|
33
26
|
},
|
|
@@ -47,5 +40,12 @@
|
|
|
47
40
|
"access": "public",
|
|
48
41
|
"registry": "https://registry.npmjs.org/"
|
|
49
42
|
},
|
|
50
|
-
"deprecated": false
|
|
51
|
-
|
|
43
|
+
"deprecated": false,
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "npm run build:commonjs && npm run build:es && npm run build:umd && npm run build:umd:min",
|
|
46
|
+
"build:commonjs": "cross-env BUILD_ENV=commonjs rollup -c",
|
|
47
|
+
"build:es": "cross-env BUILD_ENV=es rollup -c",
|
|
48
|
+
"build:umd": "cross-env BUILD_ENV=development rollup -c",
|
|
49
|
+
"build:umd:min": "cross-env BUILD_ENV=production rollup -c"
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/base-utils/index.js
CHANGED
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
/** @typedef {import('../../typings').ICreateSubAppOptions} ICreateSubAppOptions */
|
|
2
|
-
import { getNpmCdnHomePage } from '../inner-utils/index';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {string} inputPath
|
|
6
|
-
* @param {Object} options
|
|
7
|
-
* @param {'end' | 'start'} [options.loc='end']
|
|
8
|
-
* @param {boolean} [options.need=false]
|
|
9
|
-
*/
|
|
10
|
-
export function ensureSlash(inputPath, options) {
|
|
11
|
-
const { need, loc = 'end' } = options;
|
|
12
|
-
const isEnd = loc === 'end';
|
|
13
|
-
const hasSlash = isEnd ? inputPath.endsWith('/') : inputPath.startsWith('/');
|
|
14
|
-
|
|
15
|
-
const shouldDelSlash = hasSlash && !need;
|
|
16
|
-
const shouldAddSlash = !hasSlash && need;
|
|
17
|
-
if (isEnd) {
|
|
18
|
-
if (shouldDelSlash) {
|
|
19
|
-
return inputPath.substring(0, inputPath.length - 1);
|
|
20
|
-
}
|
|
21
|
-
if (shouldAddSlash) {
|
|
22
|
-
return `${inputPath}/`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (!isEnd) {
|
|
26
|
-
if (shouldDelSlash) {
|
|
27
|
-
// del start slash
|
|
28
|
-
return inputPath.substring(1);
|
|
29
|
-
}
|
|
30
|
-
if (shouldAddSlash) {
|
|
31
|
-
return `/${inputPath}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return inputPath;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** 语义化 slash 相关操作,方便上层理解和使用 */
|
|
39
|
-
export const slash = {
|
|
40
|
-
start: (path) => ensureSlash(path, { loc: 'start', need: true }),
|
|
41
|
-
noStart: (path) => ensureSlash(path, { loc: 'start', need: false }),
|
|
42
|
-
end: (path) => ensureSlash(path, { loc: 'end', need: true }),
|
|
43
|
-
noEnd: (path) => ensureSlash(path, { loc: 'end', need: false }),
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export function getHelProcessEnvParams() {
|
|
47
|
-
// 以下常量由蓝盾流水线注入(由流水线变量或bash脚本注入)
|
|
48
|
-
const {
|
|
49
|
-
HOST,
|
|
50
|
-
PORT,
|
|
51
|
-
// appHomePage, 形如 http://xxx.cdn.com/hel/app1_2020121201011666
|
|
52
|
-
HEL_APP_HOME_PAGE,
|
|
53
|
-
/** 在构建机环境时,会注入真正对应的应用名 */
|
|
54
|
-
HEL_APP_GROUP_NAME,
|
|
55
|
-
HEL_APP_NAME,
|
|
56
|
-
} = process.env;
|
|
57
|
-
|
|
58
|
-
let appHomePage = HEL_APP_HOME_PAGE;
|
|
59
|
-
// 未传递 HEL_APP_HOME_PAGE 的话,根据 HOST 和 PORT 推导
|
|
60
|
-
if (!appHomePage && (HOST || PORT)) {
|
|
61
|
-
const host = HOST || 'localhost';
|
|
62
|
-
const port = PORT || '80';
|
|
63
|
-
const hotsStr = host.startsWith('http') ? host : `http://${host}`;
|
|
64
|
-
appHomePage = `${hotsStr}:${port}`;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
appHomePage,
|
|
69
|
-
appGroupName: HEL_APP_GROUP_NAME,
|
|
70
|
-
appName: HEL_APP_NAME,
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @param {Record<string, any>} pkg
|
|
76
|
-
* @param {ICreateSubAppOptions} options
|
|
77
|
-
* @returns
|
|
78
|
-
*/
|
|
79
|
-
export function getHelEnvParams(pkg, options = {}) {
|
|
80
|
-
const { platform, distDir, homePage: userCustomHomePage, handleHomePage = true, npmCdnType } = options;
|
|
81
|
-
let cdnHomePage = '';
|
|
82
|
-
// 计算 unpkg 平台 的 homePage 值,此时如果透传了 homePage,表示 unpkg 为私服
|
|
83
|
-
if (platform === 'unpkg' && handleHomePage) {
|
|
84
|
-
cdnHomePage = getNpmCdnHomePage(pkg, { distDir, npmCdnType, homePage: userCustomHomePage });
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 来自 process.env 的值优先级最高
|
|
88
|
-
const p0EnvParams = getHelProcessEnvParams();
|
|
89
|
-
const appName = p0EnvParams.appName || pkg.appGroupName || '';
|
|
90
|
-
return {
|
|
91
|
-
appHomePage: p0EnvParams.appHomePage || cdnHomePage || userCustomHomePage || pkg.homepage || '/',
|
|
92
|
-
appGroupName: p0EnvParams.appGroupName || pkg.appGroupName || appName,
|
|
93
|
-
appName,
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* @param {string} appName - hel 管理台注册的应用名 或 package.name
|
|
99
|
-
* @param {boolean} [useTimestampSuffix=true] - default: true, 是否设置时间戳后缀
|
|
100
|
-
* 设置为 true 时,支持同一个模块正确执行多版本js文件
|
|
101
|
-
* 如不需要同屏加载同一个模块的多个版本功能,且需要自己定制一些其他逻辑,可以设置为false
|
|
102
|
-
*/
|
|
103
|
-
export function getJsonpFnName(appName, useTimestampSuffix = true) {
|
|
104
|
-
if (useTimestampSuffix) {
|
|
105
|
-
return `helJsonp_${appName}_${Date.now()}`;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return `helJsonp_${appName}`;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
* @param {string} homePage - 应用homePage
|
|
114
|
-
* @param {boolean} [needSlash]
|
|
115
|
-
* @returns
|
|
116
|
-
*/
|
|
117
|
-
export function getPublicPathOrUrl(homePage, needSlash = true) {
|
|
118
|
-
return ensureSlash(homePage, { loc: 'end', need: needSlash });
|
|
119
|
-
}
|
|
1
|
+
/** @typedef {import('../../typings').ICreateSubAppOptions} ICreateSubAppOptions */
|
|
2
|
+
import { getNpmCdnHomePage } from '../inner-utils/index';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {string} inputPath
|
|
6
|
+
* @param {Object} options
|
|
7
|
+
* @param {'end' | 'start'} [options.loc='end']
|
|
8
|
+
* @param {boolean} [options.need=false]
|
|
9
|
+
*/
|
|
10
|
+
export function ensureSlash(inputPath, options) {
|
|
11
|
+
const { need, loc = 'end' } = options;
|
|
12
|
+
const isEnd = loc === 'end';
|
|
13
|
+
const hasSlash = isEnd ? inputPath.endsWith('/') : inputPath.startsWith('/');
|
|
14
|
+
|
|
15
|
+
const shouldDelSlash = hasSlash && !need;
|
|
16
|
+
const shouldAddSlash = !hasSlash && need;
|
|
17
|
+
if (isEnd) {
|
|
18
|
+
if (shouldDelSlash) {
|
|
19
|
+
return inputPath.substring(0, inputPath.length - 1);
|
|
20
|
+
}
|
|
21
|
+
if (shouldAddSlash) {
|
|
22
|
+
return `${inputPath}/`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (!isEnd) {
|
|
26
|
+
if (shouldDelSlash) {
|
|
27
|
+
// del start slash
|
|
28
|
+
return inputPath.substring(1);
|
|
29
|
+
}
|
|
30
|
+
if (shouldAddSlash) {
|
|
31
|
+
return `/${inputPath}`;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return inputPath;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 语义化 slash 相关操作,方便上层理解和使用 */
|
|
39
|
+
export const slash = {
|
|
40
|
+
start: (path) => ensureSlash(path, { loc: 'start', need: true }),
|
|
41
|
+
noStart: (path) => ensureSlash(path, { loc: 'start', need: false }),
|
|
42
|
+
end: (path) => ensureSlash(path, { loc: 'end', need: true }),
|
|
43
|
+
noEnd: (path) => ensureSlash(path, { loc: 'end', need: false }),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function getHelProcessEnvParams() {
|
|
47
|
+
// 以下常量由蓝盾流水线注入(由流水线变量或bash脚本注入)
|
|
48
|
+
const {
|
|
49
|
+
HOST,
|
|
50
|
+
PORT,
|
|
51
|
+
// appHomePage, 形如 http://xxx.cdn.com/hel/app1_2020121201011666
|
|
52
|
+
HEL_APP_HOME_PAGE,
|
|
53
|
+
/** 在构建机环境时,会注入真正对应的应用名 */
|
|
54
|
+
HEL_APP_GROUP_NAME,
|
|
55
|
+
HEL_APP_NAME,
|
|
56
|
+
} = process.env;
|
|
57
|
+
|
|
58
|
+
let appHomePage = HEL_APP_HOME_PAGE;
|
|
59
|
+
// 未传递 HEL_APP_HOME_PAGE 的话,根据 HOST 和 PORT 推导
|
|
60
|
+
if (!appHomePage && (HOST || PORT)) {
|
|
61
|
+
const host = HOST || 'localhost';
|
|
62
|
+
const port = PORT || '80';
|
|
63
|
+
const hotsStr = host.startsWith('http') ? host : `http://${host}`;
|
|
64
|
+
appHomePage = `${hotsStr}:${port}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
appHomePage,
|
|
69
|
+
appGroupName: HEL_APP_GROUP_NAME,
|
|
70
|
+
appName: HEL_APP_NAME,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @param {Record<string, any>} pkg
|
|
76
|
+
* @param {ICreateSubAppOptions} options
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
export function getHelEnvParams(pkg, options = {}) {
|
|
80
|
+
const { platform, distDir, homePage: userCustomHomePage, handleHomePage = true, npmCdnType } = options;
|
|
81
|
+
let cdnHomePage = '';
|
|
82
|
+
// 计算 unpkg 平台 的 homePage 值,此时如果透传了 homePage,表示 unpkg 为私服
|
|
83
|
+
if (platform === 'unpkg' && handleHomePage) {
|
|
84
|
+
cdnHomePage = getNpmCdnHomePage(pkg, { distDir, npmCdnType, homePage: userCustomHomePage });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// 来自 process.env 的值优先级最高
|
|
88
|
+
const p0EnvParams = getHelProcessEnvParams();
|
|
89
|
+
const appName = p0EnvParams.appName || pkg.appGroupName || '';
|
|
90
|
+
return {
|
|
91
|
+
appHomePage: p0EnvParams.appHomePage || cdnHomePage || userCustomHomePage || pkg.homepage || '/',
|
|
92
|
+
appGroupName: p0EnvParams.appGroupName || pkg.appGroupName || appName,
|
|
93
|
+
appName,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @param {string} appName - hel 管理台注册的应用名 或 package.name
|
|
99
|
+
* @param {boolean} [useTimestampSuffix=true] - default: true, 是否设置时间戳后缀
|
|
100
|
+
* 设置为 true 时,支持同一个模块正确执行多版本js文件
|
|
101
|
+
* 如不需要同屏加载同一个模块的多个版本功能,且需要自己定制一些其他逻辑,可以设置为false
|
|
102
|
+
*/
|
|
103
|
+
export function getJsonpFnName(appName, useTimestampSuffix = true) {
|
|
104
|
+
if (useTimestampSuffix) {
|
|
105
|
+
return `helJsonp_${appName}_${Date.now()}`;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return `helJsonp_${appName}`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
* @param {string} homePage - 应用homePage
|
|
114
|
+
* @param {boolean} [needSlash]
|
|
115
|
+
* @returns
|
|
116
|
+
*/
|
|
117
|
+
export function getPublicPathOrUrl(homePage, needSlash = true) {
|
|
118
|
+
return ensureSlash(homePage, { loc: 'end', need: needSlash });
|
|
119
|
+
}
|
package/src/check.js
CHANGED
|
@@ -1,102 +1,102 @@
|
|
|
1
|
-
/*
|
|
2
|
-
|--------------------------------------------------------------------------
|
|
3
|
-
|
|
|
4
|
-
| 此脚本在流水线上会被触发,用于校验组名是否和应用里的组名保持一致
|
|
5
|
-
|
|
|
6
|
-
|--------------------------------------------------------------------------
|
|
7
|
-
*/
|
|
8
|
-
/** @typedef {import('../typings').ICheckOptions} ICheckOptions */
|
|
9
|
-
import * as fs from 'fs';
|
|
10
|
-
import * as os from 'os';
|
|
11
|
-
import * as path from 'path';
|
|
12
|
-
import cst from './configs/consts';
|
|
13
|
-
import { verbose } from './inner-utils/index';
|
|
14
|
-
import { pfstr } from './inner-utils/str';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @param {Record<string, any>} pkg - 用户模块的 package.json 文件
|
|
18
|
-
* @param {ICheckOptions['fileFullPath'] | ICheckOptions} [subAppFilePathOrOptions] - 文件全路径名字,可带或不带后缀(.ts, .js)
|
|
19
|
-
*/
|
|
20
|
-
export default function (pkg, subAppFilePathOrOptions) {
|
|
21
|
-
let fileFullPath = path.join(__dirname, cst.DEFAULT_GUESS_SUB_APP_CONF_PATH);
|
|
22
|
-
let checkEnv = true;
|
|
23
|
-
if (subAppFilePathOrOptions) {
|
|
24
|
-
if (typeof subAppFilePathOrOptions === 'string') {
|
|
25
|
-
fileFullPath = subAppFilePathOrOptions;
|
|
26
|
-
} else {
|
|
27
|
-
fileFullPath = subAppFilePathOrOptions.fileFullPath;
|
|
28
|
-
if (subAppFilePathOrOptions.checkEnv !== undefined) {
|
|
29
|
-
checkEnv = subAppFilePathOrOptions.checkEnv;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** 子应用组名 */
|
|
35
|
-
let srcAppGroupName = '';
|
|
36
|
-
let content = '';
|
|
37
|
-
if (fileFullPath.endsWith('.js') || fileFullPath.endsWith('.ts')) {
|
|
38
|
-
content = fs.readFileSync(fileFullPath);
|
|
39
|
-
} else {
|
|
40
|
-
const fileFullPathJs = `${fileFullPath}.js`;
|
|
41
|
-
const fileFullPathTs = `${fileFullPath}.ts`;
|
|
42
|
-
const isJsExist = fs.existsSync(fileFullPathJs);
|
|
43
|
-
if (isJsExist) {
|
|
44
|
-
verbose(`guess js subApp file: ${fileFullPathJs}`);
|
|
45
|
-
content = fs.readFileSync(fileFullPathJs);
|
|
46
|
-
} else {
|
|
47
|
-
verbose(`guess ts subApp file: ${fileFullPathTs}`);
|
|
48
|
-
const isTsExist = fs.existsSync(fileFullPathTs);
|
|
49
|
-
if (isTsExist) {
|
|
50
|
-
content = fs.readFileSync(fileFullPathTs);
|
|
51
|
-
} else {
|
|
52
|
-
throw new Error('no src/configs/subApp.(js|ts) file found');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const fileStr = content.toString();
|
|
58
|
-
const strList = fileStr.split(os.EOL);
|
|
59
|
-
for (const item of strList) {
|
|
60
|
-
// export const HEL_APP_GROUP_NAME = 'your-app';
|
|
61
|
-
// or
|
|
62
|
-
// export const LIB_NAME = 'your-app';
|
|
63
|
-
if (item.includes('export') && item.includes('const') && (item.includes('LIB_NAME') || item.includes('HEL_APP_GROUP_NAME'))) {
|
|
64
|
-
const noBlankStr = item.replace(/ /gi, '');
|
|
65
|
-
let [, appNameStr] = noBlankStr.split('=');
|
|
66
|
-
appNameStr = appNameStr.replace(/'/gi, '');
|
|
67
|
-
appNameStr = appNameStr.replace(/"/gi, '');
|
|
68
|
-
appNameStr = appNameStr.replace(/;/gi, '');
|
|
69
|
-
appNameStr = appNameStr.replace(/\r/gi, '');
|
|
70
|
-
appNameStr = appNameStr.replace(/\n/gi, '');
|
|
71
|
-
srcAppGroupName = appNameStr;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (!srcAppGroupName) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
pfstr(`
|
|
78
|
-
HEL_APP_GROUP_NAME or LIB_NAME not found in src/configs/subApp.(js|ts) file,
|
|
79
|
-
your should expose it like below:
|
|
80
|
-
export const HEL_APP_GROUP_NAME = 'your-app';
|
|
81
|
-
or
|
|
82
|
-
export const LIB_NAME = 'your-app';
|
|
83
|
-
`),
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const pgkAppGroupName = pkg.appGroupName || pkg.name;
|
|
88
|
-
if (pgkAppGroupName !== srcAppGroupName) {
|
|
89
|
-
throw new Error(
|
|
90
|
-
`package.json name [${pgkAppGroupName}] should be equal to src/configs/subApp LIB_NAME(or HEL_APP_GROUP_NAME) [${srcAppGroupName}]`,
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (checkEnv) {
|
|
95
|
-
// 以下常量由 ci&cd 系统注入(通常由流水线变量或 bash 脚本注入)
|
|
96
|
-
const { HEL_APP_GROUP_NAME } = process.env;
|
|
97
|
-
|
|
98
|
-
if (pgkAppGroupName !== HEL_APP_GROUP_NAME) {
|
|
99
|
-
throw new Error(`package.json name [${pgkAppGroupName}] should be equal to pipeline var HEL_APP_GROUP_NAME [${HEL_APP_GROUP_NAME}]`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
|--------------------------------------------------------------------------
|
|
3
|
+
|
|
|
4
|
+
| 此脚本在流水线上会被触发,用于校验组名是否和应用里的组名保持一致
|
|
5
|
+
|
|
|
6
|
+
|--------------------------------------------------------------------------
|
|
7
|
+
*/
|
|
8
|
+
/** @typedef {import('../typings').ICheckOptions} ICheckOptions */
|
|
9
|
+
import * as fs from 'fs';
|
|
10
|
+
import * as os from 'os';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
import cst from './configs/consts';
|
|
13
|
+
import { verbose } from './inner-utils/index';
|
|
14
|
+
import { pfstr } from './inner-utils/str';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Record<string, any>} pkg - 用户模块的 package.json 文件
|
|
18
|
+
* @param {ICheckOptions['fileFullPath'] | ICheckOptions} [subAppFilePathOrOptions] - 文件全路径名字,可带或不带后缀(.ts, .js)
|
|
19
|
+
*/
|
|
20
|
+
export default function (pkg, subAppFilePathOrOptions) {
|
|
21
|
+
let fileFullPath = path.join(__dirname, cst.DEFAULT_GUESS_SUB_APP_CONF_PATH);
|
|
22
|
+
let checkEnv = true;
|
|
23
|
+
if (subAppFilePathOrOptions) {
|
|
24
|
+
if (typeof subAppFilePathOrOptions === 'string') {
|
|
25
|
+
fileFullPath = subAppFilePathOrOptions;
|
|
26
|
+
} else {
|
|
27
|
+
fileFullPath = subAppFilePathOrOptions.fileFullPath;
|
|
28
|
+
if (subAppFilePathOrOptions.checkEnv !== undefined) {
|
|
29
|
+
checkEnv = subAppFilePathOrOptions.checkEnv;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** 子应用组名 */
|
|
35
|
+
let srcAppGroupName = '';
|
|
36
|
+
let content = '';
|
|
37
|
+
if (fileFullPath.endsWith('.js') || fileFullPath.endsWith('.ts')) {
|
|
38
|
+
content = fs.readFileSync(fileFullPath);
|
|
39
|
+
} else {
|
|
40
|
+
const fileFullPathJs = `${fileFullPath}.js`;
|
|
41
|
+
const fileFullPathTs = `${fileFullPath}.ts`;
|
|
42
|
+
const isJsExist = fs.existsSync(fileFullPathJs);
|
|
43
|
+
if (isJsExist) {
|
|
44
|
+
verbose(`guess js subApp file: ${fileFullPathJs}`);
|
|
45
|
+
content = fs.readFileSync(fileFullPathJs);
|
|
46
|
+
} else {
|
|
47
|
+
verbose(`guess ts subApp file: ${fileFullPathTs}`);
|
|
48
|
+
const isTsExist = fs.existsSync(fileFullPathTs);
|
|
49
|
+
if (isTsExist) {
|
|
50
|
+
content = fs.readFileSync(fileFullPathTs);
|
|
51
|
+
} else {
|
|
52
|
+
throw new Error('no src/configs/subApp.(js|ts) file found');
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const fileStr = content.toString();
|
|
58
|
+
const strList = fileStr.split(os.EOL);
|
|
59
|
+
for (const item of strList) {
|
|
60
|
+
// export const HEL_APP_GROUP_NAME = 'your-app';
|
|
61
|
+
// or
|
|
62
|
+
// export const LIB_NAME = 'your-app';
|
|
63
|
+
if (item.includes('export') && item.includes('const') && (item.includes('LIB_NAME') || item.includes('HEL_APP_GROUP_NAME'))) {
|
|
64
|
+
const noBlankStr = item.replace(/ /gi, '');
|
|
65
|
+
let [, appNameStr] = noBlankStr.split('=');
|
|
66
|
+
appNameStr = appNameStr.replace(/'/gi, '');
|
|
67
|
+
appNameStr = appNameStr.replace(/"/gi, '');
|
|
68
|
+
appNameStr = appNameStr.replace(/;/gi, '');
|
|
69
|
+
appNameStr = appNameStr.replace(/\r/gi, '');
|
|
70
|
+
appNameStr = appNameStr.replace(/\n/gi, '');
|
|
71
|
+
srcAppGroupName = appNameStr;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!srcAppGroupName) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
pfstr(`
|
|
78
|
+
HEL_APP_GROUP_NAME or LIB_NAME not found in src/configs/subApp.(js|ts) file,
|
|
79
|
+
your should expose it like below:
|
|
80
|
+
export const HEL_APP_GROUP_NAME = 'your-app';
|
|
81
|
+
or
|
|
82
|
+
export const LIB_NAME = 'your-app';
|
|
83
|
+
`),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const pgkAppGroupName = pkg.appGroupName || pkg.name;
|
|
88
|
+
if (pgkAppGroupName !== srcAppGroupName) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`package.json name [${pgkAppGroupName}] should be equal to src/configs/subApp LIB_NAME(or HEL_APP_GROUP_NAME) [${srcAppGroupName}]`,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (checkEnv) {
|
|
95
|
+
// 以下常量由 ci&cd 系统注入(通常由流水线变量或 bash 脚本注入)
|
|
96
|
+
const { HEL_APP_GROUP_NAME } = process.env;
|
|
97
|
+
|
|
98
|
+
if (pgkAppGroupName !== HEL_APP_GROUP_NAME) {
|
|
99
|
+
throw new Error(`package.json name [${pgkAppGroupName}] should be equal to pipeline var HEL_APP_GROUP_NAME [${HEL_APP_GROUP_NAME}]`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
package/src/configs/consts.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @type {{
|
|
3
|
-
* ARK_DIST_DIR: 'ark_dist',
|
|
4
|
-
* ARK_PROXY_DIR: 'ark_proxy',
|
|
5
|
-
* HEL_BUNDLE_DIR: 'ark_bundle',
|
|
6
|
-
* DEFAULT_GUESS_SUB_APP_CONF_PATH:string,
|
|
7
|
-
* DEFAULT_PLAT: 'unpkg',
|
|
8
|
-
* DEFAULT_NPM_CDN_TYPE: 'unpkg',
|
|
9
|
-
* DEFAULT_SEMVER_API: true,
|
|
10
|
-
* DEFAULT_HTML_INDEX_NAME: 'index.html',
|
|
11
|
-
* PLUGIN_VER:string,
|
|
12
|
-
* }}
|
|
13
|
-
*/
|
|
14
|
-
export default {
|
|
15
|
-
ARK_DIST_DIR: 'ark_dist',
|
|
16
|
-
ARK_PROXY_DIR: 'ark_proxy',
|
|
17
|
-
HEL_BUNDLE_DIR: 'ark_bundle',
|
|
18
|
-
DEFAULT_GUESS_SUB_APP_CONF_PATH: '../../../src/configs/subApp',
|
|
19
|
-
DEFAULT_PLAT: 'unpkg',
|
|
20
|
-
DEFAULT_NPM_CDN_TYPE: 'unpkg',
|
|
21
|
-
DEFAULT_HTML_INDEX_NAME: 'index.html',
|
|
22
|
-
DEFAULT_SEMVER_API: true,
|
|
23
|
-
PLUGIN_VER: '4.3.20',
|
|
24
|
-
};
|
|
1
|
+
/**
|
|
2
|
+
* @type {{
|
|
3
|
+
* ARK_DIST_DIR: 'ark_dist',
|
|
4
|
+
* ARK_PROXY_DIR: 'ark_proxy',
|
|
5
|
+
* HEL_BUNDLE_DIR: 'ark_bundle',
|
|
6
|
+
* DEFAULT_GUESS_SUB_APP_CONF_PATH:string,
|
|
7
|
+
* DEFAULT_PLAT: 'unpkg',
|
|
8
|
+
* DEFAULT_NPM_CDN_TYPE: 'unpkg',
|
|
9
|
+
* DEFAULT_SEMVER_API: true,
|
|
10
|
+
* DEFAULT_HTML_INDEX_NAME: 'index.html',
|
|
11
|
+
* PLUGIN_VER:string,
|
|
12
|
+
* }}
|
|
13
|
+
*/
|
|
14
|
+
export default {
|
|
15
|
+
ARK_DIST_DIR: 'ark_dist',
|
|
16
|
+
ARK_PROXY_DIR: 'ark_proxy',
|
|
17
|
+
HEL_BUNDLE_DIR: 'ark_bundle',
|
|
18
|
+
DEFAULT_GUESS_SUB_APP_CONF_PATH: '../../../src/configs/subApp',
|
|
19
|
+
DEFAULT_PLAT: 'unpkg',
|
|
20
|
+
DEFAULT_NPM_CDN_TYPE: 'unpkg',
|
|
21
|
+
DEFAULT_HTML_INDEX_NAME: 'index.html',
|
|
22
|
+
DEFAULT_SEMVER_API: true,
|
|
23
|
+
PLUGIN_VER: '4.3.20',
|
|
24
|
+
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
|
|
3
|
-
vue: 'Vue',
|
|
4
|
-
axios: 'axios',
|
|
5
|
-
// vuex: 'Vuex',
|
|
6
|
-
// 'vue-dim'
|
|
7
|
-
pinia: 'Pinia',
|
|
8
|
-
'pinia-plugin-persistedstate': 'piniaPluginPersistedstate',
|
|
9
|
-
'vue-i18n': 'VueI18n',
|
|
10
|
-
'vue-router': 'VueRouter',
|
|
11
|
-
'element-plus': 'ElementPlus',
|
|
12
|
-
'@arkxio/ark-micro-core': 'ArkMicroCore',
|
|
13
|
-
'@arkxio/ark-lib-proxy': 'ArkLibProxy',
|
|
14
|
-
'@arkxio/ark-micro': 'ArkMicro',
|
|
15
|
-
'@arkxio/ark-plugin': 'ArkPlugin'
|
|
16
|
-
// 'echarts': 'echarts',
|
|
17
|
-
// 'tinymce': 'tinymce'
|
|
18
|
-
// "loadjs": { //将vue依赖 "外部化",不打包进组件库
|
|
19
|
-
// root: 'loadjs',
|
|
20
|
-
// commonjs: 'loadjs',
|
|
21
|
-
// commonjs2: 'loadjs',
|
|
22
|
-
// amd: 'loadjs'
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
|
|
3
|
+
vue: 'Vue',
|
|
4
|
+
axios: 'axios',
|
|
5
|
+
// vuex: 'Vuex',
|
|
6
|
+
// 'vue-dim'
|
|
7
|
+
pinia: 'Pinia',
|
|
8
|
+
'pinia-plugin-persistedstate': 'piniaPluginPersistedstate',
|
|
9
|
+
'vue-i18n': 'VueI18n',
|
|
10
|
+
'vue-router': 'VueRouter',
|
|
11
|
+
'element-plus': 'ElementPlus',
|
|
12
|
+
'@arkxio/ark-micro-core': 'ArkMicroCore',
|
|
13
|
+
'@arkxio/ark-lib-proxy': 'ArkLibProxy',
|
|
14
|
+
'@arkxio/ark-micro': 'ArkMicro',
|
|
15
|
+
'@arkxio/ark-plugin': 'ArkPlugin'
|
|
16
|
+
// 'echarts': 'echarts',
|
|
17
|
+
// 'tinymce': 'tinymce'
|
|
18
|
+
// "loadjs": { //将vue依赖 "外部化",不打包进组件库
|
|
19
|
+
// root: 'loadjs',
|
|
20
|
+
// commonjs: 'loadjs',
|
|
21
|
+
// commonjs2: 'loadjs',
|
|
22
|
+
// amd: 'loadjs'
|
|
23
|
+
// }
|
|
24
|
+
|
|
25
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
react: {
|
|
3
|
-
react: 'React',
|
|
4
|
-
'react-dom': 'ReactDOM',
|
|
5
|
-
'react-is': 'ReactIs',
|
|
6
|
-
},
|
|
7
|
-
/** 历史原因,暂留 vue2 */
|
|
8
|
-
vue2: {
|
|
9
|
-
vue: 'Vue',
|
|
10
|
-
},
|
|
11
|
-
/** 历史原因,暂留 vue3 */
|
|
12
|
-
vue3: {
|
|
13
|
-
vue: 'Vue',
|
|
14
|
-
},
|
|
15
|
-
vue: {
|
|
16
|
-
vue: 'Vue',
|
|
17
|
-
},
|
|
18
|
-
};
|
|
1
|
+
export default {
|
|
2
|
+
react: {
|
|
3
|
+
react: 'React',
|
|
4
|
+
'react-dom': 'ReactDOM',
|
|
5
|
+
'react-is': 'ReactIs',
|
|
6
|
+
},
|
|
7
|
+
/** 历史原因,暂留 vue2 */
|
|
8
|
+
vue2: {
|
|
9
|
+
vue: 'Vue',
|
|
10
|
+
},
|
|
11
|
+
/** 历史原因,暂留 vue3 */
|
|
12
|
+
vue3: {
|
|
13
|
+
vue: 'Vue',
|
|
14
|
+
},
|
|
15
|
+
vue: {
|
|
16
|
+
vue: 'Vue',
|
|
17
|
+
},
|
|
18
|
+
};
|