create-guren-app 1.5.0 → 1.6.1

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/cli.js CHANGED
@@ -1995,6 +1995,49 @@ async function scaffoldAppBlueprint(options) {
1995
1995
  return blueprint;
1996
1996
  }
1997
1997
 
1998
+ // src/git.ts
1999
+ import { spawnSync } from "child_process";
2000
+ var GIT_TIMEOUT_MS = 3e4;
2001
+ function runGit(cwd, args, timeoutMs = GIT_TIMEOUT_MS) {
2002
+ return spawnSync("git", args, {
2003
+ cwd,
2004
+ stdio: "pipe",
2005
+ // Read at call time rather than hoisted: a caller that sets
2006
+ // GIT_AUTHOR_*/GIT_COMMITTER_* just before this runs has to reach the
2007
+ // child. GIT_TERMINAL_PROMPT keeps git from waiting on a terminal it does
2008
+ // not have.
2009
+ env: { ...process.env, GIT_TERMINAL_PROMPT: "0" },
2010
+ // spawnSync reads a non-positive timeout as "no timeout".
2011
+ timeout: Math.max(1, timeoutMs),
2012
+ // SIGTERM leaves a git blocked in a syscall alive, and spawnSync would go
2013
+ // on blocking with it.
2014
+ killSignal: "SIGKILL"
2015
+ });
2016
+ }
2017
+ function wasKilledByTimeout(result) {
2018
+ return result.error?.code === "ETIMEDOUT";
2019
+ }
2020
+ function isInsideGitWorkTree(cwd, options = {}) {
2021
+ const result = runGit(cwd, ["rev-parse", "--is-inside-work-tree"], options.timeoutMs);
2022
+ if (wasKilledByTimeout(result)) {
2023
+ return true;
2024
+ }
2025
+ return result.status === 0 && result.stdout.toString().trim() === "true";
2026
+ }
2027
+ function initGitRepository(cwd, options = {}) {
2028
+ const deadline = Date.now() + (options.timeoutMs ?? GIT_TIMEOUT_MS);
2029
+ const run = (failedStep, args) => {
2030
+ const remaining = deadline - Date.now();
2031
+ const ok = remaining > 0 && runGit(cwd, args, remaining).status === 0;
2032
+ return ok ? { ok: true } : { ok: false, failedStep, command: `git ${args.join(" ")}` };
2033
+ };
2034
+ const init2 = run("init", ["init"]);
2035
+ if (!init2.ok) return init2;
2036
+ const add = run("add", ["add", "-A"]);
2037
+ if (!add.ok) return add;
2038
+ return run("commit", ["commit", "-m", "chore: initial commit"]);
2039
+ }
2040
+
1998
2041
  // src/cli.ts
1999
2042
  var RENDERING_MODES = ["spa", "ssr"];
2000
2043
  var RENDERING_MODE_SET = new Set(RENDERING_MODES);
@@ -2025,9 +2068,9 @@ async function updateSsrPackageJson(destination) {
2025
2068
  `, "utf8");
2026
2069
  }
2027
2070
  async function runAppCli(targetDir, cliArgs) {
2028
- const { spawnSync } = await import("child_process");
2071
+ const { spawnSync: spawnSync2 } = await import("child_process");
2029
2072
  const cliBin = resolve(targetDir, "node_modules/@guren/cli/dist/bin.js");
2030
- const result = spawnSync("bun", [cliBin, ...cliArgs], {
2073
+ const result = spawnSync2("bun", [cliBin, ...cliArgs], {
2031
2074
  cwd: targetDir,
2032
2075
  stdio: "inherit"
2033
2076
  });
@@ -2096,7 +2139,7 @@ async function resolveGitInit(flagValue, target) {
2096
2139
  if (!target.wasEmpty) {
2097
2140
  return declined("the target directory already contained files.");
2098
2141
  }
2099
- if (await isInsideGitWorkTree(target.dir)) {
2142
+ if (isInsideGitWorkTree(target.dir)) {
2100
2143
  return declined("the target directory is already inside a git repository.");
2101
2144
  }
2102
2145
  if (flagValue === true) {
@@ -2108,33 +2151,25 @@ async function resolveGitInit(flagValue, target) {
2108
2151
  });
2109
2152
  return result === true;
2110
2153
  }
2111
- async function isInsideGitWorkTree(cwd) {
2112
- const { spawnSync } = await import("child_process");
2113
- const result = spawnSync("git", ["rev-parse", "--is-inside-work-tree"], { cwd, stdio: "pipe", env: process3.env });
2114
- return result.status === 0 && result.stdout.toString().trim() === "true";
2115
- }
2116
- async function initGitRepository(cwd) {
2117
- const { spawnSync } = await import("child_process");
2118
- const run = (args) => spawnSync("git", args, { cwd, stdio: "pipe", env: process3.env });
2154
+ function reportGitInit(cwd) {
2119
2155
  consola.start("Initializing git repository...");
2120
- for (const args of [["init"], ["add", "-A"]]) {
2121
- if (run(args).status !== 0) {
2122
- consola.warn(`Failed to run \`git ${args.join(" ")}\`. Initialize the repository manually.`);
2123
- return;
2124
- }
2156
+ const result = initGitRepository(cwd);
2157
+ if (result.ok) {
2158
+ consola.success("Initialized a git repository with an initial commit");
2159
+ return;
2125
2160
  }
2126
- if (run(["commit", "-m", "chore: initial commit"]).status !== 0) {
2161
+ if (result.failedStep === "commit") {
2127
2162
  consola.warn("Created a git repository, but the initial commit failed (git identity may be unset).");
2128
2163
  consola.warn('Set `git config user.name` and `git config user.email`, then run `git commit -m "chore: initial commit"`.');
2129
2164
  return;
2130
2165
  }
2131
- consola.success("Initialized a git repository with an initial commit");
2166
+ consola.warn(`Failed to run \`${result.command}\`. Initialize the repository manually.`);
2132
2167
  }
2133
2168
  async function installDependencies(cwd) {
2134
2169
  try {
2135
2170
  consola.start("Installing dependencies...");
2136
- const { spawnSync } = await import("child_process");
2137
- const result = spawnSync("bun", ["install"], { cwd, stdio: "inherit" });
2171
+ const { spawnSync: spawnSync2 } = await import("child_process");
2172
+ const result = spawnSync2("bun", ["install"], { cwd, stdio: "inherit" });
2138
2173
  if (result.status !== 0) {
2139
2174
  consola.warn("Failed to install dependencies. Run `bun install` manually.");
2140
2175
  return false;
@@ -2248,7 +2283,7 @@ var command = defineCommand({
2248
2283
  }
2249
2284
  }
2250
2285
  if (shouldInitGit) {
2251
- await initGitRepository(targetDir);
2286
+ reportGitInit(targetDir);
2252
2287
  }
2253
2288
  const relativeTarget = relative2(process3.cwd(), targetDir) || ".";
2254
2289
  consola.success(`Scaffolded a new Guren app (${blueprint.name}/${renderingMode.toUpperCase()}/${database}) in ${relativeTarget}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-guren-app",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,9 +18,9 @@
18
18
  "test": "bun test"
19
19
  },
20
20
  "dependencies": {
21
- "@guren/cli": "^2.0.0",
21
+ "@guren/cli": "^2.1.1",
22
22
  "@guren/core": "^1.5.0",
23
- "@guren/orm": "^2.0.0",
23
+ "@guren/orm": "^2.1.0",
24
24
  "drizzle-orm": "1.0.0-rc.4"
25
25
  },
26
26
  "devDependencies": {
@@ -2,13 +2,36 @@ import { createApp } from '@guren/core'
2
2
  import DatabaseProvider from '../app/Providers/DatabaseProvider.js'
3
3
  import { registerApiRoutes } from '../routes/api.js'
4
4
 
5
+ // The Host header is client-controlled, so production should answer only to the
6
+ // host this app is deployed as, which APP_URL carries.
7
+ //
8
+ // Read at module scope, where not every platform has populated process.env yet
9
+ // (the Cloudflare worker imports this module before wrangler `vars` land). A
10
+ // missing value therefore warns and leaves the check off, rather than throwing
11
+ // and stopping the app from booting at all. Emailed links do not depend on this
12
+ // — app/Auth/AppUrl.ts resolves those per request and fails closed there.
13
+ function hostAuthorization() {
14
+ const exclude = ['/health']
15
+
16
+ if (process.env.NODE_ENV !== 'production') {
17
+ return { allowedHosts: ['localhost:*', '127.0.0.1:*'], exclude }
18
+ }
19
+
20
+ const appUrl = process.env.APP_URL?.trim()
21
+ if (!appUrl) {
22
+ console.warn('[app] APP_URL is not set — host authorization is disabled. Set it to the public base URL of this app.')
23
+ return false
24
+ }
25
+
26
+ // `hostname:*` rather than the bare host: the hostname is the security
27
+ // boundary, and a proxy may or may not include the default port in `Host`.
28
+ return { allowedHosts: [`${new URL(appUrl).hostname}:*`], exclude }
29
+ }
30
+
5
31
  const app = createApp({
6
32
  routes: registerApiRoutes,
7
33
  providers: [DatabaseProvider],
8
- hostAuthorization: process.env.NODE_ENV === 'production' ? false : {
9
- allowedHosts: ['localhost:*', '127.0.0.1:*'],
10
- exclude: ['/health'],
11
- },
34
+ hostAuthorization: hostAuthorization(),
12
35
  })
13
36
 
14
37
  export default app
@@ -10,14 +10,37 @@ setInertiaDocument({
10
10
  head: '<link rel="icon" type="image/svg+xml" href="/favicon.svg" />',
11
11
  })
12
12
 
13
+ // The Host header is client-controlled, so production should answer only to the
14
+ // host this app is deployed as, which APP_URL carries.
15
+ //
16
+ // Read at module scope, where not every platform has populated process.env yet
17
+ // (the Cloudflare worker imports this module before wrangler `vars` land). A
18
+ // missing value therefore warns and leaves the check off, rather than throwing
19
+ // and stopping the app from booting at all. Emailed links do not depend on this
20
+ // — app/Auth/AppUrl.ts resolves those per request and fails closed there.
21
+ function hostAuthorization() {
22
+ const exclude = ['/healthcheck', '/up']
23
+
24
+ if (process.env.NODE_ENV !== 'production') {
25
+ return { allowedHosts: ['localhost:*', '127.0.0.1:*'], exclude }
26
+ }
27
+
28
+ const appUrl = process.env.APP_URL?.trim()
29
+ if (!appUrl) {
30
+ console.warn('[app] APP_URL is not set — host authorization is disabled. Set it to the public base URL of this app.')
31
+ return false
32
+ }
33
+
34
+ // `hostname:*` rather than the bare host: the hostname is the security
35
+ // boundary, and a proxy may or may not include the default port in `Host`.
36
+ return { allowedHosts: [`${new URL(appUrl).hostname}:*`], exclude }
37
+ }
38
+
13
39
  const app = createApp({
14
40
  auth: {},
15
41
  routes: registerWebRoutes,
16
42
  providers: [DatabaseProvider, AuthProvider, AuthorizationProvider],
17
- hostAuthorization: process.env.NODE_ENV === 'production' ? false : {
18
- allowedHosts: ['localhost:*', '127.0.0.1:*'],
19
- exclude: ['/healthcheck', '/up'],
20
- },
43
+ hostAuthorization: hostAuthorization(),
21
44
  })
22
45
 
23
46
  export default app
@@ -19,10 +19,10 @@
19
19
  "db:seed": "bunx guren db:seed"
20
20
  },
21
21
  "dependencies": {
22
- "@guren/cli": "^2.0.0",
22
+ "@guren/cli": "^2.1.1",
23
23
  "@guren/core": "^1.5.0",
24
24
  "@guren/inertia-client": "^1.0.2",
25
- "@guren/orm": "^2.0.0",
25
+ "@guren/orm": "^2.1.0",
26
26
  "@inertiajs/react": "^3.6.1",
27
27
  "drizzle-orm": "1.0.0-rc.4",
28
28
  "react": "^19.0.0",
@@ -9,13 +9,36 @@ setInertiaDocument({
9
9
  head: '<link rel="icon" type="image/svg+xml" href="/favicon.svg" />',
10
10
  })
11
11
 
12
+ // The Host header is client-controlled, so production should answer only to the
13
+ // host this app is deployed as, which APP_URL carries.
14
+ //
15
+ // Read at module scope, where not every platform has populated process.env yet
16
+ // (the Cloudflare worker imports this module before wrangler `vars` land). A
17
+ // missing value therefore warns and leaves the check off, rather than throwing
18
+ // and stopping the app from booting at all. Emailed links do not depend on this
19
+ // — app/Auth/AppUrl.ts resolves those per request and fails closed there.
20
+ function hostAuthorization() {
21
+ const exclude = ['/healthcheck', '/up']
22
+
23
+ if (process.env.NODE_ENV !== 'production') {
24
+ return { allowedHosts: ['localhost:*', '127.0.0.1:*'], exclude }
25
+ }
26
+
27
+ const appUrl = process.env.APP_URL?.trim()
28
+ if (!appUrl) {
29
+ console.warn('[app] APP_URL is not set — host authorization is disabled. Set it to the public base URL of this app.')
30
+ return false
31
+ }
32
+
33
+ // `hostname:*` rather than the bare host: the hostname is the security
34
+ // boundary, and a proxy may or may not include the default port in `Host`.
35
+ return { allowedHosts: [`${new URL(appUrl).hostname}:*`], exclude }
36
+ }
37
+
12
38
  const app = createApp({
13
39
  routes: registerWebRoutes,
14
40
  providers: [DatabaseProvider],
15
- hostAuthorization: process.env.NODE_ENV === 'production' ? false : {
16
- allowedHosts: ['localhost:*', '127.0.0.1:*'],
17
- exclude: ['/healthcheck', '/up'],
18
- },
41
+ hostAuthorization: hostAuthorization(),
19
42
  })
20
43
 
21
44
  export default app