Skip to content

Commit

Permalink
fix: export bin correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasthiebaud committed Jun 12, 2020
1 parent 6b02b2d commit 82078ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
16 changes: 16 additions & 0 deletions bin/fastify-schema-to-typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

const { program } = require("commander");
const { convert } = require("../dist/index");

program
.option(
"-g, --glob <value>",
"glob matching JSON schema to convert",
"src/**/schema.json"
)
.option("-p, --prefix <value>", "prefix to use before interfaces' name", "");

program.parse(process.argv);

convert(program.glob, program.prefix);
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "fastify-schema-to-typescript",
"version": "1.0.0",
"description": "Convert json schema for Fastify to typescript interface",
"main": "./dist/fastify-schema-to-typescript.js",
"main": "./dist/index.js",
"bin": {
"fastify-schema-to-typescript": "./dist/fastify-schema-to-typescript.js"
"fastify-schema-to-typescript": "./bin/fastify-schema-to-typescript.js"
},
"scripts": {
"clean": "rimraf ./dist",
Expand Down
15 changes: 1 addition & 14 deletions src/fastify-schema-to-typescript.ts → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { program } from "commander";
import glob from "glob";
import path from "path";
import fs from "fs";
Expand Down Expand Up @@ -46,23 +45,11 @@ export interface ${prefix}Request extends FastifyRequest {
);
}

function convert(globString: string, prefix: string) {
export function convert(globString: string, prefix: string) {
const filePaths = glob.sync(globString);
filePaths.forEach((filePath) => {
const parsedPath = path.parse(filePath);
const schema = JSON.parse(fs.readFileSync(filePath, "utf-8"));
writeFile(parsedPath, prefix, schema);
});
}

program
.option(
"-g, --glob <value>",
"glob matching JSON schema to convert",
"src/**/schema.json"
)
.option("-p, --prefix <value>", "prefix to use before interfaces' name", "");

program.parse(process.argv);

convert(program.glob, program.prefix);

0 comments on commit 82078ce

Please sign in to comment.