| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Buuilt::CLI; |
|
2
|
1
|
|
|
1
|
|
549
|
use 5.008001; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
43
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.02"; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
431
|
use Moo; |
|
|
1
|
|
|
|
|
11734
|
|
|
|
1
|
|
|
|
|
5
|
|
|
9
|
1
|
|
|
1
|
|
1795
|
use EV; |
|
|
1
|
|
|
|
|
1366
|
|
|
|
1
|
|
|
|
|
27
|
|
|
10
|
1
|
|
|
1
|
|
911
|
use AnyEvent; |
|
|
1
|
|
|
|
|
3953
|
|
|
|
1
|
|
|
|
|
28
|
|
|
11
|
1
|
|
|
1
|
|
466
|
use AnyEvent::Filesys::Notify; |
|
|
1
|
|
|
|
|
146998
|
|
|
|
1
|
|
|
|
|
36
|
|
|
12
|
1
|
|
|
1
|
|
663
|
use Archive::Zip; |
|
|
1
|
|
|
|
|
51187
|
|
|
|
1
|
|
|
|
|
44
|
|
|
13
|
1
|
|
|
1
|
|
434
|
use Path::Class; |
|
|
1
|
|
|
|
|
14510
|
|
|
|
1
|
|
|
|
|
58
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
520
|
use Mojo::UserAgent; |
|
|
1
|
|
|
|
|
245424
|
|
|
|
1
|
|
|
|
|
12
|
|
|
16
|
1
|
|
|
1
|
|
35
|
use Mojo::Asset::File; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
6
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub run { |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
|
21
|
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $action = shift @args; |
|
23
|
0
|
|
|
|
|
|
my $directory = shift @args; |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
0
|
|
|
|
|
if ( $action eq 'checkout' ) { |
|
|
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $dir = dir($directory); |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if ( -e $dir ) { |
|
30
|
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
print "Error: Checkout directory already exists, please choose a fresh one"; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} else { |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
$dir->mkpath; |
|
36
|
0
|
|
|
|
|
|
$self->checkout($directory); |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
} elsif ( $action eq 'watch' ) { |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
$self->watch($directory); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} else { |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
print 'Usage: ./buuilt checkout|watch $directory' . "\n\n"; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub config { |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return { |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
0
|
0
|
|
host => "", |
|
55
|
|
|
|
|
|
|
token => "", |
|
56
|
|
|
|
|
|
|
theme_id => "", |
|
57
|
|
|
|
|
|
|
}; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 checkout |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Checkout the whole theme into the given directory |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=cut |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub checkout { |
|
68
|
|
|
|
|
|
|
|
|
69
|
0
|
|
|
0
|
1
|
|
my ( $self, $directory ) = @_; |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $file = file( $directory, '.buuilt.zip' ); |
|
72
|
0
|
|
|
|
|
|
my $assets = dir( $directory, 'assets' ); |
|
73
|
0
|
|
|
|
|
|
my $elements = dir( $directory, 'elements' ); |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
my $config = $self->config(); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Follow redirect |
|
80
|
0
|
|
|
|
|
|
$ua->max_redirects(5)->get( $config->{host} . "/api/theme/checkout" => $config )->res->content->asset->move_to($file); |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $zip = Archive::Zip->new(); |
|
83
|
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$zip->read( $file->stringify ); |
|
85
|
0
|
|
|
|
|
|
$zip->extractTree( 'assets', $assets ); |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 watch |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Watch for changed or new files and directory, upload to cms |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=cut |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub watch { |
|
96
|
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
1
|
|
my ( $self, $directory ) = @_; |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
my $config = $self->config(); |
|
100
|
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $assets = dir( $directory, 'assets' ); |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $notifier = AnyEvent::Filesys::Notify->new( |
|
104
|
|
|
|
|
|
|
dirs => [$directory], |
|
105
|
|
|
|
|
|
|
interval => 2.0, # Optional depending on underlying watcher |
|
106
|
0
|
|
|
0
|
|
|
filter => sub { shift !~ /\.(swp|tmp|un~|sw\w)$/ }, |
|
107
|
|
|
|
|
|
|
cb => sub { |
|
108
|
0
|
|
|
0
|
|
|
my (@events) = @_; |
|
109
|
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
foreach my $event (@events) { |
|
111
|
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
my $dir = dir($directory); |
|
113
|
|
|
|
|
|
|
|
|
114
|
0
|
0
|
|
|
|
|
my $asset = -d $event->path ? dir $event->path : file $event->path; |
|
115
|
0
|
|
|
|
|
|
my $asset_relative = $asset->relative($assets); |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ( $event->is_dir ) { |
|
118
|
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
|
if ( $event->is_deleted ) { |
|
120
|
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
$self->asset_delete($asset_relative); |
|
122
|
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
printf STDERR ( "dir deleted : %s\n", $asset_relative ); |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} else { |
|
127
|
|
|
|
|
|
|
|
|
128
|
0
|
0
|
|
|
|
|
if ( $event->is_created ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$self->asset_put( $asset_relative, $asset ); |
|
131
|
0
|
|
|
|
|
|
printf STDERR ( "file created : %s\n", $asset_relative ); |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
} elsif ( $event->is_modified ) { |
|
134
|
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
$self->asset_put( $asset_relative, $asset ); |
|
136
|
0
|
|
|
|
|
|
printf STDERR ( "file modified: %s\n", $asset_relative ); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
} elsif ( $event->is_deleted ) { |
|
139
|
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$self->asset_delete($asset_relative); |
|
141
|
0
|
|
|
|
|
|
printf STDERR ( "file deleted : %s\n", $asset_relative ); |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# ... process @events ... |
|
149
|
|
|
|
|
|
|
}, |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#parse_events => 1, # Improves efficiency on certain platforms |
|
152
|
0
|
|
|
|
|
|
); |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
# Run unless end |
|
155
|
0
|
|
|
|
|
|
AnyEvent->condvar->recv; |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 asset_put |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Put an asset example stylesheets/demo.css |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub asset_put { |
|
166
|
|
|
|
|
|
|
|
|
167
|
0
|
|
|
0
|
1
|
|
my ( $self, $asset_relative, $asset ) = @_; |
|
168
|
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
my $config = $self->config(); |
|
170
|
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
|
172
|
0
|
|
|
|
|
|
my $tx = $ua->build_tx( PUT => $config->{host} . '/api/theme/assets/' . $asset_relative => $config ); |
|
173
|
0
|
|
|
|
|
|
$tx->req->content->asset( Mojo::Asset::File->new( path => $asset ) ); |
|
174
|
0
|
|
|
|
|
|
my $txr = $ua->start($tx); |
|
175
|
|
|
|
|
|
|
|
|
176
|
0
|
0
|
|
|
|
|
Mojo::IOLoop->start unless Mojo::IOLoop->is_running; |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
} |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 asset_delete |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Delete an asset, example stylesheet/demo.css |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=cut |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
sub asset_delete { |
|
187
|
|
|
|
|
|
|
|
|
188
|
0
|
|
|
0
|
1
|
|
my ( $self, $asset_relative ) = @_; |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
my $config = $self->config(); |
|
191
|
|
|
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
my $ua = Mojo::UserAgent->new; |
|
193
|
0
|
|
|
|
|
|
my $tx = $ua->build_tx( DELETE => $config->{host} . '/api/theme/assets/' . $asset_relative => $config ); |
|
194
|
0
|
|
|
|
|
|
my $txr = $ua->start($tx); |
|
195
|
|
|
|
|
|
|
|
|
196
|
0
|
0
|
|
|
|
|
Mojo::IOLoop->start unless Mojo::IOLoop->is_running; |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
} |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |
|
201
|
|
|
|
|
|
|
__END__ |