Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## v7.0.2 (05/10/2025)

- Improved argument parsing for CLI.
- Updated dependencies.

## v7.0.1 (30/09/2025)

- Fixed bug where descriptions were not set for repeated columns.
Expand Down
19 changes: 15 additions & 4 deletions bin/jsbq
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env node

const jsbq = (module.exports = {})

const gbq = require('../src/gbq')
const { get_table_id } = require('../src/utils')
const converter = require('../src/converter')
const { logger } = require('../src/log')
const fs = require('fs')
const { promisify } = require('util')
const yargs = require('yargs')
const hideBin = require('yargs/helpers').hideBin

const jsbq = (module.exports = {})

jsbq.process = async (project, datasetName, jsonSchema, options) => {
logger.info('Processing JSON schema...')
Expand Down Expand Up @@ -47,20 +49,28 @@ jsbq.process = async (project, datasetName, jsonSchema, options) => {
jsbq.run = async () => {
const readFile = promisify(fs.readFile)

const argv = require('yargs')
const argv = yargs(hideBin(process.argv))
.usage(
'Usage: $0 -p [project] -d [dataset] -j <json schema file> --preventAdditionalObjectProperties --continueOnError',
)
.version(false)
.help(false)
.options({
j: {
describe: 'JSON schema file',
demandOption: true,
type: 'string',
requiresArg: true,
},
p: {
describe: 'GCP project name',
type: 'string',
requiresArg: true,
},
d: {
describe: 'BigQuery dataset name',
type: 'string',
requiresArg: true,
},
preventAdditionalObjectProperties: {
describe: 'boolean, check for additional object properties in schemas.',
Expand All @@ -78,7 +88,8 @@ jsbq.run = async () => {
type: 'boolean',
default: false,
},
}).argv
})
.parse()

if (argv.debug) {
logger.level = 'debug'
Expand Down
171 changes: 168 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "jsonschema-bigquery",
"version": "7.0.1",
"version": "7.0.2",
"description": "Convert JSON schema to Google BigQuery schema",
"main": "src/converter.js",
"scripts": {
"ci": "npm run lint && npm run coverage",
"test": "mocha test/unit test/integration",
"test": "mocha test/unit test/integration test/system",
"coverage": "nyc npm run test",
"lint:eslint": "eslint .",
"lint:prettier": "prettier -c .",
Expand Down Expand Up @@ -47,7 +47,8 @@
"eslint-plugin-promise": "^7.0.0",
"mocha": "^11.0.1",
"nyc": "^17.0.0",
"prettier": "^3.3.3"
"prettier": "^3.3.3",
"sinon": "^21.0.0"
},
"dependencies": {
"@google-cloud/bigquery": "^8.0.0",
Expand Down
24 changes: 24 additions & 0 deletions test/system/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const assert = require('assert')
const execSync = require('child_process').execSync

describe('CLI', () => {
context('without args', () => {
it('shows help', () => {
try {
execSync('bin/jsbq')
} catch (e) {
const output = e.stderr.toString()
assert.match(output, /Usage:/)
}
})
})

context('with a schema', () => {
it('shows GBQ output', () => {
const output = execSync(
'bin/jsbq -j test/integration/samples/allOf/input.json',
).toString()
assert.match(output, /RECORD/)
})
})
})
Loading
Loading