From 0a155f84936ae30b54b365be0c8b18700ca52d14 Mon Sep 17 00:00:00 2001 From: chohmann Date: Thu, 14 Apr 2022 13:29:44 -0500 Subject: [PATCH 1/3] =?UTF-8?q?don=E2=80=99t=20know=20what=20I=20am=20doin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/cli.js | 4 ++- package.json | 1 + test/cli-test.js | 88 ++++++++++++++++++++++++------------------------ yarn.lock | 41 ++++------------------ 4 files changed, 55 insertions(+), 79 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 726eb7f..481eb13 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -17,6 +17,8 @@ var usageText = [ "means url; anything else is treated as path to a local file. ", "If no input file is specified and stdin is provided, stdin is used." ].join('\n'), + minimist = require('minimist'), + argv = minimist(process.argv.slice(2)), optimist = require('optimist') .usage(usageText) .wrap(84) @@ -33,7 +35,7 @@ var usageText = [ .alias('force','f') .describe('help', 'Show this help text.') .alias('help', 'h'), - argv = optimist.argv; + argvOld = optimist.argv; /** * @see http://tools.ietf.org/html/draft-fge-json-schema-validation-00#page-13 diff --git a/package.json b/package.json index 487b0d9..df5338a 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies": { "json-promise": "1.1.x", "mkdirp": "0.5.x", + "minimist": "1.2.6", "optimist": "0.6.x", "pretty-data": "0.40.x", "request": "2.x.x" diff --git a/test/cli-test.js b/test/cli-test.js index 4780a1e..a133cdc 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -36,47 +36,47 @@ var inputLocalPath = __dirname + '/fixtures/json/valid.json', var schemaJSON, copyJSON; -// describe('Cli', function() { -// it('Should be able to read a local file', function() { -// var json = runCli(inputLocalPath); -// console.log(typeof json); -// schemaJSON = runCli(inputLocalPath); -// expect(inputJSON).to.be.jsonSchema(schemaJSON); -// }); -// it('Should be able to read a remote file', function() { -// this.timeout(5000); -// schemaJSON = runCli(inputRemotePath); -// expect(inputJSON).to.be.jsonSchema(schemaJSON); -// inputRemotePath = null; -// }); -// it('Should be able to read stdin', function() { -// schemaJSON = runCli([], inputJSONString); -// expect(inputJSON).to.be.jsonSchema(schemaJSON); -// }); -// it('Should be able to write to a file', function() { -// runCli([inputLocalPath, '-o', './test/_file.json']); -// schemaJSON = JSON.parse(fs.readFileSync('./test/_file.json', 'utf8')); -// expect(inputJSON).to.be.jsonSchema(schemaJSON); -// fs.unlinkSync('./test/_file.json'); -// }); -// it('Should be able to write into a directory', function() { -// runCli([inputLocalPath, '--schemadir', './test/fixtures']); -// schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/valid.json', 'utf8')); -// expect(inputJSON).to.be.jsonSchema(schemaJSON); -// fs.unlinkSync('./test/fixtures/valid.json'); -// }); -// it('Should create subdirectories if necessary', function() { -// runCli([inputLocalPath, '--schemadir', './test/fixtures/var/']); -// schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); -// expect(inputJSON).to.be.jsonSchema(schemaJSON); -// fs.unlinkSync('./test/fixtures/var/valid.json'); -// fs.rmdirSync('./test/fixtures/var'); -// }); -// it('Should be able to create a copy of source', function() { -// runCli([inputLocalPath, '--jsondir', './test/fixtures/var/']); -// copyJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); -// expect(inputJSON).to.be.deep.equal(copyJSON); -// fs.unlinkSync('./test/fixtures/var/valid.json'); -// fs.rmdirSync('./test/fixtures/var'); -// }); -// }); +describe('Cli', function() { + it('Should be able to read a local file', function() { + var json = runCli(inputLocalPath); + console.log(typeof json); + schemaJSON = runCli(inputLocalPath); + expect(inputJSON).to.be.jsonSchema(schemaJSON); + }); + it('Should be able to read a remote file', function() { + this.timeout(5000); + schemaJSON = runCli(inputRemotePath); + expect(inputJSON).to.be.jsonSchema(schemaJSON); + inputRemotePath = null; + }); + it('Should be able to read stdin', function() { + schemaJSON = runCli([], inputJSONString); + expect(inputJSON).to.be.jsonSchema(schemaJSON); + }); + it('Should be able to write to a file', function() { + runCli([inputLocalPath, '-o', './test/_file.json']); + schemaJSON = JSON.parse(fs.readFileSync('./test/_file.json', 'utf8')); + expect(inputJSON).to.be.jsonSchema(schemaJSON); + fs.unlinkSync('./test/_file.json'); + }); + it('Should be able to write into a directory', function() { + runCli([inputLocalPath, '--schemadir', './test/fixtures']); + schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/valid.json', 'utf8')); + expect(inputJSON).to.be.jsonSchema(schemaJSON); + fs.unlinkSync('./test/fixtures/valid.json'); + }); + it('Should create subdirectories if necessary', function() { + runCli([inputLocalPath, '--schemadir', './test/fixtures/var/']); + schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); + expect(inputJSON).to.be.jsonSchema(schemaJSON); + fs.unlinkSync('./test/fixtures/var/valid.json'); + fs.rmdirSync('./test/fixtures/var'); + }); + it('Should be able to create a copy of source', function() { + runCli([inputLocalPath, '--jsondir', './test/fixtures/var/']); + copyJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); + expect(inputJSON).to.be.deep.equal(copyJSON); + fs.unlinkSync('./test/fixtures/var/valid.json'); + fs.rmdirSync('./test/fixtures/var'); + }); +}); diff --git a/yarn.lock b/yarn.lock index 61e501a..52ea7fa 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2200,7 +2200,7 @@ debug@^3.1.0: dependencies: ms "^2.1.1" -debuglog@*, debuglog@^1.0.1: +debuglog@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492" integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI= @@ -3517,7 +3517,7 @@ import-lazy@^2.1.0: resolved "https://registry.yarnpkg.com/import-lazy/-/import-lazy-2.1.0.tgz#05698e3d45c88e8d7e9d92cb0584e77f096f3e43" integrity sha1-BWmOPUXIjo1+nZLLBYTnfwlvPkM= -imurmurhash@*, imurmurhash@^0.1.4: +imurmurhash@^0.1.4: version "0.1.4" resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" integrity sha1-khi5srkoojixPcT7a21XbyMUU+o= @@ -4467,11 +4467,6 @@ lockfile@^1.0.4: dependencies: signal-exit "^3.0.2" -lodash._baseindexof@*: - version "3.1.0" - resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c" - integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw= - lodash._baseuniq@~4.6.0: version "4.6.0" resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8" @@ -4480,33 +4475,11 @@ lodash._baseuniq@~4.6.0: lodash._createset "~4.0.0" lodash._root "~3.0.0" -lodash._bindcallback@*: - version "3.0.1" - resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e" - integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4= - -lodash._cacheindexof@*: - version "3.0.2" - resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92" - integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI= - -lodash._createcache@*: - version "3.1.2" - resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093" - integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM= - dependencies: - lodash._getnative "^3.0.0" - lodash._createset@~4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26" integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY= -lodash._getnative@*, lodash._getnative@^3.0.0: - version "3.9.1" - resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5" - integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U= - lodash._reinterpolate@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d" @@ -4557,11 +4530,6 @@ lodash.map@^4.5.1: resolved "https://registry.yarnpkg.com/lodash.map/-/lodash.map-4.6.0.tgz#771ec7839e3473d9c4cde28b19394c3562f4f6d3" integrity sha1-dx7Hg540c9nEzeKLGTlMNWL09tM= -lodash.restparam@*: - version "3.6.1" - resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805" - integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU= - lodash.set@^4.3.2: version "4.3.2" resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23" @@ -4929,6 +4897,11 @@ minimist@1.2.5, minimist@^1.2.0, minimist@^1.2.5: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.5.tgz#67d66014b66a6a8aaa0c083c5fd58df4e4e97602" integrity sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw== +minimist@1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" + integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== + minimist@~0.0.1: version "0.0.10" resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" From 1c238cb08bfb20579a4889c77447bce407180f9d Mon Sep 17 00:00:00 2001 From: chohmann Date: Thu, 14 Apr 2022 14:09:15 -0500 Subject: [PATCH 2/3] remove optimist dep --- bin/cli.js | 50 +++++++++++++++++++++++--------------------------- package.json | 1 - yarn.lock | 15 --------------- 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 481eb13..10c0e92 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -10,32 +10,28 @@ var url = require('url'), errorHandler = cliConsole.errorHandler; var usageText = [ - //"Extract a json-schema from a json document.", - "Usage: $0 [|--url |--file |--stdin]", - "", - "If is specified, it is interpreted as follows: a protocol (like http://) ", - "means url; anything else is treated as path to a local file. ", - "If no input file is specified and stdin is provided, stdin is used." - ].join('\n'), + //"Extract a json-schema from a json document.", + "If is specified, it is interpreted as follows: a protocol (like http://) ", + "means url; anything else is treated as path to a local file. ", + "If no input file is specified and stdin is provided, stdin is used.", + "", + "Options:", + " --stdin Use stdin as input.", + " --url Remote json document to use as input.", + " --file Local json document to use as input.", + " --schemadir, -o Directory (or file, if ending with .json) where the schema will be stored.", + " --jsondir Directory (or file, if ending with .json) where the source document is copied to. Useful with --url.", + " --pretty Whether to use pretty json format. Use --no-pretty for false. Default True.", + " --force, -f If a destination file already exists, overwrite it.", + " --help, -h Show this help text." +].join('\n'), minimist = require('minimist'), - argv = minimist(process.argv.slice(2)), - optimist = require('optimist') - .usage(usageText) - .wrap(84) - .boolean(['pretty','force', 'stdin']) - .default('pretty', true) - .describe('stdin', 'Use stdin as input.') - .describe('url', 'Remote json document to use as input.') - .describe('file', 'Local json document to use as input.') - .describe('schemadir', 'Directory (or file, if ending with .json) where the schema will be stored.') - .alias('schemadir', 'o') - .describe('jsondir', 'Directory (or file, if ending with .json) where the source document is copied to. Useful with --url.') - .describe('pretty', 'Whether to use pretty json format. Use --no-pretty for false.') - .describe('force', 'If a destination file already exists, overwrite it.') - .alias('force','f') - .describe('help', 'Show this help text.') - .alias('help', 'h'), - argvOld = optimist.argv; + argv = minimist(process.argv.slice(2), + { + boolean: ['pretty', 'force', 'stdin'], + default: {'pretty': true}, + alias: {'force': 'f', 'help': 'h', 'schemadir': 'o'}, + }); /** * @see http://tools.ietf.org/html/draft-fge-json-schema-validation-00#page-13 @@ -115,7 +111,7 @@ function createConfig(argv) { case "h": case "help": // You asked for it, so stdout it is. - stdout(optimist.help()); + stdout(usageText); process.exit(0); break; } @@ -149,7 +145,7 @@ var config = createConfig(argv); // Cannot resolve without an input specification if (!config.src.type) { - errorHandler('Please specify a local file (path) or a URL of a JSON document' + '\n\n' + optimist.help()); + errorHandler('Please specify a local file (path) or a URL of a JSON document' + '\n\n' + usageText); } // Don't load this unless clearly necessary diff --git a/package.json b/package.json index df5338a..e1b99e4 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "json-promise": "1.1.x", "mkdirp": "0.5.x", "minimist": "1.2.6", - "optimist": "0.6.x", "pretty-data": "0.40.x", "request": "2.x.x" }, diff --git a/yarn.lock b/yarn.lock index 52ea7fa..16a2f90 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4902,10 +4902,6 @@ minimist@1.2.6: resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== -minimist@~0.0.1: - version "0.0.10" - resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" - minipass@^2.3.5, minipass@^2.6.0, minipass@^2.8.6, minipass@^2.9.0: version "2.9.0" resolved "https://registry.yarnpkg.com/minipass/-/minipass-2.9.0.tgz#e713762e7d3e32fed803115cf93e04bca9fcc9a6" @@ -5496,13 +5492,6 @@ opener@^1.5.1: resolved "https://registry.yarnpkg.com/opener/-/opener-1.5.2.tgz#5d37e1f35077b9dcac4301372271afdeb2a13598" integrity sha512-ur5UIdyw5Y7yEj9wLzhqXiy6GZ3Mwx0yGI+5sMn2r0N0v3cKJvUmFH5yPP+WXh9e0xfyzyJX95D8l088DNFj7A== -optimist@0.6.x: - version "0.6.1" - resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" - dependencies: - minimist "~0.0.1" - wordwrap "~0.0.2" - os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" @@ -7665,10 +7654,6 @@ wordwrap@^1.0.0: resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus= -wordwrap@~0.0.2: - version "0.0.3" - resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" - worker-farm@^1.6.0, worker-farm@^1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.7.0.tgz#26a94c5391bbca926152002f69b84a4bf772e5a8" From 63a644e034fa2b661aa22144eb6cd83156c0c049 Mon Sep 17 00:00:00 2001 From: chohmann Date: Thu, 14 Apr 2022 14:15:43 -0500 Subject: [PATCH 3/3] re-comment out tests --- test/cli-test.js | 88 ++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/test/cli-test.js b/test/cli-test.js index a133cdc..4780a1e 100644 --- a/test/cli-test.js +++ b/test/cli-test.js @@ -36,47 +36,47 @@ var inputLocalPath = __dirname + '/fixtures/json/valid.json', var schemaJSON, copyJSON; -describe('Cli', function() { - it('Should be able to read a local file', function() { - var json = runCli(inputLocalPath); - console.log(typeof json); - schemaJSON = runCli(inputLocalPath); - expect(inputJSON).to.be.jsonSchema(schemaJSON); - }); - it('Should be able to read a remote file', function() { - this.timeout(5000); - schemaJSON = runCli(inputRemotePath); - expect(inputJSON).to.be.jsonSchema(schemaJSON); - inputRemotePath = null; - }); - it('Should be able to read stdin', function() { - schemaJSON = runCli([], inputJSONString); - expect(inputJSON).to.be.jsonSchema(schemaJSON); - }); - it('Should be able to write to a file', function() { - runCli([inputLocalPath, '-o', './test/_file.json']); - schemaJSON = JSON.parse(fs.readFileSync('./test/_file.json', 'utf8')); - expect(inputJSON).to.be.jsonSchema(schemaJSON); - fs.unlinkSync('./test/_file.json'); - }); - it('Should be able to write into a directory', function() { - runCli([inputLocalPath, '--schemadir', './test/fixtures']); - schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/valid.json', 'utf8')); - expect(inputJSON).to.be.jsonSchema(schemaJSON); - fs.unlinkSync('./test/fixtures/valid.json'); - }); - it('Should create subdirectories if necessary', function() { - runCli([inputLocalPath, '--schemadir', './test/fixtures/var/']); - schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); - expect(inputJSON).to.be.jsonSchema(schemaJSON); - fs.unlinkSync('./test/fixtures/var/valid.json'); - fs.rmdirSync('./test/fixtures/var'); - }); - it('Should be able to create a copy of source', function() { - runCli([inputLocalPath, '--jsondir', './test/fixtures/var/']); - copyJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); - expect(inputJSON).to.be.deep.equal(copyJSON); - fs.unlinkSync('./test/fixtures/var/valid.json'); - fs.rmdirSync('./test/fixtures/var'); - }); -}); +// describe('Cli', function() { +// it('Should be able to read a local file', function() { +// var json = runCli(inputLocalPath); +// console.log(typeof json); +// schemaJSON = runCli(inputLocalPath); +// expect(inputJSON).to.be.jsonSchema(schemaJSON); +// }); +// it('Should be able to read a remote file', function() { +// this.timeout(5000); +// schemaJSON = runCli(inputRemotePath); +// expect(inputJSON).to.be.jsonSchema(schemaJSON); +// inputRemotePath = null; +// }); +// it('Should be able to read stdin', function() { +// schemaJSON = runCli([], inputJSONString); +// expect(inputJSON).to.be.jsonSchema(schemaJSON); +// }); +// it('Should be able to write to a file', function() { +// runCli([inputLocalPath, '-o', './test/_file.json']); +// schemaJSON = JSON.parse(fs.readFileSync('./test/_file.json', 'utf8')); +// expect(inputJSON).to.be.jsonSchema(schemaJSON); +// fs.unlinkSync('./test/_file.json'); +// }); +// it('Should be able to write into a directory', function() { +// runCli([inputLocalPath, '--schemadir', './test/fixtures']); +// schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/valid.json', 'utf8')); +// expect(inputJSON).to.be.jsonSchema(schemaJSON); +// fs.unlinkSync('./test/fixtures/valid.json'); +// }); +// it('Should create subdirectories if necessary', function() { +// runCli([inputLocalPath, '--schemadir', './test/fixtures/var/']); +// schemaJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); +// expect(inputJSON).to.be.jsonSchema(schemaJSON); +// fs.unlinkSync('./test/fixtures/var/valid.json'); +// fs.rmdirSync('./test/fixtures/var'); +// }); +// it('Should be able to create a copy of source', function() { +// runCli([inputLocalPath, '--jsondir', './test/fixtures/var/']); +// copyJSON = JSON.parse(fs.readFileSync('./test/fixtures/var/valid.json')); +// expect(inputJSON).to.be.deep.equal(copyJSON); +// fs.unlinkSync('./test/fixtures/var/valid.json'); +// fs.rmdirSync('./test/fixtures/var'); +// }); +// });