@coinbase/create-cdp-app 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +31 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/template-nextjs/src/components/ClientApp.tsx +2 -2
- package/template-nextjs/src/components/Header.tsx +1 -1
- package/template-nextjs/src/components/SignedInScreen.tsx +2 -2
- package/template-nextjs/src/components/Transaction.tsx +1 -1
- package/template-react/src/App.tsx +2 -2
- package/template-react/src/Header.tsx +1 -1
- package/template-react/src/SignedInScreen.tsx +2 -2
- package/template-react/src/Transaction.tsx +1 -1
package/dist/index.js
CHANGED
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { reset,
|
|
5
|
+
import { reset, green, red } from "kolorist";
|
|
6
6
|
import prompts from "prompts";
|
|
7
|
-
function
|
|
7
|
+
function prepareAppDirectory(targetDir, shouldOverwrite) {
|
|
8
8
|
const root = path.join(process.cwd(), targetDir);
|
|
9
9
|
if (!fs.existsSync(root)) {
|
|
10
10
|
fs.mkdirSync(root, { recursive: true });
|
|
11
11
|
}
|
|
12
12
|
return root;
|
|
13
13
|
}
|
|
14
|
-
function customizePackageJson(templateDir,
|
|
14
|
+
function customizePackageJson(templateDir, appName) {
|
|
15
15
|
const packageJsonPath = path.join(templateDir, "package.json");
|
|
16
16
|
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
|
|
17
|
-
packageJson.name =
|
|
17
|
+
packageJson.name = appName;
|
|
18
18
|
return JSON.stringify(packageJson, null, 2) + "\n";
|
|
19
19
|
}
|
|
20
20
|
function customizeEnv(templateDir, projectId) {
|
|
@@ -56,12 +56,12 @@ function detectPackageManager() {
|
|
|
56
56
|
const TEMPLATES = [
|
|
57
57
|
{
|
|
58
58
|
name: "react",
|
|
59
|
-
display: "React",
|
|
60
|
-
color:
|
|
59
|
+
display: "React Single Page App",
|
|
60
|
+
color: green
|
|
61
61
|
},
|
|
62
62
|
{
|
|
63
63
|
name: "nextjs",
|
|
64
|
-
display: "Next.js",
|
|
64
|
+
display: "Next.js Full Stack App",
|
|
65
65
|
color: green
|
|
66
66
|
}
|
|
67
67
|
];
|
|
@@ -71,33 +71,33 @@ const fileRenames = {
|
|
|
71
71
|
};
|
|
72
72
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
73
73
|
async function init() {
|
|
74
|
-
const {
|
|
74
|
+
const { appName, template, targetDirectory, projectId } = await getAppDetails();
|
|
75
75
|
console.log(`
|
|
76
|
-
Scaffolding
|
|
77
|
-
const root =
|
|
76
|
+
Scaffolding app in ${targetDirectory}...`);
|
|
77
|
+
const root = prepareAppDirectory(targetDirectory);
|
|
78
78
|
const templateDir = path.resolve(fileURLToPath(import.meta.url), "../..", `template-${template}`);
|
|
79
|
-
copyTemplateFiles(templateDir, root,
|
|
79
|
+
copyTemplateFiles(templateDir, root, appName, projectId);
|
|
80
80
|
printNextSteps(root);
|
|
81
81
|
}
|
|
82
|
-
async function
|
|
82
|
+
async function getAppDetails() {
|
|
83
83
|
let targetDir = process.argv[2];
|
|
84
|
-
const
|
|
84
|
+
const defaultAppName = targetDir ?? defaultTargetDir;
|
|
85
85
|
try {
|
|
86
86
|
const result = await prompts(
|
|
87
87
|
[
|
|
88
88
|
{
|
|
89
89
|
type: targetDir ? null : "text",
|
|
90
|
-
name: "
|
|
91
|
-
message: reset("
|
|
92
|
-
initial:
|
|
90
|
+
name: "appName",
|
|
91
|
+
message: reset("App Name:"),
|
|
92
|
+
initial: defaultAppName,
|
|
93
93
|
onState: (state) => {
|
|
94
|
-
targetDir = String(state.value).trim() ||
|
|
94
|
+
targetDir = String(state.value).trim() || defaultAppName;
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
{
|
|
98
98
|
type: "select",
|
|
99
99
|
name: "template",
|
|
100
|
-
message: reset("
|
|
100
|
+
message: reset("Template:"),
|
|
101
101
|
initial: 0,
|
|
102
102
|
choices: TEMPLATES.map((template) => ({
|
|
103
103
|
title: template.color(template.display || template.name),
|
|
@@ -111,26 +111,22 @@ async function getProjectDetails() {
|
|
|
111
111
|
"CDP Project ID (Find your project ID at https://portal.cdp.coinbase.com/projects/overview):"
|
|
112
112
|
),
|
|
113
113
|
validate: (value) => {
|
|
114
|
-
if (!value
|
|
114
|
+
if (!value) {
|
|
115
115
|
return "Project ID is required";
|
|
116
|
+
} else if (!uuidRegex.test(value)) {
|
|
117
|
+
return "Project ID must be a valid UUID";
|
|
116
118
|
}
|
|
117
119
|
return true;
|
|
118
120
|
},
|
|
119
121
|
initial: ""
|
|
120
122
|
},
|
|
121
123
|
{
|
|
122
|
-
type: "
|
|
124
|
+
type: "confirm",
|
|
123
125
|
name: "corsConfirmation",
|
|
124
126
|
message: reset(
|
|
125
|
-
"Confirm you have whitelisted 'http://localhost:3000' at https://portal.cdp.coinbase.com/products/embedded-wallets/
|
|
127
|
+
"Confirm you have whitelisted 'http://localhost:3000' at https://portal.cdp.coinbase.com/products/embedded-wallets/domains:"
|
|
126
128
|
),
|
|
127
|
-
|
|
128
|
-
if (value !== "y") {
|
|
129
|
-
return "You must whitelist your app domain for your app to be functional.";
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
},
|
|
133
|
-
initial: ""
|
|
129
|
+
initial: true
|
|
134
130
|
},
|
|
135
131
|
{
|
|
136
132
|
type: () => !fs.existsSync(targetDir) || isDirEmpty(targetDir) ? null : "confirm",
|
|
@@ -154,7 +150,7 @@ async function getProjectDetails() {
|
|
|
154
150
|
}
|
|
155
151
|
);
|
|
156
152
|
return {
|
|
157
|
-
|
|
153
|
+
appName: result.appName,
|
|
158
154
|
template: result.template,
|
|
159
155
|
targetDirectory: targetDir,
|
|
160
156
|
projectId: result.projectId
|
|
@@ -166,17 +162,17 @@ async function getProjectDetails() {
|
|
|
166
162
|
process.exit(0);
|
|
167
163
|
}
|
|
168
164
|
}
|
|
169
|
-
function printNextSteps(
|
|
165
|
+
function printNextSteps(appRoot) {
|
|
170
166
|
const packageManager = detectPackageManager();
|
|
171
167
|
console.log(green("\nDone. Now run your app:\n"));
|
|
172
|
-
if (
|
|
173
|
-
console.log(`cd ${path.relative(process.cwd(),
|
|
168
|
+
if (appRoot !== process.cwd()) {
|
|
169
|
+
console.log(`cd ${path.relative(process.cwd(), appRoot)}`);
|
|
174
170
|
}
|
|
175
171
|
const devCommand = packageManager === "npm" ? "npm run dev" : `${packageManager} dev`;
|
|
176
172
|
console.log(`${packageManager} install`);
|
|
177
173
|
console.log(devCommand);
|
|
178
174
|
}
|
|
179
|
-
function copyTemplateFiles(templateDir, root,
|
|
175
|
+
function copyTemplateFiles(templateDir, root, appName, projectId) {
|
|
180
176
|
const writeFileToTarget = (file, content) => {
|
|
181
177
|
const targetPath = path.join(root, fileRenames[file] ?? file);
|
|
182
178
|
if (content) {
|
|
@@ -188,12 +184,12 @@ function copyTemplateFiles(templateDir, root, projectName, projectId) {
|
|
|
188
184
|
const files = fs.readdirSync(templateDir);
|
|
189
185
|
for (const file of files) {
|
|
190
186
|
if (file === "package.json") {
|
|
191
|
-
const customizedPackageJson = customizePackageJson(templateDir,
|
|
187
|
+
const customizedPackageJson = customizePackageJson(templateDir, appName);
|
|
192
188
|
writeFileToTarget(file, customizedPackageJson);
|
|
193
189
|
} else if (file === "env.example" && projectId) {
|
|
194
190
|
const customizedEnv = customizeEnv(templateDir, projectId);
|
|
195
191
|
writeFileToTarget(file);
|
|
196
|
-
console.log("Copying
|
|
192
|
+
console.log("Copying CDP Project ID to .env");
|
|
197
193
|
writeFileToTarget(".env", customizedEnv);
|
|
198
194
|
} else {
|
|
199
195
|
writeFileToTarget(file);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Prepare the project directory\n *\n * @param targetDir - The target directory for the project\n * @param shouldOverwrite - Whether to overwrite the existing directory\n * @returns The path to the prepared project directory\n */\nexport function prepareProjectDirectory(targetDir: string, shouldOverwrite: boolean): string {\n const root = path.join(process.cwd(), targetDir);\n\n if (shouldOverwrite) {\n emptyDir(root);\n } else if (!fs.existsSync(root)) {\n fs.mkdirSync(root, { recursive: true });\n }\n\n return root;\n}\n\n/**\n * Customize package.json for the new project\n *\n * @param templateDir - The directory containing the template files\n * @param projectName - The name of the project\n * @returns The customized package.json content\n */\nexport function customizePackageJson(templateDir: string, projectName: string): string {\n const packageJsonPath = path.join(templateDir, \"package.json\");\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf-8\"));\n packageJson.name = projectName;\n return JSON.stringify(packageJson, null, 2) + \"\\n\";\n}\n\n/**\n * Set up the .env file for the new project\n *\n * @param templateDir - The directory containing the template files\n * @param projectId - The project ID\n * @returns The customized .env content\n */\nexport function customizeEnv(templateDir: string, projectId: string): string {\n const exampleEnvPath = path.join(templateDir, \"env.example\");\n const exampleEnv = fs.readFileSync(exampleEnvPath, \"utf-8\");\n // Replace the project ID in the env file\n const envContent = exampleEnv.replace(/(.*PROJECT_ID=).*(\\r?\\n|$)/, `$1${projectId}\\n`);\n return envContent;\n}\n\n/**\n * Copy a file or directory recursively\n *\n * @param filePath - The source path\n * @param destPath - The destination path\n */\nexport function copyFile(filePath: string, destPath: string): void {\n const stat = fs.statSync(filePath);\n if (stat.isDirectory()) {\n copyDir(filePath, destPath);\n } else {\n fs.copyFileSync(filePath, destPath);\n }\n}\n\n/**\n * Copy a directory recursively\n *\n * @param srcDir - The source directory path\n * @param destDir - The destination directory path\n */\nfunction copyDir(srcDir: string, destDir: string): void {\n fs.mkdirSync(destDir, { recursive: true });\n for (const file of fs.readdirSync(srcDir)) {\n const srcFile = path.resolve(srcDir, file);\n const destFile = path.resolve(destDir, file);\n copyFile(srcFile, destFile);\n }\n}\n\n/**\n * Check if a directory is empty\n *\n * @param dirPath - The path to the directory\n * @returns True if the directory is empty, false otherwise\n */\nexport function isDirEmpty(dirPath: string): boolean {\n const files = fs.readdirSync(dirPath);\n return files.length === 0 || (files.length === 1 && files[0] === \".git\");\n}\n\n/**\n * Empty a directory while preserving .git\n *\n * @param dirPath - The path to the directory\n */\nfunction emptyDir(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n return;\n }\n for (const file of fs.readdirSync(dirPath)) {\n if (file === \".git\") {\n continue;\n }\n fs.rmSync(path.resolve(dirPath, file), { recursive: true, force: true });\n }\n}\n\n/**\n * Detect which package manager invoked the create command\n *\n * @returns The detected package manager or 'pnpm' as default\n */\nexport function detectPackageManager(): \"npm\" | \"pnpm\" | \"yarn\" {\n const userAgent = process.env.npm_config_user_agent;\n\n if (userAgent) {\n if (userAgent.startsWith(\"yarn\")) return \"yarn\";\n if (userAgent.startsWith(\"pnpm\")) return \"pnpm\";\n if (userAgent.startsWith(\"npm\")) return \"npm\";\n }\n\n return \"npm\"; // Default to npm if we can't detect\n}\n","#!/usr/bin/env node\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { blue, red, green, reset } from \"kolorist\";\nimport prompts from \"prompts\";\n\nimport {\n prepareProjectDirectory,\n isDirEmpty,\n customizePackageJson,\n copyFile,\n customizeEnv,\n detectPackageManager,\n} from \"./utils.js\";\n\n// Available templates for project creation\nconst TEMPLATES = [\n {\n name: \"react\",\n display: \"React\",\n color: blue,\n },\n {\n name: \"nextjs\",\n display: \"Next.js\",\n color: green,\n },\n];\n\nconst defaultTargetDir = \"cdp-app\";\n\nconst fileRenames: Record<string, string | undefined> = {\n _gitignore: \".gitignore\",\n};\n\ninterface ProjectOptions {\n projectName: string;\n template: string;\n targetDirectory: string;\n projectId: string;\n}\n\nconst uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/**\n * Initialize a new CDP app project\n */\nasync function init(): Promise<void> {\n const { projectName, template, targetDirectory, projectId } = await getProjectDetails();\n\n console.log(`\\nScaffolding project in ${targetDirectory}...`);\n\n const root = prepareProjectDirectory(targetDirectory, false);\n const templateDir = path.resolve(fileURLToPath(import.meta.url), \"../..\", `template-${template}`);\n\n copyTemplateFiles(templateDir, root, projectName, projectId);\n printNextSteps(root);\n}\n\n/**\n * Get project details from command line arguments or prompt the user\n *\n * @returns The project details\n */\nasync function getProjectDetails(): Promise<ProjectOptions> {\n // Get target directory from command line args (first non-option argument)\n let targetDir = process.argv[2];\n const defaultProjectName = targetDir ?? defaultTargetDir;\n\n try {\n const result = await prompts(\n [\n {\n type: targetDir ? null : \"text\",\n name: \"projectName\",\n message: reset(\"Project name:\"),\n initial: defaultProjectName,\n onState: state => {\n targetDir = String(state.value).trim() || defaultProjectName;\n },\n },\n {\n type: \"select\",\n name: \"template\",\n message: reset(\"Select a template:\"),\n initial: 0,\n choices: TEMPLATES.map(template => ({\n title: template.color(template.display || template.name),\n value: template.name,\n })),\n },\n {\n type: \"text\",\n name: \"projectId\",\n message: reset(\n \"CDP Project ID (Find your project ID at https://portal.cdp.coinbase.com/projects/overview):\",\n ),\n validate: value => {\n if (!value || !uuidRegex.test(value)) {\n return \"Project ID is required\";\n }\n return true;\n },\n initial: \"\",\n },\n {\n type: \"text\",\n name: \"corsConfirmation\",\n message: reset(\n \"Confirm you have whitelisted 'http://localhost:3000' at https://portal.cdp.coinbase.com/products/embedded-wallets/cors by typing 'y'\",\n ),\n validate: value => {\n if (value !== \"y\") {\n return \"You must whitelist your app domain for your app to be functional.\";\n }\n return true;\n },\n initial: \"\",\n },\n {\n type: () => (!fs.existsSync(targetDir) || isDirEmpty(targetDir) ? null : \"confirm\"),\n name: \"overwrite\",\n message: () =>\n (targetDir === \".\" ? \"Current directory\" : `Target directory \"${targetDir}\"`) +\n \" is not empty. Remove existing files and continue?\",\n },\n {\n type: (_, { overwrite }: { overwrite?: boolean }) => {\n if (overwrite === false) {\n throw new Error(red(\"✖\") + \" Operation cancelled\");\n }\n return null;\n },\n name: \"overwriteChecker\",\n },\n ],\n {\n onCancel: () => {\n throw new Error(red(\"✖\") + \" Operation cancelled\");\n },\n },\n );\n\n return {\n projectName: result.projectName,\n template: result.template,\n targetDirectory: targetDir,\n projectId: result.projectId,\n };\n } catch (cancelled: unknown) {\n if (cancelled instanceof Error) {\n console.log(cancelled.message);\n }\n process.exit(0);\n }\n}\n\n/**\n * Print next steps for the user\n *\n * @param projectRoot - The root directory of the project\n */\nfunction printNextSteps(projectRoot: string): void {\n const packageManager = detectPackageManager();\n\n console.log(green(\"\\nDone. Now run your app:\\n\"));\n if (projectRoot !== process.cwd()) {\n console.log(`cd ${path.relative(process.cwd(), projectRoot)}`);\n }\n const devCommand = packageManager === \"npm\" ? \"npm run dev\" : `${packageManager} dev`;\n console.log(`${packageManager} install`);\n console.log(devCommand);\n}\n\n/**\n * Copy template files to the project directory\n *\n * @param templateDir - The directory containing the template files\n * @param root - The root directory of the project\n * @param projectName - The name of the project\n * @param projectId - The project ID\n */\nfunction copyTemplateFiles(\n templateDir: string,\n root: string,\n projectName: string,\n projectId?: string,\n): void {\n const writeFileToTarget = (file: string, content?: string) => {\n const targetPath = path.join(root, fileRenames[file] ?? file);\n if (content) {\n fs.writeFileSync(targetPath, content);\n } else {\n copyFile(path.join(templateDir, file), targetPath);\n }\n };\n\n const files = fs.readdirSync(templateDir);\n for (const file of files) {\n if (file === \"package.json\") {\n const customizedPackageJson = customizePackageJson(templateDir, projectName);\n writeFileToTarget(file, customizedPackageJson);\n } else if (file === \"env.example\" && projectId) {\n const customizedEnv = customizeEnv(templateDir, projectId);\n writeFileToTarget(file);\n console.log(\"Copying project id to .env\");\n writeFileToTarget(\".env\", customizedEnv);\n } else {\n writeFileToTarget(file);\n }\n }\n}\n\ninit().catch(e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;AAChB,CAAC;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/index.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\n\n/**\n * Prepare the app directory\n *\n * @param targetDir - The target directory for the app\n * @param shouldOverwrite - Whether to overwrite the existing directory\n * @returns The path to the prepared app directory\n */\nexport function prepareAppDirectory(targetDir: string, shouldOverwrite: boolean): string {\n const root = path.join(process.cwd(), targetDir);\n\n if (shouldOverwrite) {\n emptyDir(root);\n } else if (!fs.existsSync(root)) {\n fs.mkdirSync(root, { recursive: true });\n }\n\n return root;\n}\n\n/**\n * Customize package.json for the new app\n *\n * @param templateDir - The directory containing the template files\n * @param appName - The name of the app\n * @returns The customized package.json content\n */\nexport function customizePackageJson(templateDir: string, appName: string): string {\n const packageJsonPath = path.join(templateDir, \"package.json\");\n const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, \"utf-8\"));\n packageJson.name = appName;\n return JSON.stringify(packageJson, null, 2) + \"\\n\";\n}\n\n/**\n * Set up the .env file for the new app\n *\n * @param templateDir - The directory containing the template files\n * @param projectId - The CDP Project ID\n * @returns The customized .env content\n */\nexport function customizeEnv(templateDir: string, projectId: string): string {\n const exampleEnvPath = path.join(templateDir, \"env.example\");\n const exampleEnv = fs.readFileSync(exampleEnvPath, \"utf-8\");\n // Replace the project ID in the env file\n const envContent = exampleEnv.replace(/(.*PROJECT_ID=).*(\\r?\\n|$)/, `$1${projectId}\\n`);\n return envContent;\n}\n\n/**\n * Copy a file or directory recursively\n *\n * @param filePath - The source path\n * @param destPath - The destination path\n */\nexport function copyFile(filePath: string, destPath: string): void {\n const stat = fs.statSync(filePath);\n if (stat.isDirectory()) {\n copyDir(filePath, destPath);\n } else {\n fs.copyFileSync(filePath, destPath);\n }\n}\n\n/**\n * Copy a directory recursively\n *\n * @param srcDir - The source directory path\n * @param destDir - The destination directory path\n */\nfunction copyDir(srcDir: string, destDir: string): void {\n fs.mkdirSync(destDir, { recursive: true });\n for (const file of fs.readdirSync(srcDir)) {\n const srcFile = path.resolve(srcDir, file);\n const destFile = path.resolve(destDir, file);\n copyFile(srcFile, destFile);\n }\n}\n\n/**\n * Check if a directory is empty\n *\n * @param dirPath - The path to the directory\n * @returns True if the directory is empty, false otherwise\n */\nexport function isDirEmpty(dirPath: string): boolean {\n const files = fs.readdirSync(dirPath);\n return files.length === 0 || (files.length === 1 && files[0] === \".git\");\n}\n\n/**\n * Empty a directory while preserving .git\n *\n * @param dirPath - The path to the directory\n */\nfunction emptyDir(dirPath: string): void {\n if (!fs.existsSync(dirPath)) {\n return;\n }\n for (const file of fs.readdirSync(dirPath)) {\n if (file === \".git\") {\n continue;\n }\n fs.rmSync(path.resolve(dirPath, file), { recursive: true, force: true });\n }\n}\n\n/**\n * Detect which package manager invoked the create command\n *\n * @returns The detected package manager or 'pnpm' as default\n */\nexport function detectPackageManager(): \"npm\" | \"pnpm\" | \"yarn\" {\n const userAgent = process.env.npm_config_user_agent;\n\n if (userAgent) {\n if (userAgent.startsWith(\"yarn\")) return \"yarn\";\n if (userAgent.startsWith(\"pnpm\")) return \"pnpm\";\n if (userAgent.startsWith(\"npm\")) return \"npm\";\n }\n\n return \"npm\"; // Default to npm if we can't detect\n}\n","#!/usr/bin/env node\n\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { red, green, reset } from \"kolorist\";\nimport prompts from \"prompts\";\n\nimport {\n prepareAppDirectory,\n isDirEmpty,\n customizePackageJson,\n copyFile,\n customizeEnv,\n detectPackageManager,\n} from \"./utils.js\";\n\n// Available templates for app creation\nconst TEMPLATES = [\n {\n name: \"react\",\n display: \"React Single Page App\",\n color: green,\n },\n {\n name: \"nextjs\",\n display: \"Next.js Full Stack App\",\n color: green,\n },\n];\n\nconst defaultTargetDir = \"cdp-app\";\n\nconst fileRenames: Record<string, string | undefined> = {\n _gitignore: \".gitignore\",\n};\n\ninterface AppOptions {\n appName: string;\n template: string;\n targetDirectory: string;\n projectId: string;\n}\n\nconst uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\n/**\n * Initialize a new CDP app\n */\nasync function init(): Promise<void> {\n const { appName, template, targetDirectory, projectId } = await getAppDetails();\n\n console.log(`\\nScaffolding app in ${targetDirectory}...`);\n\n const root = prepareAppDirectory(targetDirectory, false);\n const templateDir = path.resolve(fileURLToPath(import.meta.url), \"../..\", `template-${template}`);\n\n copyTemplateFiles(templateDir, root, appName, projectId);\n printNextSteps(root);\n}\n\n/**\n * Get app details from command line arguments or prompt the user\n *\n * @returns The app details\n */\nasync function getAppDetails(): Promise<AppOptions> {\n // Get target directory from command line args (first non-option argument)\n let targetDir = process.argv[2];\n const defaultAppName = targetDir ?? defaultTargetDir;\n\n try {\n const result = await prompts(\n [\n {\n type: targetDir ? null : \"text\",\n name: \"appName\",\n message: reset(\"App Name:\"),\n initial: defaultAppName,\n onState: state => {\n targetDir = String(state.value).trim() || defaultAppName;\n },\n },\n {\n type: \"select\",\n name: \"template\",\n message: reset(\"Template:\"),\n initial: 0,\n choices: TEMPLATES.map(template => ({\n title: template.color(template.display || template.name),\n value: template.name,\n })),\n },\n {\n type: \"text\",\n name: \"projectId\",\n message: reset(\n \"CDP Project ID (Find your project ID at https://portal.cdp.coinbase.com/projects/overview):\",\n ),\n validate: value => {\n if (!value) {\n return \"Project ID is required\";\n } else if (!uuidRegex.test(value)) {\n return \"Project ID must be a valid UUID\";\n }\n return true;\n },\n initial: \"\",\n },\n {\n type: \"confirm\",\n name: \"corsConfirmation\",\n message: reset(\n \"Confirm you have whitelisted 'http://localhost:3000' at https://portal.cdp.coinbase.com/products/embedded-wallets/domains:\",\n ),\n initial: true,\n },\n {\n type: () => (!fs.existsSync(targetDir) || isDirEmpty(targetDir) ? null : \"confirm\"),\n name: \"overwrite\",\n message: () =>\n (targetDir === \".\" ? \"Current directory\" : `Target directory \"${targetDir}\"`) +\n \" is not empty. Remove existing files and continue?\",\n },\n {\n type: (_, { overwrite }: { overwrite?: boolean }) => {\n if (overwrite === false) {\n throw new Error(red(\"✖\") + \" Operation cancelled\");\n }\n return null;\n },\n name: \"overwriteChecker\",\n },\n ],\n {\n onCancel: () => {\n throw new Error(red(\"✖\") + \" Operation cancelled\");\n },\n },\n );\n\n return {\n appName: result.appName,\n template: result.template,\n targetDirectory: targetDir,\n projectId: result.projectId,\n };\n } catch (cancelled: unknown) {\n if (cancelled instanceof Error) {\n console.log(cancelled.message);\n }\n process.exit(0);\n }\n}\n\n/**\n * Print next steps for the user\n *\n * @param appRoot - The root directory of the app\n */\nfunction printNextSteps(appRoot: string): void {\n const packageManager = detectPackageManager();\n\n console.log(green(\"\\nDone. Now run your app:\\n\"));\n if (appRoot !== process.cwd()) {\n console.log(`cd ${path.relative(process.cwd(), appRoot)}`);\n }\n const devCommand = packageManager === \"npm\" ? \"npm run dev\" : `${packageManager} dev`;\n console.log(`${packageManager} install`);\n console.log(devCommand);\n}\n\n/**\n * Copy template files to the app directory\n *\n * @param templateDir - The directory containing the template files\n * @param root - The root directory of the app\n * @param appName - The name of the app\n * @param projectId - The CDP Project ID\n */\nfunction copyTemplateFiles(\n templateDir: string,\n root: string,\n appName: string,\n projectId?: string,\n): void {\n const writeFileToTarget = (file: string, content?: string) => {\n const targetPath = path.join(root, fileRenames[file] ?? file);\n if (content) {\n fs.writeFileSync(targetPath, content);\n } else {\n copyFile(path.join(templateDir, file), targetPath);\n }\n };\n\n const files = fs.readdirSync(templateDir);\n for (const file of files) {\n if (file === \"package.json\") {\n const customizedPackageJson = customizePackageJson(templateDir, appName);\n writeFileToTarget(file, customizedPackageJson);\n } else if (file === \"env.example\" && projectId) {\n const customizedEnv = customizeEnv(templateDir, projectId);\n writeFileToTarget(file);\n console.log(\"Copying CDP Project ID to .env\");\n writeFileToTarget(\".env\", customizedEnv);\n } else {\n writeFileToTarget(file);\n }\n }\n}\n\ninit().catch(e => {\n console.error(e);\n process.ex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displays the client app.
|
|
11
11
|
*/
|
|
12
12
|
export default function ClientApp() {
|
|
13
|
-
const isInitialized = useIsInitialized();
|
|
14
|
-
const isSignedIn = useIsSignedIn();
|
|
13
|
+
const { isInitialized } = useIsInitialized();
|
|
14
|
+
const { isSignedIn } = useIsSignedIn();
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<div className="app flex-col-container flex-grow">
|
|
@@ -9,7 +9,7 @@ import { IconCheck, IconCopy, IconUser } from "@/components/Icons";
|
|
|
9
9
|
* Header component
|
|
10
10
|
*/
|
|
11
11
|
export default function Header() {
|
|
12
|
-
const evmAddress = useEvmAddress();
|
|
12
|
+
const { evmAddress } = useEvmAddress();
|
|
13
13
|
const [isCopied, setIsCopied] = useState(false);
|
|
14
14
|
|
|
15
15
|
const copyAddress = async () => {
|
|
@@ -21,8 +21,8 @@ const client = createPublicClient({
|
|
|
21
21
|
* The Signed In screen
|
|
22
22
|
*/
|
|
23
23
|
export default function SignedInScreen() {
|
|
24
|
-
const isSignedIn = useIsSignedIn();
|
|
25
|
-
const evmAddress = useEvmAddress();
|
|
24
|
+
const { isSignedIn } = useIsSignedIn();
|
|
25
|
+
const { evmAddress } = useEvmAddress();
|
|
26
26
|
const [balance, setBalance] = useState<bigint | undefined>(undefined);
|
|
27
27
|
|
|
28
28
|
const formattedBalance = useMemo(() => {
|
|
@@ -22,7 +22,7 @@ interface Props {
|
|
|
22
22
|
*/
|
|
23
23
|
export default function Transaction(props: Props) {
|
|
24
24
|
const { balance, onSuccess } = props;
|
|
25
|
-
const evmAddress = useEvmAddress();
|
|
25
|
+
const { evmAddress } = useEvmAddress();
|
|
26
26
|
const [transactionHash, setTransactionHash] = useState("");
|
|
27
27
|
const [error, setError] = useState("");
|
|
28
28
|
|
|
@@ -9,8 +9,8 @@ import SignInScreen from "./SignInScreen";
|
|
|
9
9
|
* It also demonstrates how to use the AuthButton component to sign in and out of the app.
|
|
10
10
|
*/
|
|
11
11
|
function App() {
|
|
12
|
-
const isInitialized = useIsInitialized();
|
|
13
|
-
const isSignedIn = useIsSignedIn();
|
|
12
|
+
const { isInitialized } = useIsInitialized();
|
|
13
|
+
const { isSignedIn } = useIsSignedIn();
|
|
14
14
|
|
|
15
15
|
return (
|
|
16
16
|
<div className="app flex-col-container flex-grow">
|
|
@@ -8,7 +8,7 @@ import { IconCheck, IconCopy, IconUser } from "./Icons";
|
|
|
8
8
|
* Header component
|
|
9
9
|
*/
|
|
10
10
|
function Header() {
|
|
11
|
-
const evmAddress = useEvmAddress();
|
|
11
|
+
const { evmAddress } = useEvmAddress();
|
|
12
12
|
const [isCopied, setIsCopied] = useState(false);
|
|
13
13
|
|
|
14
14
|
const copyAddress = async () => {
|
|
@@ -19,8 +19,8 @@ const client = createPublicClient({
|
|
|
19
19
|
* The Signed In screen
|
|
20
20
|
*/
|
|
21
21
|
function SignedInScreen() {
|
|
22
|
-
const isSignedIn = useIsSignedIn();
|
|
23
|
-
const evmAddress = useEvmAddress();
|
|
22
|
+
const { isSignedIn } = useIsSignedIn();
|
|
23
|
+
const { evmAddress } = useEvmAddress();
|
|
24
24
|
const [balance, setBalance] = useState<bigint | undefined>(undefined);
|
|
25
25
|
|
|
26
26
|
const formattedBalance = useMemo(() => {
|
|
@@ -22,7 +22,7 @@ interface Props {
|
|
|
22
22
|
*/
|
|
23
23
|
function Transaction(props: Props) {
|
|
24
24
|
const { balance, onSuccess } = props;
|
|
25
|
-
const evmAddress = useEvmAddress();
|
|
25
|
+
const { evmAddress } = useEvmAddress();
|
|
26
26
|
const [transactionHash, setTransactionHash] = useState("");
|
|
27
27
|
const [error, setError] = useState("");
|
|
28
28
|
|