add flutter-app tpl

This commit is contained in:
Chen Asraf
2022-10-28 18:39:19 +03:00
parent 39f380a300
commit 65a3d33fd9
7 changed files with 99 additions and 8 deletions

View File

@@ -0,0 +1,20 @@
script_runner:
scripts:
- build:apk: flutter build apk
- name: get-version
cmd: dart scripts/get_version.dart
suppress_header_output: true
- name: get-name
cmd: dart scripts/get_name.dart
suppress_header_output: true
- push: 'version=$(get-version); name=$(get-name); echo "Pushing ${name}-$version.apk"; adb push build/app/outputs/flutter-apk/app-release.apk /sdcard/Download/${name}-${version}.apk'
- install: adb install build/app/outputs/flutter-apk/app-release.apk
- to-device: build:apk && push && install
- auto-fix: dart fix --apply
- format: flutter format -l 100 --fix lib/ test/
- gen:page: npx simple-scaffold@latest -t templates/page -o lib/modules -s true
- gen:model: npx simple-scaffold@latest -t templates/model -o lib/models -s false
- gen:widget: npx simple-scaffold@latest -t templates/widget -o lib/widgets -s false
- gen:icons: flutter pub run icons_launcher:create

View File

@@ -0,0 +1,11 @@
class {{pascalCase name}} {
//
factory {{pascalCase name}}.fromJson(Map<String,dynamic> json) => throw UnimplementedError();
Map<String,dynamic> toJson() {
throw UnimplementedError();
}
{{pascalCase name}} copyWith() => throw UnimplementedError();
}

View File

@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
class {{pascalCase name}}Page extends StatelessWidget {
const {{pascalCase name}}Page({super.key});
@override
Widget build(BuildContext context) {
return Container();
}
}

View File

@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';
class {{pascalCase name}} extends StatelessWidget {
const {{pascalCase name}}({super.key});
@override
Widget build(BuildContext context) {
return Container();
}
}

View File

@@ -0,0 +1,15 @@
import 'dart:io';
void main() {
// get version from pubspec.yaml
final pubspecFile = File('pubspec.yaml');
final version = pubspecFile
.readAsStringSync()
.split('\n')
.firstWhere((x) => x.startsWith('name:'))
.split(':')
.last
.trim();
// ignore: avoid_print
print(version);
}

View File

@@ -0,0 +1,15 @@
import 'dart:io';
void main() {
// get version from pubspec.yaml
final pubspecFile = File('pubspec.yaml');
final version = pubspecFile
.readAsStringSync()
.split('\n')
.firstWhere((x) => x.startsWith('version:'))
.split(':')
.last
.trim();
// ignore: avoid_print
print(version);
}

View File

@@ -1,10 +1,11 @@
SCAFFOLDS_DIR="$DOTFILES/scaffolds"
tpl() {
case $1 in
tpl_name="$1"
shift
case $tpl_name in
nextjs | cra)
tpl_name="$1"
tpl_data=""
shift
case $tpl_name in
nextjs)
tpl_data='{"nextComponents":true}'
@@ -33,17 +34,26 @@ tpl() {
prettier -w "**/*.{js,jsx,ts,tsx,json,html}"
echo_gray "Done"
;;
editorfiles)
shift
ef | editorfiles)
tpl_name="editorfiles"
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/editorfiles" -o . - $@
;;
fl | flutter | flutter-app)
shift
tpl_name="flutter-app"
echo_cyan "Creating app '$@'..."
flutter create $@
flutter pub get firebase_core cloud_firestore firebase_crashlytics firebase_remote_config firebase_auth provider shared_preferences google_sign_in sign_in_with_apple dynamic_themes cached_network_image wakelock intl intl_generator
cd $1
echo_cyan "Installing packages..."
flutter pub add firebase_core cloud_firestore firebase_crashlytics firebase_remote_config firebase_auth provider shared_preferences google_sign_in sign_in_with_apple dynamic_themes cached_network_image wakelock intl intl_generator
echo_cyan "Copying files..."
npx -y simple-scaffold@latest -t "$SCAFFOLDS_DIR/$tpl_name" -o ./ $@
cp -R $SCAFFOLDS_DIR/_subs/$tpl_name/ ./
echo_cyan "Updating pubspec.yaml..."
echo "$(cat $SCAFFOLDS_DIR/_merge/$tpl_name/pubspec.yaml)" >>./pubspec.yaml
echo_cyan "Done"
;;
*)
echo_red "Usage: tpl [nextjs|cra|editorfiles|flutter-app]]"
echo_red "Usage: tpl [nextjs|cra|editorfiles|flutter-app]"
;;
esac
}