Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
TNGD_CaveCruiser
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
SparkProjects
TNGD_CaveCruiser
Commits
072d12ca
Commit
072d12ca
authored
Aug 29, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传
parent
0f46763d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
266 additions
and
140 deletions
+266
-140
builder.js
extensions/duiba-publish/dist/builder.js
+51
-0
hooks.js
extensions/duiba-publish/dist/hooks.js
+4
-2
upload.js
extensions/duiba-publish/dist/upload.js
+16
-9
builder.ts
extensions/duiba-publish/source/builder.ts
+51
-0
hooks.ts
extensions/duiba-publish/source/hooks.ts
+10
-12
upload.ts
extensions/duiba-publish/source/upload.ts
+134
-117
No files found.
extensions/duiba-publish/dist/builder.js
View file @
072d12ca
...
...
@@ -27,6 +27,57 @@ exports.configs = {
},
verifyRules
:
[
'required'
]
},
bucket
:
{
label
:
'bucket'
,
description
:
'bucket'
,
default
:
'duiba-credits-test'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
placeholder
:
'bucket'
,
},
},
verifyRules
:
[
'required'
]
},
accessKeyId
:
{
label
:
'accessKeyId'
,
description
:
'accessKeyId'
,
default
:
'LTAI5tFiyBroYqzgu6d6E3Sz'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
password
:
true
,
placeholder
:
'accessKeyId'
,
},
},
verifyRules
:
[
'required'
]
},
accessKeySecret
:
{
label
:
'accessKeySecret'
,
description
:
'accessKeySecret'
,
default
:
'aEpPaVnxnicK6iwzcJTUpzGhCghSt0'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
password
:
true
,
placeholder
:
'accessKeySecret'
,
},
},
verifyRules
:
[
'required'
]
},
region
:
{
label
:
'region'
,
description
:
'region'
,
default
:
'oss-cn-hangzhou'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
password
:
true
,
placeholder
:
'region'
,
},
},
verifyRules
:
[
'required'
]
},
},
},
};
extensions/duiba-publish/dist/hooks.js
View file @
072d12ca
...
...
@@ -42,7 +42,7 @@ const load = async function () {
exports
.
load
=
load
;
let
buildVersion
=
0
;
function
getRemotePath
(
uploadDir
=
'template3d'
)
{
return
`/
TNGD_GAMES/
${
uploadDir
}
/
${
buildVersion
}
/`
;
return
`/
${
uploadDir
}
/
${
buildVersion
}
/`
;
}
function
getRemoteUrl
(
uploadDir
=
'template3d'
)
{
// return `https://yun.duiba.com.cn${getRemotePath(uploadDir)}`;
...
...
@@ -150,9 +150,11 @@ const onAfterBuild = async function (options, result) {
/*************************** 生成皮肤模版 ***************************/
/*************************** 打包完成,开始上传 ***************************/
console
.
log
(
"%c兑吧发布插件 >> 打包完成,开始上传"
,
"color: green"
);
const
{
uploadDir
,
accessKeySecret
,
accessKeyId
,
bucket
,
region
}
=
options
.
packages
[
PACKAGE_NAME
];
const
autoUpload
=
new
upload_1
.
default
({
dir
:
result
.
dest
,
originDir
:
getRemotePath
(
options
.
packages
[
PACKAGE_NAME
].
uploadDir
),
originDir
:
getRemotePath
(
uploadDir
),
accessKeySecret
,
accessKeyId
,
bucket
,
region
,
});
await
autoUpload
.
start
();
console
.
log
(
"%c兑吧发布插件 >> 上传完成"
,
"color: green"
);
...
...
extensions/duiba-publish/dist/upload.js
View file @
072d12ca
...
...
@@ -33,8 +33,12 @@ const progress_1 = __importDefault(require("progress"));
const
ali_oss_1
=
__importDefault
(
require
(
"ali-oss"
));
class
AutoUpload
{
options
=
{
dir
:
undefined
,
originDir
:
undefined
dir
:
""
,
originDir
:
""
,
region
:
"oss-cn-hangzhou"
,
accessKeyId
:
""
,
accessKeySecret
:
""
,
bucket
:
""
};
client
=
null
;
bar
=
null
;
...
...
@@ -43,13 +47,16 @@ class AutoUpload {
uploadFiles
=
0
;
errorFiles
=
0
;
constructor
(
props
)
{
const
defaultOptions
=
{
dir
:
undefined
,
originDir
:
undefined
};
this
.
options
=
Object
.
assign
({},
defaultOptions
,
props
);
if
(
!
this
.
options
.
dir
||
!
this
.
options
.
originDir
)
{
console
.
error
(
"缺少参数,初始化失败"
);
this
.
options
=
Object
.
assign
({},
this
.
options
,
props
);
const
checkOptions
=
[
"dir"
,
"originDir"
,
"bucket"
,
"region"
,
"accessKeySecret"
,
"accessKeyId"
,
];
for
(
const
optionKey
of
checkOptions
)
{
if
(
!
this
.
options
[
optionKey
])
{
throw
new
Error
(
`AutoUpload: required option "
${
optionKey
}
"`
);
}
}
this
.
init
();
}
...
...
extensions/duiba-publish/source/builder.ts
View file @
072d12ca
...
...
@@ -27,6 +27,57 @@ export const configs: BuildPlugin.Configs = {
},
verifyRules
:
[
'required'
]
},
bucket
:
{
label
:
'bucket'
,
description
:
'bucket'
,
default
:
'duiba-credits-test'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
placeholder
:
'bucket'
,
},
},
verifyRules
:
[
'required'
]
},
accessKeyId
:
{
label
:
'accessKeyId'
,
description
:
'accessKeyId'
,
default
:
'LTAI5tFiyBroYqzgu6d6E3Sz'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
password
:
true
,
placeholder
:
'accessKeyId'
,
},
},
verifyRules
:
[
'required'
]
},
accessKeySecret
:
{
label
:
'accessKeySecret'
,
description
:
'accessKeySecret'
,
default
:
'aEpPaVnxnicK6iwzcJTUpzGhCghSt0'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
password
:
true
,
placeholder
:
'accessKeySecret'
,
},
},
verifyRules
:
[
'required'
]
},
region
:
{
label
:
'region'
,
description
:
'region'
,
default
:
'oss-cn-hangzhou'
,
render
:
{
ui
:
'ui-input'
,
attributes
:
{
password
:
true
,
placeholder
:
'region'
,
},
},
verifyRules
:
[
'required'
]
},
},
},
};
extensions/duiba-publish/source/hooks.ts
View file @
072d12ca
...
...
@@ -6,22 +6,18 @@ import { obfuscate } from "./obfuscator";
import
{
compressAllImage
}
from
"./minImg"
;
interface
IOptions
{
remoteAddress
:
string
;
enterCocos
:
string
;
selectTest
:
string
;
objectTest
:
{
number
:
number
;
string
:
string
;
boolean
:
boolean
},
arrayTest
:
[
number
,
string
,
boolean
];
uploadDir
:
string
;
bucket
:
string
;
accessKeyId
:
string
;
accessKeySecret
:
string
;
region
:
string
;
}
const
PACKAGE_NAME
=
'duiba-publish'
;
interface
ITaskOptions
extends
IBuildTaskOption
{
packages
:
{
'cocos-plugin-template'
:
IOptions
;
[
PACKAGE_NAME
]
:
IOptions
;
};
}
...
...
@@ -39,7 +35,7 @@ export const load: BuildHook.load = async function () {
let
buildVersion
=
0
;
function
getRemotePath
(
uploadDir
=
'template3d'
)
{
return
`/
TNGD_GAMES/
${
uploadDir
}
/
${
buildVersion
}
/`
;
return
`/
${
uploadDir
}
/
${
buildVersion
}
/`
;
}
function
getRemoteUrl
(
uploadDir
=
'template3d'
)
{
...
...
@@ -176,9 +172,11 @@ export const onAfterBuild: BuildHook.onAfterBuild = async function (options: ITa
/*************************** 打包完成,开始上传 ***************************/
console
.
log
(
"%c兑吧发布插件 >> 打包完成,开始上传"
,
"color: green"
);
const
{
uploadDir
,
accessKeySecret
,
accessKeyId
,
bucket
,
region
}
=
options
.
packages
[
PACKAGE_NAME
];
const
autoUpload
=
new
AutoUpload
({
dir
:
result
.
dest
,
originDir
:
getRemotePath
(
options
.
packages
[
PACKAGE_NAME
].
uploadDir
),
originDir
:
getRemotePath
(
uploadDir
),
accessKeySecret
,
accessKeyId
,
bucket
,
region
,
});
await
autoUpload
.
start
();
...
...
extensions/duiba-publish/source/upload.ts
View file @
072d12ca
...
...
@@ -4,10 +4,23 @@ import * as Os from "os";
import
ProgressBar
from
"progress"
;
import
OSS
from
"ali-oss"
;
interface
IAutoUploadOptions
{
dir
:
string
,
originDir
:
string
,
bucket
:
string
,
accessKeyId
:
string
,
accessKeySecret
:
string
,
region
:
string
,
}
export
default
class
AutoUpload
{
options
=
{
dir
:
undefined
,
originDir
:
undefined
options
:
IAutoUploadOptions
=
{
dir
:
""
,
originDir
:
""
,
region
:
"oss-cn-hangzhou"
,
accessKeyId
:
""
,
accessKeySecret
:
""
,
bucket
:
""
};
client
=
null
;
...
...
@@ -17,119 +30,123 @@ export default class AutoUpload {
private
uploadFiles
:
number
=
0
;
private
errorFiles
:
number
=
0
;
constructor
(
props
)
{
const
defaultOptions
=
{
dir
:
undefined
,
originDir
:
undefined
}
this
.
options
=
Object
.
assign
({},
defaultOptions
,
props
);
if
(
!
this
.
options
.
dir
||
!
this
.
options
.
originDir
)
{
console
.
error
(
"缺少参数,初始化失败"
);
}
this
.
init
();
}
init
()
{
this
.
client
=
new
OSS
({
region
:
"oss-cn-hangzhou"
,
accessKeyId
:
"LTAI5tFiyBroYqzgu6d6E3Sz"
,
accessKeySecret
:
"aEpPaVnxnicK6iwzcJTUpzGhCghSt0"
,
bucket
:
"duiba-credits-test"
,
});
this
.
bar
=
new
ProgressBar
(
`文件上传中 [:bar] :current/
${
this
.
files
().
length
}
:percent :elapseds`
,
{
complete
:
"●"
,
incomplete
:
"○"
,
width
:
20
,
total
:
this
.
files
().
length
,
callback
:
()
=>
{
console
.
log
(
"%cAll complete."
,
"color: green"
);
constructor
(
props
:
IAutoUploadOptions
)
{
this
.
options
=
Object
.
assign
({},
this
.
options
,
props
);
const
checkOptions
=
[
"dir"
,
"originDir"
,
"bucket"
,
"region"
,
"accessKeySecret"
,
"accessKeyId"
,
];
for
(
const
optionKey
of
checkOptions
)
{
if
(
!
this
.
options
[
optionKey
])
{
throw
new
Error
(
`AutoUpload: required option "
${
optionKey
}
"`
);
}
}
this
.
init
();
}
init
()
{
this
.
client
=
new
OSS
({
region
:
"oss-cn-hangzhou"
,
accessKeyId
:
"LTAI5tFiyBroYqzgu6d6E3Sz"
,
accessKeySecret
:
"aEpPaVnxnicK6iwzcJTUpzGhCghSt0"
,
bucket
:
"duiba-credits-test"
,
});
this
.
bar
=
new
ProgressBar
(
`文件上传中 [:bar] :current/
${
this
.
files
().
length
}
:percent :elapseds`
,
{
complete
:
"●"
,
incomplete
:
"○"
,
width
:
20
,
total
:
this
.
files
().
length
,
callback
:
()
=>
{
console
.
log
(
"%cAll complete."
,
"color: green"
);
console
.
log
(
`%c本次队列文件共
${
this
.
files
().
length
}
个,已存在文件
${
this
.
existFiles
}
个,上传文件
${
this
.
uploadFiles
}
个,上传失败文件
${
this
.
errorFiles
}
个`
,
"color: green"
);
}
})
return
this
;
}
files
()
{
if
(
this
.
_files
)
return
this
.
_files
;
this
.
_files
=
[];
/**
* 文件遍历方法
* @param filePath 需要遍历的文件路径
*/
const
fileDisplay
=
(
filePath
)
=>
{
//根据文件路径读取文件,返回文件列表
const
files
=
fs
.
readdirSync
(
filePath
);
files
.
forEach
((
filename
)
=>
{
//获取当前文件的绝对路径
const
fileDir
=
path
.
join
(
filePath
,
filename
);
//根据文件路径获取文件信息,返回一个fs.Stats对象
const
stats
=
fs
.
statSync
(
fileDir
);
const
isFile
=
stats
.
isFile
();
//是文件
const
isDir
=
stats
.
isDirectory
();
//是文件夹
if
(
isFile
)
{
this
.
_files
.
push
(
fileDir
);
}
else
if
(
isDir
)
{
fileDisplay
(
fileDir
);
//递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
});
}
//调用文件遍历方法
fileDisplay
(
this
.
options
.
dir
);
return
this
.
_files
;
}
async
start
()
{
const
platform
=
Os
.
platform
();
const
ps
=
this
.
files
().
map
((
file
)
=>
{
let
relativePath
=
""
;
if
(
platform
===
"win32"
)
{
console
.
log
(
"win平台"
)
relativePath
=
file
.
replace
(
this
.
options
.
dir
+
"
\
\"
, "");
relativePath = relativePath.replace(/
\\
/g, "
/
");
} else {
relativePath = file.replace(this.options.dir + "
/
", "");
}
this.existFiles = 0;
this.uploadFiles = 0;
this.errorFiles = 0;
const originPath = `${this.options.originDir}${relativePath}`;
return (async () => {
let originFile = null;
originFile = await this.client.head(originPath)
.catch((error) => originFile = error);
try {
if (originFile.status === 404) {
await this.client.put(originPath, file);
this.uploadFiles += 1;
} else {
this.existFiles += 1;
}
} catch (error) {
this.errorFiles += 1;
}
this.bar.tick();
})();
});
await Promise.all(ps).catch((err) => {
console.error("
上传错误
", err);
});
}
}
})
return
this
;
}
files
()
{
if
(
this
.
_files
)
return
this
.
_files
;
this
.
_files
=
[];
/**
* 文件遍历方法
* @param filePath 需要遍历的文件路径
*/
const
fileDisplay
=
(
filePath
)
=>
{
//根据文件路径读取文件,返回文件列表
const
files
=
fs
.
readdirSync
(
filePath
);
files
.
forEach
((
filename
)
=>
{
//获取当前文件的绝对路径
const
fileDir
=
path
.
join
(
filePath
,
filename
);
//根据文件路径获取文件信息,返回一个fs.Stats对象
const
stats
=
fs
.
statSync
(
fileDir
);
const
isFile
=
stats
.
isFile
();
//是文件
const
isDir
=
stats
.
isDirectory
();
//是文件夹
if
(
isFile
)
{
this
.
_files
.
push
(
fileDir
);
}
else
if
(
isDir
)
{
fileDisplay
(
fileDir
);
//递归,如果是文件夹,就继续遍历该文件夹下面的文件
}
});
}
//调用文件遍历方法
fileDisplay
(
this
.
options
.
dir
);
return
this
.
_files
;
}
async
start
()
{
const
platform
=
Os
.
platform
();
const
ps
=
this
.
files
().
map
((
file
)
=>
{
let
relativePath
=
""
;
if
(
platform
===
"win32"
)
{
console
.
log
(
"win平台"
)
relativePath
=
file
.
replace
(
this
.
options
.
dir
+
"
\
\"
, "");
relativePath = relativePath.replace(/
\\
/g, "
/
");
} else {
relativePath = file.replace(this.options.dir + "
/
", "");
}
this.existFiles = 0;
this.uploadFiles = 0;
this.errorFiles = 0;
const originPath = `${this.options.originDir}${relativePath}`;
return (async () => {
let originFile = null;
originFile = await this.client.head(originPath)
.catch((error) => originFile = error);
try {
if (originFile.status === 404) {
await this.client.put(originPath, file);
this.uploadFiles += 1;
} else {
this.existFiles += 1;
}
} catch (error) {
this.errorFiles += 1;
}
this.bar.tick();
})();
});
await Promise.all(ps).catch((err) => {
console.error("
上传错误
", err);
});
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment