OSDN Git Service

Initial version.
[mtpm/PluginManager.git] / Build.PL
1 use strict;
2 use warnings;
3 use Module::Build;
4 use File::Spec;
5 use File::Basename;
6 use YAML qw/ Load /;
7
8 my $class = Module::Build->subclass(
9         class => 'MovableTypePluginManagerBuilder',
10         code => q{
11                 # Don't make blib
12                 # sub ACTION_code {};
13                 # Don't make blib
14                 sub ACTION_docs {};
15                 # Don't make META.yml
16                 sub ACTION_distmeta {
17                         # no warning on ACTION_distdir
18                         $_[0]->{metafile} = 'MANIFEST';
19                 };
20                 # Don't add MEATA.yml to MANIFEST
21                 sub ACTION_manifest {
22                         $_[0]->{metafile} = 'MANIFEST',
23                         $_[0]->SUPER::ACTION_manifest(@_);
24                 };
25                 sub ACTION_test {
26                         my $p = $_[0]->{properties};
27                         unshift(
28                                 @INC,
29                                 File::Spec->catdir($p->{base_dir}, 'extlib'),
30                                 File::Spec->catdir($p->{base_dir}, '../../lib'),
31                                 File::Spec->catdir($p->{base_dir}, '../../extlib'),
32                         );
33
34                         $_[0]->SUPER::ACTION_test(@_);
35                 };
36
37                 sub ACTION_zipdist {
38                         my ($self) = @_;
39                         my $dist_dir = $self->dist_dir;
40                         $self->depends_on('distdir');
41                         print "Creating $dist_dir.zip\n";
42                         system("zip -r $dist_dir.zip $dist_dir") == 0 or die $?;
43                         $self->delete_filetree($dist_dir);
44                 }
45
46                 sub ACTION_distdir {
47                         my ($self) = @_;
48
49                         $_[0]->SUPER::ACTION_distdir(@_);
50
51                         my $dist_dir = $self->dist_dir;
52                         rename($dist_dir, $self->{properties}{dist_name});
53                         use File::Path;
54                         use File::Spec;
55                         use File::Basename;
56                         my $plugins = File::Spec->catfile($dist_dir, 'plugins');
57                         mkpath($plugins, 1, 0755);
58
59                         my $new_dist_dir = File::Spec->catfile(
60                                 $plugins, $self->{properties}{dist_name}
61                         );
62                         rename($self->{properties}{dist_name}, $new_dist_dir);
63
64                         foreach my $f (glob(File::Spec->catfile($new_dist_dir, 'COPYING'))) {
65                                 rename($f, File::Spec->catfile($dist_dir, basename($f)));
66                         }
67
68                         if (my @statics = glob(File::Spec->catfile($new_dist_dir, 'static/*'))) {
69                                 my $static = File::Spec->catfile(
70                                         $dist_dir, 'mt-static/plugins'
71                                 );
72                                 mkpath($static, 1, 0755);
73
74                                 my $d = File::Spec->catfile(
75                                         $static, $self->{properties}{dist_name}
76                                 );
77                                 mkpath($d, 1, 0755);
78
79                                 foreach my $f (@statics) {
80                                         rename($f, File::Spec->catfile($d, basename($f)));
81                                 }
82
83                                 rmdir(File::Spec->catfile($new_dist_dir, 'static'));
84                         }
85
86                         if (my @tools = glob(File::Spec->catfile($new_dist_dir, 'tools/*'))) {
87                                 my $tool = File::Spec->catfile(
88                                         $dist_dir, 'tools'
89                                 );
90                                 mkpath($tool, 1, 0755);
91
92                                 foreach my $f (@tools) {
93                                         rename($f, File::Spec->catfile($tool, basename($f)));
94                                 }
95
96                                 rmdir(File::Spec->catfile($new_dist_dir, 'tools'));
97                         }
98                 }
99         }
100 );
101
102 my $yaml_string = do {
103         open(my $fh, File::Spec->catfile(dirname(__FILE__), 'config.yaml'));
104         local $/;
105         <$fh>
106 };
107 $yaml_string =~ s/^(\s*)\*/$1App::\*/gm;
108 my $yaml = Load($yaml_string);
109
110 my $builder = $class->new(
111         dist_name           => $yaml->{name},
112     dist_author         => 'Movable Type Plugin Manager Project',
113     dist_version        => $yaml->{version},
114     module_name         => $yaml->{name} . '::App',
115     license             => 'GPL',
116     add_to_cleanup      => [ $yaml->{name} . '-*' ],
117 );
118
119 $builder->create_build_script();