@@ -3,6 +3,7 @@ import { exec } from 'child_process';
33import path from 'path' ;
44import util from 'util' ;
55import { existsSync } from 'fs' ;
6+ import toml from '@iarna/toml' ;
67
78const execPromise = util . promisify ( exec ) ;
89const APP_TOML_FILE = 'shopify.app.toml' ;
@@ -16,56 +17,30 @@ async function getConfig() {
1617 }
1718
1819 const content = await fs . readFile ( APP_TOML_FILE , 'utf8' ) ;
19- const lines = content . split ( '\n' ) ;
20+
21+ // Parse the TOML content
22+ const parsedToml = toml . parse ( content ) ;
2023
2124 const config = {
2225 clientId : '' ,
2326 directories : [ ]
2427 } ;
25-
26- let inExtensionDirectories = false ;
27- const dirRegex = / ' ( [ ^ ' ] + ) ' / g;
28- const quoteRegex = / " ( [ ^ " ] + ) " / g;
29-
30- for ( const line of lines ) {
31- const trimmedLine = line . trim ( ) ;
32-
33- // Extract client_id
34- if ( trimmedLine . startsWith ( 'client_id' ) ) {
35- const match = line . match ( quoteRegex ) ;
36- if ( match ) {
37- config . clientId = match [ 0 ] . replace ( / " / g, '' ) ;
38- }
39- continue ;
40- }
41-
42- // Check if we're entering the extension_directories section
43- if ( trimmedLine . startsWith ( 'extension_directories' ) ) {
44- inExtensionDirectories = true ;
45- continue ;
46- }
47-
48- // Check if we're leaving the extension_directories section
49- if ( inExtensionDirectories && trimmedLine . startsWith ( ']' ) ) {
50- inExtensionDirectories = false ;
51- continue ;
52- }
53-
54- // Extract directories only when in extension_directories section
55- if ( inExtensionDirectories ) {
56- // Try to match with both single and double quotes
57- let match = trimmedLine . match ( dirRegex ) ;
58- if ( ! match ) {
59- match = trimmedLine . match ( quoteRegex ) ;
60- }
61-
62- if ( match ) {
63- const cleanDir = match [ 0 ] . replace ( / [ ' " ] / g, '' ) . trim ( ) ;
64- if ( cleanDir && existsSync ( cleanDir ) ) {
65- config . directories . push ( cleanDir ) ;
66- }
28+
29+ // Extract client_id if it exists
30+ if ( parsedToml . client_id ) {
31+ config . clientId = parsedToml . client_id ;
32+ }
33+
34+ // Extract extension directories if they exist
35+ if ( parsedToml . extension_directories && Array . isArray ( parsedToml . extension_directories ) ) {
36+ // Filter the directories to ensure they exist
37+ config . directories = parsedToml . extension_directories . filter ( dir => {
38+ const exists = existsSync ( dir ) ;
39+ if ( ! exists ) {
40+ console . warn ( `Directory specified in config does not exist: ${ dir } ` ) ;
6741 }
68- }
42+ return exists ;
43+ } ) ;
6944 }
7045
7146 return config ;
0 commit comments