Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GraceTemplate
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
front-end
GraceTemplate
Commits
f4e40510
Commit
f4e40510
authored
Sep 03, 2024
by
haiyoucuv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
更改
parent
5fb81cc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
199 additions
and
3 deletions
+199
-3
package.json
package.json
+2
-2
DuibaPublish.ts
plugins/DuibaPublish/DuibaPublish.ts
+42
-0
Uploader.ts
plugins/Uploader/Uploader.ts
+137
-0
vite.config.ts
vite.config.ts
+18
-1
No files found.
package.json
View file @
f4e40510
{
{
"name"
:
"
my-vue-app
"
,
"name"
:
"
spark_template
"
,
"private"
:
true
,
"private"
:
true
,
"version"
:
"0.0.
0
"
,
"version"
:
"0.0.
1
"
,
"type"
:
"module"
,
"type"
:
"module"
,
"scripts"
:
{
"scripts"
:
{
"dev"
:
"vite"
,
"dev"
:
"vite"
,
...
...
plugins/DuibaPublish/DuibaPublish.ts
0 → 100644
View file @
f4e40510
import
chalk
from
"chalk"
;
import
AutoUpload
from
"../Uploader/Uploader.ts"
;
import
*
as
path
from
"path"
;
interface
IDuibaPublishOptions
{
buildVersion
:
string
|
number
,
uploadDir
:
string
,
accessKeySecret
:
string
,
accessKeyId
:
string
,
bucket
:
string
,
region
:
string
,
}
export
default
function
DuibaPublish
(
options
:
IDuibaPublishOptions
)
{
const
{
buildVersion
,
uploadDir
,
accessKeySecret
,
accessKeyId
,
bucket
,
region
,
}
=
options
;
return
{
name
:
'duiba-publish'
,
async
closeBundle
()
{
const
autoUpload
=
new
AutoUpload
({
dir
:
path
.
resolve
(
"dist"
),
originDir
:
`/
${
uploadDir
}
/`
,
accessKeySecret
,
accessKeyId
,
bucket
,
region
,
});
await
autoUpload
.
start
();
console
.
log
(
`
${
chalk
.
green
(
`上传成功:
${
buildVersion
}
`
)}
`
);
}
}
}
plugins/Uploader/Uploader.ts
0 → 100644
View file @
f4e40510
import
*
as
path
from
"path"
;
import
*
as
fs
from
"fs"
;
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
:
IAutoUploadOptions
=
{
dir
:
""
,
originDir
:
""
,
region
:
"oss-cn-hangzhou"
,
accessKeyId
:
""
,
accessKeySecret
:
""
,
bucket
:
""
};
client
=
null
;
bar
=
null
;
private
_files
:
any
[];
private
existFiles
:
number
=
0
;
private
uploadFiles
:
number
=
0
;
private
errorFiles
:
number
=
0
;
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
()
{
const
{
accessKeyId
,
accessKeySecret
,
bucket
,
region
}
=
this
.
options
;
this
.
client
=
new
OSS
({
region
,
accessKeyId
,
accessKeySecret
,
bucket
});
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
ps
=
this
.
files
().
map
((
file
)
=>
{
const
relativePath
=
path
.
relative
(
this
.
options
.
dir
,
file
)
.
replace
(
path
.
sep
,
"/"
);
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
:
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
);
});
}
}
vite.config.ts
View file @
f4e40510
...
@@ -5,12 +5,21 @@ import legacy from '@vitejs/plugin-legacy'
...
@@ -5,12 +5,21 @@ import legacy from '@vitejs/plugin-legacy'
import
autoprefixer
from
"autoprefixer"
import
autoprefixer
from
"autoprefixer"
import
postcsspxtorem
from
"postcss-pxtorem"
import
postcsspxtorem
from
"postcss-pxtorem"
import
{
viteMockServe
}
from
"vite-plugin-mock"
;
import
{
viteMockServe
}
from
"vite-plugin-mock"
;
import
DuibaPublish
from
"./plugins/DuibaPublish/DuibaPublish.ts"
;
const
isProd
=
process
.
env
.
NODE_ENV
==
"production"
;
const
isProd
=
process
.
env
.
NODE_ENV
==
"production"
;
const
versionStamp
=
Date
.
now
();
const
origin
=
"//yun.duiba.com.cn"
;
const
uploadDir
=
`db_games/spark_template/
${
versionStamp
}
`
;
const
prodBase
=
`
${
origin
}
/
${
uploadDir
}
/`
;
// https://vitejs.dev/config/
// https://vitejs.dev/config/
export
default
defineConfig
({
export
default
defineConfig
({
base
:
isProd
?
'//yun.duiba.com.cn/db_games/qx/testSparkVite/'
:
""
,
base
:
isProd
?
prodBase
:
""
,
plugins
:
[
plugins
:
[
react
({
react
({
babel
:
{
babel
:
{
...
@@ -28,6 +37,14 @@ export default defineConfig({
...
@@ -28,6 +37,14 @@ export default defineConfig({
mockPath
:
'mock'
,
mockPath
:
'mock'
,
enable
:
true
,
enable
:
true
,
}),
}),
isProd
&&
DuibaPublish
({
buildVersion
:
versionStamp
,
uploadDir
:
uploadDir
,
region
:
"oss-cn-hangzhou"
,
bucket
:
"duiba-credits-test"
,
accessKeyId
:
"LTAI5tPUSSxgkEmKPAfVXUQQ"
,
accessKeySecret
:
"6sk3EDd1BYrXlAUoh8maMuN7hOMkh1"
,
}),
],
],
css
:
{
css
:
{
postcss
:
{
postcss
:
{
...
...
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