Skip to content

Commit

Permalink
fix: Added code zip functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Feb 22, 2023
1 parent b11b9b1 commit eb713db
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/katana_cli/lib/command/code/code.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ library katana_cli.code;
import 'dart:io';

// Project imports:
import 'package:archive/archive_io.dart';
import 'package:katana_cli/katana_cli.dart';
import 'tmp/tmp.dart';

Expand All @@ -24,6 +25,7 @@ part 'stateless.dart';
part 'stateful.dart';
part 'query.dart';
part 'cache.dart';
part 'zip.dart';

class CodeCliCommand extends CliCommandGroup {
const CodeCliCommand();
Expand Down Expand Up @@ -51,5 +53,6 @@ class CodeCliCommand extends CliCommandGroup {
"stateful": CodeStatefulCliCommand(),
"query": CodeQueryCliCommand(),
"cache": CodeCacheCliCommand(),
"zip": CodeZipCliCommand(),
};
}
124 changes: 124 additions & 0 deletions packages/katana_cli/lib/command/code/zip.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
part of katana_cli.code;

/// Output the Dart code in a hardened Zip file.
///
/// DartのコードをZipに固めて出力します。
class CodeZipCliCommand extends CliCommand {
/// Output the Dart code in a hardened Zip file.
///
/// DartのコードをZipに固めて出力します。
const CodeZipCliCommand();

@override
String get description =>
"Output the Dart code in a hardened Zip file. DartのコードをZipに固めて出力します。";

@override
Future<void> exec(ExecContext context) async {
final fileName = Directory.current.path.replaceAll(r"\", "/").last();
final encoder = ZipFileEncoder();
encoder.create("$fileName.zip");
encoder.checkAndAddDirectory(
"./",
[
r"\.class$",
r"\.log$",
r"\.pyc$",
r"\.swp$",
r"\.DS_Store",
r"\.atom/",
r"\.buildlog/",
r"\.history$",
r"\.svn/",
r"\.iml$",
r"\.ipr$",
r"\.iws$",
r"\.idea/",
// r"\.apk$",
r"\.aab$",
r"\.zip$",
r"\.exe$",
r"\.bat$",
r"\.github/",
r"^test/",
r"\.vscode/",
r"doc/api/",
r"ios/Flutter/\.last_build_id",
r"\.dart_tool/",
r"\.flutter-plugins",
r"\.flutter-plugins-dependencies",
r"\.packages$",
r"\.pub-cache/",
r"\.pub/",
r"^build/",
r"lib/generated_plugin_registrant\.dart",
r"app\.[^.]+\.symbols",
r"app\.[^.]+\.map.json",
r"katana\.yaml",
r"lefthook\.yaml",
r"/node_modules/",
r"functions/lib/",
r"\.firebase/",
r"gradle-wrapper\.jar$",
r"/\.gradle$",
r"/captures/",
r"/gradlew",
r"/gradlew\.bat",
r"GeneratedPluginRegistrant\.java",
r"pubspec_overrides\.yaml",
r".mode1v3$",
r"\.mode2v3$",
r"\.moved-aside$",
r"\.pbxuser$",
r"\.perspectivev3$",
r"/.+sync/",
r".sconsign.dblite",
r".tags",
r"/\.vagrant/",
r"/DerivedData/",
r"/Pods/",
r"/\.symlinks/",
r"profile",
r"xcuserdata",
r"/\.generated/",
r"Flutter/App\.framework",
r"Flutter/Flutter\.framework",
r"Flutter/Flutter\.podspec",
r"Flutter/Generated\.xcconfig",
r"Flutter/app\.flx",
r"Flutter/app\.zip",
r"Flutter/flutter_assets/",
r"Flutter/flutter_export_environment\.sh",
r"ServiceDefinitions\.json",
r"Runner/GeneratedPluginRegistrant\.",
],
);
encoder.close();
}
}

extension _ZipFileEncoderExtensions on ZipFileEncoder {
void checkAndAddDirectory(
String dirPath, [
List<String> ignoredList = const [],
]) {
final dir = Directory(dirPath);
final list = dir.listSync(recursive: true);
for (final tmp in list) {
final path = tmp.path.replaceAll(r"\", "/").replaceAll(dirPath, "");
if (path.contains(".git/") || path.contains("/node_modules/")) {
continue;
}
label("Check: $path");
if (ignoredList.any((element) => path.contains(RegExp(element)))) {
continue;
}
final file = File(path);
if (!file.existsSync()) {
continue;
}
label("Contain: $path");
addFile(file, path);
}
}
}

0 comments on commit eb713db

Please sign in to comment.