-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush.js
92 lines (79 loc) · 2.39 KB
/
push.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
80
81
82
83
84
85
86
87
88
89
90
91
92
const { exec, spawn } = require("child_process");
const { resolve } = require("path");
/**
* Build process
*
* 1. Increase version in main scss
* 2. Build the css file
* 3. Build the minified css file
* 4. Generate the docs
* 5. Commit changes
* 6. Update package.json version
* 7. Publish to npmjs.org
*/
class Command {
constructor(command) {
this.originalCommand = command;
let args = command.split(' ');
command = args.shift()
this.command = spawn(command, args)
}
async listen() {
this.command.stdout.on("data", data => {
console.log(`${data}`);
});
this.command.stderr.on("data", data => {
console.log(`${data}`);
});
this.command.on('error', (error) => {
console.log(`error: ${error.message}`);
});
return await new Promise(() => {
this.command.on("close", code => {
console.log(`✅ ${this.originalCommand} is done with code ${code}`);
resolve()
})
})
}
}
class Publish {
async buildCss() {
const command = new Command('npm run dev');
return await new Promise(async (resolve) => {
return await command.listen().then(_ => resolve())
})
}
buildMinifyCss() {
new Command('npm run prod');
}
}
const publish = new Publish();
const com = publish.buildCss()
com.then(() => console.log('there'))
// publish.buildMinifyCss()
return;
exec("npm run dev", commandCallback(error, stdout, stderr, (stop) => {
if (stop) return;
exec("npm run prod", commandCallback(error, stdout, stderr, (stop) => {
if (stop) return;
// exec("npm run prod", commandCallback(error, stdout, stderr, (stop) => {
}));
}));
async function commandCallback(error, stdout, stderr) {
return await new Promise((resolve, reject) => {
if (error) {
console.log(`error: ${error.message}`);
reject(error.message)
}
if (stderr) {
console.log(`stderr: ${stderr}`);
reject(stderr)
}
console.log(`stderr: ${stdout}`);
resolve()
})
}
// npm version patch && npm publish--access public
/* ------------------------------------------------------ */
/* // */
/* ------------------------------------------------------ */