run method
Performs safe generation using the CLI engine and the provided context
.
Steps:
- Create temp workspace (cross-platform)
- Clone the context with outputDirectory replaced to temp path
- Run generation into temp
- Resolve destination conflicts (replace/copy/cancel)
- Move temp project to final destination
- Always delete temp workspace
Implementation
Future<void> run(
CliContext context, {
String onConflict = 'prompt',
}) async {
final logger = context.logger;
final tempRoot = await Directory.systemTemp.createTemp('smf_cli');
// Generation will happen into: <tempRoot>/<app_name>
final tempContext = CliContext(
name: context.name,
selectedModules: context.selectedModules,
outputDirectory: tempRoot.path,
logger: logger,
strictMode: context.strictMode,
packageName: context.packageName,
initialRoute: context.initialRoute,
moduleResolver: context.moduleResolver,
);
try {
await runCli(tempContext);
final appName = context.name.snakeCase;
final tempProjectDir = p.join(tempRoot.path, appName);
final desiredDest = p.join(context.outputDirectory, appName);
final destinationPath = await _resolveDestinationPath(
desiredDest,
logger: logger,
onConflict: onConflict,
);
logger.detail('📁 Moving project to: $destinationPath');
await _moveDirectoryRobust(tempProjectDir, destinationPath);
logger
..success('✅ Project created at: $destinationPath')
..info('\n')
..info(cyan.wrap('Created an SMF App! ✨'))
..info(
green.wrap('''
+--------------------------------------------------------------+
| Want help or ideas? Join our Discord and meet the community! |
| Star the repo if this helped you - it motivates us ❤️ |
| Docs: https://doc.saymyframe.com |
| Discord: https://saymyframe.com/discord |
| GitHub: https://github.com/saymyframe/smf_flutter_cli |
+--------------------------------------------------------------+
'''),
);
} on Exception catch (e, s) {
_handleCliError(logger, e, s, logger.level == Level.verbose);
} finally {
// Best-effort cleanup
if (tempRoot.existsSync()) {
await tempRoot.delete(recursive: true);
}
}
}