MCPcopy Index your code
hub / github.com/Shopify/function-examples / expandExtensionLiquidTemplates

Function expandExtensionLiquidTemplates

util/expand-liquid.js:62–108  ·  view source on GitHub ↗
(domainName, flavor)

Source from the content-addressed store, hash-verified

60}
61
62async function expandExtensionLiquidTemplates(domainName, flavor) {
63 console.log(`Expanding liquid templates for ${domainName}`);
64 const domainPath = path.join(process.cwd(), domainName);
65
66 const langNames = await directoryNames(domainPath);
67 for (const langName of langNames) {
68 const langPath = path.join(domainPath, langName);
69 const extensionTypeNames = await directoryNames(langPath);
70
71 for (const extensionTypeName of extensionTypeNames) {
72 const extensionTypePath = path.join(langPath, extensionTypeName);
73 const templateNames = await directoryNames(extensionTypePath);
74
75 for (const templateName of templateNames) {
76 const templatePath = path.join(extensionTypePath, templateName);
77
78 if (langName === "javascript") {
79 await (await glob(path.join(templatePath, 'src', '!(*.liquid|*.graphql)'))).forEach(async (path) => await fs.rm(path));
80 }
81
82 const liquidData = {
83 name: `${domainName}-${extensionTypeName}-${templateName}`,
84 handle: `${domainName}-${extensionTypeName}-${templateName}`,
85 flavor,
86 };
87
88 await expandLiquidTemplates(templatePath, liquidData);
89
90 if (langName === "javascript") {
91 const srcFilePaths = await glob(path.join(templatePath, 'src', '!(*.liquid|*.graphql)'))
92 const srcFileExtensionsToChange = []
93
94 const fileExtension = flavor === "typescript" ? "ts" : "js";
95
96 for (const srcFilePath of srcFilePaths) {
97 srcFileExtensionsToChange.push(fs.rename(srcFilePath, `${srcFilePath}.${fileExtension}`, (err) => {
98 if (err) throw err;
99 }));
100 }
101
102 await Promise.all(srcFileExtensionsToChange)
103 }
104 }
105 }
106 }
107 console.log();
108}
109
110function ensureNoGitChanges() {
111 exec('git status --porcelain', (error, stdout, _stderr) => {

Callers 1

expand-liquid.jsFile · 0.85

Calls 2

directoryNamesFunction · 0.85
expandLiquidTemplatesFunction · 0.85

Tested by

no test coverage detected