akfun 5.1.1 → 5.1.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/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.1",
3
+ "version": "5.1.2",
4
4
  "description": "前端脚手架:支持Vue技术栈和react技术栈",
5
5
  "keywords": [
6
6
  "前端工程",
@@ -162,7 +162,9 @@
162
162
  "webpack-hot-middleware": "^2.25.1",
163
163
  "webpack-merge": "^5.8.0",
164
164
  "webpack-node-externals": "^3.0.0",
165
- "yargs": "^12.0.5"
165
+ "yargs": "^12.0.5",
166
+ "@baiducloud/sdk": "^1.0.7",
167
+ "ali-oss": "^6.17.0"
166
168
  },
167
169
  "devDependencies": {
168
170
  "@commitlint/cli": "^16.1.0",
@@ -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( {factory: 'React.createElement'} ) : undefined,
77
+ buildType === 'ts' ? jsx({ factory: 'React.createElement' }) : undefined,
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
- // Define HTTP proxies to your custom API backend
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;
@@ -1,7 +1,6 @@
1
1
  /*
2
2
  获取执行命令中的指定参数值
3
3
  */
4
-
5
4
  function catchProcessParam(paramKey) {
6
5
  const argv = process.argv;
7
6
  let paramVal = '';
@@ -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
+ }