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
c400a0fc
Commit
c400a0fc
authored
Oct 22, 2018
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加http serve: game-cli serve -h -p -f
parent
75c77533
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
278 additions
and
5 deletions
+278
-5
game-cli-mock.js
bin/game-cli-mock.js
+3
-3
game-cli-serve.js
bin/game-cli-serve.js
+31
-0
index.js
bin/http-server/index.js
+36
-0
package.json
package.json
+2
-1
yarn.lock
yarn.lock
+206
-1
No files found.
bin/game-cli-mock.js
View file @
c400a0fc
...
@@ -3,9 +3,9 @@ const {exit,} = require('./tools');
...
@@ -3,9 +3,9 @@ const {exit,} = require('./tools');
const
jsonServer
=
require
(
'./json-server'
);
const
jsonServer
=
require
(
'./json-server'
);
program
program
.
option
(
'-h, --host [string]'
,
'server host, default localhost'
)
.
option
(
'-h, --host [string]'
,
'server host, default localhost'
,
'localhost'
)
.
option
(
'-p, --port [number]'
,
'server port, default 3000'
)
.
option
(
'-p, --port [number]'
,
'server port, default 3000'
,
3000
)
.
option
(
'-f, --folder [string]'
,
'folder of json files, default ./
mock
'
)
.
option
(
'-f, --folder [string]'
,
'folder of json files, default ./
'
,
'./
'
)
.
parse
(
process
.
argv
);
.
parse
(
process
.
argv
);
async
function
execute
()
{
async
function
execute
()
{
...
...
bin/game-cli-serve.js
0 → 100755
View file @
c400a0fc
const
program
=
require
(
'commander'
);
const
{
exit
,}
=
require
(
'./tools'
);
const
httpServer
=
require
(
'./http-server'
);
program
.
option
(
'-h, --host [string]'
,
'server host, default localhost'
,
'localhost'
)
.
option
(
'-p, --port [number]'
,
'server port, default 3001'
,
3001
)
.
option
(
'-f, --folder [string]'
,
'folder of json files, default ./'
,
'./'
)
.
parse
(
process
.
argv
);
async
function
execute
()
{
console
.
log
(
'Launching...'
);
httpServer
.
start
({
host
:
program
.
host
,
port
:
program
.
port
,
folder
:
program
.
folder
,
}).
then
(
({
host
,
port
,
publicPath
})
=>
{
console
.
log
(
`Http server start at http://
${
host
}
:
${
port
}
`
);
console
.
log
(
'Http path: '
,
publicPath
);
},
(
e
)
=>
{
console
.
log
(
e
);
}
)
}
execute
().
catch
(
e
=>
{
exit
(
e
);
});
bin/http-server/index.js
0 → 100644
View file @
c400a0fc
/**
* Created by rockyl on 2018/9/18.
*
* http serve
*/
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs'
);
const
handler
=
require
(
'serve-handler'
);
const
http
=
require
(
'http'
);
exports
.
start
=
function
(
options
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
{
port
,
host
,
folder
}
=
options
;
const
publicPath
=
path
.
resolve
(
folder
);
if
(
fs
.
existsSync
(
publicPath
))
{
const
server
=
http
.
createServer
((
request
,
response
)
=>
{
return
handler
(
request
,
response
,
{
public
:
publicPath
,
});
});
server
.
on
(
'error'
,
(
err
)
=>
{
reject
(
err
.
message
);
});
server
.
listen
(
port
,
host
,
function
()
{
resolve
({
host
,
port
,
publicPath
,
});
});
}
else
{
reject
(
'Public path is not exist: '
+
publicPath
)
}
})
};
package.json
View file @
c400a0fc
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
"
commander
"
:
"
^2.18.0
"
,
"
commander
"
:
"
^2.18.0
"
,
"
fs-extra
"
:
"
^6.0.1
"
,
"
fs-extra
"
:
"
^6.0.1
"
,
"
global-npm
"
:
"
^0.3.0
"
,
"
global-npm
"
:
"
^0.3.0
"
,
"
progress
"
:
"
^2.0.0
"
"
progress
"
:
"
^2.0.0
"
,
"
serve-handler
"
:
"
^5.0.5
"
}
}
}
}
yarn.lock
View file @
c400a0fc
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