diff --git a/_webi/packages.js b/_webi/packages.js deleted file mode 100644 index 80f0bda..0000000 --- a/_webi/packages.js +++ /dev/null @@ -1,96 +0,0 @@ -'use strict'; - -var frontmarker = require('./frontmarker.js'); -var fs = require('fs'); -var path = require('path'); - -var pkgs = module.exports; -pkgs.create = function (Pkgs, basepath) { - if (!Pkgs) { - Pkgs = {}; - } - if (!basepath) { - basepath = path.join(__dirname, '../'); - } - - Pkgs.all = function () { - return fs.promises.readdir(basepath).then(function (nodes) { - var items = []; - return nodes - .reduce(function (p, node) { - return p.then(function () { - return pkgs.get(node).then(function (meta) { - if (meta && '_' !== node[0]) { - meta.name = node; - items.push(meta); - } - }); - }); - }, Promise.resolve()) - .then(function () { - return items; - }); - }); - }; - - Pkgs.get = function (node) { - return fs.promises.access(path.join(basepath, node)).then(function () { - return Pkgs._get(node); - }); - }; - Pkgs._get = function (node) { - var curlbash = path.join(basepath, node, 'install.sh'); - var readme = path.join(basepath, node, 'README.md'); - var winstall = path.join(basepath, node, 'install.ps1'); - return Promise.all([ - fs.promises - .readFile(readme, 'utf-8') - .then(function (txt) { - // TODO - return frontmarker.parse(txt); - }) - .catch(function (e) { - if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { - console.error("failed to read '" + node + "/README.md'"); - console.error(e); - } - }), - fs.promises.access(curlbash).catch(function (e) { - // no *nix installer - curlbash = ''; - if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { - console.error("failed to parse '" + node + "/install.sh'"); - console.error(e); - } - }), - fs.promises.access(winstall).catch(function (e) { - // no winstaller - winstall = ''; - if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { - console.error("failed to read '" + node + "/install.ps1'"); - console.error(e); - } - }), - ]).then(function (items) { - var meta = items[0] || items[1]; - if (!meta) { - // doesn't exist - return; - } - meta.windows = !!winstall; - meta.bash = !!curlbash; - - return meta; - }); - }; - - return Pkgs; -}; -pkgs.create(pkgs); - -if (module === require.main) { - pkgs.all().then(function (data) { - console.info('package info:'); - console.info(data); - }); -} diff --git a/_webi/packages.js b/_webi/packages.js new file mode 120000 index 0000000..a1f9185 --- /dev/null +++ b/_webi/packages.js @@ -0,0 +1 @@ +projects.js \ No newline at end of file diff --git a/_webi/projects.js b/_webi/projects.js new file mode 100644 index 0000000..80f0bda --- /dev/null +++ b/_webi/projects.js @@ -0,0 +1,96 @@ +'use strict'; + +var frontmarker = require('./frontmarker.js'); +var fs = require('fs'); +var path = require('path'); + +var pkgs = module.exports; +pkgs.create = function (Pkgs, basepath) { + if (!Pkgs) { + Pkgs = {}; + } + if (!basepath) { + basepath = path.join(__dirname, '../'); + } + + Pkgs.all = function () { + return fs.promises.readdir(basepath).then(function (nodes) { + var items = []; + return nodes + .reduce(function (p, node) { + return p.then(function () { + return pkgs.get(node).then(function (meta) { + if (meta && '_' !== node[0]) { + meta.name = node; + items.push(meta); + } + }); + }); + }, Promise.resolve()) + .then(function () { + return items; + }); + }); + }; + + Pkgs.get = function (node) { + return fs.promises.access(path.join(basepath, node)).then(function () { + return Pkgs._get(node); + }); + }; + Pkgs._get = function (node) { + var curlbash = path.join(basepath, node, 'install.sh'); + var readme = path.join(basepath, node, 'README.md'); + var winstall = path.join(basepath, node, 'install.ps1'); + return Promise.all([ + fs.promises + .readFile(readme, 'utf-8') + .then(function (txt) { + // TODO + return frontmarker.parse(txt); + }) + .catch(function (e) { + if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { + console.error("failed to read '" + node + "/README.md'"); + console.error(e); + } + }), + fs.promises.access(curlbash).catch(function (e) { + // no *nix installer + curlbash = ''; + if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { + console.error("failed to parse '" + node + "/install.sh'"); + console.error(e); + } + }), + fs.promises.access(winstall).catch(function (e) { + // no winstaller + winstall = ''; + if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { + console.error("failed to read '" + node + "/install.ps1'"); + console.error(e); + } + }), + ]).then(function (items) { + var meta = items[0] || items[1]; + if (!meta) { + // doesn't exist + return; + } + meta.windows = !!winstall; + meta.bash = !!curlbash; + + return meta; + }); + }; + + return Pkgs; +}; +pkgs.create(pkgs); + +if (module === require.main) { + pkgs.all().then(function (data) { + console.info('package info:'); + console.info(data); + }); +} diff --git a/_webi/serve-installer.js b/_webi/serve-installer.js index 08715eb..2b9dd51 100644 --- a/_webi/serve-installer.js +++ b/_webi/serve-installer.js @@ -6,7 +6,7 @@ var Fs = require('fs/promises'); var path = require('path'); var uaDetect = require('./ua-detect.js'); -var packages = require('./packages.js'); +var Projects = require('./projects.js'); var Releases = require('./releases.js'); // handlers caching and transformation, probably should be broken down @@ -84,7 +84,7 @@ Installers.helper = async function ({ ua, pkg, tag, formats, libc }) { myLibc = 'libc'; } - let cfg = await packages.get(pkg); + let cfg = await Projects.get(pkg); let releaseQuery = { pkg: cfg.alias || pkg, ver,