]> iEval git - plack-app-gruntmaster.git/commitdiff
Generate minified js/css during build
authorMarius Gavrilescu <marius@ieval.ro>
Mon, 2 Mar 2015 15:05:58 +0000 (17:05 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Mon, 2 Mar 2015 15:05:58 +0000 (17:05 +0200)
Makefile.PL
js/90-themes.js
lib/Plack/App/Gruntmaster.pm
make_static.PL [new file with mode: 0644]
tmpl/skel.en

index 0407ab781a3d9bd29094f5f81bf44828b22069c7..2f3a50f2784e73f70334031e465446dc62ca0723 100644 (file)
@@ -9,8 +9,14 @@ WriteMakefile(
        MIN_PERL_VERSION  => '5.14.0',
        LICENSE           => 'AGPL_3',
        SIGN              => 1,
+       clean             => {
+               FILES => 'static/css/ static/js.js'
+       },
        BUILD_REQUIRES    => {
-               qw/Test::MockTime             0
+               qw/CSS::Minifier::XS          0
+                  File::Slurp                0
+                  JavaScript::Minifier::XS   0
+                  Test::MockTime             0
                   Test::More                 0
                   Test::WWW::Mechanize::PSGI 0/,
        },
@@ -25,13 +31,11 @@ WriteMakefile(
                   strict      0
                   warnings    0
 
-                  CSS::Minifier::XS                0
                   Email::Simple                    0
                   Email::Sender::Simple            0
                   File::Slurp                      0
                   Gruntmaster::Data                0
                   HTML::Seamstress                 0
-                  JavaScript::Minifier::XS         0
                   JSON::MaybeXS                    0
                   Log::Log4perl                    0
                   PerlX::Maybe                     0
index caefa395a0bc7ce4edf0e05e49361494ba8ee103..1e6fdceb66d996c31291974f5d44412a4abce126 100644 (file)
@@ -1,7 +1,7 @@
 (function(){
        'use strict';
        function set_style(name){
-               $('#stylesheet').attr("href", "/css/" + name + ".css");
+               $('#stylesheet').attr("href", "/static/css/" + name + ".css");
                localStorage.setItem("theme", name);
        }
 
index 87e9e5a18586bc654a8a36852af55b7c39df1255..35d788e8887c7e5589c38ffd19d3b80d7fe66e06 100644 (file)
@@ -4,10 +4,8 @@ use 5.014000;
 use strict;
 our $VERSION = '5999.000_001';
 
-use CSS::Minifier::XS;
 use Encode qw/encode decode/;
 use File::Slurp qw/read_file/;
-use JavaScript::Minifier::XS;
 use JSON::MaybeXS qw/encode_json/;
 use PerlX::Maybe;
 use Scope::Upper qw/unwind SUB UP/;
@@ -55,8 +53,6 @@ use constant FORMAT_EXTENSION => {
 
 use constant NOT_FOUND => [404, ['X-Forever' => 1, 'Content-Type' => 'text/plain'], ['Not found']];
 
-sub development() { ($ENV{PLACK_ENV} // 'development') eq 'development' }
-
 my ($env, $privacy);
 
 sub db { $env->{'gruntmaster.dbic'} }
@@ -98,22 +94,6 @@ sub dispatch_request{
        $privacy = 'public';
 
        sub (GET) {
-               sub (/css/:theme) {
-                       my $theme = $_{theme};
-                       return NOT_FOUND unless -e "css/themes/$theme.css";
-                       my $css = read_file "css/themes/$theme.css";
-                       $css .= read_file $_ for <css/*.css>;
-                       my @headers = ('X-Forever' => 1, 'Cache-Control' => 'public, max-age=604800', 'Content-Type' => 'text/css; charset=utf-8');
-                       [200, \@headers, [development ? $css : CSS::Minifier::XS::minify $css]]
-               },
-
-               sub (/js.js) {
-                       my $js;
-                       $js .= read_file $_ for <js/*.js>;
-                       my @headers = ('X-Forever' => 1, 'Cache-Control' => 'public, max-age=604800', 'Content-Type' => 'application/javascript; charset=utf-8');
-                       [200, \@headers, [development ? $js : JavaScript::Minifier::XS::minify $js]]
-               },
-
                sub (/robots.txt) { NOT_FOUND },
 
                sub (/src/:job) {
diff --git a/make_static.PL b/make_static.PL
new file mode 100644 (file)
index 0000000..a47df2d
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use v5.14;
+use warnings;
+
+use CSS::Minifier::XS qw//;
+use JavaScript::Minifier::XS qw//;
+
+use File::Slurp qw/read_file write_file/;
+
+mkdir 'static';
+mkdir 'static/css';
+
+my $common_css;
+$common_css .= read_file $_ for <css/*.css>;
+for (<css/themes/*>) {
+       my ($theme) = m,themes/(.*)\.css,;
+       my $css = read_file $_;
+       $css .= $common_css;
+       write_file "static/css/$theme.css", CSS::Minifier::XS::minify $css;
+}
+
+my $js;
+$js .= read_file $_ for <js/*.js>;
+write_file 'static/js.js', JavaScript::Minifier::XS::minify $js;
index fd549a17bc6a83166ba8cbcf42c5e9a39ad6e8cf..93e07b87142f8b68e5cea212865788296c2c3b67 100644 (file)
@@ -3,8 +3,8 @@
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 
-<link rel="stylesheet" href="/css/cyborg.css" id="stylesheet">
-<script src="/js.js" type="text/javascript" async defer></script>
+<link rel="stylesheet" href="/static/css/cyborg.css" id="stylesheet">
+<script src="/static/js.js" type="text/javascript" async defer></script>
 
 <body>
 <nav role="navigation">
This page took 0.03294 seconds and 4 git commands to generate.