Compare commits

..

12 Commits

4 changed files with 78 additions and 44 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,25 +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,
) {
let unameAgent = ua;
let projectName = pkg;
let [rel, tmplParams] = await InstallerServer.helper({
if (!unameAgent) {
unameAgent = ua;
}
if (!projectName) {
projectName = pkg;
}
if (!installerType) {
installerType = ext;
}
let buildRequest = {
projectName,
tag,
unameAgent,
formats,
});
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) {
@@ -39,6 +67,10 @@ 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,
@@ -130,9 +162,6 @@ InstallerServer.helper = async function ({
};
let hasOs = projInfo.oses.includes(hostTarget.os);
if (!hasOs) {
hasOs = projInfo.oses.includes('ANYOS');
}
if (!hasOs) {
let pkg1 = Object.assign(buildTargetInfo, errPackage);
return [pkg1, tmplParams];
@@ -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,19 +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({
unameAgent: unameAgent,
projectName: pkgname,
tag: pkgtag || '',
unameAgent: `${nodeOs}/${nodeOsRelease} ${nodeArch}/unknown ${nodeLibc}`,
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,

View File

@@ -7,20 +7,18 @@
"scripts": {
"bump": "npm version -m \"chore(release): bump to v%s\"",
"fmt": "npm run prettier && npm run shfmt && npm run pwsh-fmt",
"lint": "npm run shellcheck && npm run jshint && npm run pwsh-lint && npm run tsc",
"lint": "npm run shellcheck && npm run jshint && npm run pwsh-lint",
"prepare": "npm run tooling-init && npm run git-hooks-init",
"test": "node _webi/test.js ./node/",
"----": "------------------------------------",
"git-hooks-init": "node ./_scripts/git-hooks-init.js",
"jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc --exclude 'node_modules/**/*' *.js */*.js",
"jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc --exclude 'node_modules/**/*' */*.js */*/*.js",
"prettier": "npx -p prettier@3.x -- prettier -w '**/*.{js,md,html}'",
"pwsh-fmt": "pwsh ./_scripts/pwsh-fmt.ps1",
"pwsh-lint": "pwsh ./_scripts/pwsh-lint.ps1",
"shellcheck": "shellcheck -s sh -S style --exclude=SC2154,SC2034 */*.sh",
"shfmt": "shfmt -w -i 4 -sr -ci -s ./",
"tsc": "npx -p typescript@5.x -- tsc -p ./jsconfig.json",
"tooling-init": "node ./_scripts/tooling-init.js",
"prepublish": "npx -p jswt@1.x -- reexport"
"tooling-init": "node ./_scripts/tooling-init.js"
},
"repository": {
"type": "git",