File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change 9
9
processUpgradeCommand ,
10
10
} from './src/commands.js'
11
11
import { getDirectories } from './src/utilities.js'
12
- import { readFileSync } from 'fs'
12
+ import { readFileSync , existsSync } from 'fs'
13
13
import path from 'path'
14
14
import { fileURLToPath } from 'url'
15
15
@@ -34,13 +34,25 @@ const configDefaults = {
34
34
*/
35
35
function loadConfig ( ) {
36
36
const filePath = path . resolve ( process . cwd ( ) , '.create-frontend-component' , 'config.json' )
37
- const configFromFile = JSON . parse (
38
- readFileSync ( filePath , 'utf8' ) . replace ( / ^ \ufeff / u, '' )
39
- )
40
37
41
- return {
42
- ...configDefaults ,
43
- ...configFromFile
38
+ try {
39
+ if ( ! existsSync ( filePath ) ) {
40
+ console . error ( `Error: Configuration file not found at ${ filePath } .` )
41
+ console . error ( 'Run "npx create-frontend-component init" to generate the configuration file.' )
42
+ process . exit ( 1 )
43
+ }
44
+
45
+ const fileContent = readFileSync ( filePath , 'utf8' ) . replace ( / ^ \ufeff / u, '' )
46
+ const configFromFile = JSON . parse ( fileContent )
47
+
48
+ return {
49
+ ...configDefaults ,
50
+ ...configFromFile
51
+ }
52
+ } catch ( error ) {
53
+ console . error ( `Error loading configuration file: ${ error . message } ` )
54
+ console . error ( 'Try running "npx create-frontend-component init" to reset the configuration.' )
55
+ process . exit ( 1 )
44
56
}
45
57
}
46
58
You can’t perform that action at this time.
0 commit comments