digipolitan-apps-tools 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32829c2a1b005c4683f9efe1e7a1ba19d82ead17
4
+ data.tar.gz: 2eec263e6b8cd9cbfe93bd597257c12630c6a889
5
+ SHA512:
6
+ metadata.gz: a0e5916533fd5d673fc3d4f22b4da9b454639dd7aea576b339de14686e5cdb26ddc99ad943820a021cc4ca427a7cdc971ad91e8437cf63b22de5a17af9a56b57
7
+ data.tar.gz: 50ffae6385ef2fe60092ed7949e9fd08c4da483622709107438faecb54c777c92c125b9a7dc0552452cf6311845172ca3841bc5c4d03613c3d4aa79985d7de27
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ `digipolitan-apps-tools` adheres to [Semantic Versioning](http://semver.org/).
5
+
6
+ ---
7
+
8
+ ## [0.2.0](https://github.com/Digipolitan/apps-tools/releases/tag/v0.2.0)
9
+
10
+ add Argv class, this class help the developer to parse command line args
11
+ add 2 file utils : mkdir_p and remove_dir
12
+ readme update
data/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2017, Digipolitan
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ * Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ * Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,133 @@
1
+ # apps-tools
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/digipolitan-apps-tools.svg)](http://badge.fury.io/rb/digipolitan-apps-tools)
4
+
5
+ Digipolitan tools for Ruby scripts
6
+
7
+ ## Cross-platform tools
8
+
9
+ ### UI
10
+
11
+ The UI class provides some tools to work with stdin / stdout
12
+
13
+ ````Ruby
14
+ Digipolitan::UI.message("Hello")
15
+ ````
16
+ Write *Hello* in stdout
17
+
18
+ ````Ruby
19
+ Digipolitan::UI.sucess("Hello")
20
+ ````
21
+ Print *Hello* in stdout with a green color
22
+
23
+ ````Ruby
24
+ Digipolitan::UI.error("Hello")
25
+ ````
26
+ Print *Hello* in stdout with a red color
27
+
28
+ ````Ruby
29
+ Digipolitan::UI.crash("Hello")
30
+ ````
31
+ Print *Hello* in stdout with a red color and kill the script
32
+
33
+ ````Ruby
34
+ name = Digipolitan::UI.input("What's your name ?")
35
+ ````
36
+ Print *What's your name ?* in stdout with a yellow color and wait the user to write content until '\n'
37
+
38
+ ````Ruby
39
+ if Digipolitan::UI.input("Are you sure ?")
40
+ Digipolitan::UI.sucess("YES !")
41
+ else
42
+ Digipolitan::UI.error("NO !")
43
+ end
44
+ ````
45
+ Print *Are you sure ?* in stdout with a yellow color and wait the user to write 'y' (yes) or 'n' (no)
46
+
47
+ ````Ruby
48
+ level = Digipolitan::UI.select("Choose your level ?", ["easy", "medium", "hard", "very hard"])
49
+ ````
50
+ Print *Choose your level ?* in stdout and wait the user to select the level : 1 -> easy, 2 -> medium, etc..
51
+
52
+ ### Argv
53
+
54
+ The Argv class provides a parser to read inputs from command line and wrap it into a map using these rules :
55
+ ````Sh
56
+ `script.rb -key1 value1 -key2 value2 value3 --key3`
57
+ ````
58
+
59
+ This command will generate the following result :
60
+
61
+ ````Json
62
+ {
63
+ "-key1": "value1",
64
+ "-key2": [
65
+ "value2",
66
+ "value3"
67
+ ],
68
+ "--key3": true
69
+ }
70
+ ````
71
+
72
+ Example with `script.rb -key hello` :
73
+
74
+ ````Ruby
75
+ args = Digipolitan::Argv.parse()
76
+ print args["-key"] # display 'hello'
77
+ ````
78
+
79
+ ### FileUtils
80
+
81
+ The FileUtils class provides some tools to work easy with files, such as rename all files from a directory, replace all matching contents in files
82
+
83
+ ````Ruby
84
+ Digipolitan::FileUtils.rename_files("bonjour", "hello")
85
+ ````
86
+ This action, replace all file name containing *bonjour* and replace it with *hello*, recursively from the current directory
87
+ Result example :
88
+ The given path `./bonbon/bonjourtoi/test/bonjouratoi.txt` will be replaced by `./bonbon/hellotoi/test/helloatoi.txt`
89
+
90
+ ````Ruby
91
+ Digipolitan::FileUtils.replace_contents_of_files("bonjour", "hello", [".git"], "./test")
92
+ ````
93
+ This action replace all *bonjour* content with *hello* inside all files from the directory `./test` ignoring the *.git* directory
94
+
95
+ ````Ruby
96
+ Digipolitan::FileUtils.write_to_file("./test/bonjour.md", "Hello world")
97
+ ````
98
+ Sample action used to write data, write *Hello world* in `./test/bonjour.md`
99
+
100
+ ````Ruby
101
+ Digipolitan::FileUtils.remove_dir("./dev")
102
+ ````
103
+ Removes the given directory
104
+
105
+ ````Ruby
106
+ Digipolitan::FileUtils.mkdir_p("a/b/c/d")
107
+ ````
108
+ Creates a directory and all its parent directories
109
+
110
+ causes to make following directories, if it does not exist.
111
+
112
+ ````Sh
113
+ mkdir a
114
+ mkdir a/b
115
+ mkdir a/b/c
116
+ mkdir a/b/c/d
117
+ ````
118
+
119
+ ## iOS tools
120
+
121
+ ### Xcodeproj
122
+
123
+ Working with Xcodeproj
124
+
125
+ ````Ruby
126
+ proj = Digipolitan::FileUtils.get_project()
127
+ ````
128
+ Retrieves the first xcode project in the current directory
129
+
130
+ ````Ruby
131
+ Digipolitan::FileUtils.rename_project()
132
+ ````
133
+ Rename the project, ask the user to confirm and choose the name of the new project
@@ -0,0 +1,39 @@
1
+ module Digipolitan
2
+
3
+ class Argv
4
+
5
+ def self.parse()
6
+ map = {}
7
+ count = ARGV.count
8
+ i = 0
9
+ while i < count
10
+ arg = ARGV[i]
11
+ if arg.index("-") == 0
12
+ key = arg
13
+ data = []
14
+ i += 1
15
+ while i < count
16
+ arg = ARGV[i]
17
+ if arg.index("-") != 0
18
+ data.push(arg)
19
+ i += 1
20
+ else
21
+ i -= 1
22
+ break
23
+ end
24
+ end
25
+ data_count = data.count
26
+ if data_count > 1
27
+ map[key] = data
28
+ elsif data_count > 0
29
+ map[key] = data[0]
30
+ else
31
+ map[key] = true
32
+ end
33
+ end
34
+ i += 1
35
+ end
36
+ return map
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,81 @@
1
+ module Digipolitan
2
+
3
+ class FileUtils
4
+
5
+ def self.rename_files(pattern, replacement, ignored_entries = nil, path = ".", recursive = true)
6
+ entries = Dir.entries(path)
7
+ entries.each do |entry|
8
+ replaced = entry
9
+ replaced_path = File.join(path, entry)
10
+ if replaced_path != __FILE__ && (ignored_entries == nil || ignored_entries.index(entry) == nil)
11
+ if entry.include?(pattern)
12
+ replaced = entry.gsub(pattern, replacement)
13
+ replaced_path = File.join(path, replaced)
14
+ File.rename(File.join(path, entry), replaced_path)
15
+ end
16
+ if recursive && File.directory?(replaced_path) && replaced != "." && replaced != ".."
17
+ self.rename_files(pattern, replacement, ignored_entries, replaced_path, recursive)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.replace_contents_of_files(pattern, replacement, ignored_entries = nil, path = ".", recursive = true)
24
+ entries = Dir.entries(path)
25
+ entries.each do |entry|
26
+ file_path = File.join(path, entry)
27
+ if file_path != __FILE__ && (ignored_entries == nil || ignored_entries.index(entry) == nil)
28
+ if recursive && File.directory?(file_path) && entry != "." && entry != ".."
29
+ self.replace_contents_of_files(pattern, replacement, ignored_entries, file_path, recursive)
30
+ elsif File.file?(file_path)
31
+ content = File.read(file_path)
32
+ if content.include?(pattern)
33
+ self.write_to_file(file_path, content.gsub(pattern, replacement))
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ def self.write_to_file(path, content = "")
41
+ File.open(path, "w") { |file|
42
+ file.puts(content)
43
+ }
44
+ end
45
+
46
+ def self.remove_dir(path)
47
+ if File.directory?(path)
48
+ entries = Dir.entries(path)
49
+ entries.each do |entry|
50
+ if entry != "." && entry != ".."
51
+ self.remove_dir(File.join(path, entry))
52
+ end
53
+ end
54
+ Dir.delete(path)
55
+ elsif File.exist?(path)
56
+ File.delete(path)
57
+ end
58
+ end
59
+
60
+ def self.mkdir_p(path)
61
+ arr = path.split(File::SEPARATOR)
62
+ count = arr.count
63
+ i = 0
64
+ f_path = nil
65
+ while i < count
66
+ f_name = arr[i]
67
+ if f_path == nil && f_name.length != 0
68
+ f_path = f_name
69
+ else
70
+ f_path = File.join(f_path != nil ? f_path : "", f_name)
71
+ end
72
+ if f_name.length != 0
73
+ if !Dir.exist?(f_path)
74
+ Dir.mkdir(f_path)
75
+ end
76
+ end
77
+ i += 1
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,61 @@
1
+ require 'colorize'
2
+
3
+ module Digipolitan
4
+
5
+ class UI
6
+
7
+ def self.message(msg, color = nil)
8
+ if color != nil
9
+ msg = msg.colorize(color)
10
+ else
11
+ msg = "#{msg}\n"
12
+ end
13
+ $stdout.puts(msg)
14
+ end
15
+
16
+ def self.success(msg)
17
+ self.message(msg, :green)
18
+ end
19
+
20
+ def self.input(msg)
21
+ self.message(msg, :yellow)
22
+ return $stdin.gets().strip()
23
+ end
24
+
25
+ def self.error(msg)
26
+ self.message("\n[!] ERROR : #{msg}", :red)
27
+ end
28
+
29
+ def self.confirm(msg)
30
+ self.message("#{msg} (y/n)", :yellow)
31
+ while c = $stdin.getch()
32
+ if c == "y"
33
+ return true
34
+ elsif c == "n"
35
+ return false
36
+ else
37
+ self.error("Select yes or no only")
38
+ end
39
+ end
40
+ end
41
+
42
+ def self.select(msg, values)
43
+ self.message(msg)
44
+ i = 0
45
+ values.each { |value|
46
+ i += 1
47
+ self.message("#{i} - #{value}")
48
+ }
49
+ while val = self.input("Select a value between [1 - #{i}]").to_i
50
+ if val >= 1 && val <= i
51
+ return values[val-1]
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.crash(msg)
57
+ abort("\n[!!!] CRASH : #{msg}".colorize(:red))
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,27 @@
1
+
2
+ module Digipolitan
3
+
4
+ class Xcodeproj
5
+
6
+ def self.rename_project(project = nil)
7
+ if project == nil
8
+ project = self.get_project()
9
+ end
10
+
11
+ project_name = File.basename(project, ".xcodeproj")
12
+ app_name = Digipolitan::UI.input("Project name ?")
13
+
14
+ if Digipolitan::UI.confirm("Are you sure to replace the current project '#{project_name}' to '#{app_name}' ?")
15
+ Digipolitan::UI.message("Starting replacement...")
16
+ ignored_entries = [".git", "DerivedData"]
17
+ Digipolitan::FileUtils.rename_files(project_name, app_name, ignored_entries)
18
+ Digipolitan::FileUtils.replace_contents_of_files(project_name, app_name, ignored_entries)
19
+ Digipolitan::UI.success("Successfully replaced '#{project_name}' with '#{app_name}'")
20
+ end
21
+ end
22
+
23
+ def self.get_project()
24
+ return Dir['*.xcodeproj'].first
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'digipolitan-apps-tools/file_utils'
4
+ require 'digipolitan-apps-tools/xcodeproj'
5
+ require 'digipolitan-apps-tools/ui'
6
+ require 'digipolitan-apps-tools/argv'
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: digipolitan-apps-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - bbriatte
8
+ - vbalasubramaniam
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.8.1
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.8.1
28
+ description: 'Digipolitan Apps Tools is a Ruby library. This module help you building
29
+ some iOS / Android app script.
30
+
31
+ '
32
+ email: contact@digipolitan.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - CHANGELOG.md
38
+ - LICENSE
39
+ - README.md
40
+ - lib/digipolitan-apps-tools.rb
41
+ - lib/digipolitan-apps-tools/argv.rb
42
+ - lib/digipolitan-apps-tools/file_utils.rb
43
+ - lib/digipolitan-apps-tools/ui.rb
44
+ - lib/digipolitan-apps-tools/xcodeproj.rb
45
+ homepage: https://github.com/Digipolitan/apps-tools
46
+ licenses:
47
+ - BSD-3-Clause
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 1.9.3
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.5.1
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: Digipolitan Ruby tools for apps
69
+ test_files: []