-
Notifications
You must be signed in to change notification settings - Fork 84
/
start.js
156 lines (150 loc) · 5.05 KB
/
start.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//modules
var fs = require('fs');
var path = require('path');
var mctool = require('./app/mc-tool');
var walk = require('./app/helpers').walk;
var pjson = require('./package.json');
var git = require('./app/git-tool');
var server = require('./app/server');
var readline = require('readline');
var github = require('./app/github');
var which=require('which');
var promisify = require('./app/helpers').promisify;
var doJson=(root)=>
Promise.resolve(root)
.then(path=>path+'/Marlin/example_configurations')
.then(walk)
.then(f=>f.filter(a=>/Configuration(_adv)?\.h/.test(a)))
.then(f=>Promise.all(f.map(mctool.makeJson(root))))
.then(a=>(console.log('done ALL json'),root))
var doH=(root)=>
Promise.resolve(root)
.then(path=>path+'/Marlin/example_configurations')
.then(walk)
.then(f=>f.filter(a=>/Configuration(_adv)?\.json/.test(a)))
.then(f=>Promise.all(f.map(mctool.makeH(root))))
.then(a=>(console.log('done ALL h'),root))
var unlink=f=>
new Promise((done,fail)=>fs.unlink(f,(e,a)=>e?fail(e):done(a)));
var rmJson=(root)=>
Promise.resolve(root)
.then(path=>path+'/Marlin/example_configurations')
.then(walk)
.then(f=>f.filter(a=>/Configuration(_adv)?\.(json|not)/.test(a)))
.then(f=>Promise.all(f.map(unlink)))
.then(a=>console.log('done rm ALL .json / .not'))
function main(){
promisify(which)('git').then(marlin).catch(a=>console.error('git not found'));
}
function marlin(){
var is={tree:1,json:1,h:1,git:0,rm:1,help:1,txt:1,conf:1,clone:1,update:1}
.filter((v,key,o,p,i)=>(p=process.argv,i=p.indexOf(key),!v&&i>=0&&i+1<p.length&&(o[key]=p[i+1]),i>=0));
if ( is.help )
help()
else
if ( is.git ) {
['Marlin/Configuration_adv','Marlin/Configuration'].forEach(f=>{
var base = Promise.all([git.root(), git.Show(is.git, f + '.h')]);
if ( is.json )
base
.then(a=>mctool.makeJson(a[0],a[1])(path.join(a[0],f+'.h')))
else
if ( is.h )
base
.then(a=>mctool.makeH(a[0],a[1])(path.join(a[0],f+'.json')))
else
if ( is.txt )
base
.then(a=>mctool.makeTxt(a[0],a[1],{git:is.git,name:pjson.name,version:pjson.version})(path.join(a[0],f+'.h')))
})
}else
if ( is.tree ){
git.root()
.then( root=> is.json ? doJson(root) : root )
.then( root=> is.h ? doH(root) : root )
.then( is.rm ? rmJson : 0);
}else
if ( is.conf ){
server.main()
}else
if ( is.update ){
console.log('Updating files from github MarlinFirmware/MarlinDocumentation...');
github.getConfig(1);
github.getGCodes(1);
}else
if ( is.clone ){
git.root().then(root=>{
console.log('there is git');
}).catch(err=>{
git.clone().then(a=>console.log('over'));
})
}else{
function getConsole(){
return readline.createInterface({
input: process.stdin,
output: process.stdout
});
}
function startWeb(){
return git.root()
.then(root=>new Promise((done,fail)=>{
console.log('type: mct help if you need more information');
if(root){
var rl = getConsole();
rl.question('press Enter to run web browser or ^C to exit', (answer) => {
rl.close();
server.main().then(done).catch(fail)
});
}
}))
}
function tryRun(){
process.chdir('Marlin')
return git.root('Marlin')
.then(a=>server.main());
}
startWeb()
.catch(a=>{
var rl = getConsole();
rl.question('press Enter to clone it from web or ^C to exit', (answer) => {
rl.close();
git.clone()
.then(tryRun)
.catch(tryRun)
.catch(a=>console.log('no Marlin folder found'))
});
})
}
}
function help(){
console.log(`${pjson.name} v ${pjson.version}
usage: mct help|git|tree|conf|clone
You need to run it in Marlin git repository
commands:
mct
asks to 'clone' if current folder has no repository then run 'conf'
mct conf
open browser for interactive configuration
mct clone
clone current Marlin repository to current working directory
mct git <git-tag> json|h|txt
json: compare [gitroot]/Marlin/Configuration*.h files
between git-tag files and files in folder then
create .json files with your personal setting
h: extend [gitroot]/Marlin/Configuration*.h files
from git-tag with .json files contained your personal setting
txt: like json but create txt files contained only changes
for publication
mct tree json|h|rm
Each of these traverse [gitroot]/Marlin/example_configurations directory
json: compare configurations with main files [gitroot]/Marlin/Configuration*.h
and generate .json file with its differences for each
and .not files for #defines which not present in base files
h: recreate .h files based on
main files [gitroot]/Marlin/Configuration*.h and .json
rm: remove .json and .not files
`);
}
module.exports.main=main;
console.log('Node', process.version, pjson.name, 'v', pjson.version);
require.main===module && main();