create-kontrolia-auth 2.2.1 → 2.2.2

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 CHANGED
@@ -5,6 +5,7 @@ import { askApplicationStep } from "./steps/application.js";
5
5
  import { askDatabaseStep } from "./steps/database.js";
6
6
  import { askDeploymentStep } from "./steps/deployment.js";
7
7
  import { bringUpAndMigrate } from "./utils/docker.js";
8
+ import { readEnvFile } from "./utils/files.js";
8
9
  import { runPreflight } from "./utils/preflight.js";
9
10
  import { textOrExit } from "./utils/prompts.js";
10
11
  import { ensureRepo, isInsideRepo } from "./utils/scaffold.js";
@@ -93,8 +94,10 @@ async function runUpdateCommand() {
93
94
  * offer) without repeating the database/application questions. For anyone
94
95
  * who already has everything running and just wants to (re)connect a
95
96
  * deploy target — e.g. adding admin-panel after auth-server was already
96
- * deployed. Doesn't persist Supabase credentials anywhere between runs, so
97
- * it still has to ask for them once here.
97
+ * deployed. A previous install/deploy already wrote these same Supabase
98
+ * values into apps/auth-server/.env.local, so this reuses them instead of
99
+ * asking again every time — only falls back to asking when that file is
100
+ * missing or incomplete (e.g. first run, or the file got deleted).
98
101
  */
99
102
  async function runDeployCommand() {
100
103
  console.clear();
@@ -105,9 +108,40 @@ async function runDeployCommand() {
105
108
  process.exitCode = 1;
106
109
  return;
107
110
  }
108
- const supabaseUrl = await textOrExit("URL de tu proyecto Supabase", "https://tu-proyecto.supabase.co");
109
- const anonKey = await textOrExit("Anon/public key");
110
- const serviceRoleKey = await textOrExit("Service role key (server-only, nunca la expongas al navegador)");
111
+ const existingEnv = await readEnvFile(`${process.cwd()}/apps/auth-server/.env.local`);
112
+ const found = existingEnv?.SUPABASE_URL && existingEnv?.NEXT_PUBLIC_SUPABASE_ANON_KEY && existingEnv?.SUPABASE_SERVICE_ROLE_KEY
113
+ ? {
114
+ supabaseUrl: existingEnv.SUPABASE_URL,
115
+ anonKey: existingEnv.NEXT_PUBLIC_SUPABASE_ANON_KEY,
116
+ serviceRoleKey: existingEnv.SUPABASE_SERVICE_ROLE_KEY,
117
+ }
118
+ : null;
119
+ let supabaseUrl;
120
+ let anonKey;
121
+ let serviceRoleKey;
122
+ if (found) {
123
+ const reuse = await p.confirm({
124
+ message: `Ya tengo las credenciales de Supabase que usaste antes (${found.supabaseUrl}) — ¿las uso, o quieres capturar otras?`,
125
+ initialValue: true,
126
+ });
127
+ if (p.isCancel(reuse)) {
128
+ p.cancel("Cancelado.");
129
+ process.exit(0);
130
+ }
131
+ if (reuse) {
132
+ ({ supabaseUrl, anonKey, serviceRoleKey } = found);
133
+ }
134
+ else {
135
+ supabaseUrl = await textOrExit("URL de tu proyecto Supabase", "https://tu-proyecto.supabase.co");
136
+ anonKey = await textOrExit("Anon/public key");
137
+ serviceRoleKey = await textOrExit("Service role key (server-only, nunca la expongas al navegador)");
138
+ }
139
+ }
140
+ else {
141
+ supabaseUrl = await textOrExit("URL de tu proyecto Supabase", "https://tu-proyecto.supabase.co");
142
+ anonKey = await textOrExit("Anon/public key");
143
+ serviceRoleKey = await textOrExit("Service role key (server-only, nunca la expongas al navegador)");
144
+ }
111
145
  const db = { mode: "existing", databaseUrl: "", supabaseUrl, anonKey, serviceRoleKey };
112
146
  await askDeploymentStep(process.cwd(), db);
113
147
  p.outro("Listo.");
@@ -1 +1 @@
1
- {"version":3,"file":"deployment.d.ts","sourceRoot":"","sources":["../../src/steps/deployment.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA8JpD;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAwI3F"}
1
+ {"version":3,"file":"deployment.d.ts","sourceRoot":"","sources":["../../src/steps/deployment.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AA8JpD;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAoJ3F"}
@@ -1,5 +1,5 @@
1
1
  import * as p from "@clack/prompts";
2
- import { updateEnvValue, writeEnvFile } from "../utils/files.js";
2
+ import { readEnvFile, updateEnvValue, writeEnvFile } from "../utils/files.js";
3
3
  import { registerOAuthClient } from "../utils/oauth-client.js";
4
4
  import { createVercelProject, detectCurrentBranch, detectGitHubRepo, triggerVercelDeployment } from "../utils/vercel-api.js";
5
5
  const NEXT_STEPS = {
@@ -128,6 +128,14 @@ async function tryAutoCreateVercelProjects(repoRoot, authServerEnv, adminPanelEn
128
128
  * ever generates env files, it never touches the database connection.
129
129
  */
130
130
  export async function askDeploymentStep(repoRoot, db) {
131
+ // A previous install/deploy already wrote these into .env.local — reuse
132
+ // them as editable defaults instead of making the user retype the same
133
+ // URLs every time they run `deploy` again.
134
+ const prevAuthServerEnv = await readEnvFile(`${repoRoot}/apps/auth-server/.env.local`);
135
+ const prevAdminPanelEnv = await readEnvFile(`${repoRoot}/apps/admin-panel/.env.local`);
136
+ const prevAuthServerUrl = prevAdminPanelEnv?.NEXT_PUBLIC_AUTH_SERVER_URL;
137
+ const prevAdminPanelUrl = prevAuthServerEnv?.NEXT_PUBLIC_ADMIN_PANEL_URL;
138
+ const prevCookieDomain = prevAuthServerEnv?.NEXT_PUBLIC_COOKIE_DOMAIN ?? prevAdminPanelEnv?.NEXT_PUBLIC_COOKIE_DOMAIN;
131
139
  const target = await p.select({
132
140
  message: "¿Dónde vas a desplegar auth-server / admin-panel?",
133
141
  options: [
@@ -147,6 +155,7 @@ export async function askDeploymentStep(repoRoot, db) {
147
155
  message: "¿En qué URL va a vivir auth-server? (admin-panel la usa para enviar ahí a quien no tenga sesión)",
148
156
  placeholder: "http://localhost:3000",
149
157
  defaultValue: "http://localhost:3000",
158
+ initialValue: prevAuthServerUrl,
150
159
  });
151
160
  if (p.isCancel(authServerUrl)) {
152
161
  p.cancel("Instalación cancelada.");
@@ -156,6 +165,7 @@ export async function askDeploymentStep(repoRoot, db) {
156
165
  message: "¿Y en qué URL va a vivir admin-panel? (auth-server la usa para regresar ahí después de iniciar sesión, en vez de mandarte a su propia pantalla de inicio)",
157
166
  placeholder: "http://localhost:3001",
158
167
  defaultValue: "http://localhost:3001",
168
+ initialValue: prevAdminPanelUrl,
159
169
  });
160
170
  if (p.isCancel(adminPanelUrl)) {
161
171
  p.cancel("Instalación cancelada.");
@@ -166,6 +176,7 @@ export async function askDeploymentStep(repoRoot, db) {
166
176
  "Si es así, escribe el dominio compartido empezando con un punto (ej. .tuempresa.com). Si comparten el mismo host, o no lo sabes todavía, déjalo vacío.",
167
177
  placeholder: "",
168
178
  defaultValue: "",
179
+ initialValue: prevCookieDomain,
169
180
  });
170
181
  if (p.isCancel(cookieDomain)) {
171
182
  p.cancel("Instalación cancelada.");
@@ -9,4 +9,6 @@ export declare function writeEnvFile(path: string, values: EnvValues): Promise<v
9
9
  */
10
10
  export declare function updateEnvValue(path: string, key: string, value: string): Promise<void>;
11
11
  export declare function fileExists(path: string): boolean;
12
+ /** Parses a simple `KEY=value` .env file (no quoting/escaping) — null if it doesn't exist. */
13
+ export declare function readEnvFile(path: string): Promise<EnvValues | null>;
12
14
  //# sourceMappingURL=files.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/utils/files.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAKjF;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ5F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD"}
1
+ {"version":3,"file":"files.d.ts","sourceRoot":"","sources":["../../src/utils/files.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAKjF;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ5F;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEhD;AAED,8FAA8F;AAC9F,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC,CAYzE"}
@@ -23,3 +23,18 @@ export async function updateEnvValue(path, key, value) {
23
23
  export function fileExists(path) {
24
24
  return existsSync(path);
25
25
  }
26
+ /** Parses a simple `KEY=value` .env file (no quoting/escaping) — null if it doesn't exist. */
27
+ export async function readEnvFile(path) {
28
+ if (!existsSync(path))
29
+ return null;
30
+ const contents = await readFile(path, "utf8");
31
+ const values = {};
32
+ for (const line of contents.split("\n")) {
33
+ const match = line.match(/^([A-Z0-9_]+)=(.*)$/);
34
+ if (match) {
35
+ const [, key, value] = match;
36
+ values[key] = value.trim();
37
+ }
38
+ }
39
+ return values;
40
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-kontrolia-auth",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "license": "MIT",
5
5
  "description": "Turnkey installer for KontrolIA Auth. `npx create-kontrolia-auth mi-app` checks requirements, downloads the repo, installs deps, and runs a wizard: (1) connect to an existing Supabase project or create a new self-hosted one via Docker; (2) where to deploy auth-server/admin-panel (Docker, Vercel, Railway, Render, Coolify). Also exposes `update`, `migrate` and `doctor` subcommands.",
6
6
  "keywords": [