akfun 5.1.1 → 5.1.3
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/module/akfunInit.js +0 -1
- package/module/main.js +4 -0
- package/package.json +5 -2
- package/src/config/rollup.config.js +2 -2
- package/src/dev-server.js +1 -1
- package/src/oss/aliBos.js +78 -0
- package/src/oss/baiduBos.js +87 -0
- package/src/utils/catchProcessParam.js +0 -1
- package/src/utils/deepMergeConfig.js +1 -1
- package/src/utils/loadAsset.js +47 -0
package/module/akfunInit.js
CHANGED
|
@@ -6,7 +6,6 @@ const templateList = {
|
|
|
6
6
|
'react&ts': 'git@github.com:wibetter/akfun-react-ts-template.git',
|
|
7
7
|
'library': 'git@github.com:wibetter/json-utils.git',
|
|
8
8
|
'json-editor': 'git@github.com:wibetter/json-editor.git',
|
|
9
|
-
'json-schema-editor': 'git@github.com:wibetter/json-schema-editor.git',
|
|
10
9
|
'pigNews': 'git@github.com:wibetter/pigNews.git',
|
|
11
10
|
};
|
|
12
11
|
|
package/module/main.js
CHANGED
|
@@ -9,6 +9,8 @@ const {resolve} = require('../src/utils/pathUtils');
|
|
|
9
9
|
const getConfigObj = require('../src/utils/getConfigObj');
|
|
10
10
|
const deepMergeConfig = require('../src/utils/deepMergeConfig');
|
|
11
11
|
const getCurWebpackConfig = require('../src/utils/getCurWebpackConfig.js'); // 用于获取当前webpack配置的方法
|
|
12
|
+
const aliBOS = require('../src/oss/aliBos.js');
|
|
13
|
+
const baiduBOS = require('../src/oss/baiduBos.js');
|
|
12
14
|
|
|
13
15
|
module.exports = {
|
|
14
16
|
dev: devAction,
|
|
@@ -22,4 +24,6 @@ module.exports = {
|
|
|
22
24
|
deepMergeConfig,
|
|
23
25
|
getCurWebpackConfig,
|
|
24
26
|
curWebpackBaseConfPath: getCurWebpackConfig('base'),
|
|
27
|
+
aliBOS,
|
|
28
|
+
baiduBOS
|
|
25
29
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "akfun",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "前端脚手架:支持Vue技术栈和react技术栈",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"前端工程",
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
"html-webpack-plugin": "^5.5.0",
|
|
117
117
|
"http-proxy-middleware": "^2.0.2",
|
|
118
118
|
"inquirer": "^8.2.0",
|
|
119
|
+
"rollup-plugin-jsx": "^1.0.3",
|
|
119
120
|
"mini-css-extract-plugin": "^2.5.3",
|
|
120
121
|
"open": "^8.4.0",
|
|
121
122
|
"ora": "^4.0.4",
|
|
@@ -162,7 +163,9 @@
|
|
|
162
163
|
"webpack-hot-middleware": "^2.25.1",
|
|
163
164
|
"webpack-merge": "^5.8.0",
|
|
164
165
|
"webpack-node-externals": "^3.0.0",
|
|
165
|
-
"yargs": "^12.0.5"
|
|
166
|
+
"yargs": "^12.0.5",
|
|
167
|
+
"@baiducloud/sdk": "^1.0.7",
|
|
168
|
+
"ali-oss": "^6.17.0"
|
|
166
169
|
},
|
|
167
170
|
"devDependencies": {
|
|
168
171
|
"@commitlint/cli": "^16.1.0",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// rollup.config.js
|
|
2
2
|
const { babel } = require('@rollup/plugin-babel');
|
|
3
3
|
const { nodeResolve } = require('@rollup/plugin-node-resolve'); // 支持node中的文件导入
|
|
4
|
-
|
|
4
|
+
const jsx = require('rollup-plugin-jsx'); // 用于处理jsx
|
|
5
5
|
const typescript = require('@rollup/plugin-typescript'); // 支持ts
|
|
6
6
|
const commonjs = require('@rollup/plugin-commonjs'); // 识别cmd模块
|
|
7
7
|
const vue = require('rollup-plugin-vue');
|
|
@@ -74,7 +74,7 @@ module.exports = function (fileName, akfunConfig) {
|
|
|
74
74
|
buildType === 'ts' ? typescript() : undefined,
|
|
75
75
|
babel(babelConfig), // 备注,需要先babel()再commjs()
|
|
76
76
|
// jsx( {factory: 'React.createElement'} ),
|
|
77
|
-
buildType === 'ts' ? jsx(
|
|
77
|
+
buildType === 'ts' ? undefined : jsx({ factory: 'React.createElement' }),
|
|
78
78
|
vue(),
|
|
79
79
|
commonjs(),
|
|
80
80
|
postcss({
|
package/src/dev-server.js
CHANGED
|
@@ -50,7 +50,7 @@ module.exports = function (akfunConfig, _consoleTag) {
|
|
|
50
50
|
// 获取开发环境的webpack基本配置
|
|
51
51
|
const webpackConfig = getDevWebpackConfig(config);
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
// Define HTTP proxies to your custom API backend
|
|
54
54
|
// https://github.com/chimurai/http-proxy-middleware
|
|
55
55
|
// 使用 config.dev.proxyTable 的配置作为 proxyTable 的代理配置
|
|
56
56
|
// 备注:需放connect-history-api-fallback前面,避免get请求的代理失效
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 百度智能云 BOS 存储对接
|
|
3
|
+
*/
|
|
4
|
+
const BosClient = require('ali-oss');
|
|
5
|
+
|
|
6
|
+
class aliBOS {
|
|
7
|
+
constructor(endpoint, region, bucket, accessKeyId, accessKeySecret) {
|
|
8
|
+
this.endpoint = endpoint;
|
|
9
|
+
this.region = region;
|
|
10
|
+
this.bucket = bucket;
|
|
11
|
+
this.accessKeyId = accessKeyId;
|
|
12
|
+
this.accessKeySecret = accessKeySecret;
|
|
13
|
+
|
|
14
|
+
this.client = new BosClient({
|
|
15
|
+
endpoint: this.endpoint,
|
|
16
|
+
// region: this.region,
|
|
17
|
+
accessKeyId: this.accessKeyId,
|
|
18
|
+
accessKeySecret: this.accessKeySecret,
|
|
19
|
+
bucket: this.bucket
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
normalizeKey(objectKey) {
|
|
24
|
+
return objectKey.replace(/^\//, '').split('?')[0];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async exists(_objectKey) {
|
|
28
|
+
try {
|
|
29
|
+
const objectKey = this.normalizeKey(_objectKey);
|
|
30
|
+
await this.client.head(objectKey);
|
|
31
|
+
return true;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async get(_objectKey) {
|
|
38
|
+
try {
|
|
39
|
+
const objectKey = this.normalizeKey(_objectKey);
|
|
40
|
+
const result = await this.client.get(objectKey);
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
headers: result.res.headers,
|
|
44
|
+
body: result.content, // 文件内容
|
|
45
|
+
url: result.res.requestUrls[0] // 文件访问地址
|
|
46
|
+
};
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 上传文件
|
|
54
|
+
* @param {*} fileKey 文件名(对象存储中的路径和文件名)
|
|
55
|
+
* @param {*} filepath 文件的本地路径
|
|
56
|
+
*/
|
|
57
|
+
async upload(fileKey, filepath) {
|
|
58
|
+
const result = await this.client.put(fileKey, filepath);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getPublicResourceUrl(key) {
|
|
63
|
+
let host = this.endpoint;
|
|
64
|
+
let protocol = 'https:'; // 默认使用https协议
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const url = new URL(this.endpoint);
|
|
68
|
+
host = url.host;
|
|
69
|
+
protocol = url.protocol;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
console.error('无效的 endpoint:', error);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return `${protocol}//${this.bucket}.${host}/${key}`;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
module.exports = aliBOS;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 百度智能云 BOS 存储对接
|
|
3
|
+
*/
|
|
4
|
+
const { BosClient } = require('@baiducloud/sdk');
|
|
5
|
+
|
|
6
|
+
class baiduBOS {
|
|
7
|
+
constructor(endpoint, bucket, ak, sk) {
|
|
8
|
+
this.endpoint = endpoint;
|
|
9
|
+
this.bucket = bucket;
|
|
10
|
+
this.ak = ak;
|
|
11
|
+
this.sk = sk;
|
|
12
|
+
|
|
13
|
+
this.client = new BosClient({
|
|
14
|
+
endpoint: endpoint,
|
|
15
|
+
credentials: {
|
|
16
|
+
ak,
|
|
17
|
+
sk
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
normalizeKey(key) {
|
|
23
|
+
return key.replace(/^\//, '').split('?')[0];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async exists(key) {
|
|
27
|
+
try {
|
|
28
|
+
key = this.normalizeKey(key);
|
|
29
|
+
await this.client.getObjectMetadata(this.bucket, key);
|
|
30
|
+
return true;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async get(_objectKey) {
|
|
37
|
+
try {
|
|
38
|
+
const objectKey = this.normalizeKey(_objectKey);
|
|
39
|
+
const result = await this.client.getObject(this.bucket, objectKey);
|
|
40
|
+
let host = this.endpoint;
|
|
41
|
+
let protocol = 'https:'; // 默认使用https协议
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const url = new URL(this.endpoint);
|
|
45
|
+
host = url.host;
|
|
46
|
+
protocol = url.protocol;
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('无效的 endpoint:', error);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
headers: result.http_headers,
|
|
53
|
+
body: result.body,
|
|
54
|
+
url: `${protocol}//${this.bucket}.${host}/${objectKey}`
|
|
55
|
+
};
|
|
56
|
+
} catch (e) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 上传文件
|
|
63
|
+
* @param {*} fileKey 文件名(对象存储中的路径和文件名)
|
|
64
|
+
* @param {*} filepath 文件的本地路径
|
|
65
|
+
*/
|
|
66
|
+
async upload(fileKey, filepath) {
|
|
67
|
+
const result = await this.client.putObjectFromFile(this.bucket, fileKey, filepath);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
getPublicResourceUrl(key) {
|
|
72
|
+
let host = this.endpoint;
|
|
73
|
+
let protocol = 'https:'; // 默认使用https协议
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const url = new URL(this.endpoint);
|
|
77
|
+
host = url.host;
|
|
78
|
+
protocol = url.protocol;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.error('无效的 endpoint:', error);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return `${protocol}//${this.bucket}.${host}/${key}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = baiduBOS;
|
|
@@ -2,7 +2,7 @@ const deepMerge = require('deepmerge');
|
|
|
2
2
|
|
|
3
3
|
const deepMergeConfig = function (defaultConfig, curConfig) {
|
|
4
4
|
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray;
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
return deepMerge(defaultConfig, curConfig, { arrayMerge: overwriteMerge });
|
|
7
7
|
};
|
|
8
8
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// 空函数
|
|
2
|
+
export function noop() {}
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 加载远程 JS脚本
|
|
6
|
+
* @param JsSrc: js脚本地址
|
|
7
|
+
* @param callback
|
|
8
|
+
*/
|
|
9
|
+
export function loadRemoteJs(JsSrc, callback) {
|
|
10
|
+
const curCallback = callback || noop;
|
|
11
|
+
if (document.querySelector(`script[src='${JsSrc}']`)) {
|
|
12
|
+
curCallback();
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const script = document.createElement('script');
|
|
17
|
+
|
|
18
|
+
const loadAction = () => {
|
|
19
|
+
script.removeEventListener('load', loadAction);
|
|
20
|
+
curCallback();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
script.addEventListener('load', loadAction);
|
|
24
|
+
script.src = JsSrc;
|
|
25
|
+
document.body.appendChild(script);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 加载远程 CSS
|
|
30
|
+
* @param cssSrc: css地址
|
|
31
|
+
* @param callback
|
|
32
|
+
*/
|
|
33
|
+
export function loadRemoteCSS(cssSrc) {
|
|
34
|
+
const loadedLink = document.querySelector(`link[href='${cssSrc}']`);
|
|
35
|
+
if (loadedLink) {
|
|
36
|
+
// 避免重复加载
|
|
37
|
+
loadedLink.disabled = false;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const head = document.getElementsByTagName('head')[0];
|
|
42
|
+
const link = document.createElement('link');
|
|
43
|
+
link.rel = 'stylesheet';
|
|
44
|
+
link.type = 'text/css';
|
|
45
|
+
link.href = src;
|
|
46
|
+
head.appendChild(link);
|
|
47
|
+
}
|