deploy method

  1. @override
Future<void> deploy()
override

Implementation

@override
Future<void> deploy() async {
  print('Build application...');
  final outputPath = await dartBuild.bundle();
  final outputFile = File(outputPath);

  // Create tmp folder
  final appTmpFolder = '$tmpFolder/${dartBuild.appName}';
  await runProcess('mkdir', ['-p', appTmpFolder]);

  try {
    // Extract files to the correct path.
    await runProcess(
      'tar',
      [
        '-xzf',
        outputFile.absolute.path,
        '-C',
        appTmpFolder,
      ],
      printCall: true,
    );

    String sanitizedServerPath = webServerPath;
    if (sanitizedServerPath.endsWith('/')) {
      sanitizedServerPath =
          sanitizedServerPath.substring(0, sanitizedServerPath.length - 1);
    }

    if (preScriptPath != null) {
      final preScriptServerPath = '$sanitizedServerPath/pre-run.sh';
      await serverConnection.upload(
        sourcePath: preScriptPath!,
        webServerPath: preScriptServerPath,
        isDryRun: dartDeploy.isDryRun,
      );
      await serverConnection.run(preScriptServerPath);
    }

    await serverConnection.upload(
      sourcePath: '$appTmpFolder/',
      webServerPath: '$sanitizedServerPath/',
      isDryRun: dartDeploy.isDryRun,
    );

    if (postScriptPath != null) {
      final postScriptServerPath = '$sanitizedServerPath/post-run.sh';
      await serverConnection.upload(
        sourcePath: postScriptPath!,
        webServerPath: postScriptServerPath,
        isDryRun: dartDeploy.isDryRun,
      );
      await serverConnection.run(postScriptServerPath);
    }

    if (dartDeploy.isDryRun) {
      print('Did NOT deploy: Remove `--dry-run` flag for deploying.');
    } else {
      print('Deploying...');
    }
  } catch (_) {
    rethrow;
  } finally {
    // Remove tmp folder
    await runProcess('rm', ['-r', tmpFolder]);
    await serverConnection.dispose();
  }
}