1
+ import { existsSync } from 'node:fs'
1
2
import { red } from '#lib/chalk'
2
3
import { readJsonFile } from '#lib/json'
3
- import { isFilePathSync , isJsonString , getAbsoluteFilePath , validateTemplateCommand } from '#lib/utils'
4
+ import { isJsonString , getAbsoluteFileUrl , validateTemplateCommand } from '#lib/utils'
4
5
import { parseGuid } from './parse_command_utils.js'
5
6
import program from './program.js'
6
7
import validateFunctionArgs from './validate_function_args.js'
@@ -20,22 +21,22 @@ const getData = args => {
20
21
return JSON . parse ( arg )
21
22
}
22
23
23
- const filepath = getAbsoluteFilePath ( arg )
24
+ const fileUrl = getAbsoluteFileUrl ( arg )
24
25
25
- if ( ! isFilePathSync ( filepath ) ) {
26
+ if ( ! existsSync ( fileUrl ) ) {
26
27
console . error ( red ( 'the argument should be a valid JSON or a JSON file path or a JS function file path' ) )
27
28
console . error ( "- it doesn't look like inline JSON" )
28
- console . error ( `couldn't parse arguments: ${ filepath } is not the path to an existing file` )
29
+ console . error ( `couldn't parse arguments: ${ fileUrl } is not the path to an existing file` )
29
30
process . exit ( 1 )
30
31
}
31
32
32
33
try {
33
34
// Try to parse it as a JSON file
34
- return readJsonFile ( filepath )
35
+ return readJsonFile ( fileUrl )
35
36
} catch ( err1 ) {
36
37
// Try to parse it as a JS module
37
38
try {
38
- return getDataFromJsModule ( filepath , args )
39
+ return getDataFromJsModule ( fileUrl , args )
39
40
} catch ( err2 ) {
40
41
if ( err2 === 'SyntaxError' ) {
41
42
console . error ( red ( 'the argument should be a valid JSON or a JSON file path or a JS function file path' ) )
@@ -50,8 +51,8 @@ const getData = args => {
50
51
}
51
52
}
52
53
53
- async function getDataFromJsModule ( filepath , args ) {
54
- const { default : jsModule } = await import ( filepath )
54
+ async function getDataFromJsModule ( fileUrl , args ) {
55
+ const { default : jsModule } = await import ( fileUrl )
55
56
if ( typeof jsModule === 'function' ) {
56
57
const inputArgs = args . slice ( 1 )
57
58
validateFunctionArgs ( jsModule , inputArgs , jsModule )
0 commit comments