Comparing version 0.1.0 to 0.1.1
@@ -14,3 +14,3 @@ #!/usr/bin/env node | ||
var name = "ask-json"; | ||
var version = "0.1.0"; | ||
var version = "0.1.1"; | ||
@@ -24,4 +24,18 @@ var ensureFile = (filePath) => { | ||
var readJSON = filePath => JSON.parse(fs.readFileSync(filePath)); | ||
class InvalidJSONError extends Error { | ||
constructor(message) { | ||
super(message); | ||
this.name = this.constructor.name; | ||
Error.captureStackTrace(this, this.constructor); | ||
} | ||
} | ||
var readJSON = filePath => { | ||
try { | ||
return JSON.parse(fs.readFileSync(filePath)); | ||
} catch (e) { | ||
throw new InvalidJSONError(e.toString()); | ||
} | ||
}; | ||
var writeJSON = (filePath, data) => fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); | ||
@@ -55,26 +69,28 @@ | ||
.version(); | ||
}, async function(args) { | ||
await runCLI(args); | ||
}) | ||
.argv; | ||
if (!fs.existsSync(argv.schema)) { | ||
console.error(`\n⛔ Unable to read JSON schema file: ${chalk.green(argv.schema)}\n`); | ||
process.exit(1); | ||
} | ||
const runCLI = async(args) => { | ||
if (!fs.existsSync(args.schema)) { | ||
console.error(`\n⛔ Unable to read JSON schema file: ${chalk.green(args.schema)}\n`); | ||
process.exit(1); | ||
} | ||
const SCHEMA = readJSON(argv.schema); | ||
let VALID_DATA; | ||
const SCHEMA = readJSON(args.schema); | ||
let VALID_DATA; | ||
const run = async() => { | ||
if (!argv.file) { | ||
if (!args.file) { | ||
VALID_DATA = await askJSON(SCHEMA, {}); | ||
} else { | ||
ensureFile(argv.file); | ||
const RAW_DATA = readJSON(argv.RAW_DATA); | ||
ensureFile(args.file); | ||
const RAW_DATA = readJSON(args.RAW_DATA); | ||
VALID_DATA = await askJSON(SCHEMA, RAW_DATA); | ||
} | ||
if (argv.output) { | ||
ensureFile(argv.output); | ||
writeJSON(argv.output, VALID_DATA); | ||
} else if (argv.file) { | ||
writeJSON(argv.file, VALID_DATA); | ||
if (args.output) { | ||
ensureFile(args.output); | ||
writeJSON(args.output, VALID_DATA); | ||
} else if (args.file) { | ||
writeJSON(args.file, VALID_DATA); | ||
} else { | ||
@@ -85,3 +101,1 @@ process.stdout.write(JSON.stringify(VALID_DATA, null, 2)); | ||
}; | ||
run(); |
{ | ||
"name": "ask-json", | ||
"description": "Easy interactive prompts to create and validate data using JSON schema", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"author": "Jon McClure <jon.r.mcclure@gmail.com>", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/reuters-graphics/ask-json", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
29179
612
0