From 82078cee9a09ec6c6a6120e2c9f63f89ad9be2b2 Mon Sep 17 00:00:00 2001 From: Thomas Thiebaud Date: Fri, 12 Jun 2020 08:35:21 +0200 Subject: [PATCH] fix: export bin correctly --- bin/fastify-schema-to-typescript.js | 16 ++++++++++++++++ package.json | 4 ++-- ...{fastify-schema-to-typescript.ts => index.ts} | 15 +-------------- 3 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 bin/fastify-schema-to-typescript.js rename src/{fastify-schema-to-typescript.ts => index.ts} (82%) diff --git a/bin/fastify-schema-to-typescript.js b/bin/fastify-schema-to-typescript.js new file mode 100644 index 0000000..89c00df --- /dev/null +++ b/bin/fastify-schema-to-typescript.js @@ -0,0 +1,16 @@ +#!/usr/bin/env node + +const { program } = require("commander"); +const { convert } = require("../dist/index"); + +program + .option( + "-g, --glob ", + "glob matching JSON schema to convert", + "src/**/schema.json" + ) + .option("-p, --prefix ", "prefix to use before interfaces' name", ""); + +program.parse(process.argv); + +convert(program.glob, program.prefix); diff --git a/package.json b/package.json index a535a5a..7595907 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/fastify-schema-to-typescript.ts b/src/index.ts similarity index 82% rename from src/fastify-schema-to-typescript.ts rename to src/index.ts index 34877f7..40714e2 100644 --- a/src/fastify-schema-to-typescript.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import { program } from "commander"; import glob from "glob"; import path from "path"; import fs from "fs"; @@ -46,7 +45,7 @@ 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); @@ -54,15 +53,3 @@ function convert(globString: string, prefix: string) { writeFile(parsedPath, prefix, schema); }); } - -program - .option( - "-g, --glob ", - "glob matching JSON schema to convert", - "src/**/schema.json" - ) - .option("-p, --prefix ", "prefix to use before interfaces' name", ""); - -program.parse(process.argv); - -convert(program.glob, program.prefix);