@@ -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 ();
0 commit comments