From 5158c8a13c79313ee1d680217d19eb808a23b13a Mon Sep 17 00:00:00 2001 From: idleberg Date: Sun, 14 Apr 2019 18:07:18 +0200 Subject: [PATCH] add build script --- tools/build.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tools/build.js diff --git a/tools/build.js b/tools/build.js new file mode 100644 index 0000000..dfbbdbf --- /dev/null +++ b/tools/build.js @@ -0,0 +1,63 @@ +const MUI = require('@nsis/mui-language-strings'); +const NLF = require('@nsis/nlf'); +const fs = require('fs'); +const globby = require('globby'); +const rimraf = require('rimraf'); +const sortKeys = require('sort-keys'); +const { basename, extname, join } = require('path'); +const { nsisDir } = require('makensis'); +const { promisify } = require('util'); + +const readFile = promisify(fs.readFile); +const writeFile = promisify(fs.writeFile); +const rimrafAsync = promisify(rimraf); +const mkdir = promisify(fs.mkdir); + +(async () => { + try { + await rimrafAsync('./data'); + await mkdir('./data'); + await mkdir('./data/languages'); + } catch(e) { + throw new Error(e); + } + + const output = {}; + const languageDir = join(await nsisDir(), 'Contrib', 'Language files'); + let languageFiles = await globby(`${languageDir}/*.nlf`); + + languageFiles = languageFiles.sort(); + + for (languageFile of languageFiles) { + const langExtname = extname(languageFile); + const langBasename = basename(languageFile, langExtname); + + const nlfFile = await readFile(`${languageDir}/${langBasename}.nlf`, 'utf8'); + const nlfContent = NLF.parse(nlfFile); + + + const nshFile = await readFile(`${languageDir}/${langBasename}.nsh`, 'utf8'); + const nshContent = await MUI.parse(nshFile, { looseQuotes: true }); + + output[nshContent.file] = { + id: nlfContent.id, + code_page: nlfContent.codepage, + rtl: nlfContent.rtl, + english: nshContent.english, + native: nshContent.native, + native_ascii: nshContent.nativeASCII, + }; + + try { + await writeFile(`data/languages/${nshContent.file}.json`, JSON.stringify(nlfContent, null, 2), 'utf8'); + } catch (e) { + throw new Error(e); + } + } + + try { + await writeFile(`data/languages/${nshContent.file}.json`, JSON.stringify(nlfContent, null, 2), 'utf8'); + } catch (e) { + await writeFile('data/meta.json', JSON.stringify(output, null, 2), 'utf8'); + } +})();