Skip to content

Commit 78bd21a

Browse files
author
serverpod_cloud
committed
feat: 9da2102f820d1ee77fddd69741eaaada9772ddb5
1 parent 3612d3f commit 78bd21a

3 files changed

Lines changed: 305 additions & 42 deletions

File tree

serverpod_cloud_cli/lib/commands/launch/launch.dart

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ abstract class Launch {
6666
throw StateError('ConfigFilePath must be set.');
6767
}
6868

69+
await suggestCodeGenerationPreDeployHook(
70+
logger,
71+
projectSetup,
72+
configFilePath,
73+
);
74+
6975
await suggestFlutterBuildPreDeployHook(
7076
logger,
7177
projectSetup,
@@ -394,6 +400,32 @@ The default API domain will be: <project-id>.api.serverpod.space
394400
projectSetup.suggestedPreDeployScripts.add(flutterBuildHook);
395401
}
396402

403+
static Future<void> suggestCodeGenerationPreDeployHook(
404+
final CommandLogger logger,
405+
final ProjectLaunch projectSetup,
406+
final String configFilePath,
407+
) async {
408+
ScloudConfig? existingConfig;
409+
try {
410+
existingConfig = ScloudConfigIO.readFromFile(configFilePath);
411+
} catch (_) {
412+
logger.debug('Failed to read config file at $configFilePath');
413+
}
414+
415+
final codeGenerationHook = 'serverpod generate';
416+
417+
final existingPreDeploy = existingConfig?.scripts.preDeploy ?? [];
418+
if (existingPreDeploy.contains(codeGenerationHook)) return;
419+
420+
final shouldAdd = await logger.confirm(
421+
'Would you like to run code generation (`serverpod generate`) before deploy?',
422+
defaultValue: true,
423+
);
424+
425+
if (!shouldAdd) return;
426+
projectSetup.suggestedPreDeployScripts.add(codeGenerationHook);
427+
}
428+
397429
static Future<void> confirmSetupAndContinue(
398430
final CommandLogger logger,
399431
final ProjectLaunch projectSetup,
@@ -597,7 +629,14 @@ class ProjectLaunch {
597629
] else
598630
['Existing project id', projectId],
599631
['Perform deploy', performDeploy == true ? 'yes' : 'no'],
600-
['Add build hook', suggestedPreDeployScripts.isNotEmpty ? 'yes' : 'no'],
632+
if (suggestedPreDeployScripts.isNotEmpty) ...[
633+
[
634+
'Pre-deploy hooks',
635+
suggestedPreDeployScripts
636+
.map((final hook) => ' - $hook')
637+
.join('\n'),
638+
],
639+
],
601640
],
602641
columnSeparator: ' ',
603642
).toString();

serverpod_cloud_cli/lib/util/project_files_writer.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ abstract final class ProjectFilesWriter {
4646
),
4747
);
4848
} else {
49+
final existingPreDeploy = config.scripts.preDeploy
50+
.where((final hook) => !suggestedPreDeployScripts.contains(hook))
51+
.toList();
4952
newConfig = config.copyWith(
5053
projectId: projectId,
5154
scripts: config.scripts.copyWith(
52-
preDeploy: [
53-
...config.scripts.preDeploy,
54-
...suggestedPreDeployScripts,
55-
],
55+
preDeploy: [...existingPreDeploy, ...suggestedPreDeployScripts],
5656
),
5757
);
5858
}

0 commit comments

Comments
 (0)