From 1ddaa43a7dbfd819edb190152f88a02d6b81c110 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 18 Jun 2020 08:43:08 +0000 Subject: [PATCH] package.yash => README.md --- README.md | 35 ++++++++---------- _webi/frontmarker.js | 87 ++++++++++++++++++++++++++++++++++++++++++++ _webi/packages.js | 5 ++- _webi/test.js | 2 +- caddy/README.md | 12 ++++++ caddy/package.yash | 14 ------- deno/README.md | 33 +++++++++++++++++ deno/package.yash | 37 ------------------- node/README.md | 74 +++++++++++++++++++++++++++++++++++++ node/package.yash | 79 ---------------------------------------- package-lock.json | 13 +++++++ package.json | 3 +- 12 files changed, 240 insertions(+), 154 deletions(-) create mode 100644 _webi/frontmarker.js create mode 100644 caddy/README.md delete mode 100644 caddy/package.yash create mode 100644 deno/README.md delete mode 100644 deno/package.yash create mode 100644 node/README.md delete mode 100644 node/package.yash diff --git a/README.md b/README.md index f9c4986..eea409b 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ An install consists of 5 parts in 4 files: ``` my-new-package/ - - package.yash + - README.md (package info in frontmatter) - releases.js - install.sh - install.bat @@ -105,27 +105,22 @@ node _webi/test.js ./new-package/ Just copy the format from any of the existing packages. It's like this: -`package.yash`: +`README.md`: -```` -# title: Node.js -# homepage: https://nodejs.org -# tagline: JavaScript V8 runtime -# description: | -# Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine -# examples: | -# ```bash -# node -e 'console.log("Hello, World!")' -# > Hello, World! -# ``` - -END -```` - -This is a dumb format. We know. Historical accident (originally these were in -bash comments). +````md +--- +title: Node.js +homepage: https://nodejs.org +tagline: JavaScript V8 runtime +description: | + Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine +--- -It's in the TODOs to replace this with either YAML or Markdown. +```bash +node -e 'console.log("Hello, World!")' +> Hello, World! +``` +```` ### 1. Fetch Releases diff --git a/_webi/frontmarker.js b/_webi/frontmarker.js new file mode 100644 index 0000000..34a2495 --- /dev/null +++ b/_webi/frontmarker.js @@ -0,0 +1,87 @@ +'use strict'; + +var fs = require('fs'); +var marked = require('marked'); + +var frontmatter = '---'; +var keyValRe = /(\w+): (.*)/; + +function parseYamlish(txt) { + var end = false; + var cfg = { title: '', tagline: '', description: '', examples: '' }; + var block = false; + + var lines = txt.trim().split('\n'); + var moreRe = /\s+/; + var last; + + if (frontmatter !== lines.shift()) { + throw new Error('no frontmatter marker at beginning of file'); + } + + function unblock() { + cfg[block] = marked(cfg[block]); + block = false; + } + + lines.some(function (line, i) { + if (frontmatter === line) { + // end of frontmatter + end = true; + return; + } + + if (end) { + if (line.trim()) { + throw new Error('missing newline after frontmatter'); + } + last = i; + return true; + } + + if (!line[0]) { + if (block) { + cfg[block] += '\n'; + } else { + throw new Error('invalid blank line in frontmatter'); + } + } + + if (block) { + if (!line || ' ' === line.slice(0, 2)) { + cfg[block] += line.slice(2) + '\n'; + return; + } + unblock(); + } + + var m = line.match(keyValRe); + if (!m) { + throw new Error( + 'invalid key format for: ' + JSON.stringify(line) + ' ' + i + ); + } + if ('|' === m[2]) { + block = m[1]; + return; + } + cfg[m[1]] = m[2]; + }); + + if (block) { + cfg[block] = marked(cfg[block]); + } + cfg.examples = marked(lines.slice(last).join('\n')); + + return cfg; +} + +module.exports.parse = parseYamlish; + +if (require.main === module) { + console.info( + parseYamlish( + fs.readFileSync(__dirname + '/../node/README.md', 'utf8') + ) + ); +} diff --git a/_webi/packages.js b/_webi/packages.js index 603dc14..b6ed221 100644 --- a/_webi/packages.js +++ b/_webi/packages.js @@ -1,5 +1,6 @@ 'use strict'; +var frontmarker = require('./frontmarker.js'); var shmatter = require('shmatter'); var fs = require('fs'); var path = require('path'); @@ -43,7 +44,7 @@ pkgs.create = function (Pkgs, basepath) { .readFile(readme, 'utf-8') .then(function (txt) { // TODO - //return frontmarker.parse(txt); + return frontmarker.parse(txt); }) .catch(function (e) { if ('ENOENT' !== e.code && 'ENOTDIR' !== e.code) { @@ -84,7 +85,7 @@ pkgs.create = function (Pkgs, basepath) { } }) ]).then(function (items) { - var meta = items[1]; + var meta = items[0] || items[1]; if (!meta) { // doesn't exist return; diff --git a/_webi/test.js b/_webi/test.js index 59c1e19..0240d1a 100755 --- a/_webi/test.js +++ b/_webi/test.js @@ -46,7 +46,7 @@ nodes.forEach(function (node) { var maxLen = 0; console.info(''); console.info('Has the necessary files?'); -['package.yash', 'releases.js', 'install.sh', 'install.bat'] +['README.md', 'releases.js', 'install.sh', 'install.bat'] .map(function (node) { maxLen = Math.max(maxLen, node.length); return node; diff --git a/caddy/README.md b/caddy/README.md new file mode 100644 index 0000000..f7f4ae5 --- /dev/null +++ b/caddy/README.md @@ -0,0 +1,12 @@ +--- +title: Caddy +homepage: https://github.com/caddyserver/caddy +tagline: | + Caddy is a fast, multi-platform web server with automatic HTTPS. +description: | + Caddy makes it easy to use Let's Encrypt to handle HTTPS (TLS/SSL) and to reverse proxy APIs and WebSockets to other apps - such as those written node, Go, python, ruby, and PHP. +--- + +```bash +caddy start +``` diff --git a/caddy/package.yash b/caddy/package.yash deleted file mode 100644 index 8993130..0000000 --- a/caddy/package.yash +++ /dev/null @@ -1,14 +0,0 @@ -# title: Caddy -# homepage: https://github.com/caddyserver/caddy -# tagline: | -# Caddy is a fast, multi-platform web server with automatic HTTPS. -# description: | -# Caddy makes it easy to use Let's Encrypt to handle HTTPS (TLS/SSL) and to reverse proxy APIs and WebSockets to other apps - such as those written node, Go, python, ruby, and PHP. -# examples: | -# ```bash -# caddy start -# ``` - -This is a comment... because... poor choices I made. - -Don't worry, this will be yaml or markdown in the... sometime... future diff --git a/deno/README.md b/deno/README.md new file mode 100644 index 0000000..84f304e --- /dev/null +++ b/deno/README.md @@ -0,0 +1,33 @@ +--- +title: Deno +homepage: https://github.com/denoland/deno +tagline: | + Deno: A secure runtime for JavaScript and TypeScript. +description: | + Deno proves that lightning does strike twice. It's the ease of use of node, the intentional tooling of Go, and built in Rust. +--- + +The obligatory Hello World + +```bash +deno run https://deno.land/std/examples/welcome.ts +``` + +Run a local file + +```bash +deno run ./hello.ts +``` + +Enable [permissions](https://deno.land/manual/getting_started/permissions) + +```bash +deno run --allow-read=./data,./public --allow-write=./data \ + --allow-net=example.com,example.net ./hello.ts +``` + +Format source code, recursively + +```bash +deno fmt ./my-project +``` diff --git a/deno/package.yash b/deno/package.yash deleted file mode 100644 index fa4535c..0000000 --- a/deno/package.yash +++ /dev/null @@ -1,37 +0,0 @@ -# title: Deno -# homepage: https://github.com/denoland/deno -# tagline: | -# Deno: A secure runtime for JavaScript and TypeScript. -# description: | -# Deno proves that lightning does strike twice. It's the ease of use of node, the intentional tooling of Go, and built in Rust. -# examples: | -# The obligatory Hello World -# -# ```bash -# deno run https://deno.land/std/examples/welcome.ts -# ``` -# -# Run a local file -# -# ```bash -# deno run ./hello.ts -# ``` -# -# Enable [permissions](https://deno.land/manual/getting_started/permissions) -# -# ```bash -# deno run --allow-read=./data,./public --allow-write=./data \ -# --allow-net=example.com,example.net ./hello.ts -# ``` -# -# Format source code, recursively -# -# ```bash -# deno fmt ./my-project -# ``` -# - - -This is a comment... because... poor choices I made. - -Don't worry, this will be yaml or markdown in the... sometime... future diff --git a/node/README.md b/node/README.md new file mode 100644 index 0000000..7a8e6d0 --- /dev/null +++ b/node/README.md @@ -0,0 +1,74 @@ +--- +title: Node.js +homepage: https://nodejs.org +tagline: | + Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. +description: | + Node is great for simple, snappy HTTP(S) servers, and for stitching APIs together with minimal fuss or muss. +--- + +Hello World + +```bash +node -e 'console.log("Hello, World!")' +> Hello, World! +``` + +A Simple Web Server + +`server.js`: + +```bash +var http = require('http'); +var app = function (req, res) { + res.end('Hello, World!'); +}; +http.createServer(app).listen(8080, function () { + console.info('Listening on', this.address()); +}); +``` + +```bash +node server.js +``` + +An Express App + +```bash +mkdir my-server +pushd my-server +npm init +npm install --save express +``` + +`app.js`: + +```js +'use strict'; + +var express = require('express'); +var app = express(); + +app.use('/', function (req, res, next) { + res.end("Hello, World!"); +}); + +module.exports = app; +``` + +`server.js`: + +```js +'use strict'; + +var http = require('http'); +var app = require('./app.js'); + +http.createServer(app).listen(8080, function () { + console.info('Listening on', this.address()); +}); +``` + +```bash +npm start +``` diff --git a/node/package.yash b/node/package.yash deleted file mode 100644 index e7508ec..0000000 --- a/node/package.yash +++ /dev/null @@ -1,79 +0,0 @@ -# -# title: Node.js -# homepage: https://nodejs.org -# tagline: | -# Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. -# description: | -# Node is great for simple, snappy HTTP(S) servers, and for stitching APIs together with minimal fuss or muss. -# examples: | -# -# ### Hello World -# -# ```bash -# node -e 'console.log("Hello, World!")' -# > Hello, World! -# ``` -# -# ### A Simple Web Server -# -# `server.js`: -# -# ```bash -# var http = require('http'); -# var app = function (req, res) { -# res.end('Hello, World!'); -# }; -# http.createServer(app).listen(8080, function () { -# console.info('Listening on', this.address()); -# }); -# ``` -# -# ```bash -# node server.js -# ``` -# -# ### An Express App -# -# ```bash -# mkdir my-server -# pushd my-server -# npm init -# npm install --save express -# ``` -# -# `app.js`: -# -# ```js -# 'use strict'; -# -# var express = require('express'); -# var app = express(); -# -# app.use('/', function (req, res, next) { -# res.end("Hello, World!"); -# }); -# -# module.exports = app; -# ``` -# -# `server.js`: -# -# ```js -# 'use strict'; -# -# var http = require('http'); -# var app = require('./app.js'); -# -# http.createServer(app).listen(8080, function () { -# console.info('Listening on', this.address()); -# }); -# ``` -# -# ```bash -# npm start -# ``` -# - -This is a comment... because... poor choices I made. - -Don't worry, this will be yaml or markdown in the... sometime... future diff --git a/package-lock.json b/package-lock.json index 928f48a..69f044a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,19 @@ "version": "1.6.1", "resolved": "https://registry.npmjs.org/@root/request/-/request-1.6.1.tgz", "integrity": "sha512-8wrWyeBLRp7T8J36GkT3RODJ6zYmL0/maWlAUD5LOXT28D3TDquUepyYDKYANNA3Gc8R5ZCgf+AXvSTYpJEWwQ==" + }, + "marked": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-1.1.0.tgz", + "integrity": "sha512-EkE7RW6KcXfMHy2PA7Jg0YJE1l8UPEZE8k45tylzmZM30/r1M1MUXWQfJlrSbsTeh7m/XTwHbWUENvAJZpp1YA==" + }, + "shmatter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/shmatter/-/shmatter-1.0.1.tgz", + "integrity": "sha512-bBAvHI8640XcMDsShK2HOR8WOkF65hMprXr7Rsqb3z+26/5qna3jZfP7VZScItGoULUYyNeen9isD60KxtD2hQ==", + "requires": { + "marked": "^1.0.0" + } } } } diff --git a/package.json b/package.json index 3c9406f..105bbe4 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ }, "homepage": "https://github.com/webinstall/packages#readme", "dependencies": { - "@root/request": "^1.6.1" + "@root/request": "^1.6.1", + "shmatter": "^1.0.1" } } -- 2.25.1