summaryrefslogtreecommitdiffstats
path: root/packages/markdown/marked/test/json-to-files.js
diff options
context:
space:
mode:
authorLauri Ojansivu <x@xet7.org>2019-04-20 15:18:33 +0300
committerLauri Ojansivu <x@xet7.org>2019-04-20 15:18:33 +0300
commit73e265d8fd050ae3daa67472b4465a5c49d68910 (patch)
tree677b233934a43d8f873e24c794ce289d85e3a9b7 /packages/markdown/marked/test/json-to-files.js
parent6117097a93bfb11c8bd4c87a23c44a50e22ceb87 (diff)
downloadwekan-73e265d8fd050ae3daa67472b4465a5c49d68910.tar.gz
wekan-73e265d8fd050ae3daa67472b4465a5c49d68910.tar.bz2
wekan-73e265d8fd050ae3daa67472b4465a5c49d68910.zip
Include to Wekan packages directory contents, so that meteor command would build all directly.
This also simplifies build scripts. Thanks to xet7 !
Diffstat (limited to 'packages/markdown/marked/test/json-to-files.js')
-rw-r--r--packages/markdown/marked/test/json-to-files.js62
1 files changed, 62 insertions, 0 deletions
diff --git a/packages/markdown/marked/test/json-to-files.js b/packages/markdown/marked/test/json-to-files.js
new file mode 100644
index 00000000..d7e72aaf
--- /dev/null
+++ b/packages/markdown/marked/test/json-to-files.js
@@ -0,0 +1,62 @@
+const path = require('path');
+const fs = require('fs');
+
+const folder = process.argv[2];
+const jsonFile = process.argv[3];
+
+if (!folder || !jsonFile) {
+ console.log('node ./json-to-files.js {path to folder} {path to json file}');
+ process.exit(1);
+}
+
+const specs = require(jsonFile);
+
+const files = specs.reduce((obj, spec) => {
+ if (!obj[spec.section]) {
+ obj[spec.section] = {
+ md: [],
+ html: [],
+ options: {}
+ };
+ }
+
+ obj[spec.section].md.push(spec.markdown);
+ obj[spec.section].html.push(spec.html);
+ Object.assign(obj[spec.section].options, spec.options);
+
+ return obj;
+}, {});
+
+try {
+ fs.mkdirSync(folder, {recursive: true});
+} catch (ex) {
+ // already exists
+}
+
+for (const section in files) {
+ const file = files[section];
+ const name = section.toLowerCase().replace(' ', '_');
+ const frontMatter = Object.keys(file.options).map(opt => {
+ let value = file.options[opt];
+ if (typeof value !== 'string') {
+ value = JSON.stringify(value);
+ }
+ return `${opt}: ${value}`;
+ }).join('\n');
+
+ let markdown = file.md.join('\n\n');
+ if (frontMatter) {
+ markdown = `---\n${frontMatter}\n---\n\n${markdown}`;
+ }
+ const html = file.html.join('\n\n');
+
+ const mdFile = path.resolve(folder, `${name}.md`);
+ const htmlFile = path.resolve(folder, `${name}.html`);
+
+ if (fs.existsSync(mdFile) || fs.existsSync(htmlFile)) {
+ throw new Error(`${name} already exists.`);
+ }
+
+ fs.writeFileSync(mdFile, markdown);
+ fs.writeFileSync(htmlFile, html);
+}