From b111df6e2f2d62a72ff1759ac1693af9455d3f27 Mon Sep 17 00:00:00 2001 From: zhangmeng <494089941@qq.com> Date: Thu, 17 Jun 2021 14:40:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BF=AE=E6=94=B9=E5=91=BD=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tool/_build.dart | 13 +++++++++++++ tool/config.dart | 14 ++++++++++++++ tool/grind.dart | 13 ++++++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tool/config.dart diff --git a/tool/_build.dart b/tool/_build.dart index a0c7bffe..79a7e81d 100644 --- a/tool/_build.dart +++ b/tool/_build.dart @@ -12,6 +12,13 @@ buildApk() async { 'BUILD_TYPE=PRODUCT', ], ); + + 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('打包Android项目') @@ -26,6 +33,12 @@ buildApkDev() async { 'BUILD_TYPE=Dev', ], ); + 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('打包iOS项目') diff --git a/tool/config.dart b/tool/config.dart new file mode 100644 index 00000000..59b0abf0 --- /dev/null +++ b/tool/config.dart @@ -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'; +} diff --git a/tool/grind.dart b/tool/grind.dart index 416dc5fa..c6fe3210 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -1,10 +1,11 @@ import 'dart:io'; - +import 'package:common_utils/common_utils.dart'; import 'package:grinder/grinder.dart'; import 'package:path/path.dart'; import 'package:pub_semver/pub_semver.dart'; import 'package:yaml/yaml.dart'; +import 'config.dart'; import 'version_tool.dart'; part '_build.dart'; @@ -26,3 +27,13 @@ void addVersion() async { String result = yamlContent.replaceFirst(version, resultVersion.toString()); await File(yamlPath).writeAsString(result); } + +@Task() +Future 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; +} \ No newline at end of file