mina-dotenv 0.2.1 → 0.2.2

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
  SHA1:
3
- metadata.gz: 947ee168136798c8b75f9c99517aa6634b63c730
4
- data.tar.gz: 639780c25e47372fbc699249c9b92566687c2fc1
3
+ metadata.gz: 294faeee8d753dc2546dd043a593cc802e5ec003
4
+ data.tar.gz: 5ab80b5ce301f478067801fc8c3c063212c22bee
5
5
  SHA512:
6
- metadata.gz: d00b88b2aee669be7bd0f0e1ccaa2fe6f72fdfc5e481428264753065b5d1b8c1ca75e1ac6c644a152aed15bb2aba3642852c6c2b1de610c77d954f36ad1f9857
7
- data.tar.gz: 660d886f55a426f6c7284644f20946aff6fe474c8d03cb690c7e9880e9214de145506ccc941a98a47a196ce061610a4ed2c05f5cbf4802b5fbcd80831c28e0cb
6
+ metadata.gz: 667f9096c89ac4a5013fac1b837952a1ba49d4ef7b00586fc8cc10f0c91f413f86fed03dc783c2159150565a250da236d003c0ab2bca67cdbb85e56c08a39c50
7
+ data.tar.gz: 8a125d9df8527cd2bf26924d02b15f55e62edc788278ced4d573c6cb0f5b006b123335e636f8696da711b0a771e400ec8b6de563f2a2b3e4625ea1f7c146b568
data/README.md CHANGED
@@ -86,7 +86,13 @@ If no local `.env` file is found a blank one will be created on the server.
86
86
 
87
87
  ### Pull
88
88
 
89
- The pull task uses the `scp` command to retrieve the `.env` file from the server. __Note:__ It will take all configuration from your `deploy.rb` file! It is intended to be used from the terminal like this:
89
+ The pull task uses [scp](https://en.wikipedia.org/wiki/Secure_copy) to retrieve the `.env` file from the server.
90
+
91
+ __Note:__ It will take all configuration from your `deploy.rb` file!
92
+
93
+ __Important:__ It will add the downloaded file to your `.gitignore` file!
94
+
95
+ It is intended to be used from the terminal like this:
90
96
 
91
97
  ```
92
98
  mina dotenv:pull
@@ -15,15 +15,33 @@ namespace :dotenv do
15
15
  desc 'Copies the remote .env file to the current directory'
16
16
  task :pull do
17
17
  scp_download(remote_dotenv_path, dotenv_location)
18
- add_to_gitignore_command = %(
19
- if [[ -z $(grep #{dotenv_location} .gitignore) ]];
20
- then echo #{dotenv_location} >> .gitignore;
21
- fi;
22
- )
23
- `#{add_to_gitignore_command}`
18
+ Mina::Dotenv::Utils.add_to_gitignore(dotenv_location)
19
+ end
20
+
21
+ desc 'Creates empty .env files, adds defaults to .gitignore and deploy.rb'
22
+ task :init do
23
+ add_default_to_gitignore
24
+ add_to_deploy_script
25
+ create_default_files
24
26
  end
25
27
  end
26
28
 
27
29
  def remote_dotenv_path
28
30
  "#{deploy_to}/#{shared_path}/.env"
29
31
  end
32
+
33
+ def add_default_to_gitignore
34
+ Mina::Dotenv::Utils.add_to_gitignore('!.env')
35
+ Mina::Dotenv::Utils.add_to_gitignore('.env.*')
36
+ end
37
+
38
+ def add_to_deploy_script
39
+ file = 'config/deploy.rb'
40
+ line = 'require \'mina/dotenv\''
41
+ Mina::Dotenv::Utils.prepend_to_file(file, line)
42
+ end
43
+
44
+ def create_default_files
45
+ Mina::Dotenv::Utils.create_file('.env')
46
+ Mina::Dotenv::Utils.create_file('.env.production')
47
+ end
@@ -5,6 +5,44 @@ module Mina
5
5
  return '' unless File.exist?(file_path)
6
6
  File.open(file_path, 'r').read
7
7
  end
8
+
9
+ def self.append_to_file(file, string, force: false)
10
+ add_to_file(file, string, before: true, force: force)
11
+ end
12
+
13
+ def self.prepend_to_file(file, string, force: false)
14
+ add_to_file(file, string, force: force)
15
+ end
16
+
17
+ def self.add_to_file(file, string, before: true, force: false)
18
+ return unless File.exist?(file)
19
+ return if !force && file_contains?(file, string)
20
+
21
+ file_content = File.read(file)
22
+
23
+ File.open(file, 'w') do |f|
24
+ f.puts(string) if before
25
+ f.puts file_content
26
+ f.puts(string) unless before
27
+ end
28
+ end
29
+
30
+ def self.file_contains?(file, regex)
31
+ File.foreach(file).grep(Regexp.new(regex)).any?
32
+ end
33
+
34
+ def self.add_to_gitignore(path)
35
+ gitignore_path = '.gitignore'
36
+ return if file_contains?(gitignore_path, path)
37
+ append_to_file(gitignore_path, path)
38
+ end
39
+
40
+ def self.create_file(path, content = '')
41
+ return if File.exist?(path)
42
+ File.open(path, 'w') do |f|
43
+ f.puts(content)
44
+ end
45
+ end
8
46
  end
9
47
  end
10
48
  end
@@ -3,7 +3,7 @@ module Mina
3
3
  module VERSION
4
4
  MAJOR = 0
5
5
  MINOR = 2
6
- TINY = 1
6
+ TINY = 2
7
7
  PRE = nil
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
data/mina-dotenv.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency 'mina'
28
28
  spec.add_dependency 'mina-scp'
29
+ spec.add_dependency 'thor'
29
30
 
30
31
  spec.add_development_dependency 'bundler', '~> 1.8'
31
32
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-dotenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stanko Krtalić Rusendić
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-23 00:00:00.000000000 Z
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mina
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
119
  version: '0'
106
120
  requirements: []
107
121
  rubyforge_project:
108
- rubygems_version: 2.4.5
122
+ rubygems_version: 2.4.5.1
109
123
  signing_key:
110
124
  specification_version: 4
111
125
  summary: Dotenv tasks for mina