diff options
| author | Лu Лinveгa <aliceffekt@gmail.com> | 2018-02-13 07:55:41 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-13 07:55:41 +1300 |
| commit | d30445d36b10ed7d9ac2c3ba37fb9302b25e3ec6 (patch) | |
| tree | d990cdc2a88c707593c791f348c722414f640e28 | |
| parent | df33ba6c26516b75be9da4ea2f66b3243fe1bb99 (diff) | |
| parent | 8276e0308860b0fc364cc2e988499c2e2b921bf3 (diff) | |
Merge pull request #9 from vaporstack/master
Proposal for schema change and a couple of trivial enhancements
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | index.js | 54 | ||||
| -rw-r--r-- | themes/deuveir.thm | 27 |
3 files changed, 61 insertions, 22 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ca0973 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.DS_Store + @@ -1,8 +1,15 @@ fs = require('fs'); +path = require('path'); var normalizedPath = require("path").join(__dirname, "themes"); var html = "# Themes\nThis collection of themes are meant to be used with [Marabu](https://github.com/hundredrabbits/Marabu), [Ronin](https://github.com/hundredrabbits/Ronin), [Left](https://github.com/hundredrabbits/Left), [Donsol](https://github.com/hundredrabbits/Donsol) and [Dotgrid](https://github.com/hundredrabbits/Dotgrid).\n\n<img src='https://raw.githubusercontent.com/hundredrabbits/Themes/master/PREVIEW.jpg' width='600'/>\n\n## Install\nTo install a theme, simply drag the `thm` file onto the application window.\nYou are welcome to submit your own themes to this collection!\n\n" +// opt in to upgrade the schema change +// would require to do 'theme = theme.data' in client apps +// idea is tradeoff for authorship and versioning, potentially multiple codepaths +// if, in the future, more colors are ever added +//var generate_v2 = false; + function build_svg(n,theme) { var name = n.split(".")[0]; @@ -24,7 +31,7 @@ function build_svg(n,theme) fs.writeFile("assets/"+name+".svg", html, function(err) { if(err) {return console.log(err);} console.log("Saved "+name) - }); + }); } function build_theme(n,theme) @@ -33,14 +40,13 @@ function build_theme(n,theme) return `## [${name}](themes/${name}.thm)\n\n\n` } -function is_json(text) +function safe_parse_json(text) { try{ - JSON.parse(text); - return true; + return JSON.parse(text); } catch (error){ - return false; + return null; } } @@ -49,17 +55,41 @@ function generate(html) fs.writeFile("README.md", html, function(err) { if(err) {return console.log(err);} console.log("Done.") - }); + }); +} + +function upgrade_with_defaults(theme) +{ + + if ( !theme.hasOwnProperty("meta")) + { + //assume v1, provide default meta + return {"meta": + { + "author": "unknown", + "version": 2, + "revision": 1 + }, + "data": theme + } + + }else{ + // v2 and up + return theme; + } } require("fs").readdirSync(normalizedPath).forEach(function(file_name) { - fs.readFile('themes/'+file_name, 'utf8', function (err,data){ + fs.readFile('themes'+path.sep+file_name, 'utf8', function (err, data){ if(err) { return console.log(err); } - if(is_json(data)){ - var theme = JSON.parse(data) - build_svg(file_name,theme) - html += build_theme(file_name,theme) - } + + var theme = safe_parse_json(data); + if (!theme ){ return console.log(err); } + build_svg(file_name, theme) + html += build_theme(file_name, theme) + theme = upgrade_with_defaults(theme); + + fs.writeFileSync('themes' + path.sep + file_name, JSON.stringify(theme, null, 2)); }); }); diff --git a/themes/deuveir.thm b/themes/deuveir.thm index 0a630a8..1ce34fa 100644 --- a/themes/deuveir.thm +++ b/themes/deuveir.thm @@ -1,11 +1,18 @@ { - "background": "#141414", - "f_high": "#f4f4f4", - "f_med": "#efefef", - "f_low": "#3d3d3d", - "f_inv": "#141414", - "b_high": "#efefef", - "b_med": "#aa0000", - "b_low": "#000000", - "b_inv": "#3d3d3d" -} + "meta": { + "author": "deuveir", + "version": 2, + "revision": 1 + }, + "data": { + "background": "#141414", + "f_high": "#f4f4f4", + "f_med": "#efefef", + "f_low": "#3d3d3d", + "f_inv": "#141414", + "b_high": "#efefef", + "b_med": "#aa0000", + "b_low": "#000000", + "b_inv": "#3d3d3d" + } +}
\ No newline at end of file |
