Skip to content

Commit

Permalink
fix: Add Icon.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Jan 18, 2023
1 parent 48a2120 commit f3d62ab
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 131 deletions.
105 changes: 105 additions & 0 deletions packages/katana_cli/lib/action/app/icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'dart:io';

import 'package:image/image.dart';
import 'package:katana_cli/katana_cli.dart';

final _sizeList = {
"document/store/icon.png": 512,
"android/app/src/main/res/mipmap-hdpi/ic_launcher.png": 72,
"android/app/src/main/res/mipmap-mdpi/ic_launcher.png": 48,
"android/app/src/main/res/mipmap-xhdpi/ic_launcher.png": 96,
"android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png": 144,
"android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png": 192,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png": 20,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png": 40,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png": 60,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png": 29,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png": 58,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png": 87,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png": 40,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png": 80,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png": 120,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png": 120,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png": 180,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png": 76,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png": 152,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png":
167,
"ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png":
1024,
};

/// Automatically creates icon files for applications.
///
/// アプリ用のアイコンファイルを自動作成します。
class AppIconCliAction extends CliCommand with CliActionMixin {
/// Automatically creates icon files for applications.
///
/// アプリ用のアイコンファイルを自動作成します。
const AppIconCliAction();

@override
String get description =>
"Automatically creates icon files for applications. アプリ用のアイコンファイルを自動作成します。";

@override
bool checkEnabled(ExecContext context) {
final value = context.yaml.getAsMap("app").getAsMap("icon");
final enabled = value.get("enable", false);
final path = value.get("path", "");
if (!enabled || path.isEmpty) {
return false;
}
return true;
}

@override
Future<void> exec(ExecContext context) async {
final app = context.yaml.getAsMap("app");
if (app.isEmpty) {
print("The item [app] is missing. Please add an item.");
return;
}
final icon = app.getAsMap("icon");
if (icon.isEmpty) {
print("The item [app]->[icon] is missing. Please add an item.");
return;
}
final path = icon.get("path", "");
if (path.isEmpty) {
print(
"The item [app]->[icon]->[path] is missing. Please provide the path to the original icon.",
);
return;
}
label("Load a file from $path");
final iconFile = File(path);
if (!iconFile.existsSync()) {
print("Icon file not found in $path.");
return;
}
final iconImage = decodeImage(iconFile.readAsBytesSync())!;
if (iconImage.width != 1024 || iconImage.height != 1024) {
print("Icon files should be 1024 x 1024.");
return;
}
for (final tmp in _sizeList.entries) {
label("Resize & Save to ${tmp.key}");
final dir = Directory(tmp.key.parentPath());
if (!dir.existsSync()) {
await dir.create(recursive: true);
}
final file = File(tmp.key);
if (file.existsSync()) {
await file.delete();
}
final resized = copyResize(
iconImage,
height: tmp.value,
width: tmp.value,
interpolation: Interpolation.average,
);
await file.writeAsBytes(encodePng(resized, level: 9));
}
}
}
20 changes: 11 additions & 9 deletions packages/katana_cli/lib/command/apply.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:katana_cli/action/app/csr.dart';
import 'package:katana_cli/action/app/icon.dart';
import 'package:katana_cli/action/app/keystore.dart';
import 'package:katana_cli/action/app/p12.dart';
import 'package:katana_cli/action/app/picker.dart';
Expand All @@ -17,15 +18,16 @@ import 'package:katana_cli/katana_cli.dart';
///
/// 実行する順番で並べてください。
const _actions = <CliActionMixin>[
AppSpreadSheetCliAction(),
AppCsrCliAction(),
AppP12CliAction(),
AppKeystoreCliAction(),
AppPickerCliAction(),
FirebaseInitCliAction(),
FirebaseMessagingCliAction(),
GitActionCliAction(),
GitPreCommitCliAction(),
// AppSpreadSheetCliAction(),
// AppCsrCliAction(),
// AppP12CliAction(),
// AppKeystoreCliAction(),
// AppPickerCliAction(),
AppIconCliAction(),
// FirebaseInitCliAction(),
// FirebaseMessagingCliAction(),
// GitActionCliAction(),
// GitPreCommitCliAction(),
];

/// Reflect the settings in katana.yaml in the application project.
Expand Down
121 changes: 2 additions & 119 deletions packages/katana_cli/lib/command/create.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';

import 'package:katana_cli/config.dart';
import 'package:katana_cli/katana_cli.dart';

/// Package to import.
Expand Down Expand Up @@ -202,125 +203,7 @@ class KatanaCliCode extends CliCode {

@override
String body(String path, String baseName, String className) {
return r"""
# Describe the application information.
# アプリケーション情報を記載します。
app:
# Retrieve data from a spreadsheet retrieved by a specific Google Form.
# Please include the URL of the spreadsheet in [url] and the email address you collected in [email].
# 特定のGoogleフォームで取得したスプレッドシートからデータを取得します。
# [url]にスプレッドシートのURL、[email]に収集したメールアドレスを記載してください。
spread_sheet:
enable: false
url:
email:
# Create a `CertificateSigningRequest.certSigningRequest` for iOS.
# Please include your support email address in [email].
# iOS用の`CertificateSigningRequest.certSigningRequest`を作成します。
# [email]にサポート用のEmailアドレスを記載してください。
csr:
enable: false
email:
# Convert the cer file created by Certificate in AppleDeveloperProgram from `CertificateSigningRequest.certSigningRequest` to a p12 file.
# `CertificateSigningRequest.certSigningRequest`からAppleDeveloperProgramのCertificateにて作成されたcerファイルをp12ファイルに変換します。
p12:
enable: false
# Create a keystore for Android.
# Enter the alias of the keystore in [alias], the common name in [name], the organization name in [organization], the state or province in [state], and the country in [country].
# Android用のkeystoreを作成します。
# [alias]にkeystoreのエイリアス、[name]に共通名、[organization]に組織名、[state]に州や都道府県、[country]に国名を入力してください。
keystore:
enable: false
alias:
name:
organization:
state: Tokyo
country: Japan
# Describe the settings for using the file picker.
# Describe the platform for using the picker in [platform]. Specify `any` or `mobile`. Import the picker package for that platform.
# Specify the permission message to use the library in IOS in [permission].
# Please include `en`, `ja`, etc. and write the message in that language there.
# ファイルピッカーを利用するための設定を記述します。
# [platform]にピッカーを利用するためのプラットフォームを記述します。`any`もしくは`mobile`を指定してください。そのプラットフォーム用のピッカーパッケージをインポートします。
# [permission]にIOSでライブラリを利用するための権限許可メッセージを指定します。
# `en`や`ja`などを記載しそこにその言語でのメッセージを記述してください。
picker:
enable: false
platform: any
permission:
en: Use the library for profile images.
# This section contains information related to Firebase.
# Firebase関連の情報を記載します。
firebase:
# Set the Firebase project ID.
# FirebaseのプロジェクトIDを設定します。
project_id:
# Enable Firebase Functions.
# Firebase Functionsを有効にします。
functions:
enable: false
# Configure Firebase Hosting settings.
# Set [use_flutter] to `true` so that all routes point to index.html, and set it to `true` when using Flutter Web.
# Firebase Hostingの設定を行います。
# [use_flutter]を`true`にするとすべてのルートがindex.htmlを向くようになります。Flutter Webを利用する際に`true`にしてください。
hosting:
enable: false
use_flutter: false
# Enable Firebase Messaging.
# Specify ChannelNotificationId for Android in [channel_id].
# Firebase Messagingを有効にします。
# [channel_id]にAndroid用のChannelNotificationIdを指定してください。
messaging:
enable: false
channel_id:
# This section contains information related to Git.
# Git関連の情報を記載します。
git:
# Add secure files to .gitignore.
# If `false`, password files, etc. will be uploaded to Git.
# Please limit your use to private repositories only.
# セキュアなファイルを.gitignoreに追加します。
# `false`にした場合、パスワードファイルなどがGitにアップロードされることになります。
# プライベートレポジトリのみでの利用に限定してください。
ignore_secure_file: true
# Ensure that the dart code is modified and verified before committing.
# lefthand installation is required.
# コミット前にdartコードの修正や確認を行うようにします。
# lefthandのインストールが必要です。
pre_commit:
enable: false
# Github-related information will be described.
# Github関連の情報を記載します。
github:
# Enable Github Actions to perform CI/CD builds on each platform.
# Enter the platform you wish to specify in [platform], separated by spaces.
# Available platforms are `android`, `ios`, `web`, `windows`, `macos`, and `linux`.
# Github Actionsを有効にして各プラットフォームでCI/CDビルドを行うようにします。
# [platform]で指定したいプラットフォームをスペース区切り入力します。
# 使用できるプラットフォームは`android`、`ios`、`web`、`windows`、`macos`、`linux`です。
action:
enable: false
platform: android ios web
ios:
# Copy the Issuer ID listed on the page at https://appstoreconnect.apple.com/access/api.
# https://appstoreconnect.apple.com/access/api のページに記載されているIssuer IDをコピーしてください。
issuer_id:
# Please copy and include your team ID from https://developer.apple.com/account.
# https://developer.apple.com/account のチームIDをコピーして記載してください。
team_id:
""";
return Config.katanaYamlCode;
}
}

Expand Down

0 comments on commit f3d62ab

Please sign in to comment.