adminforth 2.55.4-next.2 → 2.55.4-next.3
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.
|
@@ -37,6 +37,8 @@ function detectAdminforthVersion() {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const adminforthVersion = detectAdminforthVersion();
|
|
40
|
+
const SUPPORTED_DB_URL_SCHEMES = ['sqlite://', 'postgresql://', 'mongodb://', 'mysql://', 'clickhouse://'];
|
|
41
|
+
const PRISMA_MIGRATION_DB_PROTOCOLS = ['sqlite', 'postgres', 'postgresql', 'mysql'];
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
export function parseArgumentsIntoOptions(rawArgs) {
|
|
@@ -56,7 +58,6 @@ export function parseArgumentsIntoOptions(rawArgs) {
|
|
|
56
58
|
appName: args['--app-name'],
|
|
57
59
|
db: args['--db'],
|
|
58
60
|
useNpm: args['--use-npm'],
|
|
59
|
-
includePrismaMigrations: args['--include-prisma-migrations'],
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -94,8 +95,19 @@ export async function promptForMissingOptions(options) {
|
|
|
94
95
|
});
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
const answers = await inquirer.prompt(questions);
|
|
99
|
+
const resolvedOptions = {
|
|
100
|
+
...options,
|
|
101
|
+
appName: options.appName || answers.appName,
|
|
102
|
+
db: options.db || answers.db,
|
|
103
|
+
useNpm: options.useNpm || answers.useNpm,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
if (
|
|
107
|
+
resolvedOptions.includePrismaMigrations === undefined &&
|
|
108
|
+
isPrismaMigrationDbUrl(resolvedOptions.db)
|
|
109
|
+
) {
|
|
110
|
+
const prismaAnswer = await inquirer.prompt([{
|
|
99
111
|
type: 'select',
|
|
100
112
|
name: 'includePrismaMigrations',
|
|
101
113
|
message: 'Include Prisma migrations? >',
|
|
@@ -104,18 +116,13 @@ export async function promptForMissingOptions(options) {
|
|
|
104
116
|
{ name: 'No', value: false },
|
|
105
117
|
],
|
|
106
118
|
default: true,
|
|
107
|
-
});
|
|
108
|
-
|
|
119
|
+
}]);
|
|
120
|
+
resolvedOptions.includePrismaMigrations = prismaAnswer.includePrismaMigrations;
|
|
121
|
+
} else {
|
|
122
|
+
resolvedOptions.includePrismaMigrations = Boolean(resolvedOptions.includePrismaMigrations);
|
|
109
123
|
}
|
|
110
124
|
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
...options,
|
|
114
|
-
appName: options.appName || answers.appName,
|
|
115
|
-
db: options.db || answers.db,
|
|
116
|
-
useNpm: options.useNpm || answers.useNpm,
|
|
117
|
-
includePrismaMigrations: options.includePrismaMigrations || answers.includePrismaMigrations,
|
|
118
|
-
};
|
|
125
|
+
return resolvedOptions;
|
|
119
126
|
}
|
|
120
127
|
|
|
121
128
|
function checkNodeVersion(minRequiredVersion = 20) {
|
|
@@ -134,6 +141,15 @@ function parseConnectionString(dbUrl) {
|
|
|
134
141
|
return new ConnectionString(dbUrl);
|
|
135
142
|
}
|
|
136
143
|
|
|
144
|
+
function isPrismaMigrationDbUrl(dbUrl) {
|
|
145
|
+
try {
|
|
146
|
+
const connectionString = parseConnectionString(dbUrl);
|
|
147
|
+
return PRISMA_MIGRATION_DB_PROTOCOLS.includes(connectionString.protocol);
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
137
153
|
function detectDbProvider(protocol) {
|
|
138
154
|
if (protocol.startsWith('sqlite')) {
|
|
139
155
|
return 'sqlite';
|
|
@@ -143,25 +159,27 @@ function detectDbProvider(protocol) {
|
|
|
143
159
|
return 'mongodb';
|
|
144
160
|
} else if (protocol.startsWith('mysql')) {
|
|
145
161
|
return 'mysql';
|
|
162
|
+
} else if (protocol.startsWith('clickhouse')) {
|
|
163
|
+
return 'clickhouse';
|
|
146
164
|
}
|
|
147
165
|
|
|
148
|
-
const message = `Unknown database provider for ${protocol}.
|
|
166
|
+
const message = `Unknown database provider for ${protocol}. Supported database URL schemes: ${SUPPORTED_DB_URL_SCHEMES.join(', ')}.`;
|
|
149
167
|
throw new Error(message);
|
|
150
168
|
}
|
|
151
169
|
|
|
152
170
|
function generateDbUrlForPrisma(connectionString) {
|
|
171
|
+
if (!PRISMA_MIGRATION_DB_PROTOCOLS.includes(connectionString.protocol))
|
|
172
|
+
return null;
|
|
153
173
|
if (connectionString.protocol.startsWith('sqlite'))
|
|
154
174
|
return `file:${connectionString.host}`;
|
|
155
|
-
if (connectionString.protocol.startsWith('mongodb'))
|
|
156
|
-
return null;
|
|
157
175
|
return connectionString.toString();
|
|
158
176
|
}
|
|
159
177
|
|
|
160
178
|
function generateDbUrlForPrismaProd(connectionString) {
|
|
179
|
+
if (!PRISMA_MIGRATION_DB_PROTOCOLS.includes(connectionString.protocol))
|
|
180
|
+
return null;
|
|
161
181
|
if (connectionString.protocol.startsWith('sqlite'))
|
|
162
182
|
return `file:/code/db/${connectionString.host}`;
|
|
163
|
-
if (connectionString.protocol.startsWith('mongodb'))
|
|
164
|
-
return null;
|
|
165
183
|
return connectionString.toString();
|
|
166
184
|
}
|
|
167
185
|
|
|
@@ -400,7 +418,7 @@ async function writeTemplateFiles(dirname, cwd, useNpm, includePrismaMigrations,
|
|
|
400
418
|
data: {
|
|
401
419
|
appName,
|
|
402
420
|
adminforthVersion: adminforthVersion,
|
|
403
|
-
includePrismaMigrations,
|
|
421
|
+
includePrismaMigrations: Boolean(resolvedPrismaDbUrl),
|
|
404
422
|
},
|
|
405
423
|
},
|
|
406
424
|
{
|
|
@@ -425,7 +443,7 @@ async function writeTemplateFiles(dirname, cwd, useNpm, includePrismaMigrations,
|
|
|
425
443
|
)
|
|
426
444
|
}
|
|
427
445
|
|
|
428
|
-
if (
|
|
446
|
+
if (resolvedPrismaDbUrl) {
|
|
429
447
|
templateTasks.push(
|
|
430
448
|
{
|
|
431
449
|
src: 'schema.prisma.hbs',
|
|
@@ -506,7 +524,7 @@ function generateFinalInstructionsPnpm(skipPrismaSetup, options) {
|
|
|
506
524
|
${chalk.dim('// Go to the project directory')}
|
|
507
525
|
${chalk.dim('$')}${chalk.cyan(` cd ${options.appName}`)}\n`;
|
|
508
526
|
|
|
509
|
-
if (options.includePrismaMigrations)
|
|
527
|
+
if (options.includePrismaMigrations && !skipPrismaSetup)
|
|
510
528
|
instruction += `
|
|
511
529
|
${chalk.dim('// Generate and apply initial migration')}
|
|
512
530
|
${chalk.dim('$')}${chalk.cyan(' pnpm makemigration --name init && pnpm migrate:local')}\n`;
|
|
@@ -528,7 +546,7 @@ function generateFinalInstructionsNpm(skipPrismaSetup, options) {
|
|
|
528
546
|
${chalk.dim('// Go to the project directory')}
|
|
529
547
|
${chalk.dim('$')}${chalk.cyan(` cd ${options.appName}`)}\n`;
|
|
530
548
|
|
|
531
|
-
if (options.includePrismaMigrations)
|
|
549
|
+
if (options.includePrismaMigrations && !skipPrismaSetup)
|
|
532
550
|
instruction += `
|
|
533
551
|
${chalk.dim('// Generate and apply initial migration')}
|
|
534
552
|
${chalk.dim('$')}${chalk.cyan(' npm run makemigration -- --name init && npm run migrate:local')}\n`;
|