-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransform.rb
More file actions
87 lines (76 loc) · 2.05 KB
/
Copy pathtransform.rb
File metadata and controls
87 lines (76 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
$htmlMap = {
"wx:" => "a:",
"bindtap=" => "onTap=",
"bindlongTap=" => "onLongTap=",
"bindinput=" => "onInput=",
"bindchange=" => "onChange=",
"bindfocus=" => "onFocus=",
"bindblur=" => "onBlur=",
"bindconfirm=" => "onConfirm=",
"bindsubmit=" => "onSubmit=",
"bindreset=" => "onReset=",
"bindtouchstart=" => "onTouchStart=",
"bindtouchmove=" => "onTouchMove=",
"bindtouchend=" => "onTouchEnd=",
"bindtouchcancel=" => "onTouchCancel=",
"bindlongtap=" => "onLongTap=",
"bindmarkertap=" => "onMarkerTap=",
"bindcallouttap=" => "onCalloutTap=",
"bindcontroltap=" => "onControlTap=",
"bindregionchange=" => "onRegionChange=",
"canvas-id" => "id",
"bind=" => "on=",
}
$jsonMap = {
"navigationBarBackgroundColor" => "titleBarColor",
"navigationBarTitleText" => "defaultTitle",
"enablePullDownRefresh" => "pullRefresh",
"disableScroll" => "allowsBounceVertical",
"color" => "textColor",
"list" => "items",
"text" => "name",
"iconPath" => "icon",
"selectedIconPath" => "activeIcon",
}
def transformProject path
transformJson "#{path}/app.json"
transformCss "#{path}/app.wxss"
transformPages "#{path}/pages"
end
def transformPages pages
Dir.foreach(pages) { |x| transformPage("#{pages}/#{x}") unless x.start_with?(".") }
end
def transformPage page
page_path = page.split("/")[-1]
transformHtml "#{page}/#{page_path}.wxml"
transformJson "#{page}/#{page_path}.json"
transformCss "#{page}/#{page_path}.wxss"
end
def transformHtml html
content = File.read(html)
$htmlMap.each do |k, v|
content.gsub! k, v
end
File.write(html, content)
File.rename(html, "#{html.split('.').first}.axml")
end
def transformJson json
content = File.read(json)
$jsonMap.each do |k, v|
content.gsub! k, v
end
File.write(json, content)
end
def transformCss css
File.rename(css, "#{css.split('.').first}.acss")
end
paths = ARGV.map { |p| File.expand_path(p)}
paths.each do |path|
if File.exist?(path + "/app.js")
p "start transforming #{path}"
transformProject path
p "#{path} transform completed"
else
p "#{path} is not a mini program dir"
end
end