4 Commits

Author SHA1 Message Date
860056a7e2 chore: revert version bump 2023-11-30 02:14:36 +02:00
83e1e019fe chore: update dependencies 2023-11-30 02:12:15 +02:00
96400d4ed7 chore: upgrade dependencies 2023-10-07 03:36:31 +03:00
f3ce189b83 fix: update dart dependency 2023-10-07 03:08:51 +03:00
11 changed files with 53 additions and 72 deletions

View File

@@ -1,3 +1,7 @@
## 0.1.4
- upgrade dependencies
## 0.1.3 ## 0.1.3
- fix: don't color default log lines - fix: don't color default log lines

View File

@@ -70,6 +70,20 @@ Usage: btool <command> [...args]
-V, --verbose Display debug output -V, --verbose Display debug output
``` ```
#### Example
Here is an example for a simple script that pushes the apk to the device Download folder.
```sh
#!/usr/bin/env sh
name=$(dart run btool get packageName)
version=$(dart run btool get packageVersion)
source="$(pwd)/build/app/outputs/flutter-apk/app-release.apk"
target="/sdcard/Download/$name-$version.apk"
echo "adb push $source $target"
adb push $source $target
```
## Contributing ## Contributing
I am developing this package on my free time, so any support, whether code, issues, or just stars is I am developing this package on my free time, so any support, whether code, issues, or just stars is

View File

@@ -91,8 +91,7 @@ GetSetAction getAction(BToolOptions options, {required FileSystem fs}) {
setter = (value) => setMinSdkVersion(value, fs: fs); setter = (value) => setMinSdkVersion(value, fs: fs);
break; break;
case BToolOptionKey.targetSdkVersion: case BToolOptionKey.targetSdkVersion:
getter = getter = () => getTargetSdkVersion(fs: fs, workingDir: options.workingDir);
() => getTargetSdkVersion(fs: fs, workingDir: options.workingDir);
setter = (value) => setTargetSdkVersion(value, fs: fs); setter = (value) => setTargetSdkVersion(value, fs: fs);
break; break;
case BToolOptionKey.applicationId: case BToolOptionKey.applicationId:

View File

@@ -15,18 +15,12 @@ String getBuildGradleKey(String key, {FileSystem? fs, Directory? workingDir}) {
); );
logger.debug('Getting $key from ${buildFile.path}'); logger.debug('Getting $key from ${buildFile.path}');
final value = buildFile final value =
.readAsStringSync() buildFile.readAsStringSync().split('\n').firstWhere((x) => x.trim().startsWith(key)).trim().split(' ').last;
.split('\n')
.firstWhere((x) => x.trim().startsWith(key))
.trim()
.split(' ')
.last;
return value; return value;
} }
void setBuildGradleKey(String key, String value, void setBuildGradleKey(String key, String value, {FileSystem? fs, Directory? workingDir}) {
{FileSystem? fs, Directory? workingDir}) {
final _fs = fs ?? const LocalFileSystem(); final _fs = fs ?? const LocalFileSystem();
final wd = getCurrentDir(workingDir, fs: _fs).path; final wd = getCurrentDir(workingDir, fs: _fs).path;
final buildFile = _fs.file( final buildFile = _fs.file(
@@ -41,43 +35,36 @@ void setBuildGradleKey(String key, String value,
buildFile.writeAsStringSync(lines.join('\n')); buildFile.writeAsStringSync(lines.join('\n'));
} }
String getMinSdkVersion({FileSystem? fs, Directory? workingDir}) => String getMinSdkVersion({FileSystem? fs, Directory? workingDir}) => getBuildGradleKey(
getBuildGradleKey(
'minSdkVersion', 'minSdkVersion',
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
void setMinSdkVersion(String value, {FileSystem? fs, Directory? workingDir}) => void setMinSdkVersion(String value, {FileSystem? fs, Directory? workingDir}) => setBuildGradleKey(
setBuildGradleKey(
'minSdkVersion', 'minSdkVersion',
value, value,
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
String getTargetSdkVersion({FileSystem? fs, Directory? workingDir}) => String getTargetSdkVersion({FileSystem? fs, Directory? workingDir}) => getBuildGradleKey(
getBuildGradleKey(
'targetSdkVersion', 'targetSdkVersion',
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
void setTargetSdkVersion(String value, void setTargetSdkVersion(String value, {FileSystem? fs, Directory? workingDir}) => setBuildGradleKey(
{FileSystem? fs, Directory? workingDir}) =>
setBuildGradleKey(
'targetSdkVersion', 'targetSdkVersion',
value, value,
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
String getApplicationId({FileSystem? fs, Directory? workingDir}) => String getApplicationId({FileSystem? fs, Directory? workingDir}) => getBuildGradleKey(
getBuildGradleKey(
'applicationId', 'applicationId',
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
).replaceAll('"', ''); ).replaceAll('"', '');
void setApplicationId(String value, {FileSystem? fs, Directory? workingDir}) => void setApplicationId(String value, {FileSystem? fs, Directory? workingDir}) => setBuildGradleKey(
setBuildGradleKey(
'applicationId', 'applicationId',
'"$value"', '"$value"',
fs: fs, fs: fs,

View File

@@ -35,20 +35,16 @@ class Logger {
write(colorize(message.toString(), fg: fg)); write(colorize(message.toString(), fg: fg));
} }
void info(Object message) => void info(Object message) => writeLevel(LogLevel.info, message, fg: Styles.DEFAULT);
writeLevel(LogLevel.info, message, fg: Styles.DEFAULT);
void i(Object message) => info(message); void i(Object message) => info(message);
void warn(Object message) => void warn(Object message) => writeLevel(LogLevel.warn, message, fg: Styles.YELLOW);
writeLevel(LogLevel.warn, message, fg: Styles.YELLOW);
void w(Object message) => warn(message); void w(Object message) => warn(message);
void error(Object message) => void error(Object message) => writeLevel(LogLevel.error, message, fg: Styles.RED);
writeLevel(LogLevel.error, message, fg: Styles.RED);
void e(Object message) => error(message); void e(Object message) => error(message);
void debug(Object message) => void debug(Object message) => writeLevel(LogLevel.debug, message, fg: Styles.LIGHT_BLUE);
writeLevel(LogLevel.debug, message, fg: Styles.LIGHT_BLUE);
void d(Object message) => debug(message); void d(Object message) => debug(message);
} }

View File

@@ -72,9 +72,7 @@ class BToolOptions {
key: BToolOptionKey.applicationId, key: BToolOptionKey.applicationId,
action: BToolAction.get, action: BToolAction.get,
parseResult: res, parseResult: res,
workingDir: res['working-dir'] != null workingDir: res['working-dir'] != null ? _fs.directory(res['working-dir']) : null,
? _fs.directory(res['working-dir'])
: null,
); );
} }
@@ -83,8 +81,7 @@ class BToolOptions {
action: _action, action: _action,
args: _args, args: _args,
value: _value, value: _value,
workingDir: workingDir: res['working-dir'] != null ? _fs.directory(res['working-dir']) : null,
res['working-dir'] != null ? _fs.directory(res['working-dir']) : null,
parseResult: res, parseResult: res,
); );
} }
@@ -96,12 +93,9 @@ class BToolOptions {
final _parser = ArgParser(allowTrailingOptions: true); final _parser = ArgParser(allowTrailingOptions: true);
_parser.addFlag('help', abbr: 'h', negatable: false, help: 'Show help'); _parser.addFlag('help', abbr: 'h', negatable: false, help: 'Show help');
_parser.addFlag('version', _parser.addFlag('version', abbr: 'v', negatable: false, help: 'Show version');
abbr: 'v', negatable: false, help: 'Show version'); _parser.addOption('working-dir', abbr: 'd', help: 'Change working directory of script');
_parser.addOption('working-dir', _parser.addFlag('verbose', abbr: 'V', negatable: false, help: 'Display debug output');
abbr: 'd', help: 'Change working directory of script');
_parser.addFlag('verbose',
abbr: 'V', negatable: false, help: 'Display debug output');
BToolOptions._parser = _parser; BToolOptions._parser = _parser;
return _parser; return _parser;
} }

View File

@@ -12,18 +12,12 @@ String getPubspecKey(String key, {FileSystem? fs, Directory? workingDir}) {
final wd = getCurrentDir(workingDir, fs: _fs).path; final wd = getCurrentDir(workingDir, fs: _fs).path;
final pubspecFile = _fs.file(path.join(wd, 'pubspec.yaml')); final pubspecFile = _fs.file(path.join(wd, 'pubspec.yaml'));
logger.debug('Getting $key from ${pubspecFile.path}'); logger.debug('Getting $key from ${pubspecFile.path}');
final value = pubspecFile final value =
.readAsStringSync() pubspecFile.readAsStringSync().split('\n').firstWhere((x) => x.startsWith('$key:')).split(':').last.trim();
.split('\n')
.firstWhere((x) => x.startsWith('$key:'))
.split(':')
.last
.trim();
return value; return value;
} }
void setPubspecKey(String key, String value, void setPubspecKey(String key, String value, {FileSystem? fs, Directory? workingDir}) {
{FileSystem? fs, Directory? workingDir}) {
final _fs = fs ?? const LocalFileSystem(); final _fs = fs ?? const LocalFileSystem();
final wd = getCurrentDir(workingDir, fs: _fs).path; final wd = getCurrentDir(workingDir, fs: _fs).path;
final pubspecFile = _fs.file(path.join(wd, 'pubspec.yaml')); final pubspecFile = _fs.file(path.join(wd, 'pubspec.yaml'));
@@ -39,22 +33,19 @@ String getPackageName({FileSystem? fs, Directory? workingDir}) => getPubspecKey(
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
void setPackageName(String value, {FileSystem? fs, Directory? workingDir}) => void setPackageName(String value, {FileSystem? fs, Directory? workingDir}) => setPubspecKey(
setPubspecKey(
'name', 'name',
value, value,
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
String getPackageVersion({FileSystem? fs, Directory? workingDir}) => String getPackageVersion({FileSystem? fs, Directory? workingDir}) => getPubspecKey(
getPubspecKey(
'version', 'version',
fs: fs, fs: fs,
workingDir: workingDir, workingDir: workingDir,
); );
void setPackageVersion(String value, {FileSystem? fs, Directory? workingDir}) => void setPackageVersion(String value, {FileSystem? fs, Directory? workingDir}) => setPubspecKey(
setPubspecKey(
'version', 'version',
value, value,
fs: fs, fs: fs,

View File

@@ -1,19 +1,19 @@
name: btool name: btool
description: Generic build helper tools for Flutter/Dart such as manipulating version, package name or application ID description: Generic build helper tools for Flutter/Dart such as manipulating version, package name or application ID
version: 0.1.3 version: 0.1.4
homepage: 'https://github.com/chenasraf/btool' homepage: 'https://github.com/chenasraf/btool'
executables: executables:
btool: btool btool: btool
environment: environment:
sdk: '>=2.18.0 <3.0.0' sdk: '>=2.18.0 <4.0.0'
dependencies: dependencies:
args: ^2.3.1 args: ^2.4.2
colorize: ^3.0.0 colorize: ^3.0.0
file: ^6.1.4 file: ^7.0.0
path: ^1.8.2 path: ^1.8.3
dev_dependencies: dev_dependencies:
build: build:
@@ -26,6 +26,6 @@ script_runner:
- activate-local: 'dart pub global activate --source path ./' - activate-local: 'dart pub global activate --source path ./'
- activate-global: 'dart pub global activate btool' - activate-global: 'dart pub global activate btool'
- auto-fix: dart fix --apply - auto-fix: dart fix --apply
- publish: dart pub publish -f - publish: dart format .; dart pub publish; format
- watch: dart run build_runner watch --delete-conflicting-outputs - watch: dart run build_runner watch --delete-conflicting-outputs
- format: dart format . - format: dart format --line-length 120 .

View File

@@ -9,8 +9,7 @@ void main() {
late FileSystem fs; late FileSystem fs;
setUp(() { setUp(() {
fs = MemoryFileSystem(); fs = MemoryFileSystem();
var dir = var dir = path.join(fs.currentDirectory.path, 'android', 'app', 'build.gradle');
path.join(fs.currentDirectory.path, 'android', 'app', 'build.gradle');
fs.directory(path.dirname(dir)).createSync(recursive: true); fs.directory(path.dirname(dir)).createSync(recursive: true);
fs fs
.file( .file(

View File

@@ -9,9 +9,7 @@ void main() {
late FileSystem fs; late FileSystem fs;
setUp(() { setUp(() {
fs = MemoryFileSystem(); fs = MemoryFileSystem();
fs fs.file(path.join(fs.currentDirectory.path, 'pubspec.yaml')).writeAsStringSync(
.file(path.join(fs.currentDirectory.path, 'pubspec.yaml'))
.writeAsStringSync(
[ [
'name: test_app', 'name: test_app',
'version: 1.0.0+1', 'version: 1.0.0+1',

View File

@@ -8,8 +8,7 @@ class BinBuilder implements Builder {
FutureOr<void> build(BuildStep buildStep) async { FutureOr<void> build(BuildStep buildStep) async {
final contents = await buildStep.readAsString(buildStep.inputId); final contents = await buildStep.readAsString(buildStep.inputId);
return buildStep.writeAsString( return buildStep.writeAsString(
AssetId(buildStep.inputId.package, AssetId(buildStep.inputId.package, buildStep.inputId.path.replaceFirst('.bin.dart', '.dart')),
buildStep.inputId.path.replaceFirst('.bin.dart', '.dart')),
contents.replaceAll('{{VERSION}}', getPackageVersion()), contents.replaceAll('{{VERSION}}', getPackageVersion()),
); );
} }