@be-link/cos 1.11.4 → 1.12.0-beta.0
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 +420 -5
- package/dist/beLinkCos.d.ts +162 -2
- package/dist/beLinkCos.d.ts.map +1 -0
- package/dist/config.d.ts +26 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/index.cjs.js +407 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +403 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +39 -37
- package/bin/cos.js +0 -9
- package/dist/index.js +0 -1
- package/lib/config.js +0 -19
- package/lib/upload.js +0 -134
package/lib/config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
const BUCKETS_CONFIG = {
|
|
2
|
-
development: {
|
|
3
|
-
name: 'dev-1304510571',
|
|
4
|
-
host: 'dev-1304510571.cos.ap-nanjing.myqcloud.com',
|
|
5
|
-
protocol: 'https',
|
|
6
|
-
},
|
|
7
|
-
trial: {
|
|
8
|
-
name: 'dev-1304510571',
|
|
9
|
-
host: 'dev-1304510571.cos.ap-nanjing.myqcloud.com',
|
|
10
|
-
protocol: 'https',
|
|
11
|
-
},
|
|
12
|
-
production: {
|
|
13
|
-
name: 'release-1304510571',
|
|
14
|
-
host: 'release-1304510571.file.myqcloud.com',
|
|
15
|
-
protocol: 'https',
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
module.exports = BUCKETS_CONFIG
|
package/lib/upload.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
const fs = require('fs')
|
|
3
|
-
const path = require('path')
|
|
4
|
-
const COS = require('cos-nodejs-sdk-v5')
|
|
5
|
-
const BUCKETS_CONFIG = require('./config')
|
|
6
|
-
|
|
7
|
-
const argv = process.argv.slice(2)
|
|
8
|
-
const [mode] = argv
|
|
9
|
-
console.log('mode', mode)
|
|
10
|
-
|
|
11
|
-
// 获取项目名称
|
|
12
|
-
const baseUrl = mode === 'production' ? 'project/prod/' : 'project/dev/'
|
|
13
|
-
const packageUrl = path.resolve(process.cwd(), './package.json')
|
|
14
|
-
const projectPackage = fs.readFileSync(packageUrl, { encoding: 'utf-8' })
|
|
15
|
-
const projectName = JSON.parse(projectPackage).name
|
|
16
|
-
const projectRemoteUrl = baseUrl + projectName
|
|
17
|
-
|
|
18
|
-
// 构建参数输出的地址
|
|
19
|
-
const distDirUrl = process.cwd() + '/dist'
|
|
20
|
-
|
|
21
|
-
// 创建一个 cos
|
|
22
|
-
const cos = new COS({
|
|
23
|
-
SecretId: 'AKIDx3wfJo5e4FAqHSOJ5cu2y3zh9MK2Uhy6',
|
|
24
|
-
SecretKey: '3sgW7V7W1PZWIqAKI8krpY3JL9j5C3e1',
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
function upload(url, filename) {
|
|
28
|
-
if (!url) return
|
|
29
|
-
if (!filename) return
|
|
30
|
-
cos.putObject(
|
|
31
|
-
{
|
|
32
|
-
Bucket: BUCKETS_CONFIG[mode || 'development'].name,
|
|
33
|
-
Region: 'ap-nanjing',
|
|
34
|
-
Key: projectRemoteUrl + filename /* 必须 */,
|
|
35
|
-
StorageClass: 'STANDARD',
|
|
36
|
-
Body: fs.createReadStream(url), // 上传文件对象
|
|
37
|
-
onProgress: function (progressData) {},
|
|
38
|
-
},
|
|
39
|
-
function (err, data) {
|
|
40
|
-
if (err) {
|
|
41
|
-
console.log('文件上传失败', err)
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function getAllFiles(directoryPath) {
|
|
48
|
-
const files = fs.readdirSync(directoryPath, { withFileTypes: true })
|
|
49
|
-
const fileNamesAndPaths = []
|
|
50
|
-
|
|
51
|
-
files.forEach((file) => {
|
|
52
|
-
const filePath = path.join(directoryPath, file.name)
|
|
53
|
-
|
|
54
|
-
if (file.isFile()) {
|
|
55
|
-
fileNamesAndPaths.push({
|
|
56
|
-
fileName: file.name,
|
|
57
|
-
filePath: filePath,
|
|
58
|
-
})
|
|
59
|
-
} else if (file.isDirectory()) {
|
|
60
|
-
const subDirectoryFiles = getAllFiles(filePath)
|
|
61
|
-
fileNamesAndPaths.push(...subDirectoryFiles)
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
return fileNamesAndPaths
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getBucket() {
|
|
69
|
-
return new Promise((resolve, reject) => {
|
|
70
|
-
cos.getBucket(
|
|
71
|
-
{
|
|
72
|
-
Bucket: BUCKETS_CONFIG[mode || 'development'].name,
|
|
73
|
-
Region: 'ap-nanjing',
|
|
74
|
-
Prefix: 'project/dev/manager' /* 非必须 */,
|
|
75
|
-
},
|
|
76
|
-
function (err, data) {
|
|
77
|
-
console.log(err || data.Contents)
|
|
78
|
-
},
|
|
79
|
-
)
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 删除
|
|
84
|
-
function deleteProject() {
|
|
85
|
-
return new Promise((resolve, reject) => {
|
|
86
|
-
cos.deleteObject(
|
|
87
|
-
{
|
|
88
|
-
Bucket: BUCKETS_CONFIG[mode || 'development'].name,
|
|
89
|
-
Region: 'ap-nanjing',
|
|
90
|
-
Key: projectRemoteUrl /* 必须 */,
|
|
91
|
-
},
|
|
92
|
-
function (err, data) {
|
|
93
|
-
if (err) {
|
|
94
|
-
console.log('删除失败')
|
|
95
|
-
reject(err)
|
|
96
|
-
}
|
|
97
|
-
if (data) {
|
|
98
|
-
console.log('删除成功')
|
|
99
|
-
resolve(data)
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
)
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 全量
|
|
107
|
-
// 获取文件列表
|
|
108
|
-
|
|
109
|
-
// 删除cos中的文件
|
|
110
|
-
|
|
111
|
-
// 上传文件列表
|
|
112
|
-
|
|
113
|
-
// 增量
|
|
114
|
-
// 获取远程的文件列表
|
|
115
|
-
// 获取本地的文件列表
|
|
116
|
-
// 将远程的文件列表和本地的文件列表进行对比获取 diff 的文件
|
|
117
|
-
// 删除远程不再需要的文件
|
|
118
|
-
// 上传新的文件
|
|
119
|
-
|
|
120
|
-
function staticUploadToCos() {
|
|
121
|
-
console.log('资源上传至:https://release-1304510571.file.myqcloud.com/' + projectRemoteUrl)
|
|
122
|
-
const files = getAllFiles(distDirUrl)
|
|
123
|
-
deleteProject().then(() => {
|
|
124
|
-
files.forEach((file) => {
|
|
125
|
-
// 获取文件名称
|
|
126
|
-
const filename = file.filePath.replace(distDirUrl, '')
|
|
127
|
-
upload(file.filePath, filename)
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
module.exports = {
|
|
133
|
-
staticUploadToCos,
|
|
134
|
-
}
|