update grind tool

hmxc
小赖 4 years ago
parent e2214be982
commit 783b0fc48a

@ -838,7 +838,7 @@ packages:
source: hosted source: hosted
version: "5.0.0" version: "5.0.0"
pub_semver: pub_semver:
dependency: transitive dependency: "direct dev"
description: description:
name: pub_semver name: pub_semver
url: "https://pub.flutter-io.cn" url: "https://pub.flutter-io.cn"
@ -1174,7 +1174,7 @@ packages:
source: hosted source: hosted
version: "5.1.0" version: "5.1.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"

@ -2,10 +2,10 @@ name: aku_community
description: A new Flutter project. description: A new Flutter project.
publish_to: "none" publish_to: "none"
version: 1.1.21-dev+27 version: 1.2.0-dev+37
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
@ -77,6 +77,8 @@ dev_dependencies:
flutter_native_splash: ^1.1.8+4 flutter_native_splash: ^1.1.8+4
json_serializable: ^4.1.1 json_serializable: ^4.1.1
build_runner: ^2.0.2 build_runner: ^2.0.2
yaml: ^3.1.0
pub_semver: ^2.0.0
flutter: flutter:
uses-material-design: true uses-material-design: true

@ -0,0 +1,28 @@
part of './grind.dart';
@Task('打包Android项目')
buildApk() async {
await runAsync(
'flutter',
arguments: [
'build',
'apk',
'--target-platform=android-arm64',
'--dart-define',
'BUILD_TYPE=PRODUCT',
],
);
}
@Task('打包iOS项目')
buildIos() async {
await runAsync(
'flutter',
arguments: [
'build',
'ios',
'--dart-define',
'BUILD_TYPE=PRODUCT',
],
);
}

@ -0,0 +1,26 @@
part of 'grind.dart';
@Task('import 排序')
void sort() {
Pub.run('import_sorter:main');
}
@Task('格式化dart代码')
void format() {
DartFmt.format(libDir);
}
@Task('自动提交修改')
@Depends(sort, format)
void git() {
log(' commit to git');
run(
'git',
arguments: [
'commit',
'-a',
'-m',
'[auto task] sort & format',
],
);
}

@ -1,61 +1,28 @@
import 'dart:io';
import 'package:grinder/grinder.dart'; import 'package:grinder/grinder.dart';
import 'package:path/path.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:yaml/yaml.dart';
main(args) => grind(args); import 'version_tool.dart';
@Task() part '_build.dart';
test() => new TestRunner().testAsync(); part '_project_manage.dart';
@Task() main(args) => grind(args);
buildApk() async {
await runAsync(
'flutter',
arguments: [
'build',
'apk',
'--target-platform=android-arm64',
'--dart-define',
'BUILD_TYPE=PRODUCT',
],
);
}
@Task('build ios')
buildIos() async {
await runAsync(
'flutter',
arguments: [
'build',
'ios',
'--dart-define',
'BUILD_TYPE=PRODUCT',
],
);
}
@Task()
clean() => defaultClean();
@Task() @Task('add version number')
void sort() { void addVersion() async {
Pub.run('import_sorter:main'); 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'];
//rename version
@Task() Version resultVersion = VersionTool.fromText(version).nextMinorTag('dev');
void format() {
DartFmt.format(libDir);
}
@Task('auto sort and format code') String result = yamlContent.replaceFirst(version, resultVersion.toString());
@Depends(sort, format) await File(yamlPath).writeAsString(result);
void git() {
log(' commit to git');
run(
'git',
arguments: [
'commit',
'-a',
'-m',
'[auto task] sort & format',
],
);
} }

@ -0,0 +1,59 @@
import 'package:pub_semver/pub_semver.dart';
enum VersionNumber {
MAJOR,
MINOR,
PATCH,
}
class VersionTool {
Version version;
VersionTool(this.version);
VersionTool.fromText(String text) : version = Version.parse(text);
Version get nextMajor => _addBuildNumber(VersionNumber.MAJOR);
Version get nextMinor => _addBuildNumber(VersionNumber.MINOR);
Version get nextPatch => _addBuildNumber(VersionNumber.PATCH);
Version nextMajorTag(String tag) => _addBuildNumber(
VersionNumber.MAJOR,
tag: tag,
);
Version nextMinorTag(String tag) => _addBuildNumber(
VersionNumber.MINOR,
tag: tag,
);
Version nextPatchTag(String tag) => _addBuildNumber(
VersionNumber.PATCH,
tag: tag,
);
Version _addBuildNumber(VersionNumber type, {String? tag}) {
switch (type) {
case VersionNumber.MAJOR:
return Version(
version.major,
version.minor,
version.patch + 1,
pre: tag,
build: '${(version.build.first as int) + 1}',
);
case VersionNumber.MINOR:
return Version(
version.major,
version.minor + 1,
0,
pre: tag,
build: '${(version.build.first as int) + 1}',
);
case VersionNumber.PATCH:
return Version(
version.major + 1,
0,
0,
pre: tag,
build: '${(version.build.first as int) + 1}',
);
}
}
}
Loading…
Cancel
Save