@skriptfabrik/json-schema-bundler 0.0.0-dev

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/.dockerignore ADDED
@@ -0,0 +1,22 @@
1
+ # GitHub
2
+ /.github
3
+
4
+ # JetBrains IDEs - PhpStorm
5
+ /.idea
6
+
7
+ # Microsoft IDEs - VSCode
8
+ /.vscode
9
+
10
+ # Dependencies
11
+ node_modules
12
+
13
+ # Misc
14
+ .dockerignore
15
+ .editorconfig
16
+ .git*
17
+ Dockerfile
18
+ README.md
19
+
20
+ # System Files
21
+ .DS_Store
22
+ Thumbs.db
package/.editorconfig ADDED
@@ -0,0 +1,19 @@
1
+ ; This file is for unifying the coding style for different editors and IDEs.
2
+ ; More information at http://editorconfig.org
3
+
4
+ root = true
5
+
6
+ [*]
7
+ charset = utf-8
8
+ indent_size = 4
9
+ indent_style = space
10
+ end_of_line = lf
11
+ insert_final_newline = true
12
+ trim_trailing_whitespace = true
13
+
14
+ [*.{json,yml,yaml}]
15
+ indent_size = 2
16
+
17
+ [*.md]
18
+ max_line_length = off
19
+ trim_trailing_whitespace = false
@@ -0,0 +1,92 @@
1
+ name: Continuous Integration
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ tags:
8
+ - '*'
9
+
10
+ env:
11
+ DOCKER_BUILDKIT: 1
12
+ DOCKER_BUILDKIT_INLINE_CACHE: 1
13
+ DOCKER_IMAGE_NAME: skriptfabrik/json-schema-bundler
14
+ NODE_VERSION: 18.2.0
15
+
16
+ jobs:
17
+ publish-push:
18
+ name: Publish package and Push Docker images
19
+ runs-on: ubuntu-latest
20
+
21
+ steps:
22
+ - name: Checkout
23
+ uses: actions/checkout@v3
24
+ with:
25
+ fetch-depth: 0
26
+
27
+ - name: Install Node.js version ${{ env.NODE_VERSION }}
28
+ uses: actions/setup-node@v3
29
+ with:
30
+ node-version: ${{ env.NODE_VERSION }}
31
+
32
+ - name: Install dependencies
33
+ run: npm ci
34
+
35
+ - name: Bump package version
36
+ if: github.ref_type == 'tag'
37
+ run: npm version from-git --no-git-tag-version
38
+
39
+ - name: Publish package
40
+ uses: JS-DevTools/npm-publish@v1
41
+ if: github.ref_type == 'tag'
42
+ with:
43
+ access: public
44
+ token: ${{ secrets.NPM_TOKEN }}
45
+
46
+ - name: Log in to DockerHub
47
+ uses: docker/login-action@v2
48
+ with:
49
+ username: ${{ secrets.DOCKERHUB_USERNAME }}
50
+ password: ${{ secrets.DOCKERHUB_TOKEN }}
51
+
52
+ - name: Set up QEMU
53
+ uses: docker/setup-qemu-action@v2
54
+
55
+ - name: Set up Docker Buildx
56
+ uses: docker/setup-buildx-action@v2
57
+
58
+ - name: Build and Push latest Docker image
59
+ if: github.ref_name == 'main'
60
+ uses: docker/build-push-action@v2
61
+ with:
62
+ build-args: |-
63
+ BUILDKIT_INLINE_CACHE=${{ env.DOCKER_BUILDKIT_INLINE_CACHE }}
64
+ cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_NAME }}:latest
65
+ platforms: |-
66
+ linux/amd64
67
+ linux/arm64
68
+ pull: true
69
+ push: true
70
+ tags: |-
71
+ ${{ env.DOCKER_IMAGE_NAME }}:latest
72
+
73
+ - name: Export release version
74
+ if: github.ref_type == 'tag'
75
+ run: |-
76
+ echo "RELEASE_VERSION=${GITHUB_REF_NAME}" >> ${GITHUB_ENV}
77
+
78
+ - name: Build and Push Docker image release version
79
+ if: github.ref_type == 'tag'
80
+ uses: docker/build-push-action@v2
81
+ with:
82
+ build-args: |-
83
+ BUILDKIT_INLINE_CACHE=${{ env.DOCKER_BUILDKIT_INLINE_CACHE }}
84
+ JSON_SCHEMA_BUNDLER_VERSION=v${{ env.RELEASE_VERSION }}
85
+ cache-from: type=registry,ref=${{ env.DOCKER_IMAGE_NAME }}:latest
86
+ platforms: |-
87
+ linux/amd64
88
+ linux/arm64
89
+ pull: true
90
+ push: true
91
+ tags: |-
92
+ ${{ env.DOCKER_IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
package/Dockerfile ADDED
@@ -0,0 +1,17 @@
1
+ FROM node:18.2.0-alpine
2
+
3
+ LABEL maintainer="Daniel Schröder <daniel.schroeder@skriptfabrik.com>"
4
+
5
+ ARG JSON_SCHEMA_BUNDLER_VERSION=latest
6
+
7
+ ENV JSON_SCHEMA_BUNDLER_VERSION=${JSON_SCHEMA_BUNDLER_VERSION}
8
+ ENV NODE_ENV=production
9
+
10
+ COPY . /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION}
11
+
12
+ RUN set -eux; \
13
+ npm --prefix /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION} install; \
14
+ rm -Rf ~/.npm; \
15
+ ln -s /opt/json-schema-bundler-${JSON_SCHEMA_BUNDLER_VERSION}/json-schema-bundler-cli.js /usr/local/bin/json-schema-bundler
16
+
17
+ ENTRYPOINT [ "json-schema-bundler" ]
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ [![NPM Version](https://img.shields.io/npm/v/@skriptfabrik/json-schema-bundler)](https://www.npmjs.com/package/@skriptfabrik/json-schema-bundler)
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)
4
+
5
+ # JSON Schema Bundler
6
+
7
+ > The missing CLI for the [JSON Schema $Ref Parser](https://github.com/APIDevTools/json-schema-ref-parser)
8
+
9
+ ## Installation
10
+
11
+ Install using [npm](https://docs.npmjs.com/about-npm/) as global package:
12
+
13
+ ```bash
14
+ npm install -g @skriptfabrik/json-schema-bundler
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```bash
20
+ json-schema-bundler --help
21
+ ```
22
+
23
+ ```text
24
+ JSON Schema Bundler (latest)
25
+
26
+ Usage:
27
+ json-schema-bundler [options] <input>
28
+
29
+ Arguments:
30
+ input The path or URL of the input schema file
31
+
32
+ Options:
33
+ -h, --help Display this help message
34
+ -p, --pretty Pretty print output
35
+ -s, --silent Silent mode
36
+
37
+ Examples:
38
+ Bundle all references in schema.json and print output to stdout:
39
+
40
+ json-schema-bundler -ps schema.json
41
+ ```
42
+
43
+ ## Docker
44
+
45
+ Use the following command to bundle (dereference) all references in `schema.json` and print the output to `stdout`:
46
+
47
+ ```bash
48
+ docker run --rm -v `pwd`:/work -w /work skriptfabrik/json-schema-bundler -ps schema.json
49
+ ```
50
+
51
+ It is also possible to print the status logs to `stderr` and redirect `stdout` to a file:
52
+
53
+ ```bash
54
+ docker run --rm -v `pwd`:/work -w /work skriptfabrik/json-schema-bundler -p schema.json > output.json
55
+ ```
@@ -0,0 +1,59 @@
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
+
7
+ const argv = minimist(process.argv.slice(2), {
8
+ boolean: ['h', 'p', 's'],
9
+ alias: {
10
+ h: 'help',
11
+ p: 'pretty',
12
+ s: 'silent',
13
+ },
14
+ });
15
+
16
+ const colors = {
17
+ end: '\x1b[0m',
18
+ green: '\x1b[32m',
19
+ yellow: '\x1b[33m',
20
+ magenta: '\x1b[35m',
21
+ };
22
+
23
+ if (argv.h || argv._.length < 1) {
24
+ console.error(
25
+ `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`,
26
+ process.env['JSON_SCHEMA_BUNDLER_VERSION'],
27
+ `${path.basename(process.argv[1])} [options] <input>`,
28
+ `${colors.green}input${colors.end} The path or URL of the input schema file`,
29
+ [
30
+ `${colors.green}-h, --help${colors.end} Display this help message`,
31
+ `${colors.green}-p, --pretty${colors.end} Pretty print output`,
32
+ `${colors.green}-s, --silent${colors.end} Silent mode`,
33
+ ].join('\n '),
34
+ [
35
+ [
36
+ `Bundle all references in ${colors.magenta}schema.json${colors.end} and print output to ${colors.magenta}stdout${colors.end}:`,
37
+ `${colors.green}${path.basename(process.argv[1])} -ps schema.json${colors.end}`,
38
+ ].join('\n\n '),
39
+ ].join('\n '),
40
+ );
41
+ process.exit(argv.h ? 0 : 1);
42
+ }
43
+
44
+ const input = path.resolve(argv._[0]);
45
+
46
+ argv.s || console.error(`Bundling ${input}`);
47
+
48
+ (async () => {
49
+ let schema;
50
+
51
+ try {
52
+ schema = await $RefParser.dereference(input);
53
+ } catch (err) {
54
+ argv.s || console.error(err);
55
+ process.exit(1);
56
+ }
57
+
58
+ console.log(JSON.stringify(schema, undefined, argv.p ? 2 : undefined));
59
+ })();
package/output.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "schema2": {
3
+ "foo": "bar"
4
+ }
5
+ }
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@skriptfabrik/json-schema-bundler",
3
+ "version": "0.0.0-dev",
4
+ "description": "The missing CLI for the JSON Schema $Ref Parser",
5
+ "keywords": [
6
+ "json",
7
+ "schema",
8
+ "jsonschema",
9
+ "json-schema",
10
+ "json-pointer",
11
+ "$ref",
12
+ "bundle",
13
+ "cli"
14
+ ],
15
+ "author": {
16
+ "name": "Daniel Schröder",
17
+ "email": "daniel.schroeder@skriptfabrik.com"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/skriptfabrik/json-schema-bundler.git"
22
+ },
23
+ "license": "MIT",
24
+ "dependencies": {
25
+ "json-schema-ref-parser": "^9.0.9",
26
+ "minimist": "^1.2.6"
27
+ },
28
+ "bin": {
29
+ "json-schema-bundler": "./json-schema-bundler-cli.js"
30
+ }
31
+ }
package/schema.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "schema2": {
3
+ "$ref": "schema2.json"
4
+ }
5
+ }
package/schema2.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "foo": "bar"
3
+ }