line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# TODO: |
2
|
|
|
|
|
|
|
# - Generate a Makefile to bring everything up to date |
3
|
|
|
|
|
|
|
# - Use tt with Makefile template |
4
|
|
|
|
|
|
|
package Cog::Maker; |
5
|
2
|
|
|
2
|
|
2352
|
use Mo; |
|
2
|
|
|
|
|
360
|
|
|
2
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
extends 'Cog::Base'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1017
|
use Template::Toolkit::Simple; |
|
2
|
|
|
|
|
65908
|
|
|
2
|
|
|
|
|
99
|
|
9
|
2
|
|
|
2
|
|
488
|
use IO::All; |
|
2
|
|
|
|
|
9797
|
|
|
2
|
|
|
|
|
15
|
|
10
|
2
|
|
|
2
|
|
2081
|
use IPC::Run; |
|
2
|
|
|
|
|
67538
|
|
|
2
|
|
|
|
|
85
|
|
11
|
2
|
|
|
2
|
|
1236
|
use Pod::Simple::HTML; |
|
2
|
|
|
|
|
80578
|
|
|
2
|
|
|
|
|
25
|
|
12
|
2
|
|
|
2
|
|
1446
|
use File::Copy; |
|
2
|
|
|
|
|
3977
|
|
|
2
|
|
|
|
|
216
|
|
13
|
2
|
|
|
2
|
|
11
|
use File::Path; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
2043
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub make { |
16
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
17
|
0
|
|
|
|
|
|
File::Path::mkpath $self->app->build_root; |
18
|
0
|
|
|
|
|
|
File::Path::mkpath $self->app->webapp_root; |
19
|
0
|
|
|
|
|
|
$self->make_config_js(); |
20
|
0
|
|
|
|
|
|
$self->make_url_map_js(); |
21
|
0
|
|
|
|
|
|
$self->make_all_js(); |
22
|
0
|
|
|
|
|
|
$self->make_all_css(); |
23
|
0
|
|
|
|
|
|
$self->make_image(); |
24
|
0
|
|
|
|
|
|
$self->make_index_html; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub make_assets { |
28
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
29
|
0
|
|
|
|
|
|
my $files = $self->config->files_map; |
30
|
0
|
|
|
|
|
|
my $root = $self->app->build_root; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
for my $file (sort keys %$files) { |
33
|
0
|
|
|
|
|
|
my $plugin = $files->{$file}[0]; |
34
|
0
|
|
|
|
|
|
my $source = $files->{$file}[1]; |
35
|
0
|
|
|
|
|
|
my $target = "$root/$file"; |
36
|
0
|
0
|
|
|
|
|
if ($ENV{COG_SYMLINK_INSTALL}) { |
37
|
0
|
0
|
0
|
|
|
|
unless (-l $target and readlink($target) eq $source) { |
38
|
0
|
|
|
|
|
|
unlink $target; |
39
|
0
|
|
|
|
|
|
io($target)->assert->symlink($source); |
40
|
0
|
|
|
|
|
|
print "> link $source => $target\n"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
0
|
0
|
|
|
|
unless ( |
|
|
|
0
|
|
|
|
|
45
|
|
|
|
|
|
|
-f $target and |
46
|
|
|
|
|
|
|
not(-l $target) and |
47
|
|
|
|
|
|
|
io($target)->all eq io($source)->all |
48
|
|
|
|
|
|
|
) { |
49
|
0
|
|
|
|
|
|
unlink $target; |
50
|
0
|
|
|
|
|
|
io($target)->assert->print(io($source)->all); |
51
|
0
|
|
|
|
|
|
printf "Update: %-25s %s\n", $plugin, $file; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub make_config_js { |
58
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
59
|
0
|
|
|
|
|
|
my $config_path = $self->app->config_file; |
60
|
0
|
|
|
|
|
|
my $data = { |
61
|
|
|
|
|
|
|
json => $self->json->encode(YAML::XS::LoadFile($config_path)), |
62
|
|
|
|
|
|
|
}; |
63
|
0
|
|
|
|
|
|
my $build = $self->app->build_root; |
64
|
0
|
|
|
|
|
|
my $javascript = tt() |
65
|
|
|
|
|
|
|
->path(["$build/template/"]) |
66
|
|
|
|
|
|
|
->data($data) |
67
|
|
|
|
|
|
|
->post_chomp |
68
|
|
|
|
|
|
|
->render('config.js'); |
69
|
0
|
|
|
|
|
|
io("$build/js/config.js")->print($javascript); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub make_url_map_js { |
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
74
|
0
|
|
|
|
|
|
my $data = { |
75
|
|
|
|
|
|
|
json => $self->json->encode($self->config->url_map), |
76
|
|
|
|
|
|
|
}; |
77
|
0
|
|
|
|
|
|
my $build = $self->app->build_root; |
78
|
0
|
|
|
|
|
|
my $javascript = tt() |
79
|
|
|
|
|
|
|
->path(["$build/template/"]) |
80
|
|
|
|
|
|
|
->data($data) |
81
|
|
|
|
|
|
|
->post_chomp |
82
|
|
|
|
|
|
|
->render('url-map.js'); |
83
|
0
|
|
|
|
|
|
io("$build/js/url-map.js")->print($javascript); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub make_all_js { |
87
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
88
|
0
|
|
|
|
|
|
my $build = $self->app->build_root; |
89
|
0
|
|
|
|
|
|
my $js = "$build/js"; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $data = { |
92
|
|
|
|
|
|
|
build => $build, |
93
|
|
|
|
|
|
|
list => join( |
94
|
|
|
|
|
|
|
' ', |
95
|
0
|
|
|
|
|
|
@{$self->config->js_files}, |
96
|
|
|
|
|
|
|
map { |
97
|
0
|
|
|
|
|
|
s/\.coffee$/\.js/; |
98
|
0
|
|
|
|
|
|
$_; |
99
|
0
|
|
|
|
|
|
} @{$self->config->coffee_files} |
100
|
|
|
|
|
|
|
) |
101
|
|
|
|
|
|
|
}; |
102
|
0
|
|
|
|
|
|
my $makefile = tt() |
103
|
|
|
|
|
|
|
->path(["$build/template/"]) |
104
|
|
|
|
|
|
|
->data($data) |
105
|
|
|
|
|
|
|
->post_chomp |
106
|
|
|
|
|
|
|
->render('js-mf.mk'); |
107
|
0
|
|
|
|
|
|
io("$js/Makefile")->print($makefile); |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
system("(cd $js; make)") == 0 or die; |
110
|
|
|
|
|
|
|
# TODO - Make fingerprint file here instead of Makefile |
111
|
0
|
0
|
|
|
|
|
my ($file) = glob("$js/all-*.js") or die; |
112
|
0
|
|
|
|
|
|
copy $file, $self->app->webapp_root; |
113
|
0
|
|
|
|
|
|
$file =~ s!.*/!!; |
114
|
0
|
|
|
|
|
|
$self->config->all_js_file($file); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub make_all_css { |
118
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
119
|
0
|
|
|
|
|
|
my $build = $self->app->build_root; |
120
|
0
|
|
|
|
|
|
my $css = "$build/css"; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $data = { |
123
|
0
|
|
|
|
|
|
list => join(' ', @{$self->config->css_files}), |
124
|
|
|
|
|
|
|
}; |
125
|
0
|
|
|
|
|
|
my $makefile = tt() |
126
|
|
|
|
|
|
|
->path(["$build/template/"]) |
127
|
|
|
|
|
|
|
->data($data) |
128
|
|
|
|
|
|
|
->post_chomp |
129
|
|
|
|
|
|
|
->render('css-mf.mk'); |
130
|
0
|
|
|
|
|
|
io("$css/Makefile")->print($makefile); |
131
|
|
|
|
|
|
|
|
132
|
0
|
0
|
|
|
|
|
system("(cd $css; make)") == 0 or die; |
133
|
0
|
0
|
|
|
|
|
my ($file) = glob("$css/all-*.css") or die; |
134
|
0
|
|
|
|
|
|
copy $file, $self->app->webapp_root; |
135
|
0
|
|
|
|
|
|
$file =~ s!.*/!!; |
136
|
0
|
|
|
|
|
|
$self->config->all_css_file($file); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub make_image { |
140
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $build = $self->app->build_root; |
142
|
0
|
|
|
|
|
|
my $webapp = $self->app->webapp_root; |
143
|
0
|
0
|
|
|
|
|
symlink "$build/image", "$webapp/image" |
144
|
|
|
|
|
|
|
unless -e "$webapp/image"; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub make_index_html { |
148
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
149
|
0
|
|
|
|
|
|
my $build = $self->app->build_root; |
150
|
0
|
|
|
|
|
|
my $webapp = $self->app->webapp_root; |
151
|
0
|
|
|
|
|
|
my $data = +{%{$self->config}}; |
|
0
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
my $html = tt() |
153
|
|
|
|
|
|
|
->path(["$build/template/"]) |
154
|
|
|
|
|
|
|
->data($data) |
155
|
|
|
|
|
|
|
->post_chomp |
156
|
|
|
|
|
|
|
->render('index-table.html'); |
157
|
0
|
|
|
|
|
|
io("$webapp/index.html")->print($html); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub make_clean { |
161
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
162
|
0
|
0
|
|
|
|
|
my $build_root = $self->app->build_root |
163
|
|
|
|
|
|
|
or die "build_root not available"; |
164
|
0
|
0
|
|
|
|
|
my $webapp_root = $self->app->webapp_root |
165
|
|
|
|
|
|
|
or die "webapp_root not available"; |
166
|
0
|
|
|
|
|
|
for my $file_dir (qw(coffee css image js template)) { |
167
|
0
|
0
|
|
|
|
|
File::Path::rmtree "$build_root/$file_dir" |
168
|
|
|
|
|
|
|
if -e "$build_root/$file_dir"; |
169
|
|
|
|
|
|
|
} |
170
|
0
|
0
|
|
|
|
|
File::Path::rmtree $webapp_root if -e $webapp_root; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |