enoki 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +73 -5
- data/assets/project_file_tree.png +0 -0
- data/enoki.gemspec +7 -6
- data/lib/enoki/cli/common.rb +5 -0
- data/lib/enoki/cli/generate.rb +29 -3
- data/lib/enoki/cli/show.rb +1 -1
- data/lib/enoki/cli.rb +10 -0
- data/lib/enoki/version.rb +1 -1
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b25b6f2f7ad6bcf55593ec13a521539ca4d2990
|
4
|
+
data.tar.gz: 18d52ddd228e5a60aa12795531093099b707eaee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6061c4646350e534be0b99f69992aef9ba5808ad21023d930a865fb9bff6e4bbff5d7bcb4e66b2aa0676d935e973a7d94a792858e9cd681535d9789bff46e20d
|
7
|
+
data.tar.gz: 1a8f4baf6eaa558c2025c4bc276cd82749d60255ccf58b34ce3ed7ca5e7b3cf124beb2a039347fb56bcedfc18aa5a25ab9ef2622cfc4fbfe4c070cf6f2dc5541
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Enoki
|
2
2
|
|
3
3
|
Code generator for Xcode project.
|
4
|
+
You can manage multiple user-defined file template set in your project.
|
4
5
|
|
5
6
|
## Installation
|
6
7
|
|
@@ -10,13 +11,80 @@ $ gem install enoki
|
|
10
11
|
|
11
12
|
## Usage
|
12
13
|
|
13
|
-
|
14
|
+
### Setup
|
14
15
|
|
15
|
-
|
16
|
+
Run `enoki init` in your project root directory, then created `.enoki.yml` file with some questions.
|
16
17
|
|
17
|
-
|
18
|
+
### Create template set
|
18
19
|
|
19
|
-
|
20
|
+
Create template set directory in your template directory (default: ./templates) and organize template files. The template file has extension `.tt`.
|
21
|
+
|
22
|
+
For example: https://github.com/slightair/enoki/tree/master/examples/Enoki%20Example/templates
|
23
|
+
|
24
|
+
```
|
25
|
+
templates
|
26
|
+
├── Test
|
27
|
+
│ └── Enoki\ Example
|
28
|
+
│ ├── ViewController
|
29
|
+
│ │ └── __name__ViewController.swift.tt
|
30
|
+
│ └── ViewModel
|
31
|
+
│ └── __name__ViewModel.swift.tt
|
32
|
+
└── VIPER
|
33
|
+
└── Enoki\ Example
|
34
|
+
└── Modules
|
35
|
+
└── __name__
|
36
|
+
└── __name__ViewController.swift.tt
|
37
|
+
```
|
38
|
+
|
39
|
+
This example case has 2 template set, `Test` and `VIPER`.
|
40
|
+
|
41
|
+
### Generate source code
|
42
|
+
|
43
|
+
Next, run `enoki generate Test Hello` and generated following files.
|
44
|
+
|
45
|
+
```
|
46
|
+
create Enoki Example/ViewController/HelloViewController.swift
|
47
|
+
create Enoki Example/ViewModel/HelloViewModel.swift
|
48
|
+
```
|
49
|
+
|
50
|
+
Then added 2 files to your Xcode project and setup project groups that correspond to template set directory tree.
|
51
|
+
|
52
|
+

|
53
|
+
|
54
|
+
### File name rule
|
55
|
+
|
56
|
+
If you use `__name__` in file or directory name of template, replace to capitalized name argument in your command.
|
57
|
+
|
58
|
+
For example, generate `Modules/Hello/HelloViewController.swift` from template file `Modules/__name__/__name__ViewController.swift.tt` if your command is `generate TEMPLATE_SET hello`.
|
59
|
+
|
60
|
+
### Template file rule
|
61
|
+
|
62
|
+
The template file is ERB template that have extension `.tt`.
|
63
|
+
Enoki pass name to template engine.
|
64
|
+
|
65
|
+
If your template is...
|
66
|
+
|
67
|
+
```swift
|
68
|
+
import UIKit
|
69
|
+
|
70
|
+
class <%= name %>ViewController: UIViewController {
|
71
|
+
override func viewDidLoad() {
|
72
|
+
super.viewDidLoad()
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
and run generate command with name `hello`, then you got following result.
|
78
|
+
|
79
|
+
```swift
|
80
|
+
import UIKit
|
81
|
+
|
82
|
+
class HelloViewController: UIViewController {
|
83
|
+
override func viewDidLoad() {
|
84
|
+
super.viewDidLoad()
|
85
|
+
}
|
86
|
+
}
|
87
|
+
```
|
20
88
|
|
21
89
|
## Contributing
|
22
90
|
|
@@ -24,4 +92,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/slight
|
|
24
92
|
|
25
93
|
## License
|
26
94
|
|
27
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
95
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
Binary file
|
data/enoki.gemspec
CHANGED
@@ -8,20 +8,21 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Enoki::VERSION
|
9
9
|
spec.authors = ["slightair"]
|
10
10
|
spec.email = ["arksutite@gmail.com"]
|
11
|
-
|
11
|
+
|
12
12
|
spec.summary = %q{Code generator for Xcode project.}
|
13
|
-
spec.description = %q{Code generator for Xcode project.}
|
13
|
+
spec.description = %q{Code generator for Xcode project. You can manage multiple user-defined file template set in your project.}
|
14
14
|
spec.homepage = "https://github.com/slightair/enoki"
|
15
15
|
spec.license = "MIT"
|
16
|
-
|
16
|
+
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
18
|
f.match(%r{^(test|spec|features|examples)/})
|
19
19
|
end
|
20
20
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
21
|
spec.require_paths = ["lib"]
|
22
|
-
|
22
|
+
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.14"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
-
|
26
|
-
spec.add_dependency
|
25
|
+
|
26
|
+
spec.add_dependency "thor", "~> 0.19"
|
27
|
+
spec.add_dependency "xcodeproj", "~> 1.5"
|
27
28
|
end
|
data/lib/enoki/cli/common.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'yaml'
|
2
|
+
require 'xcodeproj'
|
2
3
|
|
3
4
|
module Enoki
|
4
5
|
class CLI < Thor
|
@@ -38,6 +39,10 @@ module Enoki
|
|
38
39
|
def templates
|
39
40
|
Dir.glob(File.join(template_dir, "*/")).map { |f| File.basename(f) }
|
40
41
|
end
|
42
|
+
|
43
|
+
def project
|
44
|
+
@project ||= Xcodeproj::Project.open(project_file_path)
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
data/lib/enoki/cli/generate.rb
CHANGED
@@ -2,8 +2,9 @@ require 'pathname'
|
|
2
2
|
|
3
3
|
module Enoki
|
4
4
|
class CLI < Thor
|
5
|
-
NAME_PLACEHOLDER =
|
6
|
-
EXT_TEMPLATE =
|
5
|
+
NAME_PLACEHOLDER = "__name__"
|
6
|
+
EXT_TEMPLATE = ".tt"
|
7
|
+
SOURCE_CODE_EXT_LIST = %w(c m mm swift).map { |ext| ".#{ext}" }
|
7
8
|
|
8
9
|
include Thor::Actions
|
9
10
|
|
@@ -21,17 +22,42 @@ module Enoki
|
|
21
22
|
end
|
22
23
|
|
23
24
|
file_list.each do |path|
|
25
|
+
resolved_path = Pathname.new(path.to_path.gsub(NAME_PLACEHOLDER, name.capitalize).chomp(EXT_TEMPLATE))
|
24
26
|
source_path = path.expand_path(selected_template_root).to_path
|
25
|
-
dest_path =
|
27
|
+
dest_path = resolved_path.expand_path(project_root).to_path
|
26
28
|
|
27
29
|
template(source_path, dest_path, context: context_for_template(name))
|
30
|
+
add_file_reference(resolved_path)
|
28
31
|
end
|
32
|
+
|
33
|
+
project.save
|
29
34
|
end
|
30
35
|
|
31
36
|
no_commands do
|
32
37
|
def context_for_template(name)
|
33
38
|
binding
|
34
39
|
end
|
40
|
+
|
41
|
+
def add_file_reference(path)
|
42
|
+
path_list = path.to_path.split(File::SEPARATOR)
|
43
|
+
group = project.root_object.main_group
|
44
|
+
|
45
|
+
while path_list.size > 1
|
46
|
+
dir = path_list.shift
|
47
|
+
next_group = group.children.find { |g| g.path == dir } || group.new_group(dir, dir)
|
48
|
+
group = next_group
|
49
|
+
end
|
50
|
+
|
51
|
+
file = path_list.shift
|
52
|
+
file_ref = group.files.find { |f| f.path == file } || group.new_reference(file)
|
53
|
+
|
54
|
+
if SOURCE_CODE_EXT_LIST.include?(path.extname)
|
55
|
+
target = project.targets.first
|
56
|
+
if target
|
57
|
+
target.source_build_phase.add_file_reference(file_ref, true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
35
61
|
end
|
36
62
|
end
|
37
63
|
end
|
data/lib/enoki/cli/show.rb
CHANGED
data/lib/enoki/cli.rb
CHANGED
@@ -6,3 +6,13 @@ require 'enoki/cli/init'
|
|
6
6
|
require 'enoki/cli/show'
|
7
7
|
require 'enoki/cli/list'
|
8
8
|
require 'enoki/cli/generate'
|
9
|
+
|
10
|
+
module Enoki
|
11
|
+
class CLI < Thor
|
12
|
+
desc "version", "print enoki version"
|
13
|
+
def version
|
14
|
+
puts Enoki::VERSION
|
15
|
+
end
|
16
|
+
map %w(-v --version) => :version
|
17
|
+
end
|
18
|
+
end
|
data/lib/enoki/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enoki
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- slightair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,17 +42,32 @@ dependencies:
|
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '0.19'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.19'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: xcodeproj
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description: Code generator for Xcode project.
|
68
|
+
version: '1.5'
|
69
|
+
description: Code generator for Xcode project. You can manage multiple user-defined
|
70
|
+
file template set in your project.
|
56
71
|
email:
|
57
72
|
- arksutite@gmail.com
|
58
73
|
executables:
|
@@ -65,6 +80,7 @@ files:
|
|
65
80
|
- LICENSE
|
66
81
|
- README.md
|
67
82
|
- Rakefile
|
83
|
+
- assets/project_file_tree.png
|
68
84
|
- bin/enoki
|
69
85
|
- enoki.gemspec
|
70
86
|
- lib/enoki.rb
|