From 884f35565f87e450f7b0ccb605256345898a093e Mon Sep 17 00:00:00 2001 From: michaelmccord Date: Fri, 10 Apr 2020 16:13:48 -0400 Subject: [PATCH 1/5] Plugins --- .gitignore | 1 + bin/spec-md | 84 +++++++++++++++--------- package.json | 3 +- src/index.js | 14 ++-- src/parse.js | 2 +- src/print.js | 30 ++++++--- test/runner.js | 2 +- yarn.lock | 175 ++++++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 263 insertions(+), 48 deletions(-) diff --git a/.gitignore b/.gitignore index 104c501..af98572 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ out node_modules npm-debug.log src/grammar.js +.vscode diff --git a/bin/spec-md b/bin/spec-md index 992167c..04efc02 100755 --- a/bin/spec-md +++ b/bin/spec-md @@ -1,41 +1,63 @@ #!/usr/bin/env node -var fs = require('fs'); var path = require('path'); var specmd = require('../'); +var yargs = require('yargs'); -var filepath; -var metadata; -for (var i = 2; i < process.argv.length; i++) { - if (process.argv[i] === '-m' || process.argv[i] === '--metadata') { - metadata = process.argv[++i]; - } else if (process.argv[i][0] === '-') { - errorExit('Unknown argument: ' + process.argv[i]); - } else if (!filepath) { - filepath = process.argv[i]; - } else { - errorExit('Must provide only one markdown file.'); - } -} - -if (!filepath) { - errorExit( - 'Usage: spec-md initial-file.md\n\n' + - 'Options:\n' + - ' -m, --metadata filepath to json metadata' - ); -} -var options = metadata ? require(path.resolve(process.cwd(), metadata)) : {}; -var absPath = path.resolve(process.cwd(), filepath); +yargs.strict() + .config('config') + .option('metadata', { + alias: 'm', + describe: 'Additional metadata to be used in construction of the output', + string: true, + global: true, + coerce: arg=>require(path.resolve(process.cwd(), path.normalize(arg))), + }) + .command(['$0 ','html '], 'Outputs HTML5', {}, + (argv)=>{ + return specmd.html(argv.markdown,argv.metadata ? argv.metadata : {}) + .then(_=>process.stdout.write(_)) + .catch(errorExit); + } + ) + .command(['plugin '], 'Outputs in the format of the specified plugin', + (yargs)=>{ + yargs.usage('plugin [-- plugin-args...]'); + }, + (argv)=>{ + return argv.package(argv._, + specmd.parse(argv.markdown), argv.metadata ? argv.metadata : {}) + .then(_=>process.stdout.write(_)) + .catch(errorExit); + }) + .coerce('markdown', (arg)=>path.resolve(process.cwd(), path.normalize(arg))) + .coerce('package', (arg)=>{ + console.error(`Loading ${arg} ...`); + let package = null; + let plugin = null; + try { + package = require.resolve(arg, { + paths: [process.cwd()] + }); + plugin = require(package); + } + catch(error) { + console.error(`Could not load plugin (${arg}).`); + console.error('If the plugin is installed globally, is /usr/lib/node_modules in your NODE_PATH variable (%AppData%\\npm\\node_modules on windows)?'); + errorExit(error); + } -specmd.html(absPath, options).then(function (html) { - process.stdout.write(html); -}).catch(function (error) { - errorExit(error.line ? error.message : (error.stack || error)); -}); + if(typeof plugin !== 'function') { + errorExit(`The specified package (${package}) does not appear to be a plugin...`); + } + return plugin; + }) + .help() + .parse(); -function errorExit(msg) { - process.stderr.write(msg + '\n'); +function errorExit(error) { + error.line ? error.message : (error.stack || error) + process.stderr.write(error + '\n'); process.exit(1); } diff --git a/package.json b/package.json index d4f3551..6167376 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,8 @@ }, "dependencies": { "prismjs": ">=1.16.0", - "terser": "^4.1.2" + "terser": "^4.1.2", + "yargs": "^15.3.1" }, "devDependencies": { "jest-diff": "^24.8.0", diff --git a/src/index.js b/src/index.js index 235e126..c733bd4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,4 @@ -var print = require('./print'); +var {print, ...others} = require('./print'); var parse = require('./parse'); var visit = require('./visit'); @@ -8,7 +8,11 @@ function html(filepath, options) { }); } -exports.html = html; -exports.print = print; -exports.parse = parse; -exports.visit = visit; +module.exports = { + html, + print, + parse, + visit, + ...others +} + diff --git a/src/parse.js b/src/parse.js index 2d02287..90a2b2c 100644 --- a/src/parse.js +++ b/src/parse.js @@ -2,7 +2,7 @@ var fs = require('fs'); var path = require('path'); -var grammar = require('./grammar'); +var grammar = require(path.resolve(__dirname, './grammar')); var visit = require('./visit'); diff --git a/src/print.js b/src/print.js index 60f809c..a441881 100644 --- a/src/print.js +++ b/src/print.js @@ -6,13 +6,7 @@ var terser = require('terser'); var visit = require('./visit'); function print(ast, _options) { - var options = {}; - options.highlight = _options && _options.highlight || highlight; - options.biblio = _options && _options.biblio && buildBiblio(_options.biblio) || {}; - options.head = _options && _options.head || ''; - validateSecIDs(ast, options); - assignExampleNumbers(ast, options); - assignBiblioIDs(ast, options); + var options = updateBiblio(ast, _options); return ( '\n' + '\n' + @@ -23,7 +17,27 @@ function print(ast, _options) { ); }; -module.exports = print; +function updateBiblio(ast, _options) { + var options = {}; + options.highlight = _options && _options.highlight || highlight; + options.biblio = _options && _options.biblio && buildBiblio(_options.biblio) || {}; + options.head = _options && _options.head || ''; + validateSecIDs(ast, options); + assignExampleNumbers(ast, options); + assignBiblioIDs(ast, options); + return options; +} + +module.exports = { + print, + formatText, + escape, + escapeCode, + updateBiblio, + getTerms, + anchorize, + join +}; function highlight(code, lang) { var prismLang = getPrismLanguage(lang); diff --git a/test/runner.js b/test/runner.js index 5605bf6..d60b550 100644 --- a/test/runner.js +++ b/test/runner.js @@ -3,7 +3,7 @@ const fs = require('fs'); const path = require('path'); const specMarkdown = require('../'); -const shouldRecord = Boolean(process.env.RECORD); +const shouldRecord = process.env.RECORD ? Boolean.parse(process.env.RECORD) : false; runTests([ ['../README.md', 'readme/ast.json', 'readme/output.html'], diff --git a/yarn.lock b/yarn.lock index 902a6f5..20d1da0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10,6 +10,11 @@ "@types/istanbul-reports" "^1.1.1" "@types/yargs" "^12.0.9" +"@types/color-name@^1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@types/color-name/-/color-name-1.1.1.tgz#1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0" + integrity sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ== + "@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.1.tgz#42995b446db9a48a11a07ec083499a860e9138ff" @@ -53,12 +58,25 @@ ansi-regex@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-4.1.0.tgz#8b9f8f08cf1acb843756a839ca8c7e3168c51997" +ansi-regex@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" + integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== + ansi-styles@^3.2.0, ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" dependencies: color-convert "^1.9.0" +ansi-styles@^4.0.0: + version "4.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-4.2.1.tgz#90ae75c424d008d2624c5bf29ead3177ebfcf359" + integrity sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA== + dependencies: + "@types/color-name" "^1.1.1" + color-convert "^2.0.1" + anymatch@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-2.0.0.tgz#bcb24b4f37934d9aa7ac17b4adaf89e7c76ef2eb" @@ -181,6 +199,11 @@ camelcase@^4.0.0: version "4.1.0" resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" +camelcase@^5.0.0: + version "5.3.1" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-5.3.1.tgz#e3c9b31569e106811df242f715725a1f4c494320" + integrity sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg== + capture-stack-trace@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/capture-stack-trace/-/capture-stack-trace-1.0.1.tgz#a6c0bbe1f38f3aa0b92238ecb6ff42c344d4135d" @@ -240,6 +263,15 @@ clipboard@^2.0.0: select "^1.1.2" tiny-emitter "^2.0.0" +cliui@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-6.0.0.tgz#511d702c0c4e41ca156d7d0e96021f23e13225b1" + integrity sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ== + dependencies: + string-width "^4.2.0" + strip-ansi "^6.0.0" + wrap-ansi "^6.2.0" + code-point-at@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" @@ -257,10 +289,22 @@ color-convert@^1.9.0: dependencies: color-name "1.1.3" +color-convert@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3" + integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ== + dependencies: + color-name "~1.1.4" + color-name@1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" +color-name@~1.1.4: + version "1.1.4" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" + integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== + commander@^2.20.0: version "2.20.0" resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.0.tgz#d58bb2b5c1ee8f87b0d340027e9e94e222c5a422" @@ -326,6 +370,11 @@ debug@^3.1.0, debug@^3.2.6: dependencies: ms "^2.1.1" +decamelize@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" + integrity sha1-9lNNFRSCabIDUue+4m9QH5oZEpA= + decode-uri-component@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545" @@ -379,6 +428,11 @@ duplexer3@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2" +emoji-regex@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-8.0.0.tgz#e818fd69ce5ccfcb404594f842963bf53164cc37" + integrity sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A== + escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -442,6 +496,14 @@ fill-range@^4.0.0: repeat-string "^1.6.1" to-regex-range "^2.1.0" +find-up@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-4.1.0.tgz#97afe7d6cdc0bc5928584b7c8d7b16e8a9aa5d19" + integrity sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw== + dependencies: + locate-path "^5.0.0" + path-exists "^4.0.0" + for-in@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" @@ -482,6 +544,11 @@ gauge@~2.7.3: strip-ansi "^3.0.1" wide-align "^1.1.0" +get-caller-file@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-2.0.5.tgz#4f94412a82db32f36e3b0b9741f8a97feb031f7e" + integrity sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg== + get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" @@ -694,6 +761,11 @@ is-fullwidth-code-point@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" +is-fullwidth-code-point@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" + integrity sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg== + is-glob@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-3.1.0.tgz#7ba5ae24217804ac70707b96922567486cc3e84a" @@ -812,6 +884,13 @@ latest-version@^3.0.0: dependencies: package-json "^4.0.0" +locate-path@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-5.0.0.tgz#1afba396afd676a6d42504d0a67a3a7eb9f62aa0" + integrity sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g== + dependencies: + p-locate "^4.1.0" + lowercase-keys@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/lowercase-keys/-/lowercase-keys-1.0.1.tgz#6f9e30b47084d971a7c820ff15a6c5167b74c26f" @@ -1065,6 +1144,25 @@ p-finally@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" +p-limit@^2.2.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" + integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== + dependencies: + p-try "^2.0.0" + +p-locate@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-4.1.0.tgz#a3428bb7088b3a60292f66919278b7c297ad4f07" + integrity sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A== + dependencies: + p-limit "^2.2.0" + +p-try@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/p-try/-/p-try-2.2.0.tgz#cb2868540e313d61de58fafbe35ce9004d5540e6" + integrity sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ== + package-json@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/package-json/-/package-json-4.0.1.tgz#8869a0401253661c4c4ca3da6c2121ed555f5eed" @@ -1082,6 +1180,11 @@ path-dirname@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0" +path-exists@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" + integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -1202,6 +1305,16 @@ repeat-string@^1.6.1: version "1.6.1" resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + integrity sha1-jGStX9MNqxyXbiNE/+f3kqam30I= + +require-main-filename@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-2.0.0.tgz#d0b329ecc7cc0f61649f62215be69af54aa8989b" + integrity sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg== + resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a" @@ -1248,7 +1361,7 @@ semver@^5.0.3, semver@^5.1.0, semver@^5.3.0, semver@^5.5.0: version "5.7.0" resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.0.tgz#790a7cf6fea5459bac96110b29b60412dc8ff96b" -set-blocking@~2.0.0: +set-blocking@^2.0.0, set-blocking@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" @@ -1359,6 +1472,15 @@ string-width@^1.0.1: is-fullwidth-code-point "^2.0.0" strip-ansi "^4.0.0" +string-width@^4.1.0, string-width@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.0.tgz#952182c46cc7b2c313d1596e623992bd163b72b5" + integrity sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.0" + string_decoder@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.1.1.tgz#9cf1611ba62685d7030ae9e4ba34149c3af03fc8" @@ -1377,6 +1499,13 @@ strip-ansi@^4.0.0: dependencies: ansi-regex "^3.0.0" +strip-ansi@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" + integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== + dependencies: + ansi-regex "^5.0.0" + strip-eof@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" @@ -1522,6 +1651,11 @@ util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" +which-module@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" + integrity sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho= + which@^1.2.9: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a" @@ -1540,6 +1674,15 @@ widest-line@^2.0.0: dependencies: string-width "^2.1.1" +wrap-ansi@^6.2.0: + version "6.2.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-6.2.0.tgz#e9393ba07102e6c91a3b221478f0257cd2856e53" + integrity sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" @@ -1556,6 +1699,11 @@ xdg-basedir@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4" +y18n@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-4.0.0.tgz#95ef94f85ecc81d007c264e190a120f0a3c8566b" + integrity sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w== + yallist@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" @@ -1563,3 +1711,28 @@ yallist@^2.1.2: yallist@^3.0.0, yallist@^3.0.3: version "3.0.3" resolved "https://registry.yarnpkg.com/yallist/-/yallist-3.0.3.tgz#b4b049e314be545e3ce802236d6cd22cd91c3de9" + +yargs-parser@^18.1.1: + version "18.1.2" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-18.1.2.tgz#2f482bea2136dbde0861683abea7756d30b504f1" + integrity sha512-hlIPNR3IzC1YuL1c2UwwDKpXlNFBqD1Fswwh1khz5+d8Cq/8yc/Mn0i+rQXduu8hcrFKvO7Eryk+09NecTQAAQ== + dependencies: + camelcase "^5.0.0" + decamelize "^1.2.0" + +yargs@^15.3.1: + version "15.3.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-15.3.1.tgz#9505b472763963e54afe60148ad27a330818e98b" + integrity sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA== + dependencies: + cliui "^6.0.0" + decamelize "^1.2.0" + find-up "^4.1.0" + get-caller-file "^2.0.1" + require-directory "^2.1.1" + require-main-filename "^2.0.0" + set-blocking "^2.0.0" + string-width "^4.2.0" + which-module "^2.0.0" + y18n "^4.0.0" + yargs-parser "^18.1.1" From a80ffb3f9c48a0b490018039805e75d13ba09e34 Mon Sep 17 00:00:00 2001 From: michaelmccord Date: Wed, 22 Apr 2020 21:28:05 -0400 Subject: [PATCH 2/5] feat: make the markdown file first arg of plugins --- bin/spec-md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/spec-md b/bin/spec-md index 04efc02..fb05a4e 100755 --- a/bin/spec-md +++ b/bin/spec-md @@ -26,7 +26,7 @@ yargs.strict() yargs.usage('plugin [-- plugin-args...]'); }, (argv)=>{ - return argv.package(argv._, + return argv.package([markdown, ...argv._], specmd.parse(argv.markdown), argv.metadata ? argv.metadata : {}) .then(_=>process.stdout.write(_)) .catch(errorExit); From e89545e27c2807ab0b292ef9853f7abedfbb2748 Mon Sep 17 00:00:00 2001 From: michaelmccord Date: Thu, 23 Apr 2020 15:12:42 -0400 Subject: [PATCH 3/5] fix: change plugin args to use optional, variadic, positional arg --- bin/spec-md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/bin/spec-md b/bin/spec-md index fb05a4e..3bd0d80 100755 --- a/bin/spec-md +++ b/bin/spec-md @@ -21,12 +21,10 @@ yargs.strict() .catch(errorExit); } ) - .command(['plugin '], 'Outputs in the format of the specified plugin', - (yargs)=>{ - yargs.usage('plugin [-- plugin-args...]'); - }, + .command(['plugin [args..]'], 'Outputs in the format of the specified plugin', + (yargs)=>{}, (argv)=>{ - return argv.package([markdown, ...argv._], + return argv.package([markdown, ...argv.args], specmd.parse(argv.markdown), argv.metadata ? argv.metadata : {}) .then(_=>process.stdout.write(_)) .catch(errorExit); From 8fcb5bb4f2c62c3d86c4186e3cddb8ff46ae1697 Mon Sep 17 00:00:00 2001 From: michaelmccord Date: Thu, 23 Apr 2020 15:17:44 -0400 Subject: [PATCH 4/5] fix: ensure `markdown` is referenced from the `argv` obj --- bin/spec-md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/spec-md b/bin/spec-md index 3bd0d80..96129bb 100755 --- a/bin/spec-md +++ b/bin/spec-md @@ -24,7 +24,7 @@ yargs.strict() .command(['plugin [args..]'], 'Outputs in the format of the specified plugin', (yargs)=>{}, (argv)=>{ - return argv.package([markdown, ...argv.args], + return argv.package([argv.markdown, ...argv.args], specmd.parse(argv.markdown), argv.metadata ? argv.metadata : {}) .then(_=>process.stdout.write(_)) .catch(errorExit); From 9aff2f89a9c5bc26033a6242dd1d4e81a9d41374 Mon Sep 17 00:00:00 2001 From: michaelmccord Date: Thu, 23 Apr 2020 21:32:51 -0400 Subject: [PATCH 5/5] feat: add subdir information to all nodes --- src/parse.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parse.js b/src/parse.js index 90a2b2c..633a143 100644 --- a/src/parse.js +++ b/src/parse.js @@ -22,7 +22,10 @@ function readFile(filepath) { }); } -function importAST(parser, filepath) { +function importAST(parser, filepath, subdir) { + if(!subdir) + subdir = path.dirname(filepath); + return readFile(filepath).then(function (source) { try { var ast = parser.parse(source); @@ -36,9 +39,10 @@ function importAST(parser, filepath) { } var importASTs = []; visit(ast, function (node) { + node.subdir = subdir; if (node.type === 'Import') { var subfilepath = path.resolve(path.dirname(filepath), decodeURI(node.path)); - importASTs.push(importAST(parser, subfilepath)); + importASTs.push(importAST(parser, subfilepath, path.dirname(subfilepath))); } }); return Promise.all(importASTs).then(function (asts) {