From cd9db9d8f9c9bec82e2634f5c86d74d084b31397 Mon Sep 17 00:00:00 2001 From: Valentin Dosimont Date: Mon, 25 Nov 2024 16:55:14 +0100 Subject: [PATCH] fix: create-dojo + update manifest path --- .../example-vite-kitchen-sink/dojoConfig.ts | 2 +- .../example-vite-kitchen-sink/src/main.tsx | 2 +- packages/create-dojo/src/commands/start.ts | 51 ++++++++++++------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/examples/example-vite-kitchen-sink/dojoConfig.ts b/examples/example-vite-kitchen-sink/dojoConfig.ts index e45ee85a..438105f6 100644 --- a/examples/example-vite-kitchen-sink/dojoConfig.ts +++ b/examples/example-vite-kitchen-sink/dojoConfig.ts @@ -1,6 +1,6 @@ import { createDojoConfig } from "@dojoengine/core"; -import manifest from "../../worlds/dojo-starter/manifest_dev.json"; +import manifest from "../../worlds/onchain-dash/manifests/release/deployment/manifest.json"; export const dojoConfig = createDojoConfig({ manifest, diff --git a/examples/example-vite-kitchen-sink/src/main.tsx b/examples/example-vite-kitchen-sink/src/main.tsx index 044f78ff..391ce603 100644 --- a/examples/example-vite-kitchen-sink/src/main.tsx +++ b/examples/example-vite-kitchen-sink/src/main.tsx @@ -9,7 +9,7 @@ import "./app/globals.css"; import { init } from "@dojoengine/sdk"; import { OnchainDashSchemaType, schema } from "@/dojo/models"; import { env, getRpcUrl } from "@/env"; -import { dojoConfig } from "@/dojo.config"; +import { dojoConfig } from "../dojoConfig"; import { DojoContext } from "@/dojo/provider"; async function main() { diff --git a/packages/create-dojo/src/commands/start.ts b/packages/create-dojo/src/commands/start.ts index 20febc0e..93f7f16e 100644 --- a/packages/create-dojo/src/commands/start.ts +++ b/packages/create-dojo/src/commands/start.ts @@ -44,12 +44,12 @@ const templates = [ async function init(projectName: string, cwd: string, template: string) { const projectPath = path.join(cwd, projectName); const clientPath = path.join(projectPath, "client"); - const dojoStarterPath = path.join(projectPath, "dojo-starter"); + const contractPath = path.join(projectPath, "contract"); // Create project directories await fs.mkdir(projectPath, { recursive: true }); await fs.mkdir(clientPath, { recursive: true }); - await fs.mkdir(dojoStarterPath, { recursive: true }); + await fs.mkdir(contractPath, { recursive: true }); // Clone template into client directory console.log(`Downloading ${template} into client directory...`); @@ -66,26 +66,21 @@ async function init(projectName: string, cwd: string, template: string) { // Rewrite package.json in client directory await rewritePackageJson(projectName, clientPath); - console.log(`Cloning dojo-starter repository...`); - const gitCloneResult = spawn.sync( - "git", - [ - "clone", - "https://github.com/dojoengine/dojo-starter.git", - dojoStarterPath, - ], - { stdio: "inherit" } - ); - - if (gitCloneResult.status !== 0) { - throw new Error(`Failed to clone dojo-starter repository.`); - } + // Update dojoConfig.ts imports + await rewriteDojoConfigFile(clientPath); // Clone dojo-starter console.log(`Downloading dojo-starter...`); - spawn.sync("npx", ["degit", `dojoengine/dojo-starter`, dojoStarterPath], { - stdio: "inherit", - }); + const contractRes = spawn.sync( + "npx", + ["degit", `dojoengine/dojo-starter`, contractPath], + { + stdio: "inherit", + } + ); + if (contractRes.status !== 0) { + throw new Error(`Failed to clone template: ${template}`); + } console.log(`Project initialized at ${projectPath}`); console.log("Congrats! Your new project has been set up successfully.\n"); @@ -116,6 +111,24 @@ async function rewritePackageJson(projectName: string, clientPath: string) { await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2)); } +async function rewriteDojoConfigFile(clientPath: string) { + const dojoConfigPath = path.join(clientPath, "dojoConfig.ts"); + + try { + let content = await fs.readFile(dojoConfigPath, "utf-8"); + + // Update relative imports to account for new directory structure + content = content.replace( + /from ['"]\.{0,2}\/.*manifest(?:_dev)?\.json['"]/g, + 'from "../contract/target/dev/manifest.json"' + ); + + await fs.writeFile(dojoConfigPath, content, "utf-8"); + } catch (error) { + console.warn(`Warning: Could not update dojoConfig.ts: ${error}`); + } +} + async function getLatestVersion(): Promise { return new Promise((resolve, reject) => { https