@skriptfabrik/json-schema-bundler 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ version: 2
2
+
3
+ registries:
4
+ dockerhub:
5
+ type: 'docker-registry'
6
+ url: 'https://registry.hub.docker.com'
7
+ username: '${{ secrets.DOCKERHUB_USERNAME }}'
8
+ password: '${{ secrets.DOCKERHUB_TOKEN }}'
9
+ replaces-base: true
10
+
11
+ updates:
12
+ - package-ecosystem: 'github-actions'
13
+ directory: '/'
14
+ reviewers:
15
+ - 'skriptfabrik/developers'
16
+ schedule:
17
+ interval: 'weekly'
18
+ time: '08:00'
19
+ timezone: 'Europe/Berlin'
20
+
21
+ - package-ecosystem: 'npm'
22
+ directory: '/'
23
+ ignore:
24
+ - dependency-name: '@types/*'
25
+ reviewers:
26
+ - 'skriptfabrik/developers'
27
+ schedule:
28
+ interval: 'weekly'
29
+ time: '08:00'
30
+ timezone: 'Europe/Berlin'
31
+
32
+ - package-ecosystem: 'docker'
33
+ directory: '/'
34
+ reviewers:
35
+ - 'skriptfabrik/developers'
36
+ registries:
37
+ - 'dockerhub'
38
+ schedule:
39
+ interval: 'weekly'
40
+ time: '08:00'
41
+ timezone: 'Europe/Berlin'
@@ -0,0 +1,12 @@
1
+ ## Describe your changes
2
+
3
+ - [ ] Bug fix (non-breaking change which fixes an issue)
4
+ - [ ] New feature (non-breaking change which adds functionality)
5
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
6
+
7
+ ## Checklist before requesting a review
8
+
9
+ - [ ] I have included the ticket number of the issue at the beginning of the title of this pull request.
10
+ - [ ] I have updated the docs and/or specs to reflect this change.
11
+ - [ ] I have performed a self-review of my code.
12
+ - [ ] I have added thorough tests.
@@ -69,7 +69,7 @@ jobs:
69
69
 
70
70
  - name: Build and Push latest Docker image
71
71
  if: github.ref_name == 'main'
72
- uses: docker/build-push-action@v2
72
+ uses: docker/build-push-action@v4
73
73
  with:
74
74
  build-args: |-
75
75
  BUILDKIT_INLINE_CACHE=${{ env.DOCKER_BUILDKIT_INLINE_CACHE }}
@@ -91,7 +91,7 @@ jobs:
91
91
 
92
92
  - name: Build and Push Docker image release version
93
93
  if: github.ref_type == 'tag'
94
- uses: docker/build-push-action@v2
94
+ uses: docker/build-push-action@v4
95
95
  with:
96
96
  build-args: |-
97
97
  BUILDKIT_INLINE_CACHE=${{ env.DOCKER_BUILDKIT_INLINE_CACHE }}
package/Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- FROM node:18.2.0-alpine
1
+ FROM node:18.14.0-alpine
2
2
 
3
3
  LABEL maintainer="Daniel Schröder <daniel.schroeder@skriptfabrik.com>"
4
4
 
@@ -11,6 +11,6 @@ COPY . /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION}
11
11
  RUN set -eux; \
12
12
  npm --prefix /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION} install; \
13
13
  rm -Rf ~/.npm; \
14
- ln -s /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION}/json-schema-bundler-cli.js /usr/local/bin/json-schema-bundler
14
+ ln -s /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION}/json-schema-bundler-cli.mjs /usr/local/bin/json-schema-bundler
15
15
 
16
16
  ENTRYPOINT [ "json-schema-bundler" ]
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  [![NPM Version](https://img.shields.io/npm/v/@skriptfabrik/json-schema-bundler)](https://www.npmjs.com/package/@skriptfabrik/json-schema-bundler)
2
2
  [![NPM Downloads](https://img.shields.io/npm/dt/@skriptfabrik/json-schema-bundler)](https://www.npmjs.com/package/@skriptfabrik/json-schema-bundler)
3
- [![Continuous Integration](https://img.shields.io/github/workflow/status/skriptfabrik/json-schema-bundler/Continuous%20Integration)](https://github.com/skriptfabrik/json-schema-bundler/actions/workflows/ci.yml)
3
+ [![Continuous Integration](https://img.shields.io/github/actions/workflow/status/skriptfabrik/json-schema-bundler/ci.yml)](https://github.com/skriptfabrik/json-schema-bundler/actions/workflows/ci.yml)
4
4
 
5
5
  # JSON Schema Bundler
6
6
 
@@ -27,30 +27,35 @@ Usage:
27
27
  json-schema-bundler [options] <input>
28
28
 
29
29
  Arguments:
30
- input The path or URL of the input schema file
30
+ input The path of the input schema file
31
31
 
32
32
  Options:
33
- -h, --help Display this help message
34
- -p, --pretty Pretty print output
35
- -s, --silent Silent mode
36
- -v, --version Print version number
33
+ -d, --dereference Replacing each reference with its resolved value
34
+ -h, --help Display this help message
35
+ -p, --pretty Pretty print output
36
+ -s, --silent Silent mode
37
+ -v, --version Print version number
37
38
 
38
39
  Examples:
39
- Bundle all references in schema.json and print output to stdout:
40
+ Bundle all references in schema.json with internal $ref pointers and print output to stdout:
40
41
 
41
- json-schema-bundler -ps schema.json
42
+ json-schema-bundler schema.json
43
+
44
+ Dereference all references in schema.json and print output to stdout:
45
+
46
+ json-schema-bundler -d schema.json
42
47
  ```
43
48
 
44
49
  ## Docker
45
50
 
46
- Use the following command to bundle (dereference) all references in `schema.json` and print the output to `stdout`:
51
+ Use the following command to bundle all references in `schema.json` and print the output to `stdout`:
47
52
 
48
53
  ```bash
49
- docker run --rm -v `pwd`:/work -w /work skriptfabrik/json-schema-bundler -ps schema.json
54
+ docker run --rm -v `pwd`:/work -w /work skriptfabrik/json-schema-bundler schema.json
50
55
  ```
51
56
 
52
- It is also possible to print the status logs to `stderr` and redirect `stdout` to a file:
57
+ To dereference all references in `schema.json` and print the output to `stdout` add the `-d` option:
53
58
 
54
59
  ```bash
55
- docker run --rm -v `pwd`:/work -w /work skriptfabrik/json-schema-bundler -p schema.json > output.json
60
+ docker run --rm -v `pwd`:/work -w /work skriptfabrik/json-schema-bundler -d schema.json
56
61
  ```
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ import $RefParser from '@apidevtools/json-schema-ref-parser';
4
+ import chalk from 'chalk';
5
+ import { readFile } from 'fs/promises';
6
+ import minimist from 'minimist';
7
+ import path from 'path';
8
+ import { fileURLToPath } from 'url';
9
+ import YAML from 'js-yaml';
10
+
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ const pkg = JSON.parse(await readFile(path.join(__dirname, 'package.json')));
15
+
16
+ const argv = minimist(process.argv.slice(2), {
17
+ boolean: ['d', 'h', 'p', 's', 'v', 'y'],
18
+ alias: {
19
+ d: 'dereference',
20
+ h: 'help',
21
+ p: 'pretty',
22
+ s: 'silent',
23
+ v: 'version',
24
+ y: 'yaml',
25
+ },
26
+ });
27
+
28
+ if (argv.v) {
29
+ console.log(pkg.version);
30
+ process.exit(0);
31
+ }
32
+
33
+ if (argv.h || argv._.length < 1) {
34
+ console.error(
35
+ `JSON Schema Bundler\n\n${chalk.yellow('Usage:')}\n %s\n\n${chalk.yellow('Arguments:')}\n %s\n\n${chalk.yellow('Options:')}\n %s\n\n${chalk.yellow('Examples:')}\n %s`,
36
+ ` ${path.basename(process.argv[1])} [options] <input>`,
37
+ ` ${chalk.green('input')} The path of the input schema file`,
38
+ [
39
+ ` ${chalk.green('-d, --dereference')} Replacing each reference with its resolved value`,
40
+ ` ${chalk.green('-h, --help')} Display this help message`,
41
+ ` ${chalk.green('-p, --pretty')} Pretty print output`,
42
+ ` ${chalk.green('-s, --silent')} Silent mode`,
43
+ ` ${chalk.green('-v, --version')} Print version number`,
44
+ ` ${chalk.green('-y, --yaml')} Output as YAML document instead of JSON`,
45
+ ].join('\n'),
46
+ [
47
+ ` Bundle all references in ${chalk.magenta('schema.json')} with internal $ref pointers and print output to ${chalk.magenta('stdout')}:`,
48
+ ``,
49
+ ` ${chalk.green(`${path.basename(process.argv[1])} schema.json`)}`,
50
+ ``,
51
+ ` Dereference all references in ${chalk.magenta('schema.json')} and print output to ${chalk.magenta('stdout')}:`,
52
+ ``,
53
+ ` ${chalk.green(`${path.basename(process.argv[1])} -d schema.json`)}`,
54
+ ].join('\n')
55
+ );
56
+ process.exit(argv.h ? 0 : 1);
57
+ }
58
+
59
+ const input = path.resolve(argv._[0]);
60
+
61
+ argv.s || console.error(`Bundling ${input}`);
62
+
63
+ let schema;
64
+
65
+ try {
66
+ if (argv.d) {
67
+ schema = await $RefParser.dereference(input);
68
+ } else {
69
+ schema = await $RefParser.bundle(input);
70
+ }
71
+ } catch (err) {
72
+ argv.s || console.error(err);
73
+ process.exit(1);
74
+ }
75
+
76
+ if (argv.y) {
77
+ console.log(YAML.dump(schema, argv.p ? undefined : { flowLevel: 3 }));
78
+ } else {
79
+ console.log(JSON.stringify(schema, undefined, argv.p ? 2 : undefined));
80
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skriptfabrik/json-schema-bundler",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "The missing CLI for the JSON Schema $Ref Parser",
5
5
  "keywords": [
6
6
  "json",
@@ -22,10 +22,15 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "json-schema-ref-parser": "^9.0.9",
26
- "minimist": "^1.2.6"
25
+ "@apidevtools/json-schema-ref-parser": "^10.1.0",
26
+ "chalk": "^5.2.0",
27
+ "js-yaml": "~4.0.0",
28
+ "minimist": "^1.2.7"
29
+ },
30
+ "devDependencies": {
31
+ "@types/js-yaml": "~4.0.0"
27
32
  },
28
33
  "bin": {
29
- "json-schema-bundler": "./json-schema-bundler-cli.js"
34
+ "json-schema-bundler": "./json-schema-bundler-cli.mjs"
30
35
  }
31
36
  }
@@ -1,66 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const $RefParser = require('json-schema-ref-parser');
4
- const minimist = require('minimist');
5
- const path = require('path');
6
- const pkg = require('./package.json');
7
-
8
- const argv = minimist(process.argv.slice(2), {
9
- boolean: ['h', 'p', 's'],
10
- alias: {
11
- h: 'help',
12
- p: 'pretty',
13
- s: 'silent',
14
- v: 'version',
15
- },
16
- });
17
-
18
- const colors = {
19
- end: '\x1b[0m',
20
- green: '\x1b[32m',
21
- yellow: '\x1b[33m',
22
- magenta: '\x1b[35m',
23
- };
24
-
25
- if (argv.v) {
26
- console.log(pkg.version);
27
- process.exit(0);
28
- }
29
-
30
- if (argv.h || argv._.length < 1) {
31
- console.error(
32
- `JSON Schema Bundler\n\n${colors.yellow}Usage:${colors.end}\n %s\n\n${colors.yellow}Arguments:${colors.end}\n %s\n\n${colors.yellow}Options:${colors.end}\n %s\n\n${colors.yellow}Examples:${colors.end}\n %s`,
33
- `${path.basename(process.argv[1])} [options] <input>`,
34
- `${colors.green}input${colors.end} The path or URL of the input schema file`,
35
- [
36
- `${colors.green}-h, --help${colors.end} Display this help message`,
37
- `${colors.green}-p, --pretty${colors.end} Pretty print output`,
38
- `${colors.green}-s, --silent${colors.end} Silent mode`,
39
- `${colors.green}-v, --version${colors.end} Print version number`,
40
- ].join('\n '),
41
- [
42
- [
43
- `Bundle all references in ${colors.magenta}schema.json${colors.end} and print output to ${colors.magenta}stdout${colors.end}:`,
44
- `${colors.green}${path.basename(process.argv[1])} -ps schema.json${colors.end}`,
45
- ].join('\n\n '),
46
- ].join('\n '),
47
- );
48
- process.exit(argv.h ? 0 : 1);
49
- }
50
-
51
- const input = path.resolve(argv._[0]);
52
-
53
- argv.s || console.error(`Bundling ${input}`);
54
-
55
- (async () => {
56
- let schema;
57
-
58
- try {
59
- schema = await $RefParser.dereference(input);
60
- } catch (err) {
61
- argv.s || console.error(err);
62
- process.exit(1);
63
- }
64
-
65
- console.log(JSON.stringify(schema, undefined, argv.p ? 2 : undefined));
66
- })();