Advertisement
EncryptedCow

Untitled

Feb 7th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var gulp = require("gulp"),
  2.     babel = require("gulp-babel"),
  3.     concat = require("gulp-concat"),
  4.     minify = require("gulp-minify"),
  5.     rename = require("gulp-rename"),
  6.     watch = require("gulp-watch"),
  7.     plumber = require("gulp-plumber"),
  8.     runSequence = require("run-sequence"),
  9.     browserSync = require("browser-sync"),
  10.     del = require("del");
  11.  
  12. gulp.task("default", (cb) => {
  13.     runSequence("engine", "game", "copy:lib", "copy:shaders", "copy:assets", "copy:html", "copy:css", "webserver", "watch", cb);
  14. });
  15.  
  16. gulp.task("watch", () => {
  17.     gulp.watch("app/js/engine/**", ["engine"]);
  18.     gulp.watch("app/js/game/**", ["game"]);
  19.     gulp.watch("app/lib/**", ["copy:lib"]);
  20.     gulp.watch("app/js/shaders/*.glsl", ["copy:shaders"]);
  21.     gulp.watch("app/assets/**", ["copy:assets"]);
  22.     gulp.watch("app/index.html", ["copy:html"]);
  23.     gulp.watch("app/css/**", ["copy:css"]);
  24. });
  25.  
  26. gulp.task("webserver", () => {
  27.     var _browser_URL = "./dist",
  28.         port = 80,
  29.         host = "localhost";
  30.  
  31.     browserSync({
  32.         server: _browser_URL,
  33.         port: port,
  34.         host: host
  35.     });
  36. });
  37.  
  38. gulp.task("engine", () => {
  39.     return gulp.src("app/js/engine/**")
  40.         .pipe(plumber())
  41.         // .pipe(babel({ presets: ["es2015"] }))
  42.         .pipe(gulp.dest("dist/js/engine"))
  43.         .pipe(browserSync.reload({ stream: true }));
  44. });
  45.  
  46. gulp.task("game", () => {
  47.     return gulp.src("app/js/game/**")
  48.         .pipe(plumber())
  49.         // .pipe(babel({ presets: ["es2015"] }))
  50.         .pipe(gulp.dest("dist/js/game"))
  51.         .pipe(browserSync.reload({ stream: true }));
  52. });
  53.  
  54. gulp.task("copy:lib", () => {
  55.     gulp.src("app/lib/**")
  56.         .pipe(gulp.dest("dist/lib"))
  57.         .pipe(browserSync.reload({ stream: true }));
  58. });
  59.  
  60. gulp.task("copy:shaders", () => {
  61.     gulp.src("app/js/shaders/*.glsl")
  62.         .pipe(gulp.dest("dist/shaders"))
  63.         .pipe(browserSync.reload({ stream: true }));
  64. });
  65.  
  66. gulp.task("copy:assets", () => {
  67.     gulp.src("app/assets/**")
  68.         .pipe(gulp.dest("dist/assets"))
  69.         .pipe(browserSync.reload({ stream: true }));
  70. });
  71.  
  72. gulp.task("copy:html", () => {
  73.     gulp.src("app/index.html")
  74.         .pipe(plumber())
  75.         .pipe(gulp.dest("dist"))
  76.         .pipe(browserSync.reload({ stream: true }));
  77. });
  78.  
  79. gulp.task("copy:css", () => {
  80.     gulp.src("app/css/**")
  81.         .pipe(gulp.dest("dist/css"))
  82.         .pipe(browserSync.reload({ stream: true }));
  83. });
  84.  
  85. gulp.task("clean", function(cb) {
  86.     console.log("Cleaning");
  87.     del([
  88.         "dist/**"
  89.     ], cb);
  90. });
  91.  
  92.  
  93. ////////////////////
  94. //                //
  95. //   BUILD TASK   //
  96. //                //
  97. ////////////////////
  98.  
  99. gulp.task("build", (cb) => {
  100.     runSequence("build:engine", "build:game", "build:lib", "build:shaders", "build:assets", "build:html", "build:css", cb);
  101. });
  102.  
  103. gulp.task("build:engine", () => {
  104.     return gulp.src(["app/js/engine/Cow.js",
  105.                     "app/js/engine/gl.js",
  106.                     "app/js/engine/System.js",
  107.                     "app/js/engine/Entities.js",
  108.                     "app/js/engine/Transform.js",
  109.                     "app/js/engine/Camera.js",
  110.                     "app/js/engine/Collisions.js",
  111.                     "app/js/engine/Loader.js",
  112.                     "app/js/engine/Render.js",
  113.                     "app/js/engine/Input.js",
  114.                     "app/js/engine/Network.js",
  115.                     "app/js/engine/Scenes.js",
  116.                     "app/js/engine/Scene.js",
  117.                     "app/js/engine/Component.js",
  118.                     "app/js/engine/Entity.js",
  119.                     "app/js/engine/defaultComponents/**"])
  120.         .pipe(plumber())
  121.         .pipe(concat("Cow.js"))
  122.         .pipe(babel({ presets: ["es2015"] }))
  123.         .pipe(minify())
  124.         .pipe(gulp.dest("build/js"));
  125. });
  126.  
  127. gulp.task("build:game", () => {
  128.     return gulp.src("app/js/game/**/*.js")
  129.         .pipe(plumber())
  130.         .pipe(concat("game.js"))
  131.         .pipe(babel({ presets: ["es2015"] }))
  132.         .pipe(minify())
  133.         .pipe(gulp.dest("build/js"));
  134. });
  135.  
  136. gulp.task("build:shaders", () => {
  137.     return gulp.src("app/js/shaders/*.glsl")
  138.         .pipe(plumber())
  139.         .pipe(gulp.dest("build/shaders"));
  140. });
  141.  
  142. gulp.task("build:lib", () => {
  143.     return gulp.src("app/lib/**")
  144.         .pipe(plumber())
  145.         .pipe(gulp.dest("build/lib"));
  146. });
  147.  
  148. gulp.task("build:assets", () => {
  149.     return gulp.src("app/assets/**")
  150.         .pipe(plumber())
  151.         .pipe(gulp.dest("build/assets"));
  152. });
  153.  
  154. gulp.task("build:html", () => {
  155.     return gulp.src("app/index-build.html")
  156.         .pipe(plumber())
  157.         .pipe(rename("index.html"))
  158.         .pipe(gulp.dest("build"));
  159. });
  160.  
  161. gulp.task("build:css", () => {
  162.     return gulp.src("app/css/*.css")
  163.         .pipe(plumber())
  164.         .pipe(gulp.dest("build/css"));
  165. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement