create-x402-app 0.1.3 → 0.1.4

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.
Files changed (2) hide show
  1. package/dist/index.js +53 -3
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  "package.json"(exports2, module2) {
32
32
  module2.exports = {
33
33
  name: "create-x402-app",
34
- version: "0.1.3",
34
+ version: "0.1.4",
35
35
  description: "Create a new x402 pay-per-request API project",
36
36
  keywords: [
37
37
  "x402",
@@ -97,6 +97,53 @@ var packageJson = require_package();
97
97
  function getTemplateDir(projectType, framework) {
98
98
  return `${projectType}-${framework}`;
99
99
  }
100
+ function getTemplatesDirectory() {
101
+ const possiblePaths = [
102
+ import_path.default.join(__dirname, "..", "templates"),
103
+ // When installed as package (most common)
104
+ import_path.default.join(__dirname, "templates")
105
+ // When running from source
106
+ ];
107
+ for (const templatePath of possiblePaths) {
108
+ if (import_fs_extra.default.existsSync(templatePath)) {
109
+ return templatePath;
110
+ }
111
+ }
112
+ let currentDir = __dirname;
113
+ let attempts = 0;
114
+ const maxAttempts = 10;
115
+ while (attempts < maxAttempts) {
116
+ const pkgPath = import_path.default.join(currentDir, "package.json");
117
+ if (import_fs_extra.default.existsSync(pkgPath)) {
118
+ try {
119
+ const pkg = import_fs_extra.default.readJsonSync(pkgPath);
120
+ if (pkg.name === "create-x402-app") {
121
+ const templatesPath = import_path.default.join(currentDir, "templates");
122
+ if (import_fs_extra.default.existsSync(templatesPath)) {
123
+ return templatesPath;
124
+ }
125
+ }
126
+ } catch (e) {
127
+ }
128
+ }
129
+ const parentDir = import_path.default.dirname(currentDir);
130
+ if (parentDir === currentDir) {
131
+ break;
132
+ }
133
+ currentDir = parentDir;
134
+ attempts++;
135
+ }
136
+ const npxPaths = [
137
+ import_path.default.join(process.env.HOME || process.env.USERPROFILE || "", ".npm", "_npx", "templates"),
138
+ import_path.default.join(process.cwd(), "node_modules", "create-x402-app", "templates")
139
+ ];
140
+ for (const templatePath of npxPaths) {
141
+ if (import_fs_extra.default.existsSync(templatePath)) {
142
+ return templatePath;
143
+ }
144
+ }
145
+ throw new Error(`Could not find templates directory. Searched from: ${__dirname}`);
146
+ }
100
147
  function showBanner() {
101
148
  return new Promise((resolve) => {
102
149
  import_figlet.default.text("x402", {
@@ -288,15 +335,18 @@ async function main() {
288
335
  }
289
336
  const spinner = (0, import_ora.default)("Creating project...").start();
290
337
  try {
291
- const templatePath = import_path.default.join(__dirname, "..", "templates", templateName);
338
+ const templatesDir = getTemplatesDirectory();
339
+ const templatePath = import_path.default.join(templatesDir, templateName);
292
340
  if (!import_fs_extra.default.existsSync(templatePath)) {
293
341
  spinner.fail(`Template not found: ${templateName}`);
294
342
  console.log(import_chalk.default.yellow(`
295
343
  Available templates:`));
296
- const templatesDir = import_path.default.join(__dirname, "..", "templates");
297
344
  if (import_fs_extra.default.existsSync(templatesDir)) {
298
345
  const templates = import_fs_extra.default.readdirSync(templatesDir);
299
346
  templates.forEach((t) => console.log(import_chalk.default.gray(` \u2022 ${t}`)));
347
+ } else {
348
+ console.log(import_chalk.default.red(`Templates directory not found at: ${templatesDir}`));
349
+ console.log(import_chalk.default.yellow(`__dirname: ${__dirname}`));
300
350
  }
301
351
  process.exit(1);
302
352
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-x402-app",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Create a new x402 pay-per-request API project",
5
5
  "keywords": [
6
6
  "x402",