From 9e485b15a7cf11cd6ad3cdbd0be28934cc529cb9 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Tue, 16 Jun 2020 13:11:51 -0600 Subject: [PATCH] begin support for batch templating --- .gitignore | 1 + _webi/releases.js | 34 ++++++++++++++++++++++++++++++++++ _webi/template.bat | 5 +++++ _webi/test.js | 44 +++++++++++++++++++++++++++++++------------- 4 files changed, 71 insertions(+), 13 deletions(-) create mode 100644 _webi/template.bat diff --git a/.gitignore b/.gitignore index e3a0b44..f199fa3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ install-*.sh +install-*.bat diff --git a/_webi/releases.js b/_webi/releases.js index 92c6a8c..ee0815d 100644 --- a/_webi/releases.js +++ b/_webi/releases.js @@ -111,3 +111,37 @@ Releases.renderBash = function ( }); }); }; + +Releases.renderBatch = function ( + pkgdir, + rel, + { baseurl, pkg, tag, ver, os, arch, formats } +) { + if (!Array.isArray(formats)) { + formats = []; + } + if (!tag) { + tag = ''; + } + return fs.promises + .readFile(path.join(pkgdir, 'install.bat'), 'utf8') + .then(function (installTxt) { + var vers = rel.version.split('.'); + var v = { + major: vers.shift() || '', + minor: vers.shift() || '', + patch: vers.join('.').replace(/[+\-].*/, ''), + build: vers + .join('.') + .replace(/[^+\-]*/, '') + .replace(/^-/, '') + }; + return fs.promises + .readFile(path.join(__dirname, 'template.bat'), 'utf8') + .then(function (tplTxt) { + return tplTxt + .replace(/^(REM )?WEBI_PKG=.*/im, "WEBI_PKG='" + pkg + '@' + ver + "'") + .replace(/{{ installer }}/, installTxt); + }); + }); +}; diff --git a/_webi/template.bat b/_webi/template.bat new file mode 100644 index 0000000..8b9d43b --- /dev/null +++ b/_webi/template.bat @@ -0,0 +1,5 @@ +REM REM debug + +REM WEBI_PKG= + +{{ installer }} diff --git a/_webi/test.js b/_webi/test.js index e40495e..59c1e19 100755 --- a/_webi/test.js +++ b/_webi/test.js @@ -93,25 +93,43 @@ Releases.get(path.join(process.cwd(), pkgdir)).then(function (all) { console.info(rel); console.info(''); - return Releases.renderBash(pkgdir, rel, { - baseurl: 'https://webinstall.dev', - pkg: pkgname, - tag: pkgtag || '', - ver: '', - os: osrel, - arch, - formats: formats - }).then(function (bashTxt) { + return Promise.all([ + Releases.renderBash(pkgdir, rel, { + baseurl: 'https://webinstall.dev', + pkg: pkgname, + tag: pkgtag || '', + ver: '', + os: osrel, + arch, + formats: formats + }).catch(function () {}), + Releases.renderBatch(pkgdir, rel, { + baseurl: 'https://webinstall.dev', + pkg: pkgname, + tag: pkgtag || '', + ver: '', + os: osrel, + arch, + formats: formats + }).catch(function () {}) + ]).then(function (scripts) { + var bashTxt = scripts[0]; + var batTxt = scripts[1]; var bashFile = 'install-' + pkgname + '.sh'; var batFile = 'install-' + pkgname + '.bat'; if (debug) { - bashTxt = bashTxt.replace(/#set -x/g, 'set -x'); + bashTxt = (bashTxt || 'echo ERROR').replace(/#set -x/g, 'set -x'); + batTxt = (batTxt || 'echo ERROR').replace( + /REM REM todo debug/g, + 'REM todo debug' + ); } - fs.writeFileSync(bashFile, bashTxt, 'utf-8'); console.info('Has the necessary files?'); - console.info('\tNEEDS MANUAL TEST: %s', bashFile); - console.info('\t(todo: ' + batFile + ')'); + fs.writeFileSync(bashFile, bashTxt, 'utf-8'); + console.info('\tNEEDS MANUAL TEST: bash %s', bashFile); + fs.writeFileSync(batFile, batTxt, 'utf-8'); + console.info('\tNEEDS MANUAL TEST: cmd.exe %s', batFile); console.info(''); }); }); -- 2.25.1