Skip to content

Commit

Permalink
fixed bugs: windows paths issue, menu reset function, config saving, …
Browse files Browse the repository at this point in the history
…custom bootscreen v2
  • Loading branch information
akaJes committed Oct 13, 2017
1 parent 80e6e01 commit 26a198f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 30 deletions.
2 changes: 1 addition & 1 deletion app/git-tool.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.Status=()=>promisify('status',git(root))();
exports.Fetch=()=>promisify('fetch',git(root))(['--all']);
exports.Tag=gitTag;
exports.Tags=gitTags;
exports.Show=(branch,file)=>promisify('show',git(root))([branch+':'+file]);
exports.Show = (branch, file) => promisify('show', git(root))([branch + ':' + file.replace(/\\/g, '/')]);
exports.git=git;
exports.root=a=>a?gitRoot(a):root?Promise.resolve(root):Promise.reject();

Expand Down
52 changes: 26 additions & 26 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var os = require('os');
var ifaces = os.networkInterfaces();
var natUpnp = require('nat-upnp');
var moment = require('moment');
var mkdirp = require('mkdirp');

var natClient;

Expand Down Expand Up @@ -252,8 +253,13 @@ app.get('/checkout-force', function (req, res) {
).catch(e => 'not found')
)
))
var rm = () =>
seek4File('_Bootscreen.h', [path.join('Marlin', 'src', 'config'), 'Marlin'])
.then(file => file && promisify(fs.unlink)(file));

git.Checkout('--force')
.then(a => baseCfg == 'Marlin' && a || cp())
.then(rm)
.then(a => baseCfg == 'Marlin' ? a : cp())
.then(a=>res.send(a));
});
app.get('/fetch', function (req, res) {
Expand All @@ -275,26 +281,19 @@ var copyFile=(from,to)=>
);
app.get('/save', function (req, res) {
var dt=moment().format('YYYY-MM-DD kk-mm-ss');
git.root()
.then(root=>path.join(root,store))
.then(dir=>promisify(fs.stat)(dir).catch(a=>promisify(fs.mkdir)(dir)).then(a=>dir))
.then(dir=>git.Tag().then(tag=>path.join(dir,tag)))
.then(dir=>promisify(fs.stat)(dir).catch(a=>promisify(fs.mkdir)(dir)).then(a=>dir))
.then(dir=>path.join(dir,dt))
.then(dir=>promisify(fs.stat)(dir).catch(a=>promisify(fs.mkdir)(dir)).then(a=>dir))
.then(dir=>git.root().then(root=>({dir:dir,root:root})))
Promise.all([git.root(), git.Tag()])
.then(p => {
var dir = path.join(p[0], store, p[1].replace('/', path.sep), dt);
return promisify(mkdirp)(dir).then(a => ({to: dir, root: p[0]}));
})
.then(dirs=>Promise.all(
['Configuration.h','Configuration_adv.h','_Bootscreen.h']
.map(file=>promisify(fs.stat)(path.join(dirs.root,'Marlin',file)).then(()=>file).catch(()=>null))
.map(file => seek4File(file, ['Marlin', path.join('Marlin', 'src', 'config')]).catch(()=>null))
)
.then(files=>({root:dirs.root,files:files.filter(a=>a),to:dirs.dir,message:req.query.message}))
.then(files => Object.assign(dirs, {files: files.filter(a => a), message:req.query.message}))
)
.then(dirs=>
Promise.all(
dirs.files.map(f=>
copyFile(path.join(dirs.root,'Marlin',f), path.join(dirs.to,f) )
)
)
Promise.all(dirs.files.map(f => copyFile(f, path.join(dirs.to, path.basename(f)))))
.then(()=>dirs)
)
.then(dirs=>promisify(fs.writeFile)(path.join(dirs.to,'contents.json'),JSON.stringify(dirs,null,2)).then(()=>dirs))
Expand Down Expand Up @@ -326,8 +325,9 @@ app.get('/restore/:path', function (req, res) {
.map(f=>({path:f,name:path.parse(f).base}))
var cp=files
.filter(i=>/_Bootscreen\.h/.test(i))
.map(f=>git.root()
.then(root=>copyFile(f,path.join(root,'Marlin',path.parse(f).base)))
.map(f =>
seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin'])
.then(dir => copyFile(f, path.join(dir, path.basename(f) )))
)
console.log(cp);
//return (uploadFiles(up));
Expand Down Expand Up @@ -489,18 +489,18 @@ app.get('/bs/default', function (req, res) {
});
app.post('/bs/custom', function (req, res) {
var name='_Bootscreen.h';
Promise
.resolve(path.join(__dirname,'..','views',name))
.then(file=>promisify(fs.readFile)(file,'utf8'))
.then(text=>text.replace(/{{([\w.]+)}}/g,(m,r)=>r.split('.').reduce((p,o)=>(p=p&&p[o],p),req.body)))
.then(file=>git.root().then(p=>promisify(fs.writeFile)(path.join(p,'Marlin',name),file)))
Promise.all([
seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin']),
promisify(fs.readFile)(path.join(__dirname, '..', 'views', name), 'utf8')
.then(text => text.replace(/{{([\w.]+)}}/g, (m, r) => r.split('.').reduce((p, o) => (p = p && p[o], p), req.body)))
])
.then(p => promisify(fs.writeFile)(path.join(p[0], name), p[1]))
.then(a=>res.end('writed'))
.catch(e=>res.status(403).send(e))
});
app.get('/bs/custom', function (req, res) {
git.root()
.then(f=>path.join(f,'Marlin','_Bootscreen.h'))
.then(file=>promisify(fs.readFile)(file,'utf8'))
seek4File('_Bootscreen.h', [ 'Marlin', path.join('Marlin', 'src', 'config')])
.then(file => promisify(fs.readFile)(file, 'utf8'))
.then(data=>{
var d=getMatch(/{(([^}]|\r\n?|\n)*)}/g,data);
d=d.replace(/\n/g,'').replace(/ /g,'');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "marlin-conf",
"version": "2.7.14",
"version": "2.7.16",
"description": "configuration tool for Marlin project",
"main": "./index.js",
"scripts": {
Expand Down Expand Up @@ -71,6 +71,7 @@
"jquery-ui-dist": "^1.12.1",
"js-yaml": "^3.8.4",
"marked": "^0.3.6",
"mkdirp": "^0.5.1",
"moment": "^2.18.1",
"nat-upnp": "^1.1.0",
"node-notifier": "^5.1.2",
Expand Down
2 changes: 1 addition & 1 deletion start.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,5 @@ commands:
`);
}
module.exports.main=main;
console.log('Node',process.version);
console.log('Node', process.version, pjson.name, 'v', pjson.version);
require.main===module && main();
2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ <h5 class="modal-title" id="mct-restoreModalLabel">Choose desired configuration
</button>
</div>
<div class="modal-body">
<p></p>
<p style="max-height:50vh;overflow-y:auto;"></p>
<div class="form-group">
<label for="message-text" class="form-control-label">Message:</label>
<textarea class="form-control" rows="8" id="message-text" disabled></textarea>
Expand Down

0 comments on commit 26a198f

Please sign in to comment.