Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
game-cli
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
game-cli
Commits
6968a4fe
Commit
6968a4fe
authored
Sep 19, 2018
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
game.json 改为 project.json
parent
88341b82
Changes
7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
973 additions
and
16 deletions
+973
-16
cli.js
bin/cli.js
+1
-0
game-cli-publish.js
bin/game-cli-publish.js
+2
-3
game-cli-upload.js
bin/game-cli-upload.js
+40
-0
index.js
bin/oss-upload/index.js
+80
-0
tools.js
bin/tools.js
+29
-12
package.json
package.json
+4
-1
yarn.lock
yarn.lock
+817
-0
No files found.
bin/cli.js
View file @
6968a4fe
...
...
@@ -10,4 +10,5 @@ program
.
command
(
'build'
,
'Build project'
).
alias
(
'b'
)
.
command
(
'dev'
,
'Build project automatic'
).
alias
(
'd'
)
.
command
(
'publish'
,
'Publish project'
).
alias
(
'p'
)
.
command
(
'upload'
,
'Upload project to oss'
).
alias
(
'u'
)
.
parse
(
process
.
argv
);
bin/game-cli-publish.js
View file @
6968a4fe
const
program
=
require
(
'commander'
);
const
{
exit
,
executeBuildProcess
}
=
require
(
'./tools'
);
const
{
exit
,
executeBuildProcess
,
updateProjectConfig
}
=
require
(
'./tools'
);
program
.
option
(
'-v, --version'
,
'Version of publish'
)
.
parse
(
process
.
argv
);
async
function
execute
()
{
const
version
=
await
executeBuildProcess
(
'publish'
);
console
.
log
(
version
);
updateProjectConfig
(
'version'
,
version
);
}
execute
().
catch
(
e
=>
{
...
...
bin/game-cli-upload.js
0 → 100755
View file @
6968a4fe
const
program
=
require
(
'commander'
);
const
{
exit
,
getProjectConfig
}
=
require
(
'./tools'
);
const
ossUpload
=
require
(
'./oss-upload'
);
program
.
option
(
'-v, --version-code [string]'
,
'Version to upload'
)
.
option
(
'-m, --mode [string]'
,
'prod or test'
,
'prod'
)
.
parse
(
process
.
argv
);
async
function
execute
()
{
let
remotePath
;
let
version
=
program
.
versionCode
;
const
gameProjectConfig
=
getProjectConfig
();
if
(
gameProjectConfig
){
remotePath
=
gameProjectConfig
[
'remote-path'
];
version
=
version
?
version
:
gameProjectConfig
[
'version'
];
}
if
(
version
){
if
(
remotePath
){
try
{
await
ossUpload
({
localDir
:
'./bin-release/web/'
+
version
,
remoteDir
:
`/db_games/
${
remotePath
}
/
${
version
}
`
},
program
.
mode
);
}
catch
(
e
)
{
exit
(
e
.
message
,
3
)
}
}
else
{
exit
(
'remote-path setting is not exist'
,
2
)
}
}
else
{
exit
(
'Can
\'
t find version argument or project setting'
,
3
)
}
}
execute
().
catch
(
e
=>
{
exit
(
e
);
});
bin/oss-upload/index.js
0 → 100644
View file @
6968a4fe
const
OSS
=
require
(
'ali-oss'
);
const
chalk
=
require
(
'chalk'
);
const
ProgressBar
=
require
(
'progress'
);
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
let
_type
,
_options
,
_store
,
_bar
,
_files
;
let
_uploadFiles
,
_errorFiles
;
module
.
exports
=
async
function
(
props
,
type
)
{
_type
=
type
;
const
defaultOptions
=
{
localDir
:
undefined
,
remoteDir
:
undefined
};
_options
=
Object
.
assign
({},
defaultOptions
,
props
);
if
(
!
_options
.
localDir
||
!
_options
.
remoteDir
)
{
console
.
log
(
chalk
.
red
(
'缺少参数,初始化失败'
));
return
;
}
init
();
await
start
();
};
function
init
()
{
_files
=
[];
flattenFileTree
(
_options
.
localDir
,
function
(
filePath
){
_files
.
push
(
path
.
relative
(
_options
.
localDir
,
filePath
))
});
_store
=
new
OSS
({
region
:
'oss-cn-hangzhou'
,
accessKeyId
:
'LTAIdGi1IOap7fkF'
,
accessKeySecret
:
'SKrOOp6EVtDGEV47yn0t2h97gyNioQ'
,
bucket
:
_type
===
'prod'
?
'duiba'
:
'daily-duiba'
});
_bar
=
new
ProgressBar
(
chalk
.
yellow
(
` 文件上传中 [:bar] :current/
${
_files
.
length
}
:percent :elapseds`
),
{
complete
:
'●'
,
incomplete
:
'○'
,
width
:
20
,
total
:
_files
.
length
,
callback
:
()
=>
{
console
.
log
(
chalk
.
blue
(
` 本次队列文件共
${
_files
.
length
}
个,上传文件
${
_uploadFiles
}
个,上传失败文件
${
_errorFiles
}
个`
));
}
});
return
this
;
}
function
flattenFileTree
(
parent
,
callback
){
const
filesIn
=
fs
.
readdirSync
(
parent
);
for
(
let
file
of
filesIn
){
if
(
file
.
indexOf
(
'.DS_Store'
)
<
0
){
const
filePath
=
path
.
join
(
parent
,
file
);
const
stat
=
fs
.
lstatSync
(
filePath
);
if
(
stat
.
isDirectory
()){
flattenFileTree
(
filePath
,
callback
);
}
else
{
callback
(
filePath
);
}
}
}
}
async
function
start
(){
_uploadFiles
=
0
;
_errorFiles
=
0
;
for
(
let
file
of
_files
){
try
{
const
localFile
=
path
.
join
(
_options
.
localDir
,
file
);
const
remotePath
=
path
.
join
(
_options
.
remoteDir
,
file
);
await
_store
.
put
(
remotePath
,
localFile
);
_uploadFiles
+=
1
;
_bar
.
tick
();
}
catch
(
e
)
{
_errorFiles
+=
1
;
console
.
log
(
e
);
}
}
}
bin/tools.js
View file @
6968a4fe
...
...
@@ -51,38 +51,55 @@ exports.npmRun = function (path, scriptName) {
return
childProcess
(
'npm'
,
[
'run'
,
scriptName
],
path
);
};
const
projectFile
=
'./project.json'
;
const
getProjectConfig
=
exports
.
getProjectConfig
=
function
()
{
const
gameFile
=
path
.
resolve
(
projectFile
);
if
(
fs
.
existsSync
(
gameFile
))
{
return
require
(
gameFile
)
}
};
exports
.
updateProjectConfig
=
function
(
key
,
value
)
{
const
config
=
getProjectConfig
();
if
(
config
)
{
config
[
key
]
=
value
;
}
fs
.
writeFileSync
(
projectFile
,
JSON
.
stringify
(
config
,
null
,
'
\
t'
));
};
exports
.
executeBuildProcess
=
function
(
cmd
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
let
buildProcessName
;
const
gameFile
=
path
.
resolve
(
'./game.json'
);
if
(
fs
.
existsSync
(
gameFile
)){
const
gameProjectConfig
=
require
(
gameFile
);
buildProcessName
=
gameProjectConfig
[
'build-process'
]
const
gameProjectConfig
=
getProjectConfig
();
if
(
gameProjectConfig
)
{
buildProcessName
=
gameProjectConfig
[
'build-process'
]
;
}
if
(
buildProcessName
)
{
if
(
buildProcessName
)
{
try
{
const
npm
=
require
(
'global-npm'
);
const
modulePath
=
path
.
resolve
(
npm
.
GLOBAL_NPM_PATH
,
'../game-cli-build-process-'
+
buildProcessName
);
const
buildProcess
=
require
(
modulePath
);
if
(
buildProcess
.
hasOwnProperty
(
cmd
))
{
if
(
buildProcess
.
hasOwnProperty
(
cmd
))
{
resolve
(
buildProcess
);
}
else
{
}
else
{
console
.
log
(
`Build process [
${
name
}
] has not implement
${
cmd
}
function`
)
}
}
catch
(
e
)
{
}
catch
(
e
)
{
reject
(
'Build process is not found, please install with --global'
);
}
}
reject
(
'Build process name is not found, please setup
game.json'
);
reject
(
'Build process name is not found, please setup
'
+
projectFile
);
}).
then
(
(
buildProcess
)
=>
{
(
buildProcess
)
=>
{
return
buildProcess
[
cmd
]()
}
).
then
(
(
version
)
=>
{
(
version
)
=>
{
console
.
log
(
`Build process [
${
cmd
}
] execute success`
);
return
version
;
}
...
...
package.json
View file @
6968a4fe
...
...
@@ -10,8 +10,11 @@
"author"
:
"rocky.l"
,
"license"
:
"
ISC
"
,
"dependencies"
:
{
"
ali-oss
"
:
"
^6.0.1
"
,
"
chalk
"
:
"
^2.4.1
"
,
"
commander
"
:
"
^2.18.0
"
,
"
fs-extra
"
:
"
^6.0.1
"
,
"
global-npm
"
:
"
^0.3.0
"
"
global-npm
"
:
"
^0.3.0
"
,
"
progress
"
:
"
^2.0.0
"
}
}
yarn.lock
View file @
6968a4fe
This diff is collapsed.
Click to expand it.
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