3 var frontmarker = require('./frontmarker.js');
4 var shmatter = require('shmatter');
5 var fs = require('fs');
6 var path = require('path');
8 var pkgs = module.exports;
9 pkgs.create = function (Pkgs, basepath) {
14 basepath = path.join(__dirname, '../');
17 Pkgs.all = function () {
18 return fs.promises.readdir(basepath).then(function (nodes) {
21 .reduce(function (p, node) {
22 return p.then(function () {
23 return pkgs.get(node).then(function (meta) {
24 if (meta && '_' !== node[0]) {
37 Pkgs.get = function (node) {
38 var yash = path.join(basepath, node, 'package.yash');
39 var curlbash = path.join(basepath, node, 'install.sh');
40 var readme = path.join(basepath, node, 'README.md');
41 var winstall = path.join(basepath, node, 'install.ps1');
44 .readFile(readme, 'utf-8')
45 .then(function (txt) {
47 return frontmarker.parse(txt);
50 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
51 console.error("failed to read '" + node + "/README.md'");
56 .readFile(yash, 'utf-8')
57 .then(function (txt) {
58 return shmatter.parse(txt);
61 // no yash package description
63 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
64 console.error("failed to parse '" + node + "/package.yash'");
67 return fs.promises.readFile(curlbash, 'utf-8').then(function (txt) {
68 return shmatter.parse(txt);
74 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
75 console.error("failed to parse '" + node + "/install.sh'");
79 fs.promises.access(winstall).catch(function (e) {
82 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
83 console.error("failed to read '" + node + "/install.ps1'");
87 ]).then(function (items) {
88 var meta = items[0] || items[1];
93 meta.windows = !!winstall;
94 meta.bash = !!curlbash;
104 if (module === require.main) {
105 pkgs.all().then(function (data) {
106 console.info('package info:');