Skip to content

Commit

Permalink
feat: Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mathrunet committed Dec 7, 2022
1 parent 0202401 commit a50d51a
Show file tree
Hide file tree
Showing 18 changed files with 967 additions and 0 deletions.
Binary file added packages/katana_cli/.github/images/icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packages/katana_cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Files and directories created by pub.
.dart_tool/
.packages

# Conventional directory for build output.
build/
3 changes: 3 additions & 0 deletions packages/katana_cli/.pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# See https://dart.dev/tools/pub/publishing#what-files-are-published

/pubspec_overrides.yaml
Empty file.
24 changes: 24 additions & 0 deletions packages/katana_cli/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2020, mathru (https://mathru.net)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the <organization> nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 changes: 25 additions & 0 deletions packages/katana_cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<p align="center">
<a href="https://mathru.net">
<img width="240px" src="https://raw.githubusercontent.com/mathrunet/flutter_masamune/master/.github/images/icon.png" alt="Masamune logo" style="border-radius: 32px"s><br/>
</a>
<h1 align="center">Katana Framework</h1>
</p>

<p align="center">
<a href="https://twitter.com/mathru">
<img src="https://img.shields.io/twitter/follow/mathru.svg?colorA=1da1f2&colorB=&label=Follow%20on%20Twitter&style=flat-square" alt="Follow on Twitter" />
</a>
<a href="https://github.com/invertase/melos">
<img src="https://img.shields.io/badge/maintained%20with-melos-f700ff.svg?style=flat-square" alt="Maintained with Melos" />
</a>
</p>

<p align="center">
<a href="https://www.buymeacoffee.com/mathru"><img src="https://img.buymeacoffee.com/button-api/?text=Buy me a coffee&emoji=&slug=mathru&button_colour=FF5F5F&font_colour=ffffff&font_family=Poppins&outline_colour=000000&coffee_colour=FFDD00" width="136" /></a>
</p>

---

[[YouTube]](https://www.youtube.com/c/mathrunetchannel) | [[Packages]](https://pub.dev/publishers/mathru.net/packages) | [[Twitter]](https://twitter.com/mathru) | [[LinkedIn]](https://www.linkedin.com/in/mathrunet/)

---
105 changes: 105 additions & 0 deletions packages/katana_cli/bin/command/create.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
part of katana_cli;

/// Create a new Flutter project.
///
/// 新しいFlutterプロジェクトを作成します。
class CreateCliCommand extends CliCommand {
/// Create a new Flutter project.
///
/// 新しいFlutterプロジェクトを作成します。
const CreateCliCommand();

@override
String get description =>
"Create a new Flutter project. 新しいFlutterプロジェクトを作成します。";

@override
Future<void> exec(Map yaml, List<String> args) async {
final bin = yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
if (args.length < 2 || args[1].isEmpty) {
print(
"Please provide the name of the package.\r\nパッケージ名を記載してください。\r\n\r\nkatana create [package name]",
);
return;
}
final packageName = args[1];
final projectName = packageName.split(".").lastOrNull;
final domain = packageName
.split(".")
.sublist(0, packageName.split(".").length - 1)
.join(".");
if (projectName.isEmpty || domain.isEmpty) {
print(
"The format of the package name should be specified in the following format.\r\nパッケージ名の形式は下記の形式で指定してください。\r\n\r\n[Domain].[ProjectName]\r\ne.g. net.mathru.website",
);
return;
}
await Process.start(
flutter,
[
"create",
"--org",
domain,
"--project-name",
projectName!,
".",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
flutter,
[
"pub",
"add",
"freezed_annotation",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
flutter,
[
"pub",
"add",
"json_annotation",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
flutter,
[
"pub",
"add",
"--dev",
"build_runner",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
flutter,
[
"pub",
"add",
"--dev",
"freezed",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
flutter,
[
"pub",
"add",
"--dev",
"json_serializable",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
}
}
43 changes: 43 additions & 0 deletions packages/katana_cli/bin/command/format.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
part of katana_cli;

/// Dart file formatting.
///
/// Dartファイルのフォーマッティングを行います。
class FormatCliCommand extends CliCommand {
/// Dart file formatting.
///
/// Dartファイルのフォーマッティングを行います。
const FormatCliCommand();

@override
String get description => "Dart file formatting. Dartファイルのフォーマッティングを行います。";

@override
Future<void> exec(Map yaml, List<String> args) async {
final bin = yaml.getAsMap("bin");
final dart = bin.get("dart", "dart");
final melos = bin.get("melos", "melos");
if (File("melos.yaml").existsSync()) {
await Process.start(
melos,
[
"exec",
"--",
"$dart format .",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
} else {
await Process.start(
dart,
[
"format",
".",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
}
}
}
70 changes: 70 additions & 0 deletions packages/katana_cli/bin/command/generate.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
part of katana_cli;

/// Start Dart's build_runner to automatically generate code.
///
/// Dartのbuild_runnerを起動してコードを自動生成します。
class GenerateCliCommand extends CliCommand {
/// Start Dart's build_runner to automatically generate code.
///
/// Dartのbuild_runnerを起動してコードを自動生成します。
const GenerateCliCommand();

@override
String get description =>
"Start Dart's build_runner to automatically generate code. Dartのbuild_runnerを起動してコードを自動生成します。";

@override
Future<void> exec(Map yaml, List<String> args) async {
final bin = yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
final melos = bin.get("melos", "melos");
if (File("melos.yaml").existsSync()) {
await Process.start(
melos,
[
"exec",
"--",
"$flutter packages pub run build_runner clean",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
melos,
[
"exec",
"--",
"$flutter packages pub run build_runner build --delete-conflicting-outputs",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
} else {
await Process.start(
flutter,
[
"packages",
"pub",
"run",
"build_runner",
"clean",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
await Process.start(
flutter,
[
"packages",
"pub",
"run",
"build_runner",
"build",
"--delete-conflicting-outputs",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
}
}
}
35 changes: 35 additions & 0 deletions packages/katana_cli/bin/command/publish.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
part of katana_cli;

/// Deploy the Dart package to the pub.
///
/// Dartパッケージのpubへのデプロイを行います。
class PublishCliCommand extends CliCommand {
/// Deploy the Dart package to the pub.
///
/// Dartパッケージのpubへのデプロイを行います。
const PublishCliCommand();

@override
String get description =>
"Deploy the Dart package to the pub. Dartパッケージのpubへのデプロイを行います。";

@override
Future<void> exec(Map yaml, List<String> args) async {
final bin = yaml.getAsMap("bin");
final melos = bin.get("melos", "melos");
if (!File("melos.yaml").existsSync()) {
print("The melos.yaml file does not exist.\r\nmelos.yamlのファイルが存在しません。");
return;
}
await Process.start(
melos,
[
"publish",
"--no-dry-run",
"-y",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
}
}
32 changes: 32 additions & 0 deletions packages/katana_cli/bin/command/submodule.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
part of katana_cli;

/// Recursively clone submodules.
///
/// サブモジュールを再帰的にクローンします。
class SubmoduleCliCommand extends CliCommand {
/// Recursively clone submodules.
///
/// サブモジュールを再帰的にクローンします。
const SubmoduleCliCommand();

@override
String get description =>
"Recursively clone submodules. サブモジュールを再帰的にクローンします。";

@override
Future<void> exec(Map yaml, List<String> args) async {
final bin = yaml.getAsMap("bin");
final git = bin.get("git", "git");
await Process.start(
git,
[
"submodule",
"update",
"--init",
"--recursive",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
}
}
43 changes: 43 additions & 0 deletions packages/katana_cli/bin/command/upgrade.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
part of katana_cli;

/// Upgrade the package.
///
/// パッケージのアップグレードを行います。
class UpgradeCliCommand extends CliCommand {
/// Upgrade the package.
///
/// パッケージのアップグレードを行います。
const UpgradeCliCommand();

@override
String get description => "Upgrade the package. パッケージのアップグレードを行います。";

@override
Future<void> exec(Map yaml, List<String> args) async {
final bin = yaml.getAsMap("bin");
final flutter = bin.get("flutter", "flutter");
final melos = bin.get("melos", "melos");
if (File("melos.yaml").existsSync()) {
await Process.start(
melos,
[
"exec",
"--",
"$flutter pub upgrade",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
} else {
await Process.start(
flutter,
[
"pub",
"upgrade",
],
runInShell: true,
workingDirectory: Directory.current.path,
).print();
}
}
}

0 comments on commit a50d51a

Please sign in to comment.