@mostajs/setup 2.1.12 → 2.1.13

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,11 +1,13 @@
1
1
  import type { DialectType } from '../types/index.js';
2
2
  export interface EnvWriterOptions {
3
- dialect: DialectType;
4
- uri: string;
3
+ dialect?: DialectType;
4
+ uri?: string;
5
5
  /** Extra variables to write (e.g. STRIPE_KEY, SMTP_HOST) */
6
6
  extraVars?: Record<string, string>;
7
7
  /** Default app port (default: 3000) */
8
8
  port?: number;
9
+ /** Skip writing DB_DIALECT/SGBD_URI (for NET mode) */
10
+ skipDb?: boolean;
9
11
  }
10
12
  /**
11
13
  * Write or update .env.local with DB_DIALECT + SGBD_URI.
@@ -7,7 +7,7 @@ import path from 'path';
7
7
  * Preserves commented lines. Returns true if dialect changed (needs restart).
8
8
  */
9
9
  export async function writeEnvLocal(options) {
10
- const { dialect, uri, extraVars, port = 3000 } = options;
10
+ const { dialect, uri, extraVars, port = 3000, skipDb = false } = options;
11
11
  const envPath = path.resolve(process.cwd(), '.env.local');
12
12
  let content = '';
13
13
  let previousDialect = null;
@@ -20,16 +20,24 @@ export async function writeEnvLocal(options) {
20
20
  catch {
21
21
  // .env.local doesn't exist yet
22
22
  }
23
- const schemaValue = dialect !== 'mongodb' ? 'update' : undefined;
24
23
  if (content) {
25
- // Replace only active (uncommented) lines
26
- content = upsertEnvLine(content, 'DB_DIALECT', dialect);
27
- content = upsertEnvLine(content, 'SGBD_URI', uri);
28
- if (schemaValue) {
29
- content = upsertEnvLine(content, 'DB_SCHEMA_STRATEGY', schemaValue);
24
+ if (skipDb) {
25
+ // Mode NET : commenter DB_DIALECT, SGBD_URI, DB_SCHEMA_STRATEGY
26
+ content = content.replace(/^DB_DIALECT=(.+)$/m, '#DB_DIALECT=$1');
27
+ content = content.replace(/^SGBD_URI=(.+)$/m, '#SGBD_URI=$1');
28
+ content = content.replace(/^DB_SCHEMA_STRATEGY=(.+)$/m, '#DB_SCHEMA_STRATEGY=$1');
30
29
  }
31
- else if (/^DB_SCHEMA_STRATEGY=/m.test(content)) {
32
- content = content.replace(/^DB_SCHEMA_STRATEGY=.*$/m, '#DB_SCHEMA_STRATEGY=update');
30
+ else if (dialect && uri) {
31
+ // Mode ORM : écrire DB_DIALECT + SGBD_URI
32
+ content = upsertEnvLine(content, 'DB_DIALECT', dialect);
33
+ content = upsertEnvLine(content, 'SGBD_URI', uri);
34
+ const schemaValue = dialect !== 'mongodb' ? 'update' : undefined;
35
+ if (schemaValue) {
36
+ content = upsertEnvLine(content, 'DB_SCHEMA_STRATEGY', schemaValue);
37
+ }
38
+ else if (/^DB_SCHEMA_STRATEGY=/m.test(content)) {
39
+ content = content.replace(/^DB_SCHEMA_STRATEGY=.*$/m, '#DB_SCHEMA_STRATEGY=update');
40
+ }
33
41
  }
34
42
  // Write extra vars
35
43
  if (extraVars) {
@@ -42,29 +50,25 @@ export async function writeEnvLocal(options) {
42
50
  // Fresh .env.local
43
51
  const { randomBytes } = await import('crypto');
44
52
  const secret = randomBytes(32).toString('base64');
45
- const lines = [
46
- `DB_DIALECT=${dialect}`,
47
- `SGBD_URI=${uri}`,
48
- ...(schemaValue ? [`DB_SCHEMA_STRATEGY=${schemaValue}`] : []),
49
- '',
50
- '# NextAuth Configuration',
51
- `NEXTAUTH_URL=http://localhost:${port}`,
52
- `NEXTAUTH_SECRET=${secret}`,
53
- `AUTH_SECRET=${secret}`,
54
- `NEXT_PUBLIC_APP_URL=http://localhost:${port}`,
55
- '',
56
- '# Environment',
57
- 'NODE_ENV=development',
58
- `PORT=${port}`,
59
- '',
60
- ...(extraVars
61
- ? ['# App Configuration', ...Object.entries(extraVars).map(([k, v]) => `${k}=${v}`), '']
62
- : []),
63
- ];
53
+ const lines = [];
54
+ if (!skipDb && dialect && uri) {
55
+ const schemaValue = dialect !== 'mongodb' ? 'update' : undefined;
56
+ lines.push(`DB_DIALECT=${dialect}`, `SGBD_URI=${uri}`);
57
+ if (schemaValue)
58
+ lines.push(`DB_SCHEMA_STRATEGY=${schemaValue}`);
59
+ lines.push('');
60
+ }
61
+ lines.push('# NextAuth Configuration', `NEXTAUTH_URL=http://localhost:${port}`, `NEXTAUTH_SECRET=${secret}`, `AUTH_SECRET=${secret}`, `NEXT_PUBLIC_APP_URL=http://localhost:${port}`, '', '# Environment', 'NODE_ENV=development', `PORT=${port}`, '');
62
+ if (extraVars) {
63
+ lines.push('# App Configuration');
64
+ for (const [k, v] of Object.entries(extraVars))
65
+ lines.push(`${k}=${v}`);
66
+ lines.push('');
67
+ }
64
68
  content = lines.join('\n') + '\n';
65
69
  }
66
70
  fs.writeFileSync(envPath, content, 'utf-8');
67
- return previousDialect !== null && previousDialect !== dialect;
71
+ return previousDialect !== null && previousDialect !== (dialect ?? previousDialect);
68
72
  }
69
73
  function upsertEnvLine(content, key, value) {
70
74
  const regex = new RegExp(`^${key}=.*$`, 'm');
package/dist/lib/setup.js CHANGED
@@ -121,7 +121,9 @@ async function runNetInstall(installConfig, setupConfig) {
121
121
  apiKey: installConfig.net.apiKey,
122
122
  });
123
123
  // 1. Write .env.local with NET config
124
+ // En mode NET : pas de DB_DIALECT/SGBD_URI — seulement MOSTA_DATA + MOSTA_NET_URL
124
125
  const extraVars = {
126
+ MOSTA_DATA: 'net',
125
127
  MOSTA_NET_URL: installConfig.net.url,
126
128
  MOSTA_NET_TRANSPORT: installConfig.net.transport,
127
129
  ...(installConfig.net.apiKey ? { MOSTA_NET_API_KEY: installConfig.net.apiKey } : {}),
@@ -131,8 +133,7 @@ async function runNetInstall(installConfig, setupConfig) {
131
133
  extraVars['MOSTAJS_MODULES'] = installConfig.modules.join(',');
132
134
  }
133
135
  await writeEnvLocal({
134
- dialect: 'net',
135
- uri: installConfig.net.url,
136
+ skipDb: true, // Ne pas écrire DB_DIALECT/SGBD_URI
136
137
  extraVars,
137
138
  port: setupConfig.defaultPort,
138
139
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mostajs/setup",
3
- "version": "2.1.12",
3
+ "version": "2.1.13",
4
4
  "description": "Reusable setup wizard module — multi-dialect DB configuration, .env.local writer, seed runner",
5
5
  "author": "Dr Hamid MADANI <drmdh@msn.com>",
6
6
  "license": "MIT",