Skip to content

Commit 55cde07

Browse files
committedMar 22, 2023
🚀 Improve codegen.
1 parent d911a79 commit 55cde07

18 files changed

+849
-141
lines changed
 

‎.env

+15-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
# hhh
2-
# hhh \n \r\t abc
3-
4-
5-
# hhh
1+
# type int
62
INT=90898
7-
#hello
8-
DDD=
9-
#word
10-
DOUBLE=90898.909
11-
#hello
12-
BOOL=true
13-
#hhh
14-
15-
BAC=18237
16-
CDB='18237'
17-
CDBD="18237"
3+
SIGNED_INT=-8898
4+
# type double
5+
DOUBLE=3.1415926
6+
SIGNED_DOUBLE=-.123
7+
# type bool
8+
BOOL=false
9+
# type string
10+
STRING=AAA
11+
NO_QUOTE_STRING=ABC9shj"\'\''';';;;'\n\r\thttps://google.com
12+
SINGLE_QUOTE_STRING='AB\r\n\ta\'\"C'
13+
DOUBLE_QUOTE_STRING="ABC"
14+
JSON={"a":1,"b":[1,true,"hello"]}
15+
EMPTY=
16+
EMPTY_COMMENT=#EMPTY

‎.env.prod

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#word
2-
DOUBLE=123456
1+
# covered
2+
BOOL=true
33

4+
# specical
45
QWERTY=-0.343

‎.run/env2dart.dart.run.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<component name="ProjectRunConfigurationManager">
22
<configuration default="false" name="env2dart.dart" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" nameIsGenerated="true">
3+
<option name="arguments" value="-a prod -o lib/env.g.dart -c Prod" />
34
<option name="filePath" value="$PROJECT_DIR$/bin/env2dart.dart" />
45
<option name="workingDirectory" value="$PROJECT_DIR$" />
5-
<method v="2" />
6+
<method v="2">
7+
<option name="RunConfigurationTask" enabled="true" run_configuration_name="gen_antlr" run_configuration_type="ShConfigurationType" />
8+
</method>
69
</configuration>
710
</component>

‎LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright [yyyy] [name of copyright owner]
189+
Copyright 2023 IOTA9STAR
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

‎README-ZH.md

+265-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Env2dart
22

3+
![release](https://img.shields.io/github/v/release/fluttercandies/env2dart) ![Apache License 2.0](https://img.shields.io/github/license/fluttercandies/env2dart) ![open issues](https://img.shields.io/github/issues/fluttercandies/env2dart) ![fork](https://img.shields.io/github/forks/fluttercandies/env2dart?style=social) ![code lines](https://img.shields.io/tokei/lines/github/fluttercandies/env2dart)
4+
35
[English](README.md) | 简体中文
46

57
一种简单的方式将 `.env` 文件生成 `dart` 代码。
@@ -22,11 +24,273 @@ env2dart
2224

2325
```text
2426
-p, --path 指定工作目录,CLI 将在当前目录中查找 .env 文件。
25-
(默认为 "./")
27+
(默认为 "")
2628
-o, --output 指定输出文件路径。
29+
(默认为 "lib/env.g.dart")
2730
-a, --active 指定要使用的环境变量。例如,如果指定了 `-active prod`,CLI 将查找 .env.prod 文件并将其与 .env 文件合并。
2831
-c, --class 指定生成类的名称。
2932
(默认为 "Env")
3033
-h, --help 查看帮助选项。
3134
```
3235

36+
37+
## 示例
38+
39+
<details>
40+
<summary>代码示例</summary>
41+
42+
<details>
43+
<summary>.env</summary>
44+
45+
#### [.env](.env)
46+
47+
```dotenv
48+
# type int
49+
INT=90898
50+
SIGNED_INT=-8898
51+
# type double
52+
DOUBLE=3.1415926
53+
SIGNED_DOUBLE=-.123
54+
# type bool
55+
BOOL=false
56+
# type string
57+
STRING=AAA
58+
NO_QUOTE_STRING=ABC9shj"\'\''';';;;'\n\r\thttps://google.com
59+
SINGLE_QUOTE_STRING='AB\r\n\ta\'\"C'
60+
DOUBLE_QUOTE_STRING="ABC"
61+
JSON={"a":1,"b":[1,true,"hello"]}
62+
EMPTY=
63+
EMPTY_COMMENT=#EMPTY
64+
```
65+
66+
</details>
67+
68+
<details>
69+
<summary>.env.prod</summary>
70+
71+
#### [.env.prod](.env.prod)
72+
73+
```dotenv
74+
# covered
75+
BOOL=true
76+
77+
# specical
78+
QWERTY=-0.343
79+
```
80+
81+
</details>
82+
83+
<details>
84+
<summary>env.g.dart</summary>
85+
86+
87+
#### [env.g.dart](example/env.g.dart)
88+
89+
```dart
90+
// coverage:ignore-file
91+
// ignore_for_file: camel_case_types, non_constant_identifier_names, prefer_single_quotes
92+
// ======================================
93+
// GENERATED CODE - DO NOT MODIFY BY HAND
94+
// ======================================
95+
96+
abstract class Env {
97+
const factory Env() = _Prod._;
98+
99+
static final String active = 'prod';
100+
101+
/// From .env
102+
///
103+
/// >> INT = 90898
104+
///
105+
/// type int
106+
///
107+
int get INT;
108+
109+
/// From .env
110+
///
111+
/// >> SIGNED_INT = -8898
112+
///
113+
int get SIGNED_INT;
114+
115+
/// From .env
116+
///
117+
/// >> DOUBLE = 3.1415926
118+
///
119+
/// type double
120+
///
121+
double get DOUBLE;
122+
123+
/// From .env
124+
///
125+
/// >> SIGNED_DOUBLE = -.123
126+
///
127+
double get SIGNED_DOUBLE;
128+
129+
/// Covered the default value
130+
///
131+
/// false => true
132+
/// ========================================
133+
/// From .env
134+
///
135+
/// >> BOOL = false
136+
///
137+
/// type bool
138+
///
139+
/// ========================================
140+
/// From .env.prod
141+
///
142+
/// >> BOOL = true
143+
///
144+
/// covered
145+
///
146+
bool get BOOL;
147+
148+
/// From .env
149+
///
150+
/// >> STRING = AAA
151+
///
152+
/// type string
153+
///
154+
String get STRING;
155+
156+
/// From .env
157+
///
158+
/// >> NO_QUOTE_STRING = ABC9shj"\'\''';';;;'\n\r\thttps://google.com
159+
///
160+
String get NO_QUOTE_STRING;
161+
162+
/// From .env
163+
///
164+
/// >> SINGLE_QUOTE_STRING = 'AB\r\n\ta\'\"C'
165+
///
166+
String get SINGLE_QUOTE_STRING;
167+
168+
/// From .env
169+
///
170+
/// >> DOUBLE_QUOTE_STRING = "ABC"
171+
///
172+
String get DOUBLE_QUOTE_STRING;
173+
174+
/// From .env
175+
///
176+
/// >> JSON = {"a":1,"b":[1,true,"hello"]}
177+
///
178+
String get JSON;
179+
180+
/// From .env
181+
///
182+
/// >> EMPTY =
183+
///
184+
String get EMPTY;
185+
186+
/// From .env
187+
///
188+
/// >> EMPTY_COMMENT =
189+
///
190+
/// EMPTY
191+
///
192+
String get EMPTY_COMMENT;
193+
194+
/// From .env.prod
195+
///
196+
/// >> QWERTY = -0.343
197+
///
198+
/// specical
199+
///
200+
double get QWERTY;
201+
202+
Map<String, dynamic> toJson();
203+
}
204+
205+
class _Prod implements Env {
206+
const _Prod._();
207+
208+
@override
209+
int get INT => 90898;
210+
211+
@override
212+
int get SIGNED_INT => -8898;
213+
214+
@override
215+
double get DOUBLE => 3.1415926;
216+
217+
@override
218+
double get SIGNED_DOUBLE => -0.123;
219+
220+
@override
221+
bool get BOOL => true;
222+
223+
@override
224+
String get STRING => "AAA";
225+
226+
@override
227+
String get NO_QUOTE_STRING =>
228+
"ABC9shj\"\\'\\''';';;;'\\n\\r\\thttps://google.com";
229+
230+
@override
231+
String get SINGLE_QUOTE_STRING => "'AB\\r\\n\\ta\\'\\\"C'";
232+
233+
@override
234+
String get DOUBLE_QUOTE_STRING => "ABC";
235+
236+
@override
237+
String get JSON => "{\"a\":1,\"b\":[1,true,\"hello\"]}";
238+
239+
@override
240+
String get EMPTY => '';
241+
242+
@override
243+
String get EMPTY_COMMENT => '';
244+
245+
@override
246+
double get QWERTY => -0.343;
247+
248+
@override
249+
Map<String, dynamic> toJson() {
250+
return {
251+
'INT': 90898,
252+
'SIGNED_INT': -8898,
253+
'DOUBLE': 3.1415926,
254+
'SIGNED_DOUBLE': -0.123,
255+
'BOOL': true,
256+
'STRING': "AAA",
257+
'NO_QUOTE_STRING': "ABC9shj\"\\'\\''';';;;'\\n\\r\\thttps://google.com",
258+
'SINGLE_QUOTE_STRING': "'AB\\r\\n\\ta\\'\\\"C'",
259+
'DOUBLE_QUOTE_STRING': "ABC",
260+
'JSON': "{\"a\":1,\"b\":[1,true,\"hello\"]}",
261+
'EMPTY': '',
262+
'EMPTY_COMMENT': '',
263+
'QWERTY': -0.343,
264+
};
265+
}
266+
}
267+
```
268+
269+
</details>
270+
271+
</details>
272+
273+
## 统计
274+
275+
![count viewed](https://count.getloli.com/get/@fluttercandies:env2dart?theme=rule34)
276+
277+
[![Sparkline](https://stars.medv.io/fluttercandies/env2dart.svg)](https://stars.medv.io/fluttercandies/env2dart)
278+
279+
## Licenses
280+
281+
``` text
282+
Copyright 2023 iota9star
283+
284+
Licensed under the Apache License, Version 2.0 (the "License");
285+
you may not use this file except in compliance with the License.
286+
You may obtain a copy of the License at
287+
288+
https://www.apache.org/licenses/LICENSE-2.0
289+
290+
Unless required by applicable law or agreed to in writing, software
291+
distributed under the License is distributed on an "AS IS" BASIS,
292+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
293+
See the License for the specific language governing permissions and
294+
limitations under the License.
295+
```
296+

0 commit comments

Comments
 (0)
Please sign in to comment.