添加打包自动命名脚本

hmxc
张萌 3 years ago
parent 42ea0b0c8e
commit 7a6e052e75

@ -724,7 +724,7 @@ packages:
source: hosted source: hosted
version: "0.2.1" version: "0.2.1"
path_provider: path_provider:
dependency: transitive dependency: "direct main"
description: description:
name: path_provider name: path_provider
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
@ -1065,7 +1065,7 @@ packages:
source: hosted source: hosted
version: "0.2.0" version: "0.2.0"
yaml: yaml:
dependency: transitive dependency: "direct dev"
description: description:
name: yaml name: yaml
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"

@ -30,6 +30,8 @@ dependencies:
bot_toast: ^4.0.1 bot_toast: ^4.0.1
#websocket #websocket
web_socket_channel: ^2.1.0 web_socket_channel: ^2.1.0
#文件路径
path_provider: ^2.0.1
extended_text: ^5.0.4 extended_text: ^5.0.4
@ -82,6 +84,7 @@ dev_dependencies:
#json序列化 #json序列化
json_serializable: ^4.1.1 json_serializable: ^4.1.1
build_runner: ^2.0.3 build_runner: ^2.0.3
yaml: ^3.1.0
flutter: flutter:
uses-material-design: true uses-material-design: true

@ -0,0 +1,14 @@
class Config {
///
static const String homeDir = '/users/zhangmeng';
///
static const String packageName = 'aku_community';
///
static String get buildPath =>
'./build/app/outputs/flutter-apk/app-release.apk';
///
static String get buildDir => './build/app/outputs/flutter-apk';
}

@ -1,4 +1,11 @@
import 'dart:io';
import 'package:common_utils/common_utils.dart';
import 'package:grinder/grinder.dart'; import 'package:grinder/grinder.dart';
import 'package:yaml/yaml.dart';
import 'package:path/path.dart';
import 'config.dart';
main(args) => grind(args); main(args) => grind(args);
@ -16,30 +23,49 @@ clean() => defaultClean();
@Task() @Task()
buildApk() async { buildApk() async {
await runAsync('flutter', arguments: [ await runAsync('fvm', arguments: [
'flutter',
'build', 'build',
'apk', 'apk',
'--target-platform=android-arm64', '--target-platform=android-arm64',
'--dart-define', '--dart-define',
'ISPRODUCT=true' 'ISPRODUCT=true'
]); ]);
String date = DateUtil.formatDate(DateTime.now(), format: 'yy_MM_dd_HH_mm');
String version = await getVersion();
await runAsync('mv', arguments: [
Config.buildPath,
'${Config.buildDir}/${Config.packageName}_${version}_release_$date.apk'
]);
} }
@Task() @Task()
buildApkDev() async { buildApkDev() async {
await runAsync('flutter', arguments: [ await runAsync('fvm', arguments: [
'flutter',
'build', 'build',
'apk', 'apk',
'--target-platform=android-arm64', '--target-platform=android-arm64',
'--dart-define', '--dart-define',
'ISPRODUCT=false' 'ISPRODUCT=false'
]); ]);
String date = DateUtil.formatDate(DateTime.now(), format: 'yy_MM_dd_HH_mm');
String version = await getVersion();
await runAsync('mv', arguments: [
Config.buildPath,
'${Config.buildDir}/${Config.packageName}_${version}_beta_$date.apk'
]);
} }
@Task() @Task()
buildIos() async { buildIos() async {
await runAsync('flutter', await runAsync('fvm', arguments: [
arguments: ['build', 'ios', '--dart-define', 'BUILD_TYPE=PRODUCT']); 'flutter',
'build',
'ios',
'--dart-define',
'BUILD_TYPE=PRODUCT'
]);
} }
@Task('import 排序') @Task('import 排序')
@ -56,3 +82,13 @@ void format() {
void gen() async { void gen() async {
await Pub.run('build_runner', arguments: ['build']); await Pub.run('build_runner', arguments: ['build']);
} }
@Task()
Future<String> getVersion() async {
String projectPath = Directory('.').absolute.path;
String yamlPath = join(projectPath, 'pubspec.yaml');
String yamlContent = await File(yamlPath).readAsString();
dynamic content = loadYaml(yamlContent);
String version = content['version'];
return version;
}

Loading…
Cancel
Save