@skriptfabrik/json-schema-bundler 0.1.1 → 0.3.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.
package/README.md CHANGED
@@ -21,35 +21,41 @@ json-schema-bundler --help
21
21
  ```
22
22
 
23
23
  ```text
24
- JSON Schema Bundler (latest)
24
+ JSON Schema Bundler
25
25
 
26
26
  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
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
36
38
 
37
39
  Examples:
38
- 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:
39
41
 
40
- 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
41
47
  ```
42
48
 
43
49
  ## Docker
44
50
 
45
- 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`:
46
52
 
47
53
  ```bash
48
- 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
49
55
  ```
50
56
 
51
- 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:
52
58
 
53
59
  ```bash
54
- 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
55
61
  ```
@@ -1,16 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const $RefParser = require('json-schema-ref-parser');
3
+ const $RefParser = require('@apidevtools/json-schema-ref-parser');
4
4
  const minimist = require('minimist');
5
5
  const path = require('path');
6
6
  const pkg = require('./package.json');
7
7
 
8
8
  const argv = minimist(process.argv.slice(2), {
9
- boolean: ['h', 'p', 's'],
9
+ boolean: ['d', 'h', 'p', 's', 'v'],
10
10
  alias: {
11
+ d: 'dereference',
11
12
  h: 'help',
12
13
  p: 'pretty',
13
14
  s: 'silent',
15
+ v: 'version',
14
16
  },
15
17
  });
16
18
 
@@ -21,23 +23,33 @@ const colors = {
21
23
  magenta: '\x1b[35m',
22
24
  };
23
25
 
26
+ if (argv.v) {
27
+ console.log(pkg.version);
28
+ process.exit(0);
29
+ }
30
+
24
31
  if (argv.h || argv._.length < 1) {
25
32
  console.error(
26
- `JSON Schema Bundler (%s)\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`,
27
- pkg.version,
33
+ `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`,
28
34
  `${path.basename(process.argv[1])} [options] <input>`,
29
- `${colors.green}input${colors.end} The path or URL of the input schema file`,
35
+ `${colors.green}input${colors.end} The path of the input schema file`,
30
36
  [
31
- `${colors.green}-h, --help${colors.end} Display this help message`,
32
- `${colors.green}-p, --pretty${colors.end} Pretty print output`,
33
- `${colors.green}-s, --silent${colors.end} Silent mode`,
37
+ `${colors.green}-d, --dereference${colors.end} Replacing each reference with its resolved value`,
38
+ `${colors.green}-h, --help${colors.end} Display this help message`,
39
+ `${colors.green}-p, --pretty${colors.end} Pretty print output`,
40
+ `${colors.green}-s, --silent${colors.end} Silent mode`,
41
+ `${colors.green}-v, --version${colors.end} Print version number`,
34
42
  ].join('\n '),
35
43
  [
36
44
  [
37
- `Bundle all references in ${colors.magenta}schema.json${colors.end} and print output to ${colors.magenta}stdout${colors.end}:`,
38
- `${colors.green}${path.basename(process.argv[1])} -ps schema.json${colors.end}`,
45
+ `Bundle all references in ${colors.magenta}schema.json${colors.end} with internal $ref pointers and print output to ${colors.magenta}stdout${colors.end}:`,
46
+ `${colors.green}${path.basename(process.argv[1])} schema.json${colors.end}`,
39
47
  ].join('\n\n '),
40
- ].join('\n '),
48
+ [
49
+ `Dereference all references in ${colors.magenta}schema.json${colors.end} and print output to ${colors.magenta}stdout${colors.end}:`,
50
+ `${colors.green}${path.basename(process.argv[1])} -d schema.json${colors.end}`,
51
+ ].join('\n\n '),
52
+ ].join('\n\n '),
41
53
  );
42
54
  process.exit(argv.h ? 0 : 1);
43
55
  }
@@ -50,7 +62,11 @@ argv.s || console.error(`Bundling ${input}`);
50
62
  let schema;
51
63
 
52
64
  try {
53
- schema = await $RefParser.dereference(input);
65
+ if (argv.d) {
66
+ schema = await $RefParser.dereference(input);
67
+ } else {
68
+ schema = await $RefParser.bundle(input);
69
+ }
54
70
  } catch (err) {
55
71
  argv.s || console.error(err);
56
72
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skriptfabrik/json-schema-bundler",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "The missing CLI for the JSON Schema $Ref Parser",
5
5
  "keywords": [
6
6
  "json",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "json-schema-ref-parser": "^9.0.9",
25
+ "@apidevtools/json-schema-ref-parser": "^9.0.9",
26
26
  "minimist": "^1.2.6"
27
27
  },
28
28
  "bin": {