Skip to content

Commit ca0122c

Browse files
committed
date:2019-01-23 14:17:27
1 parent 3b12451 commit ca0122c

File tree

143 files changed

+4894
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4894
-11
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
npm-debug.log
3+
webapp/

api_server/app.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var express = require('express');
2+
var path = require('path');
3+
var conf = require('../conf.js');
4+
5+
var app = express();
6+
app.use(express.static(path.join(__dirname, '../webapp/')));
7+
8+
// api
9+
// 测试API
10+
app.post(conf.test_api, function(req, res) {
11+
res.send({
12+
ret:1
13+
});
14+
});
15+
16+
17+
app.post('/api/js_demo/font.do', function(req, res) {
18+
var size = Math.floor(Math.random() * 200);
19+
if (size < 60) {
20+
size = 60;
21+
}
22+
var color = Math.floor(Math.random() * 1000000);
23+
24+
res.send({
25+
size: size,
26+
color: color,
27+
});
28+
});
29+
30+
31+
32+
33+
34+
app.listen(conf.api_port);
35+
console.log("server running at " + conf.api_port);

api_server/app_auto.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var nodemon = require('gulp-nodemon');
2+
var path = require('path');
3+
nodemon({
4+
script: path.join(__dirname,'./app.js'),
5+
ignore: [
6+
path.join(__dirname,'../src_webapp/'),
7+
path.join(__dirname,'../webapp/'),
8+
path.join(__dirname,'../gulpfile.js'),
9+
path.join(__dirname,'../cmd.js'),
10+
],
11+
env: { 'NODE_ENV': 'development' }
12+
});

cmd.js

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
var conf = require('./conf.js');
2+
var path = require('path');
3+
var Tool = require('./tool.js');
4+
var tool = new Tool();
5+
6+
var _path = "./";
7+
// =================================一键上传本地数据库--->online
8+
if (process.env.NODE_ENV == 'esc_db') {
9+
// 导出的路径、压缩、删除、上传
10+
tool
11+
// 导出文件夹
12+
._cmd(`mongodump -h 127.0.0.1:27017 -d ${conf.db} -o ${_path}`)
13+
.then(function() {
14+
console.log('导出文件夹完成');
15+
// 压缩为tar包
16+
return tool._cmd(`tar -zcvf ${_path}${conf.db}.tar.gz ${_path}${conf.db}`)
17+
})
18+
.then(function() {
19+
console.log('压缩tar.gz完成');
20+
// 删除文件夹
21+
return tool._cmd(`rm -r ${_path}${conf.db}`)
22+
})
23+
.then(function() {
24+
console.log('删除文件夹完成');
25+
// 上传
26+
return tool._cmd(`scp -P ${conf.login_port} ${_path}${conf.db}.tar.gz ${conf.user}@${conf.ip}:/home/${conf.user}/${conf.db_to_olDir}/`)
27+
})
28+
.then(function() {
29+
console.log('上传完成');
30+
// 删除文件夹
31+
return tool._cmd(`rm ${_path}${conf.db}.tar.gz`)
32+
})
33+
.then(function() {
34+
console.log('删除tar.gz完成完成');
35+
});
36+
}
37+
//
38+
// =================================一键下载本地数据库-->根目录数据库文件夹
39+
else if (process.env.NODE_ENV == 'db_dn') {
40+
tool
41+
// 导出文件夹
42+
._cmd(`mongodump -h 127.0.0.1:27017 -d ${conf.db} -o ${_path}`)
43+
.then(function() {
44+
console.log('导出文件夹完成');
45+
});
46+
}
47+
//
48+
// =================================一键上传 根目录数据库文件夹-->本地数据库
49+
else if (process.env.NODE_ENV == 'db_up') {
50+
tool
51+
// 删除原来的数据库
52+
._cmd(`mongo --host 127.0.0.1:27017 ${conf.db} --eval "db.dropDatabase()"`)
53+
.then(function() {
54+
// 导入
55+
return tool._cmd(`mongorestore --host 127.0.0.1:27017 -d ${conf.db} ./${conf.db}/`);
56+
});
57+
}
58+
//
59+
// =================================一键上传文件到github
60+
else if (process.env.NODE_ENV == 'git') {
61+
// 获取当前时间戳
62+
var timestamp = Date.parse(new Date());
63+
64+
// 要提交的目录
65+
var _url = path.join(__dirname, './');
66+
67+
var os = require('os');
68+
69+
70+
// 要提交的源的名字
71+
var origin = (os.hostname() == "LAPTOP-UJ33NHEM" ? "origin" : "name");
72+
73+
74+
75+
tool
76+
// 导出数据库
77+
._cmd(`git add ${_url}`)
78+
//
79+
// .then(function() {
80+
// return tool._cmd(`git add ${_url}`);
81+
// })
82+
.then(function() {
83+
return tool._cmd(`git commit -m "date:${tool._date(timestamp)}"`);
84+
})
85+
.then(function() {
86+
return tool._cmd(`git push -u ${origin} master`)
87+
})
88+
.then(function() {
89+
console.log('上传git完成');
90+
});
91+
}

conf.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
module.exports = {
2+
// 数据库名称
3+
db:"test",
4+
5+
// 测试模式下的端口
6+
dev_port:1010,
7+
8+
// 打包后/测试时被代理的端口
9+
api_port:1011,
10+
11+
// 测试API
12+
test_api:"/api/test.do",
13+
14+
15+
// ===========================服务器的参数
16+
// IP登录端口
17+
login_port: 22,
18+
// 登录用户名
19+
user: "cc",
20+
// 公网IP
21+
ip: "47.94.202.107",
22+
// 线上的数据库上传的文件夹
23+
db_to_olDir: 'db_task/db_from_out'
24+
}

0 commit comments

Comments
 (0)