99 processUpgradeCommand ,
1010} from './src/commands.js'
1111import { getDirectories } from './src/utilities.js'
12- import { readFileSync } from 'fs'
12+ import { readFileSync , existsSync } from 'fs'
1313import path from 'path'
1414import { fileURLToPath } from 'url'
1515
@@ -34,13 +34,25 @@ const configDefaults = {
3434 */
3535function loadConfig ( ) {
3636 const filePath = path . resolve ( process . cwd ( ) , '.create-frontend-component' , 'config.json' )
37- const configFromFile = JSON . parse (
38- readFileSync ( filePath , 'utf8' ) . replace ( / ^ \ufeff / u, '' )
39- )
4037
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 )
4456 }
4557}
4658
@@ -57,6 +69,13 @@ program
5769 return
5870 }
5971
72+ if ( componentName . toLowerCase ( ) . startsWith ( 'init:' ) ) {
73+ const nameParts = componentName . toLowerCase ( ) . split ( ':' )
74+ const presetArgument = nameParts [ 1 ]
75+ await processInitCommand ( PRESET_PATH , CONFIG_DIRECTORY , CONFIG_FILE_NAME , configDefaults , presetArgument )
76+ return
77+ }
78+
6079 const { types, templatePath, componentPath, nameStyle } = loadConfig ( )
6180 const allowedComponentTypes = types || [ ]
6281 const fullTemplatePath = path . join ( process . cwd ( ) , templatePath )
0 commit comments