Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Phara0h committed Aug 3, 2020
1 parent 15cc4c9 commit c219f35
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

node_modules
package-lock.json
44 changes: 44 additions & 0 deletions README.md
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}}

```
56 changes: 56 additions & 0 deletions index.js
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();
32 changes: 32 additions & 0 deletions package.json
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"
}
}
13 changes: 13 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Test

## Something

hello 1




## Foo

hello 2

11 changes: 11 additions & 0 deletions test/Readme.nbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Test

## Something

{{doc1}}



## Foo

{{doc2}}
1 change: 1 addition & 0 deletions test/test1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello 1
1 change: 1 addition & 0 deletions test/test2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello 2

0 comments on commit c219f35

Please sign in to comment.