Skip to content

Commit 82078ce

Browse files
fix: export bin correctly
1 parent 6b02b2d commit 82078ce

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

bin/fastify-schema-to-typescript.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env node
2+
3+
const { program } = require("commander");
4+
const { convert } = require("../dist/index");
5+
6+
program
7+
.option(
8+
"-g, --glob <value>",
9+
"glob matching JSON schema to convert",
10+
"src/**/schema.json"
11+
)
12+
.option("-p, --prefix <value>", "prefix to use before interfaces' name", "");
13+
14+
program.parse(process.argv);
15+
16+
convert(program.glob, program.prefix);

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"name": "fastify-schema-to-typescript",
33
"version": "1.0.0",
44
"description": "Convert json schema for Fastify to typescript interface",
5-
"main": "./dist/fastify-schema-to-typescript.js",
5+
"main": "./dist/index.js",
66
"bin": {
7-
"fastify-schema-to-typescript": "./dist/fastify-schema-to-typescript.js"
7+
"fastify-schema-to-typescript": "./bin/fastify-schema-to-typescript.js"
88
},
99
"scripts": {
1010
"clean": "rimraf ./dist",

src/fastify-schema-to-typescript.ts renamed to src/index.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { program } from "commander";
21
import glob from "glob";
32
import path from "path";
43
import fs from "fs";
@@ -46,23 +45,11 @@ export interface ${prefix}Request extends FastifyRequest {
4645
);
4746
}
4847

49-
function convert(globString: string, prefix: string) {
48+
export function convert(globString: string, prefix: string) {
5049
const filePaths = glob.sync(globString);
5150
filePaths.forEach((filePath) => {
5251
const parsedPath = path.parse(filePath);
5352
const schema = JSON.parse(fs.readFileSync(filePath, "utf-8"));
5453
writeFile(parsedPath, prefix, schema);
5554
});
5655
}
57-
58-
program
59-
.option(
60-
"-g, --glob <value>",
61-
"glob matching JSON schema to convert",
62-
"src/**/schema.json"
63-
)
64-
.option("-p, --prefix <value>", "prefix to use before interfaces' name", "");
65-
66-
program.parse(process.argv);
67-
68-
convert(program.glob, program.prefix);

0 commit comments

Comments
 (0)