Skip to content

Commit 1c182c4

Browse files
committedJan 8, 2021
feat(core): Format code to publish a new version automatic
1 parent 6a931b2 commit 1c182c4

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed
 

‎src/command.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import * as Joi from '@hapi/joi'
22
import path from 'path'
3-
import { parseOptions, optionsSchema, preSpawnSchema, spawnSchema } from './options'
3+
import {
4+
parseOptions,
5+
optionsSchema,
6+
preSpawnSchema,
7+
spawnSchema
8+
} from './options'
49

510
const JQ_PATH = process.env.JQ_PATH || path.join(__dirname, '..', 'bin', 'jq')
611

@@ -11,7 +16,8 @@ export const INPUT_JSON_UNDEFINED_ERROR =
1116
export const INPUT_STRING_ERROR =
1217
'node-jq: invalid json string argument supplied'
1318

14-
const NODE_JQ_ERROR_TEMPLATE = 'node-jq: invalid {#label} ' +
19+
const NODE_JQ_ERROR_TEMPLATE =
20+
'node-jq: invalid {#label} ' +
1521
'argument supplied{if(#label == "path" && #type == "json", " (not a .json file)", "")}' +
1622
'{if(#label == "path" && #type == "path", " (not a valid path)", "")}: ' +
1723
'"{if(#value != undefined, #value, "undefined")}"'
@@ -26,9 +32,21 @@ const messages = {
2632
const validateArguments = (filter, json, options) => {
2733
const context = { filter, json }
2834
const validatedOptions = Joi.attempt(options, optionsSchema)
29-
const validatedPreSpawn = Joi.attempt(context, preSpawnSchema.tailor(validatedOptions.input), { messages })
30-
const validatedArgs = parseOptions(validatedOptions, validatedPreSpawn.filter, validatedPreSpawn.json)
31-
const validatedSpawn = Joi.attempt({}, spawnSchema.tailor(validatedOptions.input), { context: { ...validatedPreSpawn, options: validatedOptions } })
35+
const validatedPreSpawn = Joi.attempt(
36+
context,
37+
preSpawnSchema.tailor(validatedOptions.input),
38+
{ messages }
39+
)
40+
const validatedArgs = parseOptions(
41+
validatedOptions,
42+
validatedPreSpawn.filter,
43+
validatedPreSpawn.json
44+
)
45+
const validatedSpawn = Joi.attempt(
46+
{},
47+
spawnSchema.tailor(validatedOptions.input),
48+
{ context: { ...validatedPreSpawn, options: validatedOptions } }
49+
)
3250

3351
if (validatedOptions.input === 'file') {
3452
return {

‎src/jq.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ import { commandFactory } from './command'
33

44
export const run = (filter, json, options = {}, jqPath, cwd) => {
55
return new Promise((resolve, reject) => {
6-
const { command, args, stdin } = commandFactory(filter, json, options, jqPath)
6+
const { command, args, stdin } = commandFactory(
7+
filter,
8+
json,
9+
options,
10+
jqPath
11+
)
12+
713
exec(command, args, stdin, cwd)
8-
.then(stdout => {
14+
.then((stdout) => {
915
if (options.output === 'json') {
1016
let result
1117
try {

‎src/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ export const INVALID_PATH_ERROR =
55
export const INVALID_JSON_PATH_ERROR =
66
'node-jq: invalid path argument supplied (not a .json file)'
77

8-
export const isJSONPath = path => {
8+
export const isJSONPath = (path) => {
99
return /\.json$/.test(path)
1010
}
1111

12-
export const validateJSONPath = path => {
12+
export const validateJSONPath = (path) => {
1313
if (!isPathValid(path)) {
1414
throw new Error(`${INVALID_PATH_ERROR}: "${path}"`)
1515
}

0 commit comments

Comments
 (0)
Please sign in to comment.