digipolitan-apps-tools 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +18 -18
- data/lib/digipolitan-apps-tools/argv.rb +3 -3
- data/lib/digipolitan-apps-tools/file_utils.rb +9 -9
- data/lib/digipolitan-apps-tools/ui.rb +8 -4
- data/lib/digipolitan-apps-tools/xcodeproj.rb +7 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d8e902b5899b35e7c429c0049485a5880fe9db1
|
4
|
+
data.tar.gz: 3ab728fadf738ed8dfefb8f49c4ebe3c7d6aa310
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d498d15d760af208c806d2ec2d4d7b28f93287d9e63956b0a75c891a490b17c2d667e7b9062cd741a77a5489a09dbfc48773ef2c05578246e341988b73cad8d5
|
7
|
+
data.tar.gz: 357f3993ebc90ed631b2517be6681eecf7be27c0692450687fa596bb18e4c9ab0072c05ec52cd9ecec069e73b9bb873b389973b029d358a8e6bd8ee72771c260
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
|
6
6
|
---
|
7
7
|
|
8
|
+
## [0.2.3](https://github.com/Digipolitan/apps-tools/releases/tag/v0.2.3)
|
9
|
+
|
10
|
+
bug fix during rename xcodeproj
|
11
|
+
update lint
|
12
|
+
add warning log
|
13
|
+
update readme
|
14
|
+
|
15
|
+
---
|
16
|
+
|
8
17
|
## [0.2.2](https://github.com/Digipolitan/apps-tools/releases/tag/v0.2.2)
|
9
18
|
|
10
19
|
Renaming define in project and catch error during replacing content of files
|
data/README.md
CHANGED
@@ -11,41 +11,41 @@ Digipolitan tools for Ruby scripts
|
|
11
11
|
The UI class provides some tools to work with stdin / stdout
|
12
12
|
|
13
13
|
````Ruby
|
14
|
-
Digipolitan::UI.message(
|
14
|
+
Digipolitan::UI.message('Hello')
|
15
15
|
````
|
16
16
|
Write *Hello* in stdout
|
17
17
|
|
18
18
|
````Ruby
|
19
|
-
Digipolitan::UI.sucess(
|
19
|
+
Digipolitan::UI.sucess('Hello')
|
20
20
|
````
|
21
21
|
Print *Hello* in stdout with a green color
|
22
22
|
|
23
23
|
````Ruby
|
24
|
-
Digipolitan::UI.error(
|
24
|
+
Digipolitan::UI.error('Hello')
|
25
25
|
````
|
26
26
|
Print *Hello* in stdout with a red color
|
27
27
|
|
28
28
|
````Ruby
|
29
|
-
Digipolitan::UI.crash(
|
29
|
+
Digipolitan::UI.crash('Hello')
|
30
30
|
````
|
31
31
|
Print *Hello* in stdout with a red color and kill the script
|
32
32
|
|
33
33
|
````Ruby
|
34
|
-
name = Digipolitan::UI.input(
|
34
|
+
name = Digipolitan::UI.input('What\'s your name ?')
|
35
35
|
````
|
36
36
|
Print *What's your name ?* in stdout with a yellow color and wait the user to write content until '\n'
|
37
37
|
|
38
38
|
````Ruby
|
39
|
-
if Digipolitan::UI.input(
|
40
|
-
Digipolitan::UI.sucess(
|
39
|
+
if Digipolitan::UI.input('Are you sure ?')
|
40
|
+
Digipolitan::UI.sucess('YES !')
|
41
41
|
else
|
42
|
-
Digipolitan::UI.error(
|
42
|
+
Digipolitan::UI.error('NO !')
|
43
43
|
end
|
44
44
|
````
|
45
45
|
Print *Are you sure ?* in stdout with a yellow color and wait the user to write 'y' (yes) or 'n' (no)
|
46
46
|
|
47
47
|
````Ruby
|
48
|
-
level = Digipolitan::UI.select(
|
48
|
+
level = Digipolitan::UI.select('Choose your level ?', %w[easy medium hard 'very hard'])
|
49
49
|
````
|
50
50
|
Print *Choose your level ?* in stdout and wait the user to select the level : 1 -> easy, 2 -> medium, etc..
|
51
51
|
|
@@ -72,8 +72,8 @@ This command will generate the following result :
|
|
72
72
|
Example with `script.rb -key hello` :
|
73
73
|
|
74
74
|
````Ruby
|
75
|
-
args = Digipolitan::Argv.parse
|
76
|
-
print args[
|
75
|
+
args = Digipolitan::Argv.parse
|
76
|
+
print args['-key'] # display 'hello'
|
77
77
|
````
|
78
78
|
|
79
79
|
### FileUtils
|
@@ -81,29 +81,29 @@ print args["-key"] # display 'hello'
|
|
81
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
82
|
|
83
83
|
````Ruby
|
84
|
-
Digipolitan::FileUtils.rename_files(
|
84
|
+
Digipolitan::FileUtils.rename_files('bonjour', 'hello')
|
85
85
|
````
|
86
86
|
This action, replace all file name containing *bonjour* and replace it with *hello*, recursively from the current directory
|
87
87
|
Result example :
|
88
88
|
The given path `./bonbon/bonjourtoi/test/bonjouratoi.txt` will be replaced by `./bonbon/hellotoi/test/helloatoi.txt`
|
89
89
|
|
90
90
|
````Ruby
|
91
|
-
Digipolitan::FileUtils.replace_contents_of_files(
|
91
|
+
Digipolitan::FileUtils.replace_contents_of_files('bonjour', 'hello', %w[.git], './test')
|
92
92
|
````
|
93
93
|
This action replace all *bonjour* content with *hello* inside all files from the directory `./test` ignoring the *.git* directory
|
94
94
|
|
95
95
|
````Ruby
|
96
|
-
Digipolitan::FileUtils.write_to_file(
|
96
|
+
Digipolitan::FileUtils.write_to_file('./test/bonjour.md', 'Hello world')
|
97
97
|
````
|
98
98
|
Sample action used to write data, write *Hello world* in `./test/bonjour.md`
|
99
99
|
|
100
100
|
````Ruby
|
101
|
-
Digipolitan::FileUtils.remove_dir(
|
101
|
+
Digipolitan::FileUtils.remove_dir('./dev')
|
102
102
|
````
|
103
103
|
Removes the given directory
|
104
104
|
|
105
105
|
````Ruby
|
106
|
-
Digipolitan::FileUtils.mkdir_p(
|
106
|
+
Digipolitan::FileUtils.mkdir_p('a/b/c/d')
|
107
107
|
````
|
108
108
|
Creates a directory and all its parent directories
|
109
109
|
|
@@ -123,11 +123,11 @@ mkdir a/b/c/d
|
|
123
123
|
Working with Xcodeproj
|
124
124
|
|
125
125
|
````Ruby
|
126
|
-
proj = Digipolitan::FileUtils.get_project
|
126
|
+
proj = Digipolitan::FileUtils.get_project
|
127
127
|
````
|
128
128
|
Retrieves the first xcode project in the current directory
|
129
129
|
|
130
130
|
````Ruby
|
131
|
-
Digipolitan::FileUtils.rename_project
|
131
|
+
Digipolitan::FileUtils.rename_project
|
132
132
|
````
|
133
133
|
Rename the project, ask the user to confirm and choose the name of the new project
|
@@ -2,19 +2,19 @@ module Digipolitan
|
|
2
2
|
|
3
3
|
class Argv
|
4
4
|
|
5
|
-
def self.parse
|
5
|
+
def self.parse
|
6
6
|
map = {}
|
7
7
|
count = ARGV.count
|
8
8
|
i = 0
|
9
9
|
while i < count
|
10
10
|
arg = ARGV[i]
|
11
|
-
if arg.index(
|
11
|
+
if arg.index('-') == 0
|
12
12
|
key = arg
|
13
13
|
data = []
|
14
14
|
i += 1
|
15
15
|
while i < count
|
16
16
|
arg = ARGV[i]
|
17
|
-
if arg.index(
|
17
|
+
if arg.index('-') != 0
|
18
18
|
data.push(arg)
|
19
19
|
i += 1
|
20
20
|
else
|
@@ -2,7 +2,7 @@ module Digipolitan
|
|
2
2
|
|
3
3
|
class FileUtils
|
4
4
|
|
5
|
-
def self.rename_files(pattern, replacement, ignored_entries = nil, path =
|
5
|
+
def self.rename_files(pattern, replacement, ignored_entries = nil, path = '.', recursive = true)
|
6
6
|
entries = Dir.entries(path)
|
7
7
|
entries.each do |entry|
|
8
8
|
replaced = entry
|
@@ -13,19 +13,19 @@ module Digipolitan
|
|
13
13
|
replaced_path = File.join(path, replaced)
|
14
14
|
File.rename(File.join(path, entry), replaced_path)
|
15
15
|
end
|
16
|
-
if recursive && File.directory?(replaced_path) && replaced !=
|
16
|
+
if recursive && File.directory?(replaced_path) && replaced != '.' && replaced != '..'
|
17
17
|
self.rename_files(pattern, replacement, ignored_entries, replaced_path, recursive)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.replace_contents_of_files(pattern, replacement, ignored_entries = nil, path =
|
23
|
+
def self.replace_contents_of_files(pattern, replacement, ignored_entries = nil, path = '.', recursive = true)
|
24
24
|
entries = Dir.entries(path)
|
25
25
|
entries.each do |entry|
|
26
26
|
file_path = File.join(path, entry)
|
27
27
|
if file_path != __FILE__ && (ignored_entries == nil || ignored_entries.index(entry) == nil)
|
28
|
-
if recursive && File.directory?(file_path) && entry !=
|
28
|
+
if recursive && File.directory?(file_path) && entry != '.' && entry != '..'
|
29
29
|
self.replace_contents_of_files(pattern, replacement, ignored_entries, file_path, recursive)
|
30
30
|
elsif File.file?(file_path)
|
31
31
|
content = File.read(file_path)
|
@@ -33,7 +33,7 @@ module Digipolitan
|
|
33
33
|
begin
|
34
34
|
self.write_to_file(file_path, content.gsub(pattern, replacement))
|
35
35
|
rescue
|
36
|
-
Digipolitan::UI.
|
36
|
+
Digipolitan::UI.warning("Error during replacement of file at path #{file_path}")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -41,8 +41,8 @@ module Digipolitan
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def self.write_to_file(path, content =
|
45
|
-
File.open(path,
|
44
|
+
def self.write_to_file(path, content = '')
|
45
|
+
File.open(path, 'w') { |file|
|
46
46
|
file.puts(content)
|
47
47
|
}
|
48
48
|
end
|
@@ -51,7 +51,7 @@ module Digipolitan
|
|
51
51
|
if File.directory?(path)
|
52
52
|
entries = Dir.entries(path)
|
53
53
|
entries.each do |entry|
|
54
|
-
if entry !=
|
54
|
+
if entry != '.' && entry != '..'
|
55
55
|
self.remove_dir(File.join(path, entry))
|
56
56
|
end
|
57
57
|
end
|
@@ -71,7 +71,7 @@ module Digipolitan
|
|
71
71
|
if f_path == nil && f_name.length != 0
|
72
72
|
f_path = f_name
|
73
73
|
else
|
74
|
-
f_path = File.join(f_path != nil ? f_path :
|
74
|
+
f_path = File.join(f_path != nil ? f_path : '', f_name)
|
75
75
|
end
|
76
76
|
if f_name.length != 0
|
77
77
|
if !Dir.exist?(f_path)
|
@@ -20,7 +20,11 @@ module Digipolitan
|
|
20
20
|
|
21
21
|
def self.input(msg)
|
22
22
|
self.message(msg, :yellow)
|
23
|
-
return $stdin.gets
|
23
|
+
return $stdin.gets.strip
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.warning(msg)
|
27
|
+
self.message("\n[!] WARNING : #{msg}", :yellow)
|
24
28
|
end
|
25
29
|
|
26
30
|
def self.error(msg)
|
@@ -29,13 +33,13 @@ module Digipolitan
|
|
29
33
|
|
30
34
|
def self.confirm(msg)
|
31
35
|
self.message("#{msg} (y/n)", :yellow)
|
32
|
-
while c = $stdin.getch
|
36
|
+
while (c = $stdin.getch)
|
33
37
|
if c == "y"
|
34
38
|
return true
|
35
39
|
elsif c == "n"
|
36
40
|
return false
|
37
41
|
else
|
38
|
-
self.error(
|
42
|
+
self.error('Select yes or no only')
|
39
43
|
end
|
40
44
|
end
|
41
45
|
end
|
@@ -47,7 +51,7 @@ module Digipolitan
|
|
47
51
|
i += 1
|
48
52
|
self.message("#{i} - #{value}")
|
49
53
|
}
|
50
|
-
while val = self.input("Select a value between [1 - #{i}]").to_i
|
54
|
+
while (val = self.input("Select a value between [1 - #{i}]").to_i)
|
51
55
|
if val >= 1 && val <= i
|
52
56
|
return values[val-1]
|
53
57
|
end
|
@@ -5,15 +5,15 @@ module Digipolitan
|
|
5
5
|
|
6
6
|
def self.rename_project(project = nil)
|
7
7
|
if project == nil
|
8
|
-
project = self.get_project
|
8
|
+
project = self.get_project
|
9
9
|
end
|
10
10
|
|
11
|
-
project_name = File.basename(project,
|
12
|
-
app_name = Digipolitan::UI.input(
|
11
|
+
project_name = File.basename(project, '.xcodeproj')
|
12
|
+
app_name = Digipolitan::UI.input('Project name ?')
|
13
13
|
|
14
14
|
if Digipolitan::UI.confirm("Are you sure to replace the current project '#{project_name}' to '#{app_name}' ?")
|
15
|
-
Digipolitan::UI.message(
|
16
|
-
ignored_entries = [
|
15
|
+
Digipolitan::UI.message('Starting replacement...')
|
16
|
+
ignored_entries = %w[.git DerivedData]
|
17
17
|
Digipolitan::FileUtils.rename_files(project_name, app_name, ignored_entries)
|
18
18
|
Digipolitan::FileUtils.replace_contents_of_files(project_name, app_name, ignored_entries)
|
19
19
|
|
@@ -23,17 +23,14 @@ module Digipolitan
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def self.get_project
|
26
|
+
def self.get_project
|
27
27
|
return Dir['*.xcodeproj'].first
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.build_define(project_name)
|
31
31
|
res = project_name.upcase
|
32
|
-
res = res.gsub(
|
32
|
+
res = res.gsub(' ', '_')
|
33
33
|
return "_#{res}_H"
|
34
34
|
end
|
35
|
-
|
36
|
-
# Visibility
|
37
|
-
private_class_method :build_define
|
38
35
|
end
|
39
36
|
end
|