WIP: ref(installer): use new names for template vars

This commit is contained in:
AJ ONeal
2023-12-30 23:40:14 -07:00
parent 6e3eb1d9ad
commit 722df7641d
3 changed files with 76 additions and 41 deletions

View File

@@ -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);
/*

View File

@@ -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];
};

View File

@@ -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,