diff --git a/.gitignore b/.gitignore index d248d88..6100cf3 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,6 @@ app.*.map.json /android/app/app.key linux.AppDir -GPTBox-x86_64.AppImage +GPTBox*.AppImage **/*.bak diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index 42ba02f..2d6a246 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -363,7 +363,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 160; + CURRENT_PROJECT_VERSION = 166; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -494,7 +494,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 160; + CURRENT_PROJECT_VERSION = 166; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; @@ -519,7 +519,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements; - CURRENT_PROJECT_VERSION = 160; + CURRENT_PROJECT_VERSION = 166; DEVELOPMENT_TEAM = BA88US33G6; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; diff --git a/lib/data/res/build.dart b/lib/data/res/build.dart index 59867e0..e9fdbe9 100644 --- a/lib/data/res/build.dart +++ b/lib/data/res/build.dart @@ -2,8 +2,8 @@ class Build { static const String name = "GPTBox"; - static const int build = 160; + static const int build = 166; static const String engine = "3.22.1"; - static const String buildAt = "2024-05-26 00:15:05"; - static const int modifications = 1; + static const String buildAt = "2024-05-29 16:09:39"; + static const int modifications = 5; } diff --git a/make.dart b/make.dart deleted file mode 100755 index 8d62ee2..0000000 --- a/make.dart +++ /dev/null @@ -1,326 +0,0 @@ -#!/usr/bin/env dart -// ignore_for_file: avoid_print - -import 'dart:convert'; -import 'dart:io'; - -const appName = 'GPTBox'; -final appNameLower = appName.toLowerCase(); - -const buildDataFilePath = 'lib/data/res/build.dart'; -const apkPath = 'build/app/outputs/flutter-apk/app-release.apk'; -const appleXCConfigPath = 'Runner.xcodeproj/project.pbxproj'; -const uploadPathPrefix = 'cda:/var/www/res/'; - -var regAppleProjectVer = RegExp(r'CURRENT_PROJECT_VERSION = .+;'); -var regAppleMarketVer = RegExp(r'MARKETING_VERSION = .+'); - -const buildFuncs = { - 'ios': flutterBuildIOS, - 'android': flutterBuildAndroid, - 'mac': flutterBuildMacOS, - 'linux': flutterBuildLinux, - 'windows': flutterBuildWin, - 'web': flutterBuildWeb, -}; - -int? build; - -Future getGitCommitCount() async { - final result = await Process.run('git', ['log', '--oneline']); - build = (result.stdout as String) - .split('\n') - .where((line) => line.isNotEmpty) - .length; -} - -Future writeStaicConfigFile( - Map data, String className, String path) async { - final buffer = StringBuffer(); - buffer.writeln('// This file is generated by ./make.dart'); - buffer.writeln(''); - buffer.writeln('class $className {'); - for (var entry in data.entries) { - final type = entry.value.runtimeType; - final value = json.encode(entry.value); - buffer.writeln(' static const $type ${entry.key} = $value;'); - } - buffer.writeln('}'); - await File(path).writeAsString(buffer.toString()); -} - -Future getGitModificationCount() async { - final result = - await Process.run('git', ['ls-files', '-mo', '--exclude-standard']); - return (result.stdout as String) - .split('\n') - .where((line) => line.isNotEmpty) - .length; -} - -Future getFlutterVersion() async { - final result = await Process.run('flutter', ['--version'], runInShell: true); - final stdout = result.stdout as String; - return stdout.split('\n')[0].split('•')[0].split(' ')[1].trim(); -} - -Future> getBuildData() async { - final data = { - 'name': appName, - 'build': build, - 'engine': await getFlutterVersion(), - 'buildAt': DateTime.now().toString().split('.').firstOrNull, - 'modifications': await getGitModificationCount(), - //'script': await getScriptCommitCount(), - }; - return data; -} - -String jsonEncodeWithIndent(Map json) { - const encoder = JsonEncoder.withIndent(' '); - return encoder.convert(json); -} - -Future updateBuildData() async { - print('Updating BuildData...'); - final data = await getBuildData(); - print(jsonEncodeWithIndent(data)); - await writeStaicConfigFile(data, 'Build', buildDataFilePath); -} - -Future dartFormat() async { - final result = await Process.run('dart', ['format', '.'], runInShell: true); - print(result.stdout); - if (result.exitCode != 0) { - print(result.stderr); - exit(1); - } -} - -Future getFileSha256(String path) async { - final result = await Process.run('shasum', ['-a', '256', path]); - final stdout = result.stdout as String; - return stdout.split(' ')[0]; -} - -Future flutterBuild(String buildType) async { - final args = [ - 'build', - buildType, - '--build-number=$build', - '--build-name=1.0.$build', - ]; - final skslPath = '$buildType.sksl.json'; - if (await File(skslPath).exists()) { - args.add('--bundle-sksl-path=$skslPath'); - } - final isAndroid = 'apk' == buildType; - if (isAndroid) { - // Only arm64 - args.add('--target-platform=android-arm64'); - } - print('\n[$buildType]\nBuilding with args: ${args.join(' ')}'); - final buildResult = await Process.run('flutter', args, runInShell: true); - final exitCode = buildResult.exitCode; - - if (exitCode != 0) { - print(buildResult.stdout); - print(buildResult.stderr); - exit(exitCode); - } -} - -Future flutterBuildIOS() async { - await flutterBuild('ipa'); -} - -Future flutterBuildMacOS() async { - await flutterBuild('macos'); -} - -Future flutterBuildAndroid() async { - await flutterBuild('apk'); - await killJava(); - await scpApk2CDN(); -} - -Future flutterBuildLinux() async { - await flutterBuild('linux'); - const appDirName = 'linux.AppDir'; - // cp -r build/linux/x64/release/bundle/* appName.AppDir - await Process.run('cp', [ - '-r', - 'build/linux/x64/release/bundle', - appDirName, - ]); - // cp -r assets/app_icon.png ServerBox.AppDir - await Process.run('cp', [ - '-r', - './assets/app_icon.png', - appDirName, - ]); - // Create AppRun - const appRun = ''' -#!/bin/sh -cd "\$(dirname "\$0")" -exec ./$appName -'''; - const appRunName = '$appDirName/AppRun'; - await File(appRunName).writeAsString(appRun); - // chmod +x AppRun - await Process.run('chmod', ['+x', appRunName]); - // Create .desktop - const desktop = ''' -[Desktop Entry] -Name=$appName -Exec=$appName -Icon=app_icon -Type=Application -Categories=Utility; -'''; - await File('$appDirName/default.desktop').writeAsString(desktop); - // Run appimagetool - await Process.run('sh', ['-c', 'ARCH=x86_64 appimagetool $appDirName']); - - await scpLinux2CDN(); -} - -Future flutterBuildWin() async { - await flutterBuild('windows'); - //await scpWindows2CDN(); -} - -Future flutterBuildWeb() async { - await flutterBuild('web'); - await scpWeb2CDN(); -} - -Future scpApk2CDN() async { - final result = await Process.run( - 'scp', - [apkPath, '$uploadPathPrefix$appNameLower/${appName}_$build.apk'], - runInShell: true, - ); - if (result.exitCode != 0) { - print(result.stderr); - exit(1); - } -} - -Future scpLinux2CDN() async { - final result = await Process.run( - 'scp', - [ - '$appName-x86_64.AppImage', - '$uploadPathPrefix$appNameLower/${appName}_$build.AppImage', - ], - runInShell: true, - ); - if (result.exitCode != 0) { - print(result.stderr); - exit(1); - } - print('Upload $build.AppImage finished.'); -} - -Future scpWindows2CDN() async { - final result = await Process.run( - 'scp', - [ - './build/windows/runner/Release/$appName.zip', - '$uploadPathPrefix$appNameLower/${appName}_$build.zip', - ], - runInShell: true, - ); - if (result.exitCode != 0) { - print(result.stderr); - exit(1); - } - print('Upload Windows $build.zip finished.'); -} - -Future scpWeb2CDN() async { - final result = await Process.run( - 'scp', - [ - '-r', - './build/web', - 'hk:/var/www/$appNameLower/', - ], - runInShell: true, - ); - if (result.exitCode != 0) { - print(result.stderr); - exit(1); - } - print('Upload Web $build finished.'); -} - -Future changeAppleVersion() async { - for (final path in ['ios', 'macos']) { - final file = File('$path/$appleXCConfigPath'); - final contents = await file.readAsString(); - final newContents = contents - .replaceAll(regAppleMarketVer, 'MARKETING_VERSION = 1.0.$build;') - .replaceAll(regAppleProjectVer, 'CURRENT_PROJECT_VERSION = $build;'); - await file.writeAsString(newContents); - } -} - -Future killJava() async { - if (!Platform.isMacOS) return; - final result = await Process.run('ps', ['-A']); - final lines = (result.stdout as String).split('\n'); - for (final line in lines) { - if (line.contains('java')) { - final pid = line.split(' ')[0]; - print('Killing java process: $pid'); - await Process.run('kill', [pid]); - } - } -} - -void main(List args) async { - if (args.isEmpty) { - print('No action. Exit.'); - return; - } - - final command = args[0]; - switch (command) { - case 'build': - await dartFormat(); - await getGitCommitCount(); - // always change version to avoid dismatch version between different - // platforms - await changeAppleVersion(); - await updateBuildData(); - - final funcs = Function()>[]; - - if (args.length > 1) { - final platforms = args[1]; - for (final platform in platforms.split(',')) { - if (buildFuncs.keys.contains(platform)) { - funcs.add(buildFuncs[platform]!); - } else { - print('Unknown platform: $platform'); - } - } - } else { - funcs.addAll(buildFuncs.values); - } - - final stopwatch = Stopwatch(); - for (final func in funcs) { - stopwatch.start(); - await func(); - print('Build finished in ${stopwatch.elapsed}'); - stopwatch.reset(); - } - break; - default: - print('Unsupported command: $command'); - break; - } -} diff --git a/pubspec.lock b/pubspec.lock index c6a3463..477b74a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -284,10 +284,11 @@ packages: dart_openai: dependency: "direct main" description: - name: dart_openai - sha256: "853bb57fed6a71c3ba0324af5cb40c16d196cf3aa55b91d244964ae4a241ccf1" - url: "https://pub.dev" - source: hosted + path: "." + ref: a2f5f0dc8aea25530bbd38b3004f656b85e730b6 + resolved-ref: a2f5f0dc8aea25530bbd38b3004f656b85e730b6 + url: "https://github.com/lollipopkit/dart_openai" + source: git version: "5.1.0" dart_style: dependency: transitive @@ -397,8 +398,8 @@ packages: dependency: "direct dev" description: path: "." - ref: "52b78c04e73e49b39e2b291241f57c564faab881" - resolved-ref: "52b78c04e73e49b39e2b291241f57c564faab881" + ref: "v1.0.11" + resolved-ref: ead58f6e985600c03cd27fb6563c10b6afa2d640 url: "https://github.com/lollipopkit/fl_build.git" source: git version: "1.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index a62f9a7..035a47d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,7 +11,10 @@ dependencies: sdk: flutter flutter_localizations: sdk: flutter - dart_openai: ^5.1.0 + dart_openai: #^5.1.0 + git: + url: https://github.com/lollipopkit/dart_openai + ref: a2f5f0dc8aea25530bbd38b3004f656b85e730b6 file_picker: ^8.0.0+1 flutter_highlight: # ^0.7.0 git: @@ -39,7 +42,8 @@ dev_dependencies: fl_build: git: url: https://github.com/lollipopkit/fl_build.git - ref: 52b78c04e73e49b39e2b291241f57c564faab881 + ref: v1.0.11 + # path: ../fl_build flutter: generate: true