dotenv-android 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f6a53019c82367cac781d5b598a0c03bb46e1712d28317d236fdb26b630a868
4
- data.tar.gz: 25a44ce79404add065ff8e23a46405c67e1141c8b82c68a6fe42086f474ed920
3
+ metadata.gz: bf9107a7eac6ffceeeaf4712d9e70915ad47c9d5577eb76be97360b97b85addd
4
+ data.tar.gz: 5dfbc805c2c8331ad16a9d421767ab94401970629dbc768627f5634901365cd0
5
5
  SHA512:
6
- metadata.gz: de0253f90662bd6a45c4afecbd8bd6184290867a9597ae448fb21770213e06afd1d32010e32c424980f67d4d256dc24174f1d6771951954324bb6169b3a8fc3f
7
- data.tar.gz: 771fe82ea8241df5466da3f1e0a7a4267a20f9cfcfe6b72c15c3f278d4329f694639cecda3f939a47ab13c4e53eacf550c70be8dcc4609bd6cd204c1e8384104
6
+ metadata.gz: 20651196c68f0a337f54d62f4a694f8d6eb76db602073ed9b251eddc93b1dd556f4b2639b298cf0f10c869eef8d053eb388b7f4d20666dc10845fcf9d55054ae
7
+ data.tar.gz: a360617fcb5d34ad1bb244a293b006bfe86dce259b8657cb20a872ee8451d78af1dcb6d8cc48d9690913a70ab62c0a977b1fb0200e88a1e43f524775d5b5c77a
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # [0.1.1] - 2019-11-30
2
+
3
+ ## Fixed
4
+ - Tested out CLI on a local Android Studio project and found bugs with it.
5
+ - Fix README docs on how to create Gradle build task.
6
+
1
7
  # [0.1.0] - 2019-11-30
2
8
 
3
9
  ## Added
data/README.md CHANGED
@@ -22,17 +22,26 @@ gem install dotenv-android
22
22
  val apiHost: String = Env.apiHost
23
23
  ```
24
24
 
25
- At first, Android Studio will complain that `Env.apiHost` cannot be found. Don't worry. We will be fixing that. `dotenv-android` CLI crawls your source code looking for `Env.X` requests and generating a `Env.kt` file for you! Anytime you want to use environmental variables, you just need to add it to your source. Super easy.
25
+ At first, Android Studio will complain that `Env.apiHost` cannot be found. Don't worry. We will be fixing that. `dotenv-android` CLI crawls your source code looking for `Env.X` requests and generating a `Env.kt` file for you! Anytime you want to use environmental variables, you just need to add it to your source. Super easy. If `dotenv-android` cannot find the variable in your `.env` file, it will throw an error so you can feel confident that if your app compiles, everything will work great.
26
26
 
27
- * In your `app/build.gradle` file, add the following to the bottom of the file:
27
+ * Create a bash script in the root of your project, `generate_env.sh`, with the contents:
28
28
 
29
29
  ```
30
- task buildEnv << {
31
- dotenv-android --source app/src/main/java/com/example/
32
- }
30
+ #!/bin/bash
31
+
32
+ dotenv-android --source app/src/main/java/com/example/myapplication/ --package PACKAGE_NAME
33
+ ```
33
34
 
34
- build.dependsOn buildEnv
35
+ In your `app/build.gradle` file, add the following to the bottom of the file:
35
36
  ```
37
+ task generateEnv(type:Exec) {
38
+ workingDir '../'
39
+ commandLine './generate_env.sh'
40
+ }
41
+ preBuild.dependsOn generateEnv
42
+ ```
43
+
44
+ You have just created a Gradle task that will run every time that you build your app. This will run the `dotenv-android` CLI to generate the `Env.kt` file each time you build!
36
45
 
37
46
  * Run a build in Android Studio to run the `dotenv-android` CLI tool.
38
47
 
@@ -11,7 +11,7 @@ require_relative './version'
11
11
  require 'dotenv'
12
12
 
13
13
  module DotEnvAndroid
14
- Options = Struct.new(:source, :out, :verbose, :debug)
14
+ Options = Struct.new(:source, :out, :verbose, :debug, :package_name)
15
15
 
16
16
  class CLI
17
17
  def initialize
@@ -47,6 +47,9 @@ module DotEnvAndroid
47
47
  options.verbose = true
48
48
  options.debug = true
49
49
  end
50
+ opts.on('--package PACKAGE_NAME', 'Package name to add to the top of the generated Env.kt file (example: com.yourdomain.app, or PACKAGE_NAME environment variable found in .env)') do |package_name|
51
+ options.package_name = package_name
52
+ end
50
53
  opts.on('-o', '--out FILE', 'Output file (example: Path/Env.kt)') do |out|
51
54
  options.out = out
52
55
  end
@@ -67,6 +70,7 @@ module DotEnvAndroid
67
70
  def assert_options
68
71
  prefix = '[ERROR]'
69
72
  @ui.fail("#{prefix} --source required") unless @options.source
73
+ @ui.fail("#{prefix} --package required") unless @options.package_name
70
74
  end
71
75
  end
72
76
  end
@@ -14,6 +14,8 @@ module DotEnvAndroid
14
14
  @options = options
15
15
 
16
16
  @ui = DotEnvAndroid::UI.new(@options.verbose, @options.debug)
17
+
18
+ @all_env_vars = Dotenv.parse('.env')
17
19
  end
18
20
 
19
21
  def start
@@ -23,7 +25,7 @@ module DotEnvAndroid
23
25
  end
24
26
 
25
27
  def iterate_source
26
- source_pattern = File.expand_path("#{@options.source}/**/*.kotlin")
28
+ source_pattern = File.expand_path("#{@options.source}/**/*.kt")
27
29
  @ui.verbose("Searching for environment vars in source: #{source_pattern}")
28
30
 
29
31
  requests = Set[]
@@ -58,24 +60,39 @@ module DotEnvAndroid
58
60
  requests
59
61
  end
60
62
 
61
- def get_values(requests)
62
- variables = Dotenv.parse('.env')
63
+ def get_values(requests)
63
64
  values = {}
64
65
 
65
66
  requests.each do |request|
66
- @ui.fail("Environment variable #{request} not found in .env") unless variables[request]
67
+ @ui.fail("Environment variable #{request} not found in .env") unless @all_env_vars[request]
67
68
 
68
- values[request] = variables[request]
69
+ values[request] = @all_env_vars[request]
69
70
  end
70
71
 
71
72
  @ui.debug("Values: #{values}")
72
73
  values
73
74
  end
74
75
 
76
+ def get_package_header
77
+ package_name_header = "package #{@options.package_name}"
78
+
79
+ if !@options.package_name.include? "."
80
+ package_name = @all_env_vars[@options.package_name]
81
+ @ui.fail("Cannot find package name in .env file with key, #{@options.package_name}") if package_name.nil?
82
+ package_name_header = "package #{package_name}"
83
+ end
84
+
85
+ @ui.debug("Package name header: #{package_name_header}")
86
+
87
+ return package_name_header
88
+ end
89
+
75
90
  def generate_output(env_variables)
76
91
  @ui.verbose("Outputting environment variables to #{@options.out}")
77
92
 
78
- file_contents = "object Env {\n\n"
93
+ package_name_header = get_package_header
94
+ file_contents = "#{package_name_header}\n\n"
95
+ file_contents += "object Env {\n\n"
79
96
  env_variables.each do |key, value|
80
97
  file_contents += " val #{DotEnvAndroid::Util.snake_to_camel(key)} = \"#{value}\"\n"
81
98
  end
@@ -3,7 +3,7 @@
3
3
  module DotEnvAndroid
4
4
  class Version
5
5
  def self.get
6
- '0.1.0'
6
+ '0.1.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotenv-android
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Levi Bostian