-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpublish.js
executable file
·79 lines (64 loc) · 1.86 KB
/
publish.js
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
var Mocha = require('mocha'),
fs = require('fs'),
path = require('path'),
spawn = require('child_process').spawn;
// Instantiate a Mocha instance.
var mocha = new Mocha();
var testDir = './test/test'
// Add each .js file to the mocha instance
fs
.readdirSync(testDir)
.filter(function(file){
// Only keep the .js files
return file.substr(-3) === '.js';
})
.forEach(function(file){
mocha.addFile(
path.join(testDir, file)
);
});
// Run the tests.
mocha.run(function(failures){
process.on('exit', function () {
process.exit(failures); // exit with non-zero status if there were failures
});
if(0 === failures){
console.log('Compile js file');
let git = spawn('npm', ['run', 'build:js']);
git.stdout.on('data', (data) => {
console.log(`${data}`);
});
git.stderr.on('data', (data) => {
console.log(`${data}`);
});
git.on('close', (code) => {
if(0 === code){
console.log('Commit file');
let git = spawn('git', ['commit', '-a', '-m', '"' + (process.argv[2] || 'Commit via publish file, after test and min js file') + '"']);
git.stdout.on('data', (data) => {
console.log(`${data}`);
});
git.stderr.on('data', (data) => {
console.log(`${data}`);
});
git.on('close', (code) => {
if(0 === code){
console.log('Push');
let git = spawn('git', ['push', 'https://[email protected]/lobor/stargate.git']);
git.stdout.on('data', (data) => {
console.log(`${data}`);
});
git.stderr.on('data', (data) => {
console.log(`${data}`);
});
git.on('close', (code) => {
if(0 === code){
process.exit();
}
});
}
});
}
});
}
});