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 = /[<>'"`$\\]/; var BAD_SH_RE = /[<>'"`$\\]/;
Installers.renderBash = async function ( Installers.renderBash = async function (
pkgdir, baseurl,
rel, posixTemplate,
{ baseurl, pkg, tag, ver, os = '', arch = '', libc = '', formats, latest }, buildRequest,
buildMatch,
) { ) {
if (!Array.isArray(formats)) {
formats = [];
}
if (!tag) {
tag = '';
}
let installTxt = await Fs.readFile(path.join(pkgdir, 'install.sh'), 'utf8'); let installTxt = await Fs.readFile(path.join(pkgdir, 'install.sh'), 'utf8');
installTxt = padScript(installTxt); installTxt = padScript(installTxt);
var vers = rel.version.split('.'); var vers = rel.version.split('.');
@@ -131,17 +126,18 @@ Installers.renderBash = async function (
return tplTxt; return tplTxt;
}; };
/**
* @param {String} pkgdir
* @param {String} baseurl
* @param {BuildRequest} buildRequest
* @param {BuildMatch} buildMatch
*/
Installers.renderPowerShell = async function ( Installers.renderPowerShell = async function (
pkgdir, baseurl,
rel, pwshTemplate,
{ baseurl, pkg, tag, ver, os, arch, libc = '', formats }, buildRequest,
buildMatch,
) { ) {
if (!Array.isArray(formats)) {
formats = [];
}
if (!tag) {
tag = '';
}
let installTxt = await Fs.readFile(path.join(pkgdir, 'install.ps1'), 'utf8'); let installTxt = await Fs.readFile(path.join(pkgdir, 'install.ps1'), 'utf8');
installTxt = padScript(installTxt); installTxt = padScript(installTxt);
/* /*

View File

@@ -10,25 +10,53 @@ let Builds = require('./builds.js');
let Installers = require('./installers.js'); let Installers = require('./installers.js');
InstallerServer.INSTALLERS_DIR = Path.join(__dirname, '..'); 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 ( InstallerServer.serveInstaller = async function (
baseurl, baseurl,
ua, ua, // TODO nix
pkg, unameAgent,
pkg, // TODO nix
projectName,
tag, tag,
ext, ext, // TODO nix
installerType,
formats, formats,
) { ) {
let unameAgent = ua; if (!unameAgent) {
let projectName = pkg; unameAgent = ua;
let [rel, tmplParams] = await InstallerServer.helper({ }
if (!projectName) {
projectName = pkg;
}
if (!installerType) {
installerType = ext;
}
let buildRequest = {
projectName, projectName,
tag, tag,
unameAgent, unameAgent,
formats, 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); var pkgdir = Path.join(InstallerServer.INSTALLERS_DIR, projectName);
if ('ps1' === ext) { if ('ps1' === ext) {
@@ -39,6 +67,10 @@ InstallerServer.serveInstaller = async function (
// TODO put some of this in a middleware? or common function? // TODO put some of this in a middleware? or common function?
// TODO maybe move package/version/lts/channel detection into getReleases // TODO maybe move package/version/lts/channel detection into getReleases
/**
* @param {BuildRequest}
* @returns {BuildMatch}
*/
InstallerServer.helper = async function ({ InstallerServer.helper = async function ({
unameAgent, unameAgent,
projectName, projectName,
@@ -130,9 +162,6 @@ InstallerServer.helper = async function ({
}; };
let hasOs = projInfo.oses.includes(hostTarget.os); let hasOs = projInfo.oses.includes(hostTarget.os);
if (!hasOs) {
hasOs = projInfo.oses.includes('ANYOS');
}
if (!hasOs) { if (!hasOs) {
let pkg1 = Object.assign(buildTargetInfo, errPackage); let pkg1 = Object.assign(buildTargetInfo, errPackage);
return [pkg1, tmplParams]; return [pkg1, tmplParams];
@@ -162,10 +191,11 @@ InstallerServer.helper = async function ({
if (version.startsWith('v')) { if (version.startsWith('v')) {
version = version.slice(1); version = version.slice(1);
} }
let ver = version;
buildPkg = Object.assign(buildTargetInfo, buildPkg, { ext, version }); buildPkg = Object.assign(buildTargetInfo, buildPkg, { ext, version, tag });
console.log('dbg: buildPkg', buildPkg); Object.assign(tmplParams, { tag, ext, ver, version });
console.log('dbg: tmplParams', tmplParams); //console.log(`VERSION: ${version}`, ext);
return [buildPkg, tmplParams]; 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']; var formats = ['exe', 'xz', 'tar', 'zip', 'git'];
let unameAgent = `${nodeOs}/${nodeOsRelease} ${nodeArch}/unknown ${nodeLibc}`;
console.log(`DEBUG: ${unameAgent}`);
let [rel, opts] = await ServeInstaller.helper({ let [rel, opts] = await ServeInstaller.helper({
unameAgent: unameAgent,
projectName: pkgname, projectName: pkgname,
tag: pkgtag || '', tag: pkgtag || '',
unameAgent: `${nodeOs}/${nodeOsRelease} ${nodeArch}/unknown ${nodeLibc}`,
formats: formats, formats: formats,
libc: nodeLibc,
}); });
console.log('DEBUG opts:');
console.log(opts);
Object.assign( Object.assign(
rel,
{ {
ver: '', version: '{test-version}',
git_tag: '{test-git-tag}',
git_commit_hash: '{test-git-commit-hash}',
lts: null, lts: null,
channel: '', channel: '{test-channel}',
os: '', date: '1970-01-01T00:00:00Z',
arch: '', os: '{test-os}',
arch: '{test-arch}',
ext: '{test-ext}',
limit: 0, limit: 0,
}, },
opts, opts,

View File

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