Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.03 KB | None | 0 0
  1. "use strict";
  2.  
  3. var gulp = require('gulp');
  4. var autoprefixer = require('gulp-autoprefixer');
  5. var browserSync = require('browser-sync');
  6. var concat = require('gulp-concat');
  7. var connect = require('gulp-connect');
  8. var imagemin = require('gulp-imagemin');
  9. var newer = require('gulp-newer');
  10. var notify = require('gulp-notify');
  11. var plumber = require('gulp-plumber');
  12. var pngquant = require('imagemin-pngquant');
  13. var rename = require('gulp-rename');
  14. var sass = require('gulp-sass');
  15. var sourcemaps = require('gulp-sourcemaps');
  16. var uglify = require('gulp-uglify');
  17. var webkitAssign = require('webkit-assign/gulp');
  18. var gulpif = require('gulp-if');
  19. var gutil = require('gulp-util');
  20. var gulpHtml = require('gulp-htmlmin');
  21. var decomment = require('gulp-decomment');
  22. var inject = require('gulp-inject');
  23. var createHash = require('hash-generator');
  24. var clean = require('gulp-clean');
  25. var runSequence = require('run-sequence');
  26. var del = require('del');
  27. var fs = require('fs');
  28.  
  29. var src = "./static-src";
  30. var bower = "./static/bower_components";
  31. var nodeModules = './node_modules';
  32. var lib = './static/lib';
  33. var dist = "./static";
  34.  
  35. var appFileName = 'beta-app-'+createHash(8)+'.js';
  36. var vendorFileName = 'alpha-vendor-'+createHash(8)+'.js';
  37. var cssFileName = 'style-'+createHash(8)+'.css';
  38.  
  39. var onLocal = gutil.env.local;
  40. var errorHandlerFactory = function (taskName) {
  41. return function (err) {
  42. notify.onError({
  43. title: "Gulp Error: " + taskName,
  44. message: "<%= error.message %>",
  45. sound: "Beep"
  46. })(err);
  47.  
  48. this.emit('end');
  49. };
  50. };
  51.  
  52. gulp.task('clean-scripts', function () {
  53. // return del(['./static/js/**/*.js'])
  54. return gulp.src(['./static/js/temp/**/*.js', './static/css/**/style-*.css'], {read: false})
  55. .pipe(clean());
  56. });
  57.  
  58.  
  59.  
  60.  
  61. gulp.task('html', function () {
  62. return gulp.src('./templates/**/*.{htm,html}')
  63. .pipe(browserSync.stream());
  64. });
  65.  
  66.  
  67.  
  68. gulp.task('html-partials', function () {
  69. return gulp.src(src + '/templates/*')
  70. .pipe(gulpHtml({ collapseWhitespace: true }))
  71. .pipe(decomment({ trim: true }))
  72. .pipe(gulp.dest(dist + '/templates'));
  73. });
  74.  
  75. gulp.task('injectFile', function () {
  76. var injReq = '<!-- inject:css --> <!-- endinject --> <!-- inject:js --> <!-- endinject -->';
  77. fs.writeFileSync('templates/inject.html', injReq);
  78. });
  79.  
  80. gulp.task('index', function () {
  81.  
  82. var target = gulp.src('./templates/inject.html');
  83. // It's not necessary to read the files (will speed up things), we're only after their paths:
  84. var sources = gulp.src(['./static/js/temp/**/*.js', './static/css/'+ cssFileName], {read: false}, {relative : true});
  85.  
  86. return target
  87. .pipe(inject(sources))
  88. .pipe(gulp.dest('./templates'));
  89. });
  90.  
  91.  
  92.  
  93. gulp.task('images', function () {
  94. var onError = errorHandlerFactory('images');
  95.  
  96. return gulp.src(src + '/img/*')
  97. .pipe(plumber({ errorHandler: onError }))
  98. .pipe(newer(dist + '/img'))
  99. .pipe(imagemin({
  100. optimizationLevel: 7,
  101. multipass: true,
  102. use: [pngquant()]
  103. }))
  104. .pipe(gulp.dest(dist + '/img'));
  105. });
  106.  
  107. gulp.task('npm-scripts' ,function() {
  108. var onError = errorHandlerFactory('scripts');
  109.  
  110. return gulp.src([
  111. nodeModules + '/jquery/dist/jquery.js',
  112. nodeModules + '/angular-dragula/dist/angular-dragula.js',
  113. nodeModules + '/angular/angular.js',
  114. nodeModules + '/angular-ui-bootstrap/dist/ui-bootstrap.js',
  115. nodeModules + '/angular-ui-bootstrap/dist/ui-bootstrap-tpls.js',
  116. nodeModules + '/angular-drag-scroll/src/ng-drag-scroll.js',
  117. nodeModules + '/angulartics/src/angulartics.js',
  118. nodeModules + '/angulartics/dist/angulartics-debug.min.js',
  119. nodeModules + '/angulartics-google-analytics/dist/angulartics-ga.min.js',
  120. nodeModules + '/angular-moment/angular-moment.js',
  121. nodeModules + '/angular-animate/angular-animate.min.js',
  122. nodeModules + '/angular-aria/angular-aria.min.js',
  123. nodeModules + '/angular-cookies/angular-cookies.min.js',
  124. nodeModules + '/angular-scroll/angular-scroll.min.js',
  125. nodeModules + '/angular-route/angular-route.min.js',
  126. nodeModules + '/angular-sanitize/angular-sanitize.min.js',
  127. nodeModules + '/angular-filter/dist/angular-filter.min.js',
  128. nodeModules + '/angular-messages/angular-messages.min.js',
  129. nodeModules + '/angular-touch/angular-touch.min.js',
  130. nodeModules + '/ngstorage/ngStorage.min.js',
  131. nodeModules + '/ng-file-upload/dist/ng-file-upload.min.js',
  132. nodeModules + '/ui-select/dist/select.js',
  133. lib + '/jquery.ui.draggable.min.js',
  134. nodeModules + '/bootstrap-sass/assets/javascripts/bootstrap.min.js',
  135. nodeModules + '/jquery.easing/jquery.easing.min.js',
  136. nodeModules + '/moment/min/moment.min.js',
  137. nodeModules + '/video.js/dist/video.min.js',
  138. nodeModules + '/videojs-ga/dist/videojs-ga.min.js',
  139. nodeModules + '/raven-js/dist/raven.js',
  140. nodeModules + '/raven-js/dist/plugins/angular.js'
  141.  
  142. ])
  143. .pipe(plumber({ errorHandler: onError }))
  144. .pipe(decomment({ trim: true }))
  145. .pipe(concat('vendor.js'))
  146. .pipe(gulp.dest(dist + '/js'))
  147. .pipe(concat(vendorFileName))
  148. .pipe(gulpif(!onLocal, uglify()))
  149. .pipe(gulp.dest(dist + '/js/temp'));
  150. });
  151.  
  152. gulp.task('scripts', function () {
  153. var onError = errorHandlerFactory('scripts');
  154.  
  155. return gulp.src([
  156. src + '/js/scripts.js',
  157. // src + '/js/app.js',
  158. src + '/js/app.module.js',
  159.  
  160. src + '/js/utilitiesApp/app.utilities.module.js',
  161. src + '/js/utilitiesApp/config.js',
  162. src + '/js/utilitiesApp/config.setCsrftoken.js',
  163. src + '/js/utilitiesApp/*.directive.js',
  164. src + '/js/utilitiesApp/*.service.js',
  165. src + '/js/utilitiesApp/*.filter.js',
  166. src + '/js/utilitiesApp/*.controller.js',
  167. src + '/js/projectApp/config.js',
  168. src + '/js/projectApp/run.js',
  169. src + '/js/projectApp/*.directive.js',
  170. src + '/js/projectApp/*.service.js',
  171. src + '/js/projectApp/*.controller.js',
  172. src + '/js/projectApp/filters.js',
  173.  
  174. src + '/js/registrationApp/app.registration.module.js',
  175. src + '/js/registrationApp/*config.js',
  176. src + '/js/registrationApp/*.directive.js',
  177. src + '/js/registrationApp/*.service.js',
  178. src + '/js/registrationApp/*.controller.js',
  179.  
  180.  
  181. src + '/js/userApp/app.user.module.js',
  182. src + '/js/userApp/*.config.js',
  183. src + '/js/userApp/constants.js',
  184. src + '/js/userApp/*.directive.js',
  185. src + '/js/userApp/*.service.js',
  186.  
  187. src + '/js/userApp/ProjectList.controller.js',
  188. src + '/js/userApp/Benefits.controller.js',
  189. src + '/js/userApp/ExpandedProject.controller.js',
  190. src + '/js/userApp/ManagerDashboard.controller.js',
  191. src + '/js/userApp/VideoModal.controller.js',
  192. src + '/js/wizardApp/app.wizard.module.js',
  193. src + '/js/wizardApp/interpolate.config.js',
  194. src + '/js/wizardApp/constants.js',
  195. src + '/js/wizardApp/unsafe.filter.js',
  196. src + '/js/wizardApp/compile.directive.js',
  197. src + '/js/wizardApp/*.service.js',
  198. src + '/js/wizardApp/routes.js',
  199. src + '/js/wizardApp/run.js',
  200. src + '/js/wizardApp/constants.js',
  201. src + '/js/wizardApp/*.controller.js',
  202. src + '/js/searchApp/app.search.module.js',
  203. src + '/js/searchApp/*.config.js',
  204. src + '/js/searchApp/constants.js',
  205.  
  206. src + '/js/searchApp/*.service.js',
  207. src + '/js/searchApp/*.directive.js',
  208. src + '/js/searchApp/*.filter.js',
  209. src + '/js/searchApp/*.controller.js',
  210.  
  211. src + '/js/mezzanineApp/app.mezzanine.module.js'
  212. ])
  213. .pipe(webkitAssign())
  214. .pipe(plumber({ errorHandler: onError }))
  215. .pipe(gulpif(!onLocal, sourcemaps.init()))
  216. .pipe(decomment({ trim: true }))
  217. .pipe(concat('app.js'))
  218. .pipe(gulp.dest(dist + '/js'))
  219. .pipe(concat(appFileName))
  220. .pipe(gulpif(!onLocal, sourcemaps.write()))
  221. .pipe(gulp.dest(dist + '/js/temp'));
  222. });
  223.  
  224. gulp.task('styles', function () {
  225. var onError = errorHandlerFactory('styles');
  226. return gulp.src(src + '/scss/**/*.scss')
  227. .pipe(plumber({ errorHandler: onError }))
  228. .pipe(gulpif(!onLocal, sourcemaps.init()))
  229. .pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
  230. .pipe(autoprefixer())
  231. .pipe(rename({ suffix: '.min' }))
  232. .pipe(gulpif(!onLocal, sourcemaps.write()))
  233. .pipe(gulp.dest(dist + '/css'))
  234. .pipe(concat(cssFileName))
  235. .pipe(gulp.dest(dist + '/css'))
  236. .pipe(browserSync.stream({ match: '**/*.css' }));
  237. });
  238.  
  239. gulp.task('vendor-styles', function() {
  240. var onError = errorHandlerFactory('vendor-styles');
  241. return gulp.src([
  242. nodeModules + '/animate.css/animate.min.css',
  243. nodeModules + '/ui-select/dist/select.min.css'
  244. ])
  245. .pipe(plumber({ errorHandler: onError }))
  246. .pipe(gulp.dest(dist + '/css/vendor'));
  247. });
  248.  
  249. gulp.task('fonts', function () {
  250. var onError = errorHandlerFactory('fonts');
  251. return gulp.src(nodeModules + '/bootstrap-sass/assets/fonts/**/*.{eot,svg,ttf,woff,woff2}')
  252. .pipe(plumber({ errorHandler: onError }))
  253. .pipe(gulp.dest(dist + '/fonts'));
  254. });
  255.  
  256. gulp.task('scripts-watch', ['scripts'], browserSync.reload);
  257. gulp.task('image-watch', ['images'], browserSync.reload);
  258.  
  259. gulp.task('watch', ['browserSync'], function () {
  260. gulp.watch(src + '/scss/*.scss', ['styles']);
  261. gulp.watch(src + '/js/**/*.js', ['scripts-watch']);
  262.  
  263. gulp.watch('./templates/**/*.{htm,html}', ['html']);
  264. gulp.watch(src + '/templates/*', ['html-partials']);
  265.  
  266. gulp.watch(src + '/img/*', ['image-watch']);
  267. });
  268.  
  269. gulp.task('browserSync', function () {
  270. browserSync({
  271. proxy: onLocal ? '0.0.0.0:8000' : '192.168.99.100:8000'
  272. })
  273. });
  274.  
  275. gulp.task('build', function() {
  276. runSequence('clean-scripts',
  277. ['npm-scripts', 'scripts', 'styles', 'vendor-styles', 'images', 'fonts', 'html-partials', 'injectFile'],
  278. 'index');
  279. });
  280. gulp.task('default', ['build', 'watch']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement