line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dist::Zilla::Plugin::Web::NPM::Package; |
2
|
|
|
|
|
|
|
$Dist::Zilla::Plugin::Web::NPM::Package::VERSION = '0.0.7'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Generate the `package.json` file, suitable for `npm` package manager |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
656624
|
use Moose; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
16
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::FileGatherer'; |
8
|
|
|
|
|
|
|
# to allow `dzil run` commands |
9
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::BuildRunner'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
with 'Dist::Zilla::Role::AfterBuild'; |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
12083
|
use Dist::Zilla::File::FromCode; |
|
2
|
|
|
|
|
65591
|
|
|
2
|
|
|
|
|
70
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
31
|
use JSON 2; |
|
2
|
|
|
|
|
48
|
|
|
2
|
|
|
|
|
16
|
|
16
|
2
|
|
|
2
|
|
305
|
use Path::Class; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
141
|
|
17
|
|
|
|
|
|
|
|
18
|
2
|
|
|
2
|
|
861
|
use File::ShareDir; |
|
2
|
|
|
|
|
6183
|
|
|
2
|
|
|
|
|
88
|
|
19
|
2
|
|
|
2
|
|
13
|
use Cwd; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
3143
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has 'name' => ( |
23
|
|
|
|
|
|
|
is => 'rw', |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
default => sub { |
28
|
|
|
|
|
|
|
return lc($_[0]->zilla->name) |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'version' => ( |
34
|
|
|
|
|
|
|
is => 'rw', |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
lazy => 1, |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
default => sub { |
39
|
|
|
|
|
|
|
my $version = $_[0]->zilla->version; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$version .= '.0' if $version !~ m!\d+\.\d+\.\d+!; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# strip leading zeros |
44
|
|
|
|
|
|
|
$version =~ s/\.0+(\d+)/.$1/g; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
return $version |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
has 'author' => ( |
52
|
|
|
|
|
|
|
is => 'rw', |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
lazy => 1, |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
default => sub { |
57
|
|
|
|
|
|
|
return $_[0]->zilla->authors->[0] |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has 'description' => ( |
63
|
|
|
|
|
|
|
is => 'rw', |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
lazy => 1, |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
default => sub { |
68
|
|
|
|
|
|
|
return $_[0]->zilla->abstract |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
has 'homepage' => ( |
74
|
|
|
|
|
|
|
is => 'rw', |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
lazy => 1, |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
default => sub { |
79
|
|
|
|
|
|
|
my $meta = $_[0]->zilla->distmeta; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
return $meta->{ resources } && $meta->{ resources }->{ homepage } |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has 'repository' => ( |
87
|
|
|
|
|
|
|
is => 'rw', |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
lazy => 1, |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
default => sub { |
92
|
|
|
|
|
|
|
my $meta = $_[0]->zilla->distmeta; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
return $meta->{ resources } && $meta->{ resources }->{ repository } |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
); |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
has 'contributor' => ( |
100
|
|
|
|
|
|
|
is => 'rw', |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
lazy => 1, |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
default => sub { |
105
|
|
|
|
|
|
|
my @authors = @{$_[0]->zilla->authors}; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
shift @authors; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
return \@authors; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
has 'main' => ( |
115
|
|
|
|
|
|
|
is => 'rw', |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
lazy => 1, |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
default => sub { |
120
|
|
|
|
|
|
|
my $name = $_[0]->zilla->name; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$name =~ s!-!/!g; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
return 'lib/' . $name; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
has 'dependency' => ( |
130
|
|
|
|
|
|
|
is => 'rw', |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
lazy => 1, |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
default => sub { [] } |
135
|
|
|
|
|
|
|
); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
has 'devDependency' => ( |
139
|
|
|
|
|
|
|
is => 'rw', |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
lazy => 1, |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
default => sub { [] } |
144
|
|
|
|
|
|
|
); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
has 'engine' => ( |
149
|
|
|
|
|
|
|
is => 'rw', |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
lazy => 1, |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
default => sub { [] } |
154
|
|
|
|
|
|
|
); |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
has 'bin' => ( |
158
|
|
|
|
|
|
|
is => 'rw', |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
default => sub { [] } |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
has 'links_deps' => ( |
165
|
|
|
|
|
|
|
is => 'rw', |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
default => 1 |
168
|
|
|
|
|
|
|
); |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
#================================================================================================================================================================================================================================================ |
173
|
|
|
|
|
|
|
# to satisfy BuildRunner |
174
|
0
|
|
|
0
|
0
|
0
|
sub build { |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
#================================================================================================================================================================================================================================================ |
180
|
|
|
|
|
|
|
sub gather_files { |
181
|
1
|
|
|
1
|
0
|
130000
|
my ($self) = @_; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
$self->add_file(Dist::Zilla::File::FromCode->new({ |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
name => file('package.json') . '', |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
code => sub { |
188
|
|
|
|
|
|
|
|
189
|
1
|
|
|
1
|
|
52111
|
my $package = {}; |
190
|
|
|
|
|
|
|
|
191
|
1
|
|
|
|
|
52
|
$package->{ $_ } = $self->$_ for qw( name version description homepage repository author main ); |
192
|
|
|
|
|
|
|
|
193
|
1
|
|
|
|
|
46
|
$package->{ contributors } = $self->contributor; |
194
|
1
|
50
|
|
|
|
3
|
$package->{ dependencies } = $self->convert_dependencies($self->dependency) if @{$self->dependency} > 0; |
|
1
|
|
|
|
|
47
|
|
195
|
1
|
50
|
|
|
|
2
|
$package->{ dependencies } = $self->convert_dependencies($self->dependency) if @{$self->dependency} > 0; |
|
1
|
|
|
|
|
111
|
|
196
|
|
|
|
|
|
|
|
197
|
1
|
50
|
|
|
|
2
|
$package->{ engines } = $self->convert_engines($self->engine) if @{$self->engine} > 0; |
|
1
|
|
|
|
|
53
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
$package->{ directories } = { |
200
|
1
|
|
|
|
|
7
|
"doc" => "./doc/mmd", |
201
|
|
|
|
|
|
|
"man" => "./man", |
202
|
|
|
|
|
|
|
"lib" => "./lib" |
203
|
|
|
|
|
|
|
}; |
204
|
|
|
|
|
|
|
|
205
|
1
|
50
|
|
|
|
2
|
$package->{ bin } = $self->convert_dependencies($self->bin) if @{$self->bin} > 0; |
|
1
|
|
|
|
|
52
|
|
206
|
|
|
|
|
|
|
|
207
|
1
|
|
|
|
|
66
|
return JSON->new->utf8(1)->pretty(1)->encode($package) |
208
|
|
|
|
|
|
|
} |
209
|
1
|
|
|
|
|
10
|
})); |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#================================================================================================================================================================================================================================================ |
214
|
|
|
|
|
|
|
sub convert_dependencies { |
215
|
5
|
|
|
5
|
0
|
7
|
my ($self, $deps) = @_; |
216
|
|
|
|
|
|
|
|
217
|
8
|
|
|
|
|
11
|
my %converted = map { |
218
|
|
|
|
|
|
|
|
219
|
5
|
|
|
|
|
9
|
my $dep = $_; |
220
|
|
|
|
|
|
|
|
221
|
8
|
|
|
|
|
32
|
$dep =~ m/ ['"]? ([\w\-._]+) ['"]? \s* (.*)/x; |
222
|
|
|
|
|
|
|
|
223
|
8
|
|
50
|
|
|
53
|
$1 => ($2 || '*'); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
} (@$deps); |
226
|
|
|
|
|
|
|
|
227
|
5
|
|
|
|
|
22
|
return \%converted; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
#================================================================================================================================================================================================================================================ |
232
|
|
|
|
|
|
|
sub convert_engines { |
233
|
1
|
|
|
1
|
0
|
2
|
my ($self, $engines) = @_; |
234
|
|
|
|
|
|
|
|
235
|
2
|
|
|
|
|
3
|
my @converted = map { |
236
|
|
|
|
|
|
|
|
237
|
1
|
|
|
|
|
4
|
my $engine = $_; |
238
|
|
|
|
|
|
|
|
239
|
2
|
|
|
|
|
15
|
$engine =~ m/^["']?(.*?)["']?$/; |
240
|
|
|
|
|
|
|
|
241
|
2
|
50
|
|
|
|
11
|
$1 || ''; |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
} (@$engines); |
244
|
|
|
|
|
|
|
|
245
|
1
|
|
|
|
|
5
|
return \@converted; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#================================================================================================================================================================================================================================================ |
250
|
|
|
|
|
|
|
sub mvp_multivalue_args { |
251
|
1
|
|
|
1
|
0
|
290
|
qw( contributor dependency devDependency engine bin ) |
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
#================================================================================================================================================================================================================================================ |
256
|
|
|
|
|
|
|
sub after_build { |
257
|
1
|
|
|
1
|
0
|
1285
|
my ($self, $params) = @_; |
258
|
|
|
|
|
|
|
|
259
|
1
|
50
|
|
|
|
50
|
return unless $self->links_deps; |
260
|
|
|
|
|
|
|
|
261
|
1
|
|
|
|
|
3
|
my $build_root = $params->{ build_root }; |
262
|
|
|
|
|
|
|
|
263
|
1
|
|
|
|
|
8
|
my $dir = getcwd; |
264
|
|
|
|
|
|
|
|
265
|
1
|
|
|
|
|
5
|
chdir($build_root); |
266
|
|
|
|
|
|
|
|
267
|
1
|
|
|
|
|
34
|
for my $package (keys(%{$self->convert_dependencies($self->dependency)})) { |
|
1
|
|
|
|
|
50
|
|
268
|
2
|
50
|
|
|
|
122
|
next if -d dir($build_root, "node_modules", $package); |
269
|
|
|
|
|
|
|
|
270
|
0
|
|
|
|
|
0
|
my $res = `npm link $package`; |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
0
|
chomp($res); |
273
|
|
|
|
|
|
|
|
274
|
0
|
|
|
|
|
0
|
$self->log($res); |
275
|
|
|
|
|
|
|
} |
276
|
|
|
|
|
|
|
|
277
|
1
|
|
|
|
|
97
|
for my $package (keys(%{$self->convert_dependencies($self->devDependency)})) { |
|
1
|
|
|
|
|
53
|
|
278
|
0
|
0
|
|
|
|
0
|
next if -d dir($build_root, "node_modules", $package); |
279
|
|
|
|
|
|
|
|
280
|
0
|
|
|
|
|
0
|
my $res = `npm link $package`; |
281
|
|
|
|
|
|
|
|
282
|
0
|
|
|
|
|
0
|
chomp($res); |
283
|
|
|
|
|
|
|
|
284
|
0
|
|
|
|
|
0
|
$self->log($res); |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
1
|
|
|
|
|
17
|
chdir($dir); |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
|
295
|
2
|
|
|
2
|
|
12
|
no Moose; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
17
|
|
296
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable(inline_constructor => 0); |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
1; |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
__END__ |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=pod |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
=encoding UTF-8 |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
=head1 NAME |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
Dist::Zilla::Plugin::Web::NPM::Package - Generate the `package.json` file, suitable for `npm` package manager |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=head1 VERSION |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
version 0.0.7 |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=head1 SYNOPSIS |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
In your F<dist.ini>: |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
[Web::NPM::Package] |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
name = some-distro ; lowercased distribution name if not provided |
322
|
|
|
|
|
|
|
version = 1.2.3 ; version, appended with ".0" to conform semver |
323
|
|
|
|
|
|
|
; (if not provided) |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
author = Clever Guy <cg@cleverguy.org> ; the 1st specified author |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
contributor = Clever Guy2 <cg2@cleverguy.org> ; note the singular spelling |
328
|
|
|
|
|
|
|
contributor = Clever Guy3 <cg3@cleverguy.org> ; other authors from main config |
329
|
|
|
|
|
|
|
|
330
|
|
|
|
|
|
|
description = Some clever, yet compact description ; asbtract from main config |
331
|
|
|
|
|
|
|
|
332
|
|
|
|
|
|
|
homepage = http://cleverguy.org ; can recommend Dist::Zilla::Plugin::GithubMeta |
333
|
|
|
|
|
|
|
repository = git://git.cleverguy.org ; |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
main = 'lib/some/distro' ; default to main module in distribution |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
dependency = foo 1.0.0 - 2.9999.9999 ; note the singular spelling |
338
|
|
|
|
|
|
|
dependency = bar >=1.0.2 <2.1.2 ; |
339
|
|
|
|
|
|
|
|
340
|
|
|
|
|
|
|
engine = node >=0.1.27 <0.1.30 ; note the singular spelling |
341
|
|
|
|
|
|
|
engine = dode >=0.1.27 <0.1.30 ; |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
bin = bin_name ./bin/path/to.js |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
=head1 DESCRIPTION |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
Generate the "package.json" file for your distribution, based on the content of "dist.ini" |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Link the dependencies (including "devDepencies" after build). Linking is not performed, if the distribution |
350
|
|
|
|
|
|
|
already contains the package in "node_modules" |
351
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
=head1 AUTHOR |
353
|
|
|
|
|
|
|
|
354
|
|
|
|
|
|
|
Nickolay Platonov <nplatonov@cpan.org> |
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Nickolay Platonov. |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
361
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
362
|
|
|
|
|
|
|
|
363
|
|
|
|
|
|
|
=cut |