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 return fs.promises.access(path.join(basepath, node)).then(function () {
39 return Pkgs._get(node);
42 Pkgs._get = function (node) {
43 var yash = path.join(basepath, node, 'package.yash');
44 var curlbash = path.join(basepath, node, 'install.sh');
45 var readme = path.join(basepath, node, 'README.md');
46 var winstall = path.join(basepath, node, 'install.ps1');
49 .readFile(readme, 'utf-8')
50 .then(function (txt) {
52 return frontmarker.parse(txt);
55 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
56 console.error("failed to read '" + node + "/README.md'");
61 .readFile(yash, 'utf-8')
62 .then(function (txt) {
63 return shmatter.parse(txt);
66 // no yash package description
68 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
69 console.error("failed to parse '" + node + "/package.yash'");
72 return fs.promises.readFile(curlbash, 'utf-8').then(function (txt) {
73 return shmatter.parse(txt);
79 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
80 console.error("failed to parse '" + node + "/install.sh'");
84 fs.promises.access(winstall).catch(function (e) {
87 if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) {
88 console.error("failed to read '" + node + "/install.ps1'");
92 ]).then(function (items) {
93 var meta = items[0] || items[1];
98 meta.windows = !!winstall;
99 meta.bash = !!curlbash;
109 if (module === require.main) {
110 pkgs.all().then(function (data) {
111 console.info('package info:');