Skip to content

Commit 9a01588

Browse files
committed
Fix expand-liquid for JS
1 parent 9386156 commit 9a01588

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

.gitignore

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ node_modules
99
## Extensions
1010
**/.output.graphql
1111
**/input.graphql
12-
**/Cargo.lock
13-
**/Cargo.toml
12+
*/rust/**/Cargo.lock
13+
*/rust/**/Cargo.toml
1414
**/shopify.function.extension.toml
15+
*/javascript/**/package.json
16+
*/javascript/**/src/*
17+
!*/javascript/**/src/*.liquid
1518
!sample-apps/**/input.graphql
16-
!sample-apps/**/Cargo.lock
17-
!sample-apps/**/Cargo.toml
1819
!sample-apps/**/shopify.function.extension.toml
1920

2021
## Sample Apps
2122
sample-apps/*/web/frontend/metafields.js
22-
!sample-apps/discounts/web/frontend/metafields.js
23+
!sample-apps/discounts/web/frontend/metafields.js

util/expand-liquid.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ async function expandLiquidTemplates(template, liquidData) {
1818

1919
for (const entry of entries) {
2020
const engine = new Liquid();
21-
const content = await fs.readFile(entry, "utf8");
2221
const rendered = await engine.renderFile(entry, liquidData);
2322
const outputPath = entry.replace(".liquid", "");
2423
await fs.writeFile(outputPath, rendered);
@@ -59,7 +58,7 @@ async function directoryNames(parentPath) {
5958
.map(dirent => dirent.name);
6059
}
6160

62-
async function expandExtensionLiquidTemplates(domainName) {
61+
async function expandExtensionLiquidTemplates(domainName, flavor) {
6362
console.log(`Expanding liquid templates for ${domainName}`);
6463
const domainPath = path.join(process.cwd(), domainName);
6564

@@ -74,23 +73,46 @@ async function expandExtensionLiquidTemplates(domainName) {
7473

7574
for (const templateName of templateNames) {
7675
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+
7781
const liquidData = {
78-
name: templateName,
82+
name: `${domainName}-${extensionTypeName}-${templateName}`,
83+
flavor,
7984
};
8085

8186
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+
}
82102
}
83103
}
84104
}
85105
console.log();
86106
}
87107

108+
const flavor = process.argv[2] || "vanilla-js";
109+
88110
const SAMPLE_APP_DIR = 'sample-apps';
89111
await expandAppLiquidTemplates(SAMPLE_APP_DIR);
90112

91-
const DOMAINS = ['checkout', 'discounts'];
113+
const DOMAINS = ['checkout', 'discounts', 'order-routing'];
92114
for (const domain of DOMAINS) {
93-
await expandExtensionLiquidTemplates(domain);
115+
await expandExtensionLiquidTemplates(domain, flavor);
94116
}
95117

96118
console.log('The above files should be added to .gitignore if they have not already been added.');

0 commit comments

Comments
 (0)