Skip to content

Commit

Permalink
fix: removed old binary
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed May 23, 2024
1 parent 6ea7714 commit b26d0a3
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 147 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"args": ["ts-json-schema-generator.ts", "-p", "${file}"],
"args": ["bin/run.js", "${file}"],
"cwd": "${workspaceFolder}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Or install the package and then run it

```bash
$ npm install -D ts-json-schema-generator
$ node_modules/.bin/ts-json-schema-generator -t 'My.Type.Name' 'my/project/**/*.ts'
$ node_modules/.bin/tsjg -t 'My.Type.Name' 'my/project/**/*.ts'
```

Note that different platforms (e.g. Windows) may use different path separators so you may have to adjust the command above.
Expand All @@ -60,7 +60,7 @@ Also note that you need to quote paths with `*` as otherwise the shell will expa
<!-- commands -->

- [`tjsg autocomplete [SHELL]`](#tjsg-autocomplete-shell)
- [`tjsg generate [PATH]`](#tjsg-generate-path)
- [`tjsg generate PATH`](#tjsg-generate-path)
- [`tjsg help [COMMAND]`](#tjsg-help-command)

## `tjsg autocomplete [SHELL]`
Expand Down Expand Up @@ -94,19 +94,19 @@ EXAMPLES

_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v3.0.18/src/commands/autocomplete/index.ts)_

## `tjsg generate [PATH]`
## `tjsg generate PATH`

Generate JSON schema from your Typescript sources

```
USAGE
$ tjsg generate [PATH] [-t <value>] [--top-ref] [-i <value>] [-p <value>] [-e all|none|export] [-j
$ tjsg generate PATH [-t <value>] [--top-ref] [-i <value>] [-p <value>] [-e all|none|export] [-j
none|basic|extended] [--markdown-description] [--sort-props] [--strict-tuples] [--type-check] [--ref-encode]
[--additional-properties] [--functions fail|comment|hide] [--minify] [-o <value>] [--extra-tags <value>]
[--discriminator-type json-schema|open-api]
ARGUMENTS
PATH Source file path
PATH [default: *] Source file path
FLAGS
-e, --expose=<option> [default: export] Type exposing
Expand All @@ -115,7 +115,8 @@ FLAGS
-j, --jsdoc=<option> [default: extended] Read JsDoc annotations
<options: none|basic|extended>
-o, --out=<value> Set the output file (default: stdout)
-p, --tsconfig=<value> Your tsconfig.json to load entry files and compilation settings
-p, --tsconfig=<value> [default: tsconfig.json] Your tsconfig.json to load entry files and compilation
settings
-t, --type=<value> Type name
--additional-properties Allow additional properties for objects with no index signature
--discriminator-type=<option> [default: json-schema] Type of discriminator to use
Expand All @@ -137,9 +138,13 @@ DESCRIPTION
Generate JSON schema from your Typescript sources
EXAMPLES
Analyzes src/types.ts using tsconfig.json and writes the schema to schema.json.
Analyzes src/types.ts using tsconfig.json and pipes to stdout
$ tjsg generate src/types.ts -p tsconfig.json
Analyzes src/types.ts and writes the schema to schema.json
$ tjsg generate -f tsconfig.json -o schema.json src/types.ts
$ tjsg generate src/types.ts -o schema.json
```

_See code: [src/commands/generate.ts](https://github.com/vega/ts-json-schema-generator/blob/v2.0.0/src/commands/generate.ts)_
Expand Down
2 changes: 0 additions & 2 deletions bin/ts-json-schema-generator.js

This file was deleted.

23 changes: 19 additions & 4 deletions commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ export default class Generate extends Command {

static override examples = [
{
command: "<%= config.bin %> <%= command.id %> -f tsconfig.json -o schema.json src/types.ts ",
description: "Analyzes src/types.ts using tsconfig.json and writes the schema to schema.json.",
command: "<%= config.bin %> <%= command.id %> src/types.ts -p tsconfig.json",
description: "Analyzes src/types.ts using tsconfig.json and pipes to stdout",
},
{
command: "<%= config.bin %> <%= command.id %> src/types.ts -o schema.json",
description: "Analyzes src/types.ts and writes the schema to schema.json",
},
];

static override args = {
path: Args.file({
required: false,
description: "Source file path",
}),
};
Expand All @@ -42,6 +45,7 @@ export default class Generate extends Command {
char: "p", // Keep similar to tsc and other cli tools
aliases: ["project"],
description: "Your tsconfig.json to load entry files and compilation settings",
default: "tsconfig.json",
}),
expose: Flags.string({
char: "e",
Expand Down Expand Up @@ -119,7 +123,11 @@ export default class Generate extends Command {
}

if (flags["type-check"] && !flags.tsconfig) {
this.warn("Cannot type check without a tsconfig file. Skipping type check.");
// When printing to stdout, we cannot output anything else than a JSON
if (flags.out) {
this.warn("Cannot type check without a tsconfig file. Skipping type check.");
}

flags["type-check"] = false;
}

Expand Down Expand Up @@ -160,7 +168,14 @@ export default class Generate extends Command {
// write to stdout
process.stdout.write(`${schemaString}\n`);
}

// When printing to stdout, we cannot output anything else than a JSON
if (flags.out) {
this.log("Schema generated successfully");
}
} catch (error) {
this.error("Could not generate schema", { exit: false });

if (error instanceof BaseError) {
process.stderr.write(error.format());
process.exit(1);
Expand Down
10 changes: 1 addition & 9 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ export default tseslint.config(
},
eslint.configs.recommended,
{
files: [
"ts-json-schema-generator.ts",
"index.ts",
"src/**/*.ts",
"factory/**/*.ts",
"bin/**",
"test/**/*.test.ts",
"test/utils.ts",
],
files: ["index.ts", "src/**/*.ts", "factory/**/*.ts", "bin/**", "test/**/*.test.ts", "test/utils.ts"],
extends: tseslint.configs.recommendedTypeChecked,
languageOptions: {
sourceType: "module",
Expand Down
2 changes: 1 addition & 1 deletion factory/generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config, DEFAULT_CONFIG } from "../src/Config.js";
import { type Config, DEFAULT_CONFIG } from "../src/Config.js";
import { SchemaGenerator } from "../src/SchemaGenerator.js";
import { createFormatter } from "./formatter.js";
import { createParser } from "./parser.js";
Expand Down
12 changes: 9 additions & 3 deletions oclif.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
"aliases": [],
"args": {
"path": {
"default": "*",
"description": "Source file path",
"name": "path",
"required": false
"required": true
}
},
"description": "Generate JSON schema from your Typescript sources",
"examples": [
{
"command": "<%= config.bin %> <%= command.id %> -f tsconfig.json -o schema.json src/types.ts ",
"description": "Analyzes src/types.ts using tsconfig.json and writes the schema to schema.json."
"command": "<%= config.bin %> <%= command.id %> src/types.ts -p tsconfig.json",
"description": "Analyzes src/types.ts using tsconfig.json and pipes to stdout"
},
{
"command": "<%= config.bin %> <%= command.id %> src/types.ts -o schema.json",
"description": "Analyzes src/types.ts and writes the schema to schema.json"
}
],
"flags": {
Expand Down Expand Up @@ -45,6 +50,7 @@
"char": "p",
"description": "Your tsconfig.json to load entry files and compilation settings",
"name": "tsconfig",
"default": "tsconfig.json",
"hasDynamicHelp": false,
"multiple": false,
"type": "option"
Expand Down
14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,27 @@
"types": "dist/index.d.ts",
"bin": {
"tjsg": "./bin/run.js",
"tjsg-dev": "./bin/dev.js",
"ts-json-schema-generator": "./bin/ts-json-schema-generator.js"
"tjsg-dev": "./bin/dev.js"
},
"files": [
"dist",
"cjs",
"src",
"factory",
"commands",
"index.*",
"ts-json-schema-generator.*"
"index.*"
],
"scripts": {
"build": "npm run build:cjs && npm run build:esm",
"postbuild": "oclif manifest && oclif readme && prettier --write README.md oclif.manifest.json",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.json",
"debug": "tsx --inspect-brk ts-json-schema-generator.ts",
"debug": "tsx --inspect-brk bin/run.js",
"format": "eslint --fix",
"lint": "eslint",
"prepublishOnly": "yarn build",
"release": "yarn build && git diff && auto shipit",
"run": "tsx ts-json-schema-generator.ts",
"run": "tsx bin/run.js",
"test": "jest test/ --verbose",
"test:coverage": "yarn jest test/ --collectCoverage=true",
"test:fast": "cross-env FAST_TEST=1 jest test/ --verbose",
Expand Down Expand Up @@ -116,10 +114,6 @@
},
"oclif": {
"bin": "tjsg",
"binAliases": [
"tjsg-dev",
"ts-json-schema-generator"
],
"dirname": "ts-json-schema-generator",
"topicSeparator": " ",
"additionalHelpFlags": [
Expand Down
10 changes: 5 additions & 5 deletions test/minify/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from "child_process";
import path from "path";
import { execSync } from "node:child_process";
import path from "node:path";

const BIN = path.resolve(__dirname, "../../dist/ts-json-schema-generator.js");
const BIN = path.resolve(__dirname, "../../bin/run.js");
const SCHEMA_PATH = path.resolve(__dirname, "./schema.ts");

const EXPECTED = {
Expand All @@ -22,7 +22,7 @@ const EXPECTED = {

describe("Tests --minify output", () => {
it("With minify", () => {
const stdout = execSync(`node ${BIN} -p ${SCHEMA_PATH} --minify`).toString().trimEnd();
const stdout = execSync(`node ${BIN} generate ${SCHEMA_PATH} --no-type-check --minify`).toString().trimEnd();

// Only a newline at the end
expect(stdout.split("\n").length).toBe(1);
Expand All @@ -35,7 +35,7 @@ describe("Tests --minify output", () => {
});

it("Without minify", () => {
const stdout = execSync(`node ${BIN} -p ${SCHEMA_PATH}`).toString().trimEnd();
const stdout = execSync(`node ${BIN} generate ${SCHEMA_PATH} --no-type-check`).toString().trimEnd();

// There's more than one \n (formatting)
expect(stdout.split("\n").length).toBeGreaterThan(2);
Expand Down
103 changes: 0 additions & 103 deletions ts-json-schema-generator.ts

This file was deleted.

2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"incremental": true,
"importHelpers": true
},
"files": ["ts-json-schema-generator.ts", "index.ts"],
"files": ["index.ts"],
"include": ["src/**/*.ts", "factory/**/*.ts", "commands/**/*.ts"],
"exclude": ["node_modules", "dist", "cjs"]
}

0 comments on commit b26d0a3

Please sign in to comment.