-
Notifications
You must be signed in to change notification settings - Fork 0
/
game
125 lines (120 loc) · 3.44 KB
/
game
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env node
// settings
var default_url = 'localhost:8000',
deploy_url = 'ggj.devap1.miio.info:8000';
var util = require('util'),
cp = require('child_process'),
fs = require('fs'),
os = require('os').platform(),
argv = process.argv,
message = [
'Usage: node game [command]',
'',
'Command:',
' install [address:port] Game install',
' start Game start'
].join('\n');
if (typeof(argv[2]) === 'undefined') util.puts('command is required\n\n' + message); else {
switch (argv[2]) {
case 'install':
util.log('Wait a minute.');
// server setting
var server = '';
if (argv[3] === 'deploy') {
server = deploy_url;
} else {
server = argv[3] ? argv[3] : default_url;
}
// define command
var port = Number(server.split(':')[1]),
c = {
cd: {
c: 'cd client',
s: 'cd server'
},
npm: 'npm install',
cake: 'node node_modules/coffee-script/bin/cake compile'
},
conf = {
index: ['index.html',
[
'<!DOCTYPE HTML>',
'<html lang="ja,en">',
'<head>',
' <meta charset="UTF-8">',
' <script type="text/javascript" src="http://' + server + '/socket.io/socket.io.js"></script>',
' <script src="client/lib/enchant.min.js" type="text/javascript"></script>',
' <script src="client/jubiol.min.js" type="text/javascript"></script>',
' <link media="all" rel="stylesheet" href="client/jubiol.css" type="text/css" />',
' <title>Osushi</title>',
'</head>',
'<body>',
' <div id="enchant-stage"></div>',
'</body>',
'</html>'
].join('\n')
],
client: ['client/src/server_config.coffee',
'class ServerConfig\n @config : {\n ADDRESS : \'http://' + server + '\'\n }'
],
server: ['server/config.json',
JSON.stringify({
port: port ? port : 80,
room_max: 4,
objects_file: 'sushi.json'
})
]
},
sep = (os.indexOf('win') > -1) ? '&&' : ';';
// client install
fs.writeFile(conf.index[0], conf.index[1], 'utf8', function (err) {
if (err !== null) console.error(err);
util.log('output: ' + conf.index[0]);
});
cp.exec([c.cd.c, c.npm].join(sep), function (error, stdout, stderr) {
if (error !== null) return console.log(error);
util.print(stdout);
util.print(stderr);
util.log('[' + [c.cd.c, c.npm].join(sep) + '] finished.');
fs.writeFile(conf.client[0], conf.client[1], 'utf8', function (err) {
if (err !== null) console.error(err);
util.log('output: ' + conf.client[0]);
cp.exec([c.cd.c, c.cake].join(sep), function (error, stdout, stderr) {
if (error !== null) return console.log(error);
util.print(stdout);
util.print(stderr);
util.log('[' + [c.cd.c, c.cake].join(sep) + '] finished.');
});
});
});
// server install
fs.writeFile(conf.server[0], conf.server[1], 'utf8', function (err) {
if (err !== null) console.error(err);
util.log('output: ' + conf.server[0]);
});
cp.exec([c.cd.s, c.npm].join(sep), function (error, stdout, stderr) {
if (error !== null) return console.error(error);
util.print(stdout);
util.print(stderr);
util.log('[' + [c.cd.s, c.npm].join(sep) + '] finished.');
});
break;
case 'start':
// exec server
var server = cp.fork('server/socket_server.js');
server.on('stdout', function (data) {
console.log(data);
});
server.on('stderr', function (data) {
console.log(data);
});
break;
case 'help':
util.puts(message);
break;
default:
util.puts(argv[2] + ' is not found.\n');
util.puts(message);
break;
}
}