@konkonam/nuxt-shopify
Version:
Easily integrate shopify with nuxt 3 and 4 🚀
45 lines (43 loc) • 1.36 kB
JavaScript
import { access, readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { defineCommand, runMain } from 'citty';
import log from 'consola';
import { downloadTemplate } from 'giget';
const command = defineCommand({
meta: {
name: "init",
description: "Create a new Nuxt Shopify template project"
},
args: {
directory: {
type: "positional",
description: "Directory to initialize the project template into.",
required: true
}
},
run: async ({ args }) => {
const template = await downloadTemplate("gh:konkonam/nuxt-shopify/template", {
dir: args.directory
}).catch((error) => {
log.error("Failed to download template:", error);
});
if (!template) {
log.error("Failed to download template.");
return;
}
const configPath = join(template.dir, "nuxt.config.ts");
if (!await access(configPath).then(() => true).catch(() => false)) {
log.error("Failed to prepare template contents.");
return;
}
const configContent = await readFile(configPath, "utf-8").then((data) => data.replace("../src/module", "@konkonam/nuxt-shopify"));
await writeFile(
configPath,
configContent,
"utf-8"
);
log.success(`Nuxt Shopify Template initialized in ${template.dir}`);
}
});
runMain(command);