Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 7232a9e

Browse files
committed
add JSON Schema tool scaffold
1 parent 129e3b3 commit 7232a9e

File tree

22 files changed

+490
-69
lines changed

22 files changed

+490
-69
lines changed

README.md

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Interweb Build
1+
# Interweb Build Tools
22

33
<p align="center" width="100%">
44
<img height="90" src="https://user-images.githubusercontent.com/545047/190171432-5526db8f-9952-45ce-a745-bea4302f912b.svg" />
@@ -10,82 +10,40 @@
1010
</a>
1111
<br />
1212
<a href="https://github.com/cosmology-tech/interweb-build/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
13-
<a href="https://www.npmjs.com/package/@interweb/build"><img height="20" src="https://img.shields.io/github/package-json/v/cosmology-tech/interweb-build?filename=packages%2Fbuild%2Fpackage.json"></a>
1413
</p>
1514

16-
Interweb Build is a powerful wrapper around esbuild, designed to simplify and streamline your build process for Interweb projects.
15+
Interweb is a collection of powerful tools designed to simplify and streamline your development process for web and TypeScript projects.
1716

17+
## Packages
1818

19-
## Features
19+
This monorepo contains the following packages:
2020

21-
- Simple API for building TypeScript projects
22-
- Customizable build options
23-
- Built-in support for common Interweb project configurations
24-
- Easy integration with existing projects
21+
### [@interweb/build](./packages/build)
2522

23+
[![npm version](https://img.shields.io/npm/v/@interweb/build.svg)](https://www.npmjs.com/package/@interweb/build)
2624

27-
## Installation
25+
Interweb Build is a powerful wrapper around esbuild, designed to simplify and streamline your build process for Interweb projects.
2826

27+
#### Installation
2928
```sh
3029
npm install @interweb/build
3130
```
3231

33-
## Usage
32+
[Read more about @interweb/build](./packages/build)
3433

35-
Here's a basic example of how to use Interweb Build:
34+
### [@interweb/ts-json-schema](./packages/ts-json-schema)
3635

37-
```js
38-
import { InterwebBuild, defaultOptions } from '@interweb/build';
36+
[![npm version](https://img.shields.io/npm/v/@interweb/ts-json-schema.svg)](https://www.npmjs.com/package/@interweb/ts-json-schema)
3937

40-
// Use default options
41-
InterwebBuild.build();
38+
Interweb TS JSON Schema is a powerful wrapper around ts-json-schema-generator, designed to simplify the process of generating JSON schemas from TypeScript files in Interweb projects.
4239

43-
// Customize options
44-
InterwebBuild.build({
45-
entryPoints: ['src/custom-entry.ts'],
46-
outfile: 'dist/custom-bundle.js',
47-
minify: true,
48-
});
49-
50-
// Use default options as a base for a custom configuration
51-
const myConfig = {
52-
...defaultOptions,
53-
minify: true,
54-
target: 'es2018',
55-
};
56-
InterwebBuild.build(myConfig);
40+
#### Installation
41+
```sh
42+
npm install @interweb/ts-json-schema
5743
```
5844

59-
## API Reference
60-
61-
### `InterwebBuild.build(options)`
62-
63-
Builds your project using the provided options.
64-
65-
- `options` (optional): An object containing build options. If not provided, default options will be used.
66-
67-
Returns a Promise that resolves to the build result.
68-
69-
### `defaultOptions`
70-
71-
An object containing the default build options. You can spread these into your own configuration for easy customization.
72-
73-
## Default Configuration
74-
75-
Interweb Build comes with the following default configuration:
76-
77-
```ts
78-
{
79-
bundle: true,
80-
minify: false,
81-
outfile: 'dist/bundle.js',
82-
platform: 'node',
83-
sourcemap: true,
84-
target: 'ESNext',
85-
logLevel: 'info',
86-
}
87-
```
45+
[Read more about @interweb/ts-json-schema](./packages/ts-json-schema)
8846

8947
## License
9048

91-
Interweb Build is MIT licensed.
49+
Interweb Build is [MIT licensed](./LICENSE).

__fixtures__/schema-test/src/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export interface User {
2+
id: number;
3+
name: string;
4+
email: string;
5+
}
6+
7+
export interface Post {
8+
id: number;
9+
title: string;
10+
content: string;
11+
author: User;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es2018",
4+
"module": "commonjs",
5+
"strict": true,
6+
"esModuleInterop": true,
7+
"skipLibCheck": true,
8+
"forceConsistentCasingInFileNames": true
9+
},
10+
"include": ["src/**/*"]
11+
}

packages/build/__output__/first/bundle.js renamed to __output__/first/bundle.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

__output__/schema-test/schema.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"definitions": {
4+
"User": {
5+
"type": "object",
6+
"properties": {
7+
"id": {
8+
"type": "number"
9+
},
10+
"name": {
11+
"type": "string"
12+
},
13+
"email": {
14+
"type": "string"
15+
}
16+
},
17+
"required": [
18+
"id",
19+
"name",
20+
"email"
21+
],
22+
"additionalProperties": false
23+
},
24+
"Post": {
25+
"type": "object",
26+
"properties": {
27+
"id": {
28+
"type": "number"
29+
},
30+
"title": {
31+
"type": "string"
32+
},
33+
"content": {
34+
"type": "string"
35+
},
36+
"author": {
37+
"$ref": "#/definitions/User"
38+
}
39+
},
40+
"required": [
41+
"id",
42+
"title",
43+
"content",
44+
"author"
45+
],
46+
"additionalProperties": false
47+
}
48+
}
49+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"$ref": "#/definitions/User",
4+
"definitions": {
5+
"User": {
6+
"type": "object",
7+
"properties": {
8+
"id": {
9+
"type": "number"
10+
},
11+
"name": {
12+
"type": "string"
13+
},
14+
"email": {
15+
"type": "string"
16+
}
17+
},
18+
"required": [
19+
"id",
20+
"name",
21+
"email"
22+
],
23+
"additionalProperties": false
24+
}
25+
}
26+
}

packages/build/__tests__/first.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { join, resolve } from 'path';
33

44
import { InterwebBuild, InterwebBuildOptions } from '../src/index';
55

6-
const fixtureDir = resolve(join(__dirname, '/../__fixtures__/', 'first'));
7-
const outputDir = resolve(join(__dirname, '/../__output__/', 'first'));
6+
const fixtureDir = resolve(join(__dirname, '/../../../__fixtures__/', 'first'));
7+
const outputDir = resolve(join(__dirname, '/../../../__output__/', 'first'));
88

99
describe('InterwebBuild', () => {
1010
it('builds the fixture project successfully', async () => {

packages/build/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ module.exports = {
1414
transformIgnorePatterns: [`/node_modules/*`],
1515
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
1616
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
17-
modulePathIgnorePatterns: ['dist/*', '__output__/*']
17+
modulePathIgnorePatterns: ['dist/*']
1818
};

packages/build/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"rootDir": "src/"
66
},
77
"include": ["src/**/*.ts"],
8-
"exclude": ["dist", "node_modules", "**/*.spec.*", "**/*.test.*", "__output__"]
8+
"exclude": ["dist", "node_modules", "**/*.spec.*", "**/*.test.*"]
99
}

packages/ts-json-schema/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# @interweb/ts-json-schema
2+
3+
<p align="center" width="100%">
4+
<img height="90" src="https://user-images.githubusercontent.com/545047/190171432-5526db8f-9952-45ce-a745-bea4302f912b.svg" />
5+
</p>
6+
7+
<p align="center" width="100%">
8+
<a href="https://github.com/cosmology-tech/interweb-build/actions/workflows/run-tests.yml">
9+
<img height="20" src="https://github.com/cosmology-tech/interweb-build/actions/workflows/run-tests.yml/badge.svg" />
10+
</a>
11+
<br />
12+
<a href="https://github.com/cosmology-tech/interweb-build/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
13+
<a href="https://www.npmjs.com/package/@interweb/ts-json-schema"><img height="20" src="https://img.shields.io/github/package-json/v/cosmology-tech/interweb-build?filename=packages%2Fts-json-schema%2Fpackage.json"></a>
14+
</p>
15+
16+
`@interweb/ts-json-schema` is a wrapper around ts-json-schema-generator, designed to simplify the process of generating JSON schemas from TypeScript files in Interweb projects.
17+
18+
## Features
19+
20+
- Simple API for generating JSON schemas from TypeScript
21+
- Customizable schema generation options
22+
- Built-in support for common Interweb project configurations
23+
24+
## Installation
25+
26+
```sh
27+
npm install @interweb/ts-json-schema
28+
```
29+
30+
## Usage
31+
32+
Here's a basic example of how to use Interweb TS JSON Schema:
33+
34+
```ts
35+
import { generateSchema } from '@interweb/ts-json-schema';
36+
37+
// Generate schema for all types in a file
38+
await generateSchema({
39+
sourcePath: 'path/to/source/file.ts',
40+
tsconfigPath: 'path/to/tsconfig.json',
41+
outputPath: 'path/to/output/schema.json'
42+
});
43+
44+
// Generate schema for a specific type
45+
await generateSchema({
46+
sourcePath: 'path/to/source/file.ts',
47+
tsconfigPath: 'path/to/tsconfig.json',
48+
outputPath: 'path/to/output/schema.json',
49+
type: 'User'
50+
});
51+
```
52+
53+
## API Reference
54+
55+
### `generateSchema(options)`
56+
57+
Generates a JSON schema from TypeScript files using the provided options.
58+
59+
- `options`: An object containing the following properties:
60+
- `sourcePath` (required): Path to the source TypeScript file.
61+
- `tsconfigPath` (required): Path to the tsconfig.json file.
62+
- `outputPath` (required): Path where the generated schema will be saved.
63+
- `type` (optional): Specific type to generate schema for. If not provided, generates schema for all types.
64+
65+
Returns a Promise that resolves when the schema has been generated and saved.
66+
67+
## Configuration
68+
69+
Interweb TS JSON Schema uses the following configuration by default:
70+
71+
```ts
72+
{
73+
path: sourcePath,
74+
tsconfig: tsconfigPath,
75+
type: '*', // Or the specified type if provided
76+
}
77+
```
78+
79+
These options are passed to the underlying `ts-json-schema-generator`. You can customize these by modifying the `generateSchema` function or by creating your own wrapper around it.
80+
81+
## Example
82+
83+
Here's an example of how you might use Interweb TS JSON Schema in a project:
84+
85+
```ts
86+
import { generateSchema } from '@interweb/ts-json-schema';
87+
import { join } from 'path';
88+
89+
const sourcePath = join(__dirname, 'src/types.ts');
90+
const tsconfigPath = join(__dirname, 'tsconfig.json');
91+
const outputPath = join(__dirname, 'schema.json');
92+
93+
async function generateProjectSchema() {
94+
try {
95+
await generateSchema({
96+
sourcePath,
97+
tsconfigPath,
98+
outputPath
99+
});
100+
console.log('Schema generated successfully!');
101+
} catch (error) {
102+
console.error('Error generating schema:', error);
103+
}
104+
}
105+
106+
generateProjectSchema();
107+
```
108+
109+
## License
110+
111+
Interweb TS JSON Schema is MIT licensed.

0 commit comments

Comments
 (0)