浏览代码

Added Grunt task to deploy build/prod to the gh-pages branch. Partial solution to #19.

n1474335 8 年之前
父节点
当前提交
43fa4370a3
共有 2 个文件被更改,包括 49 次插入3 次删除
  1. 31 3
      Gruntfile.js
  2. 18 0
      src/static/ga.html

+ 31 - 3
Gruntfile.js

@@ -9,7 +9,8 @@ module.exports = function(grunt) {
         
         
     grunt.registerTask("prod",
     grunt.registerTask("prod",
         "Creates a production-ready build. Use the --msg flag to add a compile message.",
         "Creates a production-ready build. Use the --msg flag to add a compile message.",
-        ["jshint", "exec:stats", "clean", "jsdoc", "concat", "copy", "cssmin", "uglify:prod", "inline", "htmlmin", "chmod"]);
+        ["jshint", "exec:stats", "clean", "jsdoc", "concat", "copy:html_dev", "copy:html_prod", "copy:html_inline",
+         "copy:static_dev", "copy:static_prod", "cssmin", "uglify:prod", "inline", "htmlmin", "chmod"]);
         
         
     grunt.registerTask("docs",
     grunt.registerTask("docs",
         "Compiles documentation in the /docs directory.",
         "Compiles documentation in the /docs directory.",
@@ -18,6 +19,10 @@ module.exports = function(grunt) {
     grunt.registerTask("stats",
     grunt.registerTask("stats",
         "Provides statistics about the code base such as how many lines there are as well as details of file sizes before and after compression.",
         "Provides statistics about the code base such as how many lines there are as well as details of file sizes before and after compression.",
         ["concat:js", "uglify:prod", "exec:stats", "exec:repo_size", "exec:display_stats"]);
         ["concat:js", "uglify:prod", "exec:stats", "exec:repo_size", "exec:display_stats"]);
+
+    grunt.registerTask("release",
+        "Prepares and deploys a production version of CyberChef to the gh-pages branch.",
+        ["copy:gh_pages", "exec:deploy_gh_pages"]);
     
     
     grunt.registerTask("default",
     grunt.registerTask("default",
         "Lints the code base and shows stats",
         "Lints the code base and shows stats",
@@ -274,7 +279,8 @@ module.exports = function(grunt) {
                         src: [
                         src: [
                             "**/*",
                             "**/*",
                             "**/.*",
                             "**/.*",
-                            "!stats.txt"
+                            "!stats.txt",
+                            "!ga.html"
                         ],
                         ],
                         dest: "build/dev/"
                         dest: "build/dev/"
                     }
                     }
@@ -288,11 +294,24 @@ module.exports = function(grunt) {
                         src: [
                         src: [
                             "**/*",
                             "**/*",
                             "**/.*",
                             "**/.*",
-                            "!stats.txt"
+                            "!stats.txt",
+                            "!ga.html"
                         ],
                         ],
                         dest: "build/prod/"
                         dest: "build/prod/"
                     }
                     }
                 ]
                 ]
+            },
+            gh_pages: {
+                options: {
+                    process: function(content, srcpath) {
+                        // Add Google Analytics code to index.html
+                        content = content.replace("</body></html>",
+                            grunt.file.read("src/static/ga.html") + "</body></html>");
+                        return grunt.template.process(content, template_options);
+                    }
+                },
+                src: "build/prod/index.html",
+                dest: "build/prod/index.html"
             }
             }
         },
         },
         uglify: {
         uglify: {
@@ -423,6 +442,15 @@ module.exports = function(grunt) {
             clean_git: {
             clean_git: {
                 command: "git gc --prune=now --aggressive"
                 command: "git gc --prune=now --aggressive"
             },
             },
+            deploy_gh_pages: {
+                command: [
+                        "git add build/prod/index.html -v",
+                        "git commit -m 'GitHub Pages release'",
+                        "git push origin `git subtree split --prefix build/prod master`:gh-pages --force",
+                        "git reset HEAD~",
+                        "git checkout build/prod/index.html"
+                ].join(";")
+            }
         },
         },
         watch: {
         watch: {
             css: {
             css: {

+ 18 - 0
src/static/ga.html

@@ -0,0 +1,18 @@
+
+
+<!-- Begin Google Analytics -->
+<script>
+  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
+  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
+  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
+  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
+
+  ga('create', 'UA-85682716-2', 'auto');
+
+  // Specifying location.pathname here overrides the default URL which would include arguments.
+  // This method prevents Google Analytics from logging any recipe or input data in the URL.
+  ga('send', 'pageview', location.pathname);
+
+</script>
+<!-- End Google Analytics -->
+