openadminjs 0.1.6 → 0.1.7

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.
@@ -1,5 +1,5 @@
1
1
  import { existsSync, readdirSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
2
+ import { dirname, join, resolve } from "node:path";
3
3
  import { spawnSync } from "node:child_process";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { cancel, confirm, intro, isCancel, outro, select, text } from "@clack/prompts";
@@ -62,6 +62,9 @@ export function createProject(options) {
62
62
  errorOnExist: true,
63
63
  filter: (source) => !source.includes("node_modules") && !source.includes(".next") && !source.includes("dist")
64
64
  });
65
+ if (!existsSync(join(targetDir, "package.json"))) {
66
+ throw new Error(`Template copy failed: package.json not found in ${targetDir}`);
67
+ }
65
68
  renderTemplateFiles(targetDir, {
66
69
  __APP_NAME__: appName,
67
70
  __PACKAGE_NAME__: packageName,
@@ -74,11 +77,17 @@ export function createProject(options) {
74
77
  __API_PORT__: options.apiPort
75
78
  });
76
79
  if (options.git) {
77
- spawnSync("git", ["init"], { cwd: targetDir, stdio: "ignore" });
80
+ const gitResult = spawnSync("git", ["init"], { cwd: targetDir, stdio: "ignore" });
81
+ if (gitResult.status !== 0 || gitResult.error) {
82
+ throw new Error("Failed to initialize git repository.");
83
+ }
78
84
  }
79
85
  if (options.install) {
80
86
  const installArgs = options.packageManager === "yarn" ? [] : ["install"];
81
- spawnSync(options.packageManager, installArgs, { cwd: targetDir, stdio: "inherit" });
87
+ const installResult = spawnSync(options.packageManager, installArgs, { cwd: targetDir, stdio: "inherit" });
88
+ if (installResult.status !== 0 || installResult.error) {
89
+ throw new Error(`Dependency installation failed. Run "${options.packageManager} ${installArgs.join(" ")}" inside ${targetDir}.`);
90
+ }
82
91
  }
83
92
  return {
84
93
  appName,
@@ -1,4 +1,4 @@
1
- import { mkdtempSync, readFileSync, rmSync } from "node:fs";
1
+ import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
2
  import { join } from "node:path";
3
3
  import { tmpdir } from "node:os";
4
4
  import { describe, expect, it } from "vitest";
@@ -43,4 +43,33 @@ describe("create project", () => {
43
43
  rmSync(cwd, { recursive: true, force: true });
44
44
  }
45
45
  });
46
+ it("fails fast when template package.json is missing", () => {
47
+ const cwd = mkdtempSync(join(tmpdir(), "openadminjs-cli-test-"));
48
+ const badTemplate = mkdtempSync(join(tmpdir(), "openadminjs-cli-template-"));
49
+ try {
50
+ writeFileSync(join(badTemplate, ".env.example"), "DATABASE_URL=__DATABASE_URL__\n");
51
+ mkdirSync(join(badTemplate, "apps"), { recursive: true });
52
+ expect(() => createProject({
53
+ projectName: "broken-app",
54
+ cwd,
55
+ packageManager: "pnpm",
56
+ database: "postgresql",
57
+ superadminEmail: "admin@localhost.dev",
58
+ superadminPassword: "12345678",
59
+ databaseUrl: "postgresql://localhost:5432/broken-app?schema=public",
60
+ redisUrl: "redis://localhost:6379",
61
+ jwtSecret: "test-jwt-secret",
62
+ jwtRefreshSecret: "test-jwt-refresh-secret",
63
+ adminOrigin: "http://localhost:3000",
64
+ apiPort: "4000",
65
+ git: false,
66
+ install: false,
67
+ templateDir: badTemplate
68
+ })).toThrow(/package\.json not found/);
69
+ }
70
+ finally {
71
+ rmSync(cwd, { recursive: true, force: true });
72
+ rmSync(badTemplate, { recursive: true, force: true });
73
+ }
74
+ });
46
75
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openadminjs",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "openadminjs": "dist/index.js"