Skip to content

Commit

Permalink
Implement basic function
Browse files Browse the repository at this point in the history
  • Loading branch information
PipecraftNet committed Sep 22, 2021
1 parent 6f8af46 commit 7bbfa97
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ build/**
LICENSE
*.html
*.lock
*.hbs
*.handlebars
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
[![LICENSE][license-image]][license-url]
[![code style: prettier][code-style-prettier-image]][code-style-prettier-url]

> generate + easy = geneasy = ge
A command line tool that can easily generate HTML, Markdown documents, etc.

## Installation
Expand Down
18 changes: 14 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env node
import process from 'node:process';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';
import { Command } from 'commander';
import fsExtra from 'fs-extra';
import { render } from './lib/index.js';

const __dirname = dirname(fileURLToPath(import.meta.url));
const { readJsonSync } = fsExtra;
Expand Down Expand Up @@ -30,9 +32,17 @@ Examples:
.showHelpAfterError();

program.parse();
// Program.parse(process.argv);
// 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);
// if (options.template) console.log(`- template: ${options.template}`);
// if (options.output) console.log(`- output: ${options.output}`);
// console.log('Remaining arguments:', program.args);
(async () => {
try {
await render(options.template, program.args, options.output);
} catch (error) {
console.error(error);
process.exitCode = 1;
}
})();
26 changes: 21 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
function register() {}
const geneasy = {
register
};
export default geneasy;
import renderHbs from 'geneasy-handlebars';
import parse from 'geneasy-yaml';
import fsExtra from 'fs-extra';

const { readFile, writeFile } = fsExtra;

export function register() {}
export async function render(template, dataFiles, output) {
const data = {};
const contents = await Promise.all(
dataFiles.map((file) => readFile(file, 'utf-8').then((data) => parse(data)))
);
Object.assign(data, ...contents);
template = await readFile(template, 'utf-8');
const result = await renderHbs(template, data);
if (output) {
await writeFile(output, result);
} else {
console.log(result);
}
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geneasy",
"version": "0.0.2",
"version": "0.1.0",
"description": "A command line tool that can easily generate HTML, Markdown documents, etc.",
"type": "module",
"bin": {
Expand Down Expand Up @@ -57,7 +57,9 @@
"xo": {
"space": 2,
"prettier": true,
"rules": {},
"rules": {
"capitalized-comments": 0
},
"overrides": [
{
"files": "test/*.js",
Expand Down

0 comments on commit 7bbfa97

Please sign in to comment.