Skip to content

Commit 5bad453

Browse files
authored
feat: add docs and improve config (#2)
* docs: add example folder * docs: add README file * chore: add TravisCI config and tweak other configs * ci: rename Travis CI config file
1 parent dfbb2f6 commit 5bad453

File tree

9 files changed

+2028
-1788
lines changed

9 files changed

+2028
-1788
lines changed

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: node_js
2+
cache: yarn
3+
notifications:
4+
email: false
5+
node_js:
6+
- 10
7+
- 12
8+
install: yarn --frozen-lockfile
9+
script: yarn validate
10+
after_success:
11+
- npx codecov --disable=gcov
12+
- test $TRAVIS_BRANCH = "master" && test $TRAVIS_PULL_REQUEST = "false" && npx semantic-release
13+
branches:
14+
only:
15+
- develop
16+
- master

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# snippets-table
2+
3+
## Overview
4+
5+
Tool to easily manage a table of snippets on a README file.
6+
7+
## Installation
8+
9+
Install the package:
10+
11+
`npm i --dev snippets-table` or `yarn add -D snippets-table`
12+
13+
## Usage
14+
15+
Add the following lines to the README where the table of snippets should be created:
16+
17+
```markdown
18+
<!-- SNIPPETS-TABLE:START - Do not remove or modify this line -->
19+
20+
<!-- SNIPPETS-TABLE:END -->
21+
```
22+
23+
Run the command:
24+
25+
`npm run snippets-table generate` or `yarn snippets-table generate`
26+
27+
Alternatively, run it with `npx`:
28+
29+
`npx snippets-table generate`
30+
31+
## License
32+
33+
MIT © [Arthur Denner](https://github.com/arthurdenner/)

example/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# snippets-table-example
2+
3+
Example of usage of the package. Check the raw version [here](https://raw.githubusercontent.com/arthurdenner/snippets-table/master/example/README.md).
4+
5+
## How to test it
6+
7+
- Check the `snippets/snippets.json` file;
8+
- Run the `update-readme` script;
9+
- See the ✨magic ✨.
10+
11+
<!-- SNIPPETS-TABLE:START - Do not remove or modify this line -->
12+
13+
<!-- SNIPPETS-TABLE:END -->

example/package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "snippets-table-example",
3+
"version": "0.0.0",
4+
"main": "index.js",
5+
"author": "Arthur Denner <[email protected]>",
6+
"license": "MIT",
7+
"scripts": {
8+
"update-readme": "node ../src/cli.js"
9+
}
10+
}

example/snippets/snippets.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"Sing ABC": {
3+
"description": "Song by Jackson 5",
4+
"prefix": "abc",
5+
"body": [
6+
"A, B, C",
7+
"Easy as 1, 2, 3",
8+
"Or simple as Do-Re-Mi",
9+
"A, B, C, 1, 2, 3, baby you and me, girl!"
10+
]
11+
},
12+
"Sing Take on Me": {
13+
"description": "Song by a-ha",
14+
"prefix": "takeOnMe",
15+
"body": [
16+
"Take on me (take on me)",
17+
"Take me on (take on me)",
18+
"I'll be gone",
19+
"In a day or two"
20+
]
21+
},
22+
"Sing Help": {
23+
"description": "Song by The Beatles",
24+
"prefix": "help",
25+
"body": [
26+
"I need somebody",
27+
"(Help!) not just anybody",
28+
"(Help!) you know I need someone",
29+
"Help!"
30+
]
31+
}
32+
}

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
"bin": {
77
"snippets-table": "dist/cli.js"
88
},
9+
"engines": {
10+
"node": ">=10 <11 || >=12"
11+
},
912
"files": [
1013
"dist"
1114
],
1215
"scripts": {
16+
"validate": "yarn lint && yarn build",
1317
"build": "kcd-scripts build",
1418
"lint": "kcd-scripts lint"
1519
},
@@ -39,6 +43,7 @@
3943
"eslintConfig": {
4044
"extends": "./node_modules/kcd-scripts/eslint.js",
4145
"rules": {
46+
"no-console": "off",
4247
"no-process-exit": "off"
4348
}
4449
}

src/cli.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function promptForCommand({ argv }) {
2424
message: 'What do you want to do?',
2525
choices: [
2626
{
27-
name: 'Re-generate the table of snippets',
27+
name: 'Generate the table of snippets',
2828
value: 'generate',
2929
},
3030
],
@@ -33,12 +33,12 @@ function promptForCommand({ argv }) {
3333
},
3434
];
3535

36-
return inquirer.prompt(questions).then(answers => {
36+
return inquirer.prompt(questions).then((answers) => {
3737
return answers.command || argv._[0];
3838
});
3939
}
4040

41-
promptForCommand(yargv).then(command => {
41+
promptForCommand(yargv).then((command) => {
4242
switch (command) {
4343
case 'generate':
4444
return generate(yargv.parsed.argv);

src/generate/index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
/* eslint-disable no-console */
2-
31
const fs = require('fs');
42
const chalk = require('chalk');
53
const prettier = require('prettier');
64

75
const START_TAG =
86
'<!-- SNIPPETS-TABLE:START - Do not remove or modify this line -->';
97
const END_TAG = '<!-- SNIPPETS-TABLE:END -->';
10-
const readFile = path => fs.promises.readFile(path, 'utf8');
11-
const getPrefix = p => (Array.isArray(p) ? p.join(', ') : p);
8+
const readFile = (path) => fs.promises.readFile(path, 'utf8');
9+
const getPrefix = (p) => (Array.isArray(p) ? p.join(', ') : p);
1210

1311
function createTableLines(snippets, headers) {
14-
const separatorLine = headers.reduce(acc => acc.concat(`--- | `), '\n| ');
12+
const separatorLine = headers.reduce((acc) => acc.concat(`--- | `), '\n| ');
1513
const headersLine = headers.reduce((acc, h) => acc.concat(`${h} | `), '| ');
16-
const bodyLines = Object.keys(snippets).reduce((acc, key) => {
14+
const keys = Object.keys(snippets).sort();
15+
const bodyLines = keys.reduce((acc, key) => {
1716
const { description = '---', prefix } = snippets[key];
1817
const newLine = `\n| \`${getPrefix(prefix)}\` | ${key} | ${description} |`;
1918

0 commit comments

Comments
 (0)