run method

Future<void> run()

Implementation

Future<void> run() async {
  final locations = Locations();
  if (!locations.isValid) {
    throw ArgumentError("Cannot find the plugin source");
  }

  final pluginData = await buildPluginYaml(locations);
  _logger.info('Found plugin "${pluginData['id']}" v${pluginData['version']}');

  final dist = locations.dist(pluginData['id'], pluginData['version']);
  if (dist.existsSync()) {
    _logger.info("Overwriting file ${dist.path}");
    await dist.delete();
  }

  final zipOutput = OutputFileStream(dist.path);
  final zip = ZipEncoder();
  zip.startEncode(zipOutput, level: DeflateLevel.defaultCompression);

  // Write the plugin.yaml.
  zip.add(ArchiveFile.string("plugin.yaml", YamlWriter().write(pluginData)));

  // Write the compiled code.
  if (locations.codeRoot != null && locations.pubspecYaml != null) {
    zip.add(ArchiveFile.bytes("plugin.evc", await compileCode(locations)));
  }

  // Write the rest of static files.
  if (locations.staticPluginRoot != null) {
    for (final f in locations.staticPluginRoot!.listSync(recursive: true)) {
      if (f is File) {
        if (p.isWithin(dist.parent.path, f.path)) continue;
        final path = p.relative(f.path, from: locations.staticPluginRoot!.path);
        if (path == 'plugin.yaml') continue;
        _logger.info('Adding $path');
        zip.add(ArchiveFile.bytes(path, await f.readAsBytes()));
      }
    }
  }

  zip.endEncode();
}