添加打包自动命名脚本

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

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

@ -30,6 +30,8 @@ dependencies:
bot_toast: ^4.0.1
#websocket
web_socket_channel: ^2.1.0
#文件路径
path_provider: ^2.0.1
extended_text: ^5.0.4
@ -82,6 +84,7 @@ dev_dependencies:
#json序列化
json_serializable: ^4.1.1
build_runner: ^2.0.3
yaml: ^3.1.0
flutter:
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:yaml/yaml.dart';
import 'package:path/path.dart';
import 'config.dart';
main(args) => grind(args);
@ -16,30 +23,49 @@ clean() => defaultClean();
@Task()
buildApk() async {
await runAsync('flutter', arguments: [
await runAsync('fvm', arguments: [
'flutter',
'build',
'apk',
'--target-platform=android-arm64',
'--dart-define',
'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()
buildApkDev() async {
await runAsync('flutter', arguments: [
await runAsync('fvm', arguments: [
'flutter',
'build',
'apk',
'--target-platform=android-arm64',
'--dart-define',
'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()
buildIos() async {
await runAsync('flutter',
arguments: ['build', 'ios', '--dart-define', 'BUILD_TYPE=PRODUCT']);
await runAsync('fvm', arguments: [
'flutter',
'build',
'ios',
'--dart-define',
'BUILD_TYPE=PRODUCT'
]);
}
@Task('import 排序')
@ -56,3 +82,13 @@ void format() {
void gen() async {
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