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
ed9ac7e4
Commit
ed9ac7e4
authored
Dec 25, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add code serve
parent
534c71e3
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
336 additions
and
9 deletions
+336
-9
game-cli-code-serve.js
bin/game-cli-code-serve.js
+19
-0
game-cli.js
bin/game-cli.js
+1
-0
index.js
bin/json-server/index.js
+1
-1
package.json
package.json
+2
-1
index.js
src/index.js
+39
-0
yarn.lock
yarn.lock
+274
-7
No files found.
bin/game-cli-code-serve.js
0 → 100644
View file @
ed9ac7e4
#!/usr/bin/env node
/**
* Created by rockyl on 2019-12-25.
*/
const
program
=
require
(
'commander'
);
const
{
start
}
=
require
(
'../src/index'
);
program
.
option
(
'-p, --port [string]'
,
'Server port'
,
'7788'
)
.
option
(
'-f, --file [string]'
,
'Target file'
)
.
parse
(
process
.
argv
);
if
(
!
program
.
file
){
console
.
error
(
'Target file must be specified'
);
}
else
{
start
(
program
);
}
bin/game-cli.js
View file @
ed9ac7e4
...
...
@@ -12,4 +12,5 @@ program
.
command
(
'dev'
,
'Build project automatic'
).
alias
(
'd'
)
.
command
(
'build'
,
'Publish project'
).
alias
(
'b'
)
.
command
(
'upload'
,
'Upload project to oss'
).
alias
(
'u'
)
.
command
(
'code-serve'
,
'Code sync serve'
)
.
parse
(
process
.
argv
);
bin/json-server/index.js
View file @
ed9ac7e4
...
...
@@ -30,7 +30,7 @@ function handler(jsonPath, proxy) {
if
(
proxy
)
{
const
target
=
proxy
.
startsWith
(
'http'
)
?
proxy
:
`http://
${
proxy
}
`
;
console
.
log
(
`proxy:
${
target
}${
url
}
`
)
console
.
log
(
`proxy:
${
target
}${
url
}
`
)
;
Object
.
entries
(
headers
).
forEach
(([
key
,
val
])
=>
response
.
setHeader
(
key
,
val
));
return
proxyServer
.
web
(
request
,
response
,
{
target
},
err
=>
{
console
.
log
(
err
);
...
...
package.json
View file @
ed9ac7e4
...
...
@@ -13,11 +13,12 @@
"
ali-oss
"
:
"
^6.0.1
"
,
"
chalk
"
:
"
^2.4.1
"
,
"
commander
"
:
"
^2.18.0
"
,
"
fs-extra
"
:
"
^
6.0.1
"
,
"
fs-extra
"
:
"
^
8.1.0
"
,
"
global-modules
"
:
"
^2.0.0
"
,
"
http-proxy
"
:
"
^1.17.0
"
,
"
progress
"
:
"
^2.0.0
"
,
"
serve-handler
"
:
"
^5.0.5
"
,
"
socket.io
"
:
"
^2.3.0
"
,
"
yarn-config-directory
"
:
"
^1.0.2
"
}
}
src/index.js
0 → 100644
View file @
ed9ac7e4
/**
* Created by rockyl on 2019-12-25.
*/
const
Server
=
require
(
'socket.io'
);
const
path
=
require
(
'path'
);
const
fs
=
require
(
'fs-extra'
);
exports
.
start
=
function
(
options
)
{
const
sockets
=
[];
let
watching
=
false
;
fs
.
watch
(
options
.
file
,
{},
(
eventType
)
=>
{
if
(
watching
)
{
if
(
eventType
===
'change'
)
{
const
code
=
fs
.
readFileSync
(
options
.
file
,
'utf-8'
);
for
(
let
socket
of
sockets
){
socket
.
emit
(
'edit-save'
,
code
);
}
}
}
});
let
server
=
Server
(
options
.
port
);
server
.
on
(
'connection'
,
function
(
socket
)
{
sockets
.
push
(
socket
);
socket
.
on
(
'disconnect'
,
function
()
{
sockets
.
splice
(
sockets
.
indexOf
(
socket
),
1
);
});
socket
.
on
(
'edit-open'
,
function
(
data
)
{
fs
.
ensureDir
(
path
.
dirname
(
options
.
file
));
watching
=
false
;
fs
.
writeFileSync
(
options
.
file
,
data
);
setTimeout
(
function
()
{
watching
=
true
;
},
500
);
})
});
};
yarn.lock
View file @
ed9ac7e4
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