Skip to content

Commit e3b9efc

Browse files
authored
Merge pull request #2 from yardexx/release/v0.0.1-dev.2
Release/v0.0.1 dev.2
2 parents 8dbfd87 + d7d079d commit e3b9efc

File tree

5 files changed

+96
-22
lines changed

5 files changed

+96
-22
lines changed

README.md

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
</p>
88

99
<p align="center">
10-
A brick to automate configuration of freeRASP <a href="https://pub.dev/packages/freerasp">freeRASP</a>.
10+
A brick for configuration generation and automatic setup for <a href="https://pub.dev/packages/freerasp">freeRASP</a>.
1111
</p>
1212

13-
> 🚧 This brick experimental and not stable! Changes to API reserved. 🚧
13+
> 🚧 This brick is experimental and not stable! Changes to API reserved. 🚧
1414
1515
## Overview
1616
Setting up freeRASP can be quite tedious and repetitive. freerasp_brick provides you error-prone
@@ -21,6 +21,19 @@ way to create configuration.
2121
- 🎯 Dependency check using `pub get`
2222
- 🔧 Fix apply using `dart fix`
2323

24+
## How to add ➕
25+
This brick is currently **NOT** available on [brickhub.dev](https://brickhub.dev/).
26+
27+
For now, you can add via git-url:
28+
```
29+
mason add --git-url https://github.com/yardexx/freerasp_brick freerasp_brick
30+
```
31+
32+
Globally available:
33+
```
34+
mason add -g --git-url https://github.com/yardexx/freerasp_brick freerasp_brick
35+
```
36+
2437
## How to use 🚀
2538

2639
Generate configuration:
@@ -55,19 +68,32 @@ and provide it in `freerasp.g.dart`;
5568
| pre-gen |||
5669
| post-gen |||
5770

58-
## Getting started with [mason][1] 🧱
71+
## Getting started with [freeRASP][freerasp-pubdev]
72+
- [freeRASP on GitHub][freerasp-github]
73+
- [freeRASP website][freerasp-website]
74+
- [Medium article: freeRASP — In-App protection SDK and app security monitoring service][freerasp-medium]
75+
76+
## Getting started with [mason][mason-github] 🧱
5977

6078
If this is your first touch with mason, please refer to resources to get started:
6179

62-
- [Mason on pub.dev][1]
63-
- [Official Mason Documentation][2]
64-
- [Code generation with Mason Blog][3]
65-
- [Very Good Livestream: Felix Angelov Demos Mason][4]
80+
- [Mason on GitHub][mason-github]
81+
- [Official Mason Documentation][mason-docs]
82+
- [Code generation with Mason Blog][mason-blog]
83+
- [Very Good Livestream: Felix Angelov Demos Mason][mason-yt]
84+
85+
[mason-github]: https://github.com/felangel/mason
86+
87+
[mason-docs]: https://github.com/felangel/mason/tree/master/packages/mason_cli#readme
88+
89+
[mason-blog]: https://verygood.ventures/blog/code-generation-with-mason
90+
91+
[mason-yt]: https://youtu.be/G4PTjA6tpTU
6692

67-
[1]: https://github.com/felangel/mason
93+
[freerasp-github]: https://github.com/talsec/Free-RASP-Flutter
6894

69-
[2]: https://github.com/felangel/mason/tree/master/packages/mason_cli#readme
95+
[freerasp-pubdev]: https://pub.dev/packages/freerasp
7096

71-
[3]: https://verygood.ventures/blog/code-generation-with-mason
97+
[freerasp-website]: https://www.talsec.app/freerasp-in-app-protection-security-talsec
7298

73-
[4]: https://youtu.be/G4PTjA6tpTU
99+
[freerasp-medium]: https://medium.com/geekculture/freerasp-in-app-protection-sdk-and-app-security-monitoring-service-de12d8e49400

__brick__/lib/freerasp/freerasp.g.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// GENERATED FILE
2+
// Generated using mason
3+
// mason • lay the foundation!
4+
15
import 'package:freerasp/talsec_app.dart';
26
part 'freerasp_callback.g.dart';
37

__brick__/lib/freerasp/freerasp_callback.g.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// GENERATED FILE
2+
// Generated using mason
3+
// mason • lay the foundation!
4+
15
part of 'freerasp.g.dart';
26

37
final callback = TalsecCallback({{#android}}

hooks/post_gen.dart

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,40 @@ const String flutterBuild = 'lib';
88
void run(HookContext context) async {
99
final logger = context.logger;
1010

11-
await _runPub(logger);
11+
await _runPubAdd(logger);
12+
await _runPubGet(logger);
1213
await _runDartFix(logger);
1314
}
1415

15-
Future<void> _runPub(Logger logger) async {
16+
Future<void> _runPubAdd(Logger logger) async {
17+
final progress = logger.progress('Running dart pub add');
18+
final result = await Process.run('dart', ['pub', 'add', 'freerasp']);
19+
20+
if (result.exitCode == 0) {
21+
return progress.complete('freeRASP dependency added successfully');
22+
}
23+
24+
if ((result.stderr as String).contains('is already in "dependencies".')) {
25+
return progress.complete('freeRASP dependency found in pubspec.yaml');
26+
}
27+
28+
return progress.fail(
29+
'Failed to add freeRASP dependency. Please handle it manually.',
30+
);
31+
}
32+
33+
Future<void> _runPubGet(Logger logger) async {
1634
final progress = logger.progress('Running dart pub get');
1735
final result = await Process.run('dart', ['pub', 'get']);
1836
return result.exitCode == 0
19-
? progress.complete('Pub get run successfully')
37+
? progress.complete('Dependencies fetched')
2038
: progress.fail('Pub get failed. Please handle dependency manually.');
2139
}
2240

2341
Future<void> _runDartFix(Logger logger) async {
2442
final progress = logger.progress('Running dart fix --apply');
2543
final result = await Process.run('dart', ['fix', '--apply']);
2644
return result.exitCode == 0
27-
? progress.complete('Fix applied.')
45+
? progress.complete('Fix applied')
2846
: progress.fail('Fix couldn\'t be applied');
2947
}

hooks/pre_gen.dart

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@ void run(HookContext context) {
1414
void parseCupertinoData(HookContext context) {
1515
final logger = context.logger;
1616

17-
final bundleId =
18-
logger.prompt("What's app bundle ID?", defaultValue: defaultAppPackage);
19-
final teamId =
20-
logger.prompt("What's app team ID?", defaultValue: defaultAppPackage);
17+
final bundleId = logger.masonPrompt(
18+
"What's app bundle ID?",
19+
defaultValue: defaultAppPackage,
20+
);
21+
22+
final teamId = logger.masonPrompt(
23+
"What's app team ID?",
24+
defaultValue: defaultAppPackage,
25+
);
2126

2227
context.vars.addAll({
2328
'bundle_id': bundleId,
@@ -28,12 +33,29 @@ void parseCupertinoData(HookContext context) {
2833
void parseAndroidData(HookContext context) {
2934
final logger = context.logger;
3035

31-
final packageName = logger.prompt("What's app package name?",
32-
defaultValue: defaultAppPackage);
33-
final signingHash = logger.prompt("What's app singing hash?");
36+
final packageName = logger.masonPrompt(
37+
"What's app package name?",
38+
defaultValue: defaultAppPackage,
39+
);
40+
41+
final signingHash = logger.masonPrompt("What's app singing hash?");
3442

3543
context.vars.addAll({
3644
'package_name': packageName,
3745
'signing_hash': signingHash,
3846
});
3947
}
48+
49+
extension LoggerX on Logger {
50+
String masonPrompt(
51+
String? message, {
52+
Object? defaultValue,
53+
bool hidden = false,
54+
}) {
55+
return prompt(
56+
'${green.wrap('?')} ${message ?? ''}',
57+
defaultValue: defaultValue,
58+
hidden: hidden,
59+
);
60+
}
61+
}

0 commit comments

Comments
 (0)