pxg 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/pxg +2 -1
- data/lib/pxg.rb +133 -14
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MThkNGYyNGY4M2M2OGRlZGRkNThjNmRhYmUyMmE5YzQzOTFkYWE4Zg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTBlOTUyOWU2YWMwM2JlMzQwZTJjMjQxZjc3MzE5MjgxMzJmZDJhNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YThjZjU0MTk3NDBjN2RlZWI1Y2MxOTZkZWNmN2FiZmI3NWRkZWUyNmY4YTU1
|
10
|
+
NDVmYTNjMDVjMGU5ZDkzNGQ3OTg3M2M3ZTcyMGM5Njg1NDhmMjkyODIwMTdi
|
11
|
+
OTQyMTc0Y2UxNjI0MzA2MzA1NmExYTRmM2Y4MGU3YzZlMzM1NTU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTliYjRiNTIyYzIxYjRmYTM2NzkzZjJlNTNkYmM4YTNiMTYyOGZjYzA5ZDU5
|
14
|
+
OWI0ODZiZjlkMDNjNDQ5OGFmNzE2Y2NhMmU0ZmYzNWI3NTg3NGE3ODJiMTc1
|
15
|
+
NzNmN2VhMWE0ZmE3MDUzZWFhZGFjMjYwMTY1ZGQ5NmRiMTJkYjA=
|
data/bin/pxg
CHANGED
@@ -15,7 +15,8 @@ puts
|
|
15
15
|
puts <<eos
|
16
16
|
Commands
|
17
17
|
------------------------------------------------------------------------------
|
18
|
-
pxg
|
18
|
+
pxg version - current interface version
|
19
|
+
pxg compile [<dir>] - reads pxg.json from directory and resolves it
|
19
20
|
eos
|
20
21
|
|
21
22
|
end#if
|
data/lib/pxg.rb
CHANGED
@@ -8,6 +8,8 @@ require 'json'
|
|
8
8
|
|
9
9
|
class Pxg
|
10
10
|
|
11
|
+
VERSION = '1.1.0'
|
12
|
+
|
11
13
|
def find_and_replace(path, search, replace)
|
12
14
|
clean_path = path.sub(/(\/)+$/, '') + '/'
|
13
15
|
Dir.glob "#{clean_path}**/*.php" do |file|
|
@@ -15,48 +17,165 @@ class Pxg
|
|
15
17
|
text = File.read file
|
16
18
|
text = text.gsub search, replace
|
17
19
|
File.write file, text
|
18
|
-
end
|
20
|
+
end#glob
|
21
|
+
end#def
|
22
|
+
|
23
|
+
def ensure_copy(rawsrcpath, rawlocalpath, rawthemepath)
|
24
|
+
srcpath = File.expand_path(rawsrcpath) + '/'
|
25
|
+
localpath = File.expand_path(rawlocalpath) + '/'
|
26
|
+
themepath = File.expand_path(rawthemepath) + '/'
|
27
|
+
Dir.glob "#{srcpath}**/*" do |file|
|
28
|
+
next if file == '.' or file == '..'
|
29
|
+
filepath = File.expand_path(file)
|
30
|
+
filesubpath = filepath.sub srcpath, ''
|
31
|
+
localfilepath = localpath + filesubpath
|
32
|
+
if ! File.exists? localfilepath
|
33
|
+
localfilesubpath = localfilepath.sub themepath, ''
|
34
|
+
puts " - #{localfilesubpath}"
|
35
|
+
text = File.read filepath
|
36
|
+
FileUtils.mkpath File.dirname(localfilepath)
|
37
|
+
File.write localfilepath, text
|
38
|
+
end#if
|
39
|
+
end#glob
|
40
|
+
end#def
|
41
|
+
|
42
|
+
def force_copy(filepaths, rawsrcpath, rawlocalpath, rawthemepath)
|
43
|
+
srcpath = File.expand_path(rawsrcpath) + '/'
|
44
|
+
localpath = File.expand_path(rawlocalpath) + '/'
|
45
|
+
themepath = File.expand_path(rawthemepath) + '/'
|
46
|
+
Dir.glob "#{srcpath}**/*" do |file|
|
47
|
+
next if file == '.' or file == '..'
|
48
|
+
filepath = File.expand_path(file)
|
49
|
+
filesubpath = filepath.sub srcpath, ''
|
50
|
+
if filepaths.include? filesubpath
|
51
|
+
|
52
|
+
localfilepath = localpath + filesubpath
|
53
|
+
localfilesubpath = localfilepath.sub themepath, ''
|
54
|
+
text = File.read filepath
|
55
|
+
updatefile = false
|
56
|
+
|
57
|
+
if File.exists? localfilepath
|
58
|
+
localtext = File.read localfilepath
|
59
|
+
if ! localtext.eql? text
|
60
|
+
updatefile = true
|
61
|
+
end#if
|
62
|
+
else # file does not exist
|
63
|
+
updatefile = true
|
64
|
+
end#if
|
65
|
+
|
66
|
+
if updatefile
|
67
|
+
puts " - #{localfilesubpath}"
|
68
|
+
FileUtils.mkpath File.dirname(localfilepath)
|
69
|
+
File.write localfilepath, text
|
70
|
+
end#if
|
71
|
+
|
72
|
+
end#if
|
73
|
+
end#glob
|
19
74
|
end#def
|
20
75
|
|
21
76
|
def wp_core(path, conf)
|
22
77
|
Dir.chdir path
|
78
|
+
themepath = path.sub(/(\/)+$/, '') + '/'
|
23
79
|
core_path = conf['path'].sub(/(\/)+$/, '')
|
24
|
-
|
80
|
+
|
81
|
+
puts " processing #{core_path}"
|
25
82
|
# remove the core if it exists
|
26
83
|
FileUtils.rm_rf core_path
|
27
84
|
# clone a fresh copy
|
28
|
-
puts "cloning #{conf['repo']} -> #{conf['version']}"
|
85
|
+
puts " cloning #{conf['repo']} -> #{conf['version']}"
|
29
86
|
g = Git.clone conf['repo'], core_path
|
30
87
|
g.checkout conf['version']
|
31
88
|
FileUtils.rm_rf core_path+'/.git'
|
89
|
+
|
32
90
|
# refactor name space
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
91
|
+
if conf.has_key? 'namespace'
|
92
|
+
ns_src = conf['namespace']['src']
|
93
|
+
ns_target = conf['namespace']['target']
|
94
|
+
puts " refactoring #{core_path}"
|
95
|
+
self.find_and_replace core_path, ns_src, ns_target
|
96
|
+
self.find_and_replace core_path, ns_src.capitalize, ns_target.capitalize
|
97
|
+
end#if
|
98
|
+
|
99
|
+
# ensure partials
|
100
|
+
if conf.has_key? 'partials'
|
101
|
+
partials_src = core_path + '/' + conf['partials']['src']
|
102
|
+
partials_local = themepath + conf['partials']['local']
|
103
|
+
puts " ensuring copy of system partials"
|
104
|
+
self.ensure_copy partials_src, partials_local, themepath
|
105
|
+
end#if
|
106
|
+
|
107
|
+
# ensure behavior tests
|
108
|
+
if conf.has_key? 'features'
|
109
|
+
features_src = core_path + '/' + conf['features']['src']
|
110
|
+
features_local = themepath + conf['features']['local']
|
111
|
+
if conf['features'].has_key? 'ensure'
|
112
|
+
rawfilenames = conf['features']['ensure']
|
113
|
+
filenames = []
|
114
|
+
rawfilenames.each do |file|
|
115
|
+
filenames.push (file + '.feature')
|
116
|
+
end#each
|
117
|
+
puts " ensuring latest copy of active feature tests"
|
118
|
+
self.force_copy filenames, features_src, features_local, themepath
|
119
|
+
end#if
|
120
|
+
end#if
|
121
|
+
|
38
122
|
end#def
|
39
123
|
|
40
124
|
def compile(args)
|
41
|
-
|
125
|
+
if args.length != 0
|
126
|
+
dirpath = args[0].sub(/(\/)+$/,'')+'/'
|
127
|
+
else # no parameters, assume .
|
128
|
+
dirpath = './'
|
129
|
+
end
|
130
|
+
|
42
131
|
if ! File.exist? dirpath
|
43
|
-
puts 'Err: target directory does not exist.'
|
132
|
+
puts ' Err: target directory does not exist.'
|
44
133
|
return;
|
45
134
|
end
|
46
135
|
|
47
|
-
jsonconfigfile = dirpath+'pxg.json'
|
136
|
+
jsonconfigfile = dirpath+'pxg.json'
|
48
137
|
if ! File.exist? jsonconfigfile
|
49
|
-
puts 'Err: Missing pxg.json file in target directory.'
|
138
|
+
puts ' Err: Missing pxg.json file in target directory.'
|
50
139
|
return;
|
51
140
|
end
|
52
141
|
|
53
|
-
conf = JSON.parse(open(jsonconfigfile).read)
|
142
|
+
conf = JSON.parse(open(jsonconfigfile).read)
|
143
|
+
|
144
|
+
# interface was introduced after 1.0.0
|
145
|
+
if conf.has_key? 'interface'
|
146
|
+
conf['interface'] = "1.0.0"
|
147
|
+
end#if
|
148
|
+
|
149
|
+
# ensure pxg.json interface isn't newer
|
150
|
+
pxgi = Pxg::VERSION.split '.'
|
151
|
+
jsoni = conf['interface'].split '.'
|
152
|
+
|
153
|
+
if jsoni[0] != pxgi[0]
|
154
|
+
self.failed_version_check conf['interface']
|
155
|
+
else # major versions are equal
|
156
|
+
if jsoni[1] > pxgi[1]
|
157
|
+
# ie. json requires extra features
|
158
|
+
self.failed_version_check conf['interface']
|
159
|
+
elsif jsoni[1] == pxgi[1] && jsoni[2] > pxgi[2]
|
160
|
+
# ie. potential problems with bugfix'es
|
161
|
+
self.failed_version_check conf['interface']
|
162
|
+
end#if
|
163
|
+
end#if
|
54
164
|
|
55
165
|
conf['wp-cores'].each do |wpcoreconf|
|
56
166
|
self.wp_core dirpath, wpcoreconf
|
57
167
|
end#each
|
58
168
|
|
59
|
-
puts
|
169
|
+
puts ""
|
170
|
+
puts " fin"
|
171
|
+
end#def
|
172
|
+
|
173
|
+
def version(args)
|
174
|
+
puts " #{Pxg::VERSION}"
|
175
|
+
end#def
|
176
|
+
|
177
|
+
def failed_version_check(interface)
|
178
|
+
puts " Err: Incompatible versions: pxg.json @ #{interface} but pxg.gem @ #{Pxg::VERSION}"
|
60
179
|
end#def
|
61
180
|
|
62
181
|
end#class
|