Skip to content

Commit

Permalink
Add cli.js
Browse files Browse the repository at this point in the history
  • Loading branch information
PipecraftNet committed Sep 22, 2021
1 parent 322a046 commit 6f8af46
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 8 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ A command line tool that can easily generate HTML, Markdown documents, etc.
npm i -g geneasy
```

## Usage

```sh
Usage: cli|ge [options] <data-file...>

A command line tool that can easily generate HTML, Markdown documents, etc.

Arguments:
data-file data file used to fill the document

Options:
-t, --template <file> template file used to render the document
-o, --output <file> output file
-V, --version output the version number
-h, --help display help for command

Examples:
$ geneasy -t template.hbs -o README.md readme.json
$ geneasy -t template.hbs -o index.html data.yaml
$ ge -t template.hbs -o /list/index.html data.yaml
```

## Plugins

- [geneasy-yaml](https://github.com/geneasy/geneasy-yaml) - A plugin that enables geneasy to use dafa files in YAML format.
Expand Down
38 changes: 38 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env node
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Command } from 'commander';
import fsExtra from 'fs-extra';

const __dirname = dirname(fileURLToPath(import.meta.url));
const { readJsonSync } = fsExtra;
const packageInfo = readJsonSync(resolve(__dirname, 'package.json'));
const program = new Command();

program
.alias('ge')
.description(packageInfo.description)
.argument('<data-file...>', 'data file used to fill the document')
.requiredOption(
'-t, --template <file>',
'template file used to render the document'
)
.option('-o, --output <file>', 'output file')
.version(packageInfo.version)
.addHelpText(
'after',
`
Examples:
$ geneasy -t template.hbs -o README.md readme.json
$ geneasy -t template.hbs -o index.html data.yaml
$ ge -t template.hbs -o /list/index.html data.yaml`
)
.showHelpAfterError();

program.parse();
// Program.parse(process.argv);

const options = program.opts();
if (options.template) console.log(`- template: ${options.template}`);
if (options.output) console.log(`- output: ${options.output}`);
console.log('Remaining arguments:', program.args);
6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export default {
register: function () {}
function register() {}
const geneasy = {
register
};
export default geneasy;
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "geneasy",
"version": "0.0.1",
"version": "0.0.2",
"description": "A command line tool that can easily generate HTML, Markdown documents, etc.",
"type": "module",
"exports": "./lib/index.js",
"bin": {
"geneasy": "./cli.js",
"ge": "./cli.js"
},
"scripts": {
"lint": "prettier --write . && xo",
"lint:fix": "prettier --write . && xo --fix",
Expand All @@ -30,13 +33,20 @@
"url": "https://github.com/geneasy/geneasy/issues"
},
"homepage": "https://github.com/geneasy/geneasy#readme",
"dependencies": {
"commander": "^8.2.0",
"fs-extra": "^10.0.0",
"geneasy-handlebars": "^0.0.1",
"geneasy-yaml": "^0.0.1"
},
"devDependencies": {
"chai": "^4.3.4",
"mocha": "^9.1.1",
"prettier": "^2.4.1",
"xo": "^0.44.0"
},
"files": [
"cli.js",
"lib/",
"LICENSE",
"README.md"
Expand All @@ -57,9 +67,5 @@
]
}
]
},
"dependencies": {
"geneasy-handlebars": "^0.0.1",
"geneasy-yaml": "^0.0.1"
}
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@ colorette@^1.3.0:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==

commander@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-8.2.0.tgz#37fe2bde301d87d47a53adeff8b5915db1381ca8"
integrity sha512-LLKxDvHeL91/8MIyTAD5BFMNtoIwztGPMiM/7Bl8rIPmHCZXRxmSWr91h57dpOpnQ6jIUqEWdXE/uBYMfiVZDA==

commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
Expand Down

0 comments on commit 6f8af46

Please sign in to comment.