| 1 | package Dist::Zilla::Plugin::Web::NPM::Package; | ||||||||||||||||||||
| 2 | 2 | $Dist::Zilla::Plugin::Web::NPM::Package::VERSION = '0.0.10'; | |||||||||||||||||||
| 3 | # ABSTRACT: Generate the `package.json` file, suitable for `npm` package manager | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 2 | with 'Dist::Zilla::Role::FileGatherer'; | |||||||||||||||||||
| 8 | # to allow `dzil run` commands | ||||||||||||||||||||
| 9 | 2 | with 'Dist::Zilla::Role::BuildRunner'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 2 | with 'Dist::Zilla::Role::AfterBuild'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 2 | ▶ | use Dist::Zilla::File::FromCode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 2 | ▶ | use JSON 2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 2 | ▶ | use Path::Class; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | ▶ | use File::ShareDir; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 2 | ▶ | use Cwd; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | has 'name' => ( | ||||||||||||||||||||
| 23 | is => 'rw', | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | lazy => 1, | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 1 | return lc($_[0]->zilla->name) | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | 2 | ); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | has 'version' => ( | ||||||||||||||||||||
| 34 | is => 'rw', | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | lazy => 1, | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 39 | 1 | my $version = $_[0]->zilla->version; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 1 | ▶ | $version .= '.0' if $version !~ m!\d+\.\d+\.\d+!; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # strip leading zeros | ||||||||||||||||||||
| 44 | 1 | $version =~ s/\.0+(\d+)/.$1/g; | |||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | return $version | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | 2 | ); | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | has 'author' => ( | ||||||||||||||||||||
| 52 | is => 'rw', | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | lazy => 1, | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 1 | return $_[0]->zilla->authors->[0] | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | 2 | ); | |||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | has 'description' => ( | ||||||||||||||||||||
| 63 | is => 'rw', | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | lazy => 1, | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 68 | 1 | return $_[0]->zilla->abstract | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 2 | ); | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | has 'homepage' => ( | ||||||||||||||||||||
| 74 | is => 'rw', | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | lazy => 1, | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||
| 79 | 1 | my $meta = $_[0]->zilla->distmeta; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | return $meta->{ resources } && $meta->{ resources }->{ homepage } | ||||||||||||||||||||
| 82 | 1 | ▶ | } | ||||||||||||||||||
|
Condition33%1/3
$meta->{'resources'} && $meta->{'resources'}{'homepage'}
MC/DC0%0/2
$meta->{'resources'} && $meta->{'resources'}{'homepage'}
$meta->{'resources'}
$meta->{'resources'}{'homepage'}
Truth table33%1/3
A && B
A= $meta->{'resources'}B= $meta->{'resources'}{'homepage'}
| |||||||||||||||||||||
| 83 | 2 | ); | |||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | has 'repository' => ( | ||||||||||||||||||||
| 87 | is => 'rw', | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | lazy => 1, | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||
| 92 | 1 | my $meta = $_[0]->zilla->distmeta; | |||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | return $meta->{ resources } && $meta->{ resources }->{ repository } | ||||||||||||||||||||
| 95 | 1 | ▶ | } | ||||||||||||||||||
|
Condition33%1/3
$meta->{'resources'} && $meta->{'resources'}{'repository'}
MC/DC0%0/2
$meta->{'resources'} && $meta->{'resources'}{'repository'}
$meta->{'resources'}
$meta->{'resources'}{'repository'}
Truth table33%1/3
A && B
A= $meta->{'resources'}B= $meta->{'resources'}{'repository'}
| |||||||||||||||||||||
| 96 | 2 | ); | |||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | has 'contributor' => ( | ||||||||||||||||||||
| 100 | is => 'rw', | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | lazy => 1, | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 105 | 1 | my @authors = @{$_[0]->zilla->authors}; | |||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | 1 | shift @authors; | |||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 1 | return \@authors; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | 2 | ); | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | has 'main' => ( | ||||||||||||||||||||
| 115 | is => 'rw', | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | lazy => 1, | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 120 | 1 | my $name = $_[0]->zilla->name; | |||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 1 | $name =~ s!-!/!g; | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | 1 | return 'lib/' . $name; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | 2 | ); | |||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | has 'dependency' => ( | ||||||||||||||||||||
| 130 | is => 'rw', | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | lazy => 1, | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | 0 | ▶ | default => sub { [] } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 135 | 2 | ); | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | has 'devDependency' => ( | ||||||||||||||||||||
| 139 | is => 'rw', | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | lazy => 1, | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 1 | ▶ | default => sub { [] } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 144 | 2 | ); | |||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | has 'engine' => ( | ||||||||||||||||||||
| 149 | is => 'rw', | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | lazy => 1, | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 0 | ▶ | default => sub { [] } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 154 | 2 | ); | |||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | has 'bin' => ( | ||||||||||||||||||||
| 158 | is => 'rw', | ||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | 0 | ▶ | default => sub { [] } | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 161 | 2 | ); | |||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | 2 | has 'links_deps' => ( | |||||||||||||||||||
| 165 | is => 'rw', | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | default => 1 | ||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | #================================================================================================================================================================================================================================================ | ||||||||||||||||||||
| 173 | # to satisfy BuildRunner | ||||||||||||||||||||
| 174 | 0 | ▶ | sub build { | ||||||||||||||||||
|
Subroutine
build: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | #================================================================================================================================================================================================================================================ | ||||||||||||||||||||
| 180 | 1 | ▶ | sub gather_files { | ||||||||||||||||||
|
Subroutine
gather_files: called CC=1 SCAR=0.1
Pod
undocumented
| |||||||||||||||||||||
| 181 | 1 | my ($self) = @_; | |||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | $self->add_file(Dist::Zilla::File::FromCode->new({ | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | name => file('package.json') . '', | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 1 | ▶ | code => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.3
| |||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | 1 | my $package = {}; | |||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | 1 | $package->{ $_ } = $self->$_ for qw( name version description homepage repository author main ); | |||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 1 | $package->{ contributors } = $self->contributor; | |||||||||||||||||||
| 194 | 1 | ▶ | $package->{ dependencies } = $self->convert_dependencies($self->dependency) if @{$self->dependency} > 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 195 | 1 | ▶ | $package->{ dependencies } = $self->convert_dependencies($self->dependency) if @{$self->dependency} > 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 196 | |||||||||||||||||||||
| 197 | 1 | ▶ | $package->{ engines } = $self->convert_engines($self->engine) if @{$self->engine} > 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | $package->{ directories } = { | ||||||||||||||||||||
| 200 | 1 | "doc" => "./doc/mmd", | |||||||||||||||||||
| 201 | "man" => "./man", | ||||||||||||||||||||
| 202 | "lib" => "./lib" | ||||||||||||||||||||
| 203 | }; | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | 1 | ▶ | $package->{ bin } = $self->convert_dependencies($self->bin) if @{$self->bin} > 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | 1 | return JSON->new->utf8(1)->pretty(1)->encode($package) | |||||||||||||||||||
| 208 | } | ||||||||||||||||||||
| 209 | 1 | })); | |||||||||||||||||||
| 210 | } | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | #================================================================================================================================================================================================================================================ | ||||||||||||||||||||
| 214 | 5 | ▶ | sub convert_dependencies { | ||||||||||||||||||
|
Subroutine
convert_dependencies: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 215 | 5 | my ($self, $deps) = @_; | |||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | my %converted = map { | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | 5 | my $dep = $_; | |||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | 8 | $dep =~ m/ ['"]? ([\w\-._]+) ['"]? \s* (.*)/x; | |||||||||||||||||||
| 222 | |||||||||||||||||||||
| 223 | 8 | ▶ | $1 => ($2 || '*'); | ||||||||||||||||||
|
Condition50%1/2
$2 || '*'
MC/DC0%0/1
$2 || '*'
$2
Truth table50%1/2
A
A= $2
| |||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | } (@$deps); | ||||||||||||||||||||
| 226 | |||||||||||||||||||||
| 227 | 5 | return \%converted; | |||||||||||||||||||
| 228 | } | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | #================================================================================================================================================================================================================================================ | ||||||||||||||||||||
| 232 | 1 | ▶ | sub convert_engines { | ||||||||||||||||||
|
Subroutine
convert_engines: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 233 | 1 | my ($self, $engines) = @_; | |||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | my @converted = map { | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 1 | my $engine = $_; | |||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | 2 | $engine =~ m/^["']?(.*?)["']?$/; | |||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | 2 | ▶ | $1 || ''; | ||||||||||||||||||
|
Condition50%1/2
$1 || ''
MC/DC0%0/1
$1 || ''
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | } (@$engines); | ||||||||||||||||||||
| 244 | |||||||||||||||||||||
| 245 | 1 | return \@converted; | |||||||||||||||||||
| 246 | } | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | #================================================================================================================================================================================================================================================ | ||||||||||||||||||||
| 250 | 1 | ▶ | sub mvp_multivalue_args { | ||||||||||||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 251 | 1 | qw( contributor dependency devDependency engine bin ) | |||||||||||||||||||
| 252 | } | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | |||||||||||||||||||||
| 255 | #================================================================================================================================================================================================================================================ | ||||||||||||||||||||
| 256 | 1 | ▶ | sub after_build { | ||||||||||||||||||
|
Subroutine
after_build: called CC=6 SCAR=22.5
Pod
undocumented
| |||||||||||||||||||||
| 257 | 1 | my ($self, $params) = @_; | |||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | 1 | ▶ | return unless $self->links_deps; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | 1 | my $build_root = $params->{ build_root }; | |||||||||||||||||||
| 262 | |||||||||||||||||||||
| 263 | 1 | my $dir = getcwd; | |||||||||||||||||||
| 264 | |||||||||||||||||||||
| 265 | 1 | chdir($build_root); | |||||||||||||||||||
| 266 | |||||||||||||||||||||
| 267 | 1 | for my $package (keys(%{$self->convert_dependencies($self->dependency)})) { | |||||||||||||||||||
| 268 | 2 | ▶ | next if -d dir($build_root, "node_modules", $package); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | 0 | my $res = `npm link $package`; | |||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | 0 | chomp($res); | |||||||||||||||||||
| 273 | |||||||||||||||||||||
| 274 | 0 | $self->log($res); | |||||||||||||||||||
| 275 | } | ||||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | 1 | for my $package (keys(%{$self->convert_dependencies($self->devDependency)})) { | |||||||||||||||||||
| 278 | 0 | ▶ | next if -d dir($build_root, "node_modules", $package); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 279 | |||||||||||||||||||||
| 280 | 0 | my $res = `npm link $package`; | |||||||||||||||||||
| 281 | |||||||||||||||||||||
| 282 | 0 | chomp($res); | |||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | 0 | $self->log($res); | |||||||||||||||||||
| 285 | } | ||||||||||||||||||||
| 286 | |||||||||||||||||||||
| 287 | 1 | chdir($dir); | |||||||||||||||||||
| 288 | } | ||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | |||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | |||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | |||||||||||||||||||||
| 295 | 2 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 296 | 2 | __PACKAGE__->meta->make_immutable(inline_constructor => 0); | |||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | 2 | 1; | |||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | __END__ | ||||||||||||||||||||