lad 0.0.2 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +8 -5
- data/lib/config.rb +14 -0
- data/lib/files.rb +14 -5
- data/lib/lad.rb +36 -11
- data/lib/lad/version.rb +1 -1
- metadata +8 -8
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Strapping Young Lad (or just Lad for short)
|
2
2
|
|
3
|
+
[![endorse](http://api.coderwall.com/kouphax/endorsecount.png)](http://coderwall.com/kouphax)
|
4
|
+
|
3
5
|
__Strapping Young Lad__ is a tokenised solution template substitution engine. A bit of a mouthful I know but it actually much simpler than it sounds (and hopefully much more useful that you'd think). So what does it do? Well running
|
4
6
|
|
5
7
|
lad /path/to/git/repo MyNewProject
|
@@ -39,7 +41,7 @@ The example above shows you how to use the gem,
|
|
39
41
|
lad <PathToRepo> <ProjectName>
|
40
42
|
|
41
43
|
- `PathToRepo` is the git repository url that will be cloned
|
42
|
-
- `ProjectName` is the name of the project. This will replace the `__NAME__` token in the repository directories, files and contents
|
44
|
+
- `ProjectName` is the name of the project. This will replace the `__NAME__` token in the repository directories, files and contents. It is possible to declare other tokens as well via the `.ladconfig` file
|
43
45
|
|
44
46
|
## Configuring the engine via `.ladconfig`
|
45
47
|
|
@@ -47,7 +49,7 @@ SYL, once the repository has been cloned will check for the existence of file wi
|
|
47
49
|
|
48
50
|
### Configuration Options
|
49
51
|
|
50
|
-
- `token` - this is the token/indetifier that will be replaced in the template with the name of the project (defaults to `__NAME__`)
|
52
|
+
- `token` - this is the token/indetifier that will be replaced in the template with the name of the project (defaults to `__NAME__`). This option will also accept and array of tokens ['__NAME__', '__NAMESPACE__']. In this case the user will be prompted for the values of these tokens.
|
51
53
|
- `ignore` - a list of extensions that SYL will ignore when it comes to replacing CONTENTS. It will still RENAME the file if the file name includes the token. This allows us to ignore binary files whose contents should not change.
|
52
54
|
|
53
55
|
## Contributing
|
@@ -60,10 +62,11 @@ SYL, once the repository has been cloned will check for the existence of file wi
|
|
60
62
|
|
61
63
|
## Changes
|
62
64
|
|
63
|
-
|
64
|
-
17 Apr 2012 - Version 0.0.
|
65
|
+
20 Apr 2012 - Version 0.1.2 released. .ladconfig now accepts multiple tokens to be specified.
|
66
|
+
17 Apr 2012 - Version 0.0.2 released. Addition of simple help text on the command line.
|
67
|
+
17 Apr 2012 - Version 0.0.1 released.
|
65
68
|
|
66
69
|
## Roadmap
|
67
70
|
|
68
|
-
- __accept multiple tokens via command line or via interactive shell__
|
69
71
|
- zip support (generate project from zip file)
|
72
|
+
- other things as yet undetermined
|
data/lib/config.rb
CHANGED
@@ -9,5 +9,19 @@ module Lad
|
|
9
9
|
default_config
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
def self.get_token_values(cfg, default_value)
|
14
|
+
tokens = cfg['token']
|
15
|
+
if(tokens.class == Array)
|
16
|
+
Hash[*tokens.map {|token|
|
17
|
+
formatted = token.match(/__(.*)__/)[1].downcase
|
18
|
+
value = Readline.readline(" #{formatted}#{' (' + default_value + ')' if formatted == 'name' }: ", true)
|
19
|
+
value = default_value if formatted == 'name' && value == ''
|
20
|
+
[token, value]
|
21
|
+
}.flatten]
|
22
|
+
else
|
23
|
+
{ tokens => default_value }
|
24
|
+
end
|
25
|
+
end
|
12
26
|
end
|
13
27
|
end
|
data/lib/files.rb
CHANGED
@@ -17,11 +17,20 @@ module Lad
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.replace_token_in_file(exclusions, file, token, name)
|
20
|
-
if
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
if exclusions.nil? || !exclusion.member?(File.extname file)
|
21
|
+
begin
|
22
|
+
contents = File.read(file).gsub!(token, name)
|
23
|
+
File.open(file, 'w') { |f|
|
24
|
+
f.puts contents
|
25
|
+
}
|
26
|
+
rescue
|
27
|
+
# oh yeah great idea swallow exceptions! so binary files can't be parsed etc these
|
28
|
+
# need to be excluded by the config. Wait lets rethrow like a boss
|
29
|
+
Console.error ' Looks like you are trying to token replace the contents of a binary. '
|
30
|
+
Console.error ' Perhaps you need to exclude this in the .ladconfig file? '
|
31
|
+
|
32
|
+
throw 'Attempting to modify binary file'
|
33
|
+
end
|
25
34
|
end
|
26
35
|
end
|
27
36
|
end
|
data/lib/lad.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'readline'
|
2
3
|
|
3
4
|
module Lad
|
4
5
|
class Bootstrapper
|
5
6
|
def self.execute
|
6
7
|
|
8
|
+
# input_tokens = nil
|
9
|
+
|
7
10
|
optparser = OptionParser.new do |opts|
|
8
11
|
opts.banner = '''
|
9
12
|
Usage: lad [-h|--help] [<path_to_git_repo> <project_name>]
|
@@ -14,6 +17,14 @@ module Lad
|
|
14
17
|
puts opts
|
15
18
|
exit
|
16
19
|
end
|
20
|
+
|
21
|
+
# opts.on('-t TOKENS', '--tokens TOKENS', 'Tokens to replace in the form of, token:value token:value') do |tokens|
|
22
|
+
# input_tokens = Hash[*tokens.map { |v|
|
23
|
+
# v.split ':'
|
24
|
+
# }.flat_map { |kvp|
|
25
|
+
# ["__#{kvp.first.upcase}__", kvp.last]
|
26
|
+
# }]
|
27
|
+
# end
|
17
28
|
end
|
18
29
|
|
19
30
|
optparser.parse!
|
@@ -33,22 +44,31 @@ module Lad
|
|
33
44
|
|
34
45
|
Console.task 'Loading configuration' do
|
35
46
|
config = Config.load dir, {
|
36
|
-
token
|
37
|
-
ignore: [
|
38
|
-
'.png', '.jpg', '.gif', '.cache', '.suo',
|
39
|
-
'.dll', '.zip', '.nupkg', '.pdb', '.exe'
|
40
|
-
]
|
47
|
+
'token' => '__NAME__'
|
41
48
|
}
|
42
49
|
end
|
43
50
|
|
51
|
+
Console.task 'Parsing tokens and stuff' do
|
52
|
+
puts ''
|
53
|
+
config['token_values'] = Config.get_token_values config, options[:name]
|
54
|
+
puts ''
|
55
|
+
end
|
56
|
+
|
44
57
|
Console.task 'Processing files' do
|
45
58
|
Dir.glob(File.join dir, '**/*').each do |item|
|
46
59
|
if !File.directory?(item)
|
47
|
-
files_processed += 1
|
48
|
-
|
49
|
-
|
60
|
+
files_processed += 1
|
61
|
+
|
62
|
+
config['token_values'].each do |token|
|
63
|
+
new_item = Files.new_filename item, *token
|
50
64
|
|
51
|
-
|
65
|
+
if item != new_item
|
66
|
+
File.rename(item, new_item)
|
67
|
+
item = new_item
|
68
|
+
end
|
69
|
+
|
70
|
+
Files.replace_token_in_file config['ignore'], new_item, *token
|
71
|
+
end
|
52
72
|
end
|
53
73
|
end
|
54
74
|
end
|
@@ -57,8 +77,13 @@ module Lad
|
|
57
77
|
Dir.glob(File.join dir, '**/*').each do |item|
|
58
78
|
if File.directory?(item)
|
59
79
|
dirs_processed += 1
|
60
|
-
|
61
|
-
|
80
|
+
config['token_values'].each do |token|
|
81
|
+
new_item = Files.new_filename item, *token
|
82
|
+
if item != new_item
|
83
|
+
File.rename(item, new_item)
|
84
|
+
item = new_item
|
85
|
+
end
|
86
|
+
end
|
62
87
|
end
|
63
88
|
end
|
64
89
|
end
|
data/lib/lad/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lad
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: git
|
16
|
-
requirement: &
|
16
|
+
requirement: &70274558009640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70274558009640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: colorize
|
27
|
-
requirement: &
|
27
|
+
requirement: &70274558009180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70274558009180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: minitest
|
38
|
-
requirement: &
|
38
|
+
requirement: &70274558008320 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70274558008320
|
47
47
|
description: ! 'Strapping Young Lad: Project Template Bootstrapper'
|
48
48
|
email:
|
49
49
|
- james@yobriefca.se
|