mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-02-14 09:39:51 +00:00
WIP: ref(installer): use new names for template vars
This commit is contained in:
@@ -14,16 +14,11 @@ function padScript(txt) {
|
||||
|
||||
var BAD_SH_RE = /[<>'"`$\\]/;
|
||||
Installers.renderBash = async function (
|
||||
pkgdir,
|
||||
rel,
|
||||
{ baseurl, pkg, tag, ver, os = '', arch = '', libc = '', formats, latest },
|
||||
baseurl,
|
||||
posixTemplate,
|
||||
buildRequest,
|
||||
buildMatch,
|
||||
) {
|
||||
if (!Array.isArray(formats)) {
|
||||
formats = [];
|
||||
}
|
||||
if (!tag) {
|
||||
tag = '';
|
||||
}
|
||||
let installTxt = await Fs.readFile(path.join(pkgdir, 'install.sh'), 'utf8');
|
||||
installTxt = padScript(installTxt);
|
||||
var vers = rel.version.split('.');
|
||||
@@ -131,17 +126,18 @@ Installers.renderBash = async function (
|
||||
return tplTxt;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {String} pkgdir
|
||||
* @param {String} baseurl
|
||||
* @param {BuildRequest} buildRequest
|
||||
* @param {BuildMatch} buildMatch
|
||||
*/
|
||||
Installers.renderPowerShell = async function (
|
||||
pkgdir,
|
||||
rel,
|
||||
{ baseurl, pkg, tag, ver, os, arch, libc = '', formats },
|
||||
baseurl,
|
||||
pwshTemplate,
|
||||
buildRequest,
|
||||
buildMatch,
|
||||
) {
|
||||
if (!Array.isArray(formats)) {
|
||||
formats = [];
|
||||
}
|
||||
if (!tag) {
|
||||
tag = '';
|
||||
}
|
||||
let installTxt = await Fs.readFile(path.join(pkgdir, 'install.ps1'), 'utf8');
|
||||
installTxt = padScript(installTxt);
|
||||
/*
|
||||
|
||||
@@ -10,27 +10,53 @@ let Builds = require('./builds.js');
|
||||
let Installers = require('./installers.js');
|
||||
|
||||
InstallerServer.INSTALLERS_DIR = Path.join(__dirname, '..');
|
||||
|
||||
/**
|
||||
* @typedef BuildRequest
|
||||
* @prop {String} unameAgent
|
||||
* @prop {String} projectName
|
||||
* @prop {String} tag
|
||||
* @prop {Array<String>} formats
|
||||
*/
|
||||
|
||||
InstallerServer.serveInstaller = async function (
|
||||
baseurl,
|
||||
ua,
|
||||
pkg,
|
||||
ua, // TODO nix
|
||||
unameAgent,
|
||||
pkg, // TODO nix
|
||||
projectName,
|
||||
tag,
|
||||
ext,
|
||||
ext, // TODO nix
|
||||
installerType,
|
||||
formats,
|
||||
libc,
|
||||
) {
|
||||
let unameAgent = ua;
|
||||
let projectName = pkg;
|
||||
let [rel, tmplParams] = await InstallerServer.helper({
|
||||
unameAgent,
|
||||
if (!unameAgent) {
|
||||
unameAgent = ua;
|
||||
}
|
||||
if (!projectName) {
|
||||
projectName = pkg;
|
||||
}
|
||||
if (!installerType) {
|
||||
installerType = ext;
|
||||
}
|
||||
let buildRequest = {
|
||||
projectName,
|
||||
tag,
|
||||
unameAgent,
|
||||
formats,
|
||||
libc,
|
||||
});
|
||||
Object.assign(tmplParams, {
|
||||
baseurl,
|
||||
});
|
||||
};
|
||||
|
||||
let hostTarget = {};
|
||||
let buildMatch;
|
||||
{
|
||||
let terms = unameAgent.split(/[\s\/]+/g);
|
||||
void HostTargets.termsToTarget(hostTarget, terms);
|
||||
buildMatch = await InstallerServer.getBuild(buildRequest, hostTarget);
|
||||
}
|
||||
Object.assign(tmplParams, { baseurl, });
|
||||
|
||||
console.log('dbg: buildPkg', rel);
|
||||
console.log('dbg: tmplParams', tmplParams);
|
||||
|
||||
var pkgdir = Path.join(InstallerServer.INSTALLERS_DIR, projectName);
|
||||
if ('ps1' === ext) {
|
||||
@@ -41,12 +67,15 @@ InstallerServer.serveInstaller = async function (
|
||||
|
||||
// TODO put some of this in a middleware? or common function?
|
||||
// TODO maybe move package/version/lts/channel detection into getReleases
|
||||
/**
|
||||
* @param {BuildRequest}
|
||||
* @returns {BuildMatch}
|
||||
*/
|
||||
InstallerServer.helper = async function ({
|
||||
unameAgent,
|
||||
projectName,
|
||||
tag,
|
||||
formats,
|
||||
libc,
|
||||
}) {
|
||||
console.log(`dbg: Installer User-Agent: ${unameAgent}`);
|
||||
|
||||
@@ -162,10 +191,11 @@ InstallerServer.helper = async function ({
|
||||
if (version.startsWith('v')) {
|
||||
version = version.slice(1);
|
||||
}
|
||||
let ver = version;
|
||||
|
||||
buildPkg = Object.assign(buildTargetInfo, buildPkg, { ext, version });
|
||||
console.log('dbg: buildPkg', buildPkg);
|
||||
console.log('dbg: tmplParams', tmplParams);
|
||||
buildPkg = Object.assign(buildTargetInfo, buildPkg, { ext, version, tag });
|
||||
Object.assign(tmplParams, { tag, ext, ver, version });
|
||||
//console.log(`VERSION: ${version}`, ext);
|
||||
return [buildPkg, tmplParams];
|
||||
};
|
||||
|
||||
|
||||
@@ -81,20 +81,29 @@ Releases.get(path.join(process.cwd(), pkgdir)).then(async function (all) {
|
||||
}
|
||||
var formats = ['exe', 'xz', 'tar', 'zip', 'git'];
|
||||
|
||||
let unameAgent = `${nodeOs}/${nodeOsRelease} ${nodeArch}/unknown ${nodeLibc}`;
|
||||
console.log(`DEBUG: ${unameAgent}`);
|
||||
let [rel, opts] = await ServeInstaller.helper({
|
||||
ua: `${nodeOs}/${nodeOsRelease} ${nodeArch}/unknown ${nodeLibc}`,
|
||||
pkg: pkgname,
|
||||
unameAgent: unameAgent,
|
||||
projectName: pkgname,
|
||||
tag: pkgtag || '',
|
||||
formats: formats,
|
||||
libc: nodeLibc,
|
||||
});
|
||||
console.log('DEBUG opts:');
|
||||
console.log(opts);
|
||||
Object.assign(
|
||||
rel,
|
||||
{
|
||||
ver: '',
|
||||
version: '{test-version}',
|
||||
git_tag: '{test-git-tag}',
|
||||
git_commit_hash: '{test-git-commit-hash}',
|
||||
lts: null,
|
||||
channel: '',
|
||||
os: '',
|
||||
arch: '',
|
||||
channel: '{test-channel}',
|
||||
date: '1970-01-01T00:00:00Z',
|
||||
os: '{test-os}',
|
||||
arch: '{test-arch}',
|
||||
ext: '{test-ext}',
|
||||
limit: 0,
|
||||
},
|
||||
opts,
|
||||
|
||||
Reference in New Issue
Block a user