Export getAvailableScripts#229
Open
sitch wants to merge 1 commit into
Open
Conversation
In order to export a markdown table version of the `nps` output, it's much easier to leverage this function vs copy/pasting it.
Author
|
Maybe there is an easier/more idiomatic way to integrate this? i.e. formatters and move the current chalk version into one, as well as having a markdown one. |
Codecov Report
@@ Coverage Diff @@
## master #229 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 12 12
Lines 399 476 +77
Branches 98 117 +19
=========================================
+ Hits 399 476 +77
Continue to review full report at Codecov.
|
Author
|
If it's useful code more or less looks like: const { getAvailableScripts } = require('nps/dist/bin-utils');
const config = require('package-scripts');
const markdownReplacements = [
[/\*/g, '\\*'],
[/_/g, '\\_'],
[/-/g, '\\-'],
[/\+/g, '\\+'],
[/=/g, '\\='],
[/#/g, '\\#'],
[/`/g, '\\`'],
[/~/g, '\\~'],
[/&/g, '&'],
[/\|/g, '\\|'],
[/\(/g, '\\('],
[/\)/g, '\\)'],
[/\[/g, '\\['],
[/\]/g, '\\]'],
[/</g, '<'],
[/>/g, '>'],
[/(\d+)\./g, '$1\\.'],
];
const escapeMarkdown = (text = '') =>
markdownReplacements.reduce(
(search, replacement) => search.replace(replacement[0], replacement[1]),
text
);
function codeEscape(script = '') {
script = script.replace(/\n/g, '<br/>');
return `<code>${escapeMarkdown(script)}</code>`;
}
function markdownTable({ scripts, options }) {
const availableScripts = getAvailableScripts(scripts).filter((script) => !script.hiddenFromHelp);
const header = `| Name | Description | Script |`;
const separator = `| -- | -- | -- |`;
const rows = availableScripts.map(
({ name, description, script }) =>
`| \`${escapeMarkdown(name)}\` | ${escapeMarkdown(description)} | ${codeEscape(script)} |`
);
return [header, separator, ...rows].join('\n');
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In order to export a markdown table version of the
npsoutput, it's much easier to leverage this function vs copy/pasting it.What:
Why:
How:
Checklist: