-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
161 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
node_modules | ||
package-lock.json |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# mdsquash | ||
|
||
Merges multiple MD files into one readme | ||
|
||
## Install | ||
```sh | ||
npm install -g mdsquash | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
Usage: mdsquash [options] | ||
|
||
Options: | ||
-t, --template Readme.nbs file (defaults to current dir, then to no template) | ||
-o, --out <type> Where to output Readme.md file (defaults to current dir/README.md) (default: "README.md") | ||
-i, --input <items> comma separated list of md file paths to be merged in order | ||
-h, --help display help for command | ||
|
||
``` | ||
|
||
## Example Use | ||
|
||
|
||
```sh | ||
mdsquash -i /some/mdfile.md,/another/mdfile.md | ||
``` | ||
|
||
This example expects two MD files as the input. | ||
## Example Readme.nbs | ||
|
||
```md | ||
|
||
# Test | ||
|
||
## Something | ||
|
||
{{doc1}} | ||
|
||
|
||
## Foo | ||
|
||
{{doc2}} | ||
|
||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs').promises; | ||
const { program } = require('commander'); | ||
|
||
function commaSeparatedList(value, dummyPrevious) { | ||
return value.split(','); | ||
} | ||
|
||
async function start() { | ||
const {NBars} = await import("nbars"); | ||
program.option('-t, --template', 'Readme.nbs file (defaults to current dir, then to no template)') | ||
.option('-o, --out <type>', 'Where to output Readme.md file (defaults to current dir/README.md)', 'README.md') | ||
.requiredOption('-i, --input <items>', 'comma separated list of md file paths to be merged in order', commaSeparatedList); | ||
|
||
program.parse(process.argv); | ||
|
||
// if(!program.input) { | ||
// console.log('Must include comma separated list of md file paths to be merged in order via the "-i" option') | ||
// } | ||
var template = null; | ||
if(!program.template) { | ||
try { | ||
program.template = await fs.readFile('Readme.nbs', {encoding: 'ascii'}); | ||
template = NBars.compile(program.template); | ||
} catch (e) { | ||
console.log('No template found in current dir. Using default'); | ||
var dtemp = ""; | ||
for (var i = 0; i < program.input.length; i++) { | ||
dtemp += `{{doc${i+1}}} \n\n` | ||
} | ||
template = NBars.compile(dtemp); | ||
} | ||
} else { | ||
try { | ||
program.template = await fs.readFile('Readme.nbs', {encoding: 'ascii'}); | ||
template = NBars.compile(program.template); | ||
} catch (e) { | ||
console.log('Error reading file '+program.template); | ||
process.exit(); | ||
} | ||
} | ||
|
||
|
||
var mdFiles = {}; | ||
for (var i = 0; i < program.input.length; i++) { | ||
mdFiles[`doc${i+1}`] = await fs.readFile(program.input[i], {encoding: 'ascii'}); | ||
} | ||
console.log(mdFiles) | ||
var merged = template(mdFiles); | ||
console.log(merged) | ||
await fs.writeFile(program.out,merged, {encoding: 'ascii'}); | ||
|
||
console.log('Done'); | ||
|
||
} | ||
start(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "mdsquash", | ||
"version": "1.0.0", | ||
"description": "Merges multiple MD files into one readme", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Phara0h/mdsquash.git" | ||
}, | ||
"keywords": [ | ||
"md", | ||
"merge", | ||
"readme", | ||
"template" | ||
], | ||
"author": "Jt Whissel", | ||
"license": "GPL-3.0-or-later", | ||
"bugs": { | ||
"url": "https://github.com/Phara0h/mdsquash/issues" | ||
}, | ||
"bin": { | ||
"mdsquash": "./index.js" | ||
}, | ||
"homepage": "https://github.com/Phara0h/mdsquash#readme", | ||
"dependencies": { | ||
"commander": "^6.0.0", | ||
"nbars": "^1.0.1" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Test | ||
|
||
## Something | ||
|
||
hello 1 | ||
|
||
|
||
|
||
|
||
## Foo | ||
|
||
hello 2 | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Test | ||
|
||
## Something | ||
|
||
{{doc1}} | ||
|
||
|
||
|
||
## Foo | ||
|
||
{{doc2}} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello 2 |