@@ -18,7 +18,6 @@ async function expandLiquidTemplates(template, liquidData) {
18
18
19
19
for ( const entry of entries ) {
20
20
const engine = new Liquid ( ) ;
21
- const content = await fs . readFile ( entry , "utf8" ) ;
22
21
const rendered = await engine . renderFile ( entry , liquidData ) ;
23
22
const outputPath = entry . replace ( ".liquid" , "" ) ;
24
23
await fs . writeFile ( outputPath , rendered ) ;
@@ -59,7 +58,7 @@ async function directoryNames(parentPath) {
59
58
. map ( dirent => dirent . name ) ;
60
59
}
61
60
62
- async function expandExtensionLiquidTemplates ( domainName ) {
61
+ async function expandExtensionLiquidTemplates ( domainName , flavor ) {
63
62
console . log ( `Expanding liquid templates for ${ domainName } ` ) ;
64
63
const domainPath = path . join ( process . cwd ( ) , domainName ) ;
65
64
@@ -74,23 +73,46 @@ async function expandExtensionLiquidTemplates(domainName) {
74
73
75
74
for ( const templateName of templateNames ) {
76
75
const templatePath = path . join ( extensionTypePath , templateName ) ;
76
+
77
+ if ( langName === "javascript" ) {
78
+ await ( await glob ( path . join ( templatePath , 'src' , '!(*.liquid)' ) ) ) . forEach ( async ( path ) => await fs . rm ( path ) ) ;
79
+ }
80
+
77
81
const liquidData = {
78
- name : templateName ,
82
+ name : `${ domainName } -${ extensionTypeName } -${ templateName } ` ,
83
+ flavor,
79
84
} ;
80
85
81
86
await expandLiquidTemplates ( templatePath , liquidData ) ;
87
+
88
+ if ( langName === "javascript" ) {
89
+ const srcFilePaths = await glob ( path . join ( templatePath , 'src' , '!(*.liquid)' ) )
90
+ const srcFileExtensionsToChange = [ ]
91
+
92
+ const fileExtension = flavor === "typescript" ? "ts" : "js" ;
93
+
94
+ for ( const srcFilePath of srcFilePaths ) {
95
+ srcFileExtensionsToChange . push ( fs . rename ( srcFilePath , `${ srcFilePath } .${ fileExtension } ` , ( err ) => {
96
+ if ( err ) throw err ;
97
+ } ) ) ;
98
+ }
99
+
100
+ await Promise . all ( srcFileExtensionsToChange )
101
+ }
82
102
}
83
103
}
84
104
}
85
105
console . log ( ) ;
86
106
}
87
107
108
+ const flavor = process . argv [ 2 ] || "vanilla-js" ;
109
+
88
110
const SAMPLE_APP_DIR = 'sample-apps' ;
89
111
await expandAppLiquidTemplates ( SAMPLE_APP_DIR ) ;
90
112
91
- const DOMAINS = [ 'checkout' , 'discounts' ] ;
113
+ const DOMAINS = [ 'checkout' , 'discounts' , 'order-routing' ] ;
92
114
for ( const domain of DOMAINS ) {
93
- await expandExtensionLiquidTemplates ( domain ) ;
115
+ await expandExtensionLiquidTemplates ( domain , flavor ) ;
94
116
}
95
117
96
118
console . log ( 'The above files should be added to .gitignore if they have not already been added.' ) ;
0 commit comments