Guest User

Untitled

a guest
Jan 23rd, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. const gulp = require('gulp');
  2. let using = require('gulp-using');
  3. const pkg = require('./package.json');
  4. const jshint = require('gulp-jshint');
  5. const watch = require('gulp-watch');
  6. const stylus = require('gulp-stylus');
  7. const livereload = require('gulp-livereload');
  8. const zip = require('gulp-zip');
  9. let uglify = require('gulp-uglify-es').default;
  10. const concat = require('gulp-concat');
  11. const rename = require("gulp-rename");
  12. const changed = require('gulp-changed');
  13. const plumber = require('gulp-plumber');
  14. const babel = require('gulp-babel');
  15. const browserify = require('browserify');
  16. const source = require('vinyl-source-stream');
  17. const browserSync = require('browser-sync');
  18. const cleanCSS = require('gulp-clean-css');
  19. const imagemin = require('gulp-imagemin');
  20. const ftp = require('vinyl-ftp');
  21. const del = require('del');
  22. let reload = browserSync.reload;
  23.  
  24. // browser-sync
  25.  
  26.  
  27. function clean(cb) {
  28. del(['build'], cb);
  29. }
  30.  
  31. // caminhos
  32. let paths = {
  33. php: '*.php',
  34. html: '*.html',
  35. stylus: './src-css/*.styl',
  36. js: {
  37. all: ['./src-js/vue.min.js', './src-js/jquery.js', './src-js/bundle.js', './src-js/plugins.js', './src-js/app.js'],
  38. imports: './src-js/imports.js',
  39. src: './src-js',
  40. dist: './js',
  41. handlers: './src-js/handlers.js'
  42. },
  43. images: {
  44. all: ['./img/*.jpg', './img/*.gif', './img/*.png', './img/*.svg', './img/*.jpeg'],
  45. dist: './img'
  46. },
  47. css: {
  48. bundle: ['./css/bundle.css', './css/build.css'],
  49. dist: './css'
  50. },
  51. globs: ['css/**', 'js/**', 'fonts/**', '*.php', '*.html', 'img/**', 'style.css'],
  52. conn: {
  53. host: '170.247.49.167',
  54. user: 'mateusavila-com-br',
  55. password: 'GAULKE MALDITO',
  56. parallel: 5,
  57. newer: '/public/gulp',
  58. dest: '/public/gulp'
  59. }
  60. };
  61.  
  62.  
  63. let t_browsersync = () => {
  64. return browserSync({
  65. proxy: "localhost/mateuswp",
  66. ghostMode: {
  67. clicks: true,
  68. location: true,
  69. forms: true,
  70. scroll: true
  71. }
  72. });
  73. };
  74. let t_php = () => {
  75. return gulp.src(paths.php)
  76. .pipe(livereload())
  77. .pipe(reload({stream: true}));
  78. };
  79.  
  80. let t_html = () => {
  81. return gulp.src(paths.html)
  82. .pipe(livereload())
  83. .pipe(reload({stream: true}));
  84. };
  85.  
  86. let t_stylus = () => {
  87. return gulp.src(paths.stylus)
  88. .pipe(plumber())
  89. .pipe(stylus())
  90. .pipe(concat('build.css'))
  91. .pipe(gulp.dest('./css'))
  92. .pipe(livereload())
  93. .pipe(reload({stream:true}));
  94. };
  95.  
  96. let t_browserify = () => {
  97. return browserify(paths.js.imports)
  98. .bundle()
  99. .pipe(source('bundle.js'))
  100. .pipe(gulp.dest(paths.js.src))
  101. .pipe(livereload())
  102. .pipe(reload({stream:true}));
  103. };
  104.  
  105. let t_lint = () => {
  106. return gulp.src(paths.js.handlers)
  107. .pipe(jshint('.jshintrc'))
  108. .pipe(jshint.reporter('jshint-stylish'))
  109. .pipe(babel({
  110. presets: ['@babel/env']
  111. }))
  112. .pipe(plumber())
  113. .pipe(concat('app.js'))
  114. .pipe(gulp.dest(paths.js.src))
  115. .pipe(livereload())
  116. .pipe(reload({stream:true}));
  117. };
  118.  
  119. // funções pré-produção
  120. let t_images = () => {
  121. return gulp.src(paths.images.all)
  122. .pipe(imagemin())
  123. .pipe(gulp.dest(paths.images.dist));
  124. };
  125.  
  126. let t_concatcss = () => {
  127. return gulp.src(paths.css.bundle)
  128. .pipe(concat('style.css'))
  129. .pipe(cleanCSS())
  130. .pipe(rename({suffix: '.min'}))
  131. .pipe(gulp.dest(paths.css.dist));
  132. };
  133.  
  134. let t_minify = () => {
  135. return gulp.src(paths.js.all)
  136. .pipe(concat('build.js'))
  137. .pipe(gulp.dest(paths.js.src))
  138. .pipe(plumber())
  139. .pipe(uglify())
  140. .pipe(rename('app.min.js'))
  141. .pipe(gulp.dest(paths.js.dist));
  142. };
  143.  
  144. // deploy
  145. let t_deploy = () => {
  146. let conn = ftp.create({
  147. host: paths.conn.host,
  148. user: paths.conn.user,
  149. password: paths.conn.password,
  150. parallel: paths.conn.parallel
  151. });
  152. return gulp.src(paths.globs, {base: '.'})
  153. .pipe(conn.newer(paths.conn.newer))
  154. .pipe(conn.dest(paths.conn.dest))
  155. };
  156.  
  157. // watch
  158. let t_watch = () => {
  159. gulp.watch(paths.php, t_php);
  160. gulp.watch(paths.stylus, t_stylus);
  161. gulp.watch(paths.js.imports, t_browserify);
  162. gulp.watch(paths.js.handlers, t_lint);
  163. livereload.listen(35729);
  164. };
  165.  
  166. // paralelos
  167. let all = gulp.parallel(t_watch, t_php, t_stylus, t_html, t_browserify, t_lint);
  168.  
  169. let production = gulp.parallel(t_minify, t_concatcss, t_images);
  170.  
  171. let simple = gulp.parallel(t_minify, t_concatcss);
  172. let simplecss = gulp.parallel(t_concatcss);
  173.  
  174. let browser = gulp.parallel(t_watch, t_php, t_stylus, t_html, t_browserify, t_lint, t_browsersync);
  175.  
  176. let publish = gulp.parallel(t_minify, t_concatcss, t_images, t_deploy);
  177.  
  178.  
  179. // processamento das tarefas
  180. gulp.task('default', gulp.series(all));
  181.  
  182. gulp.task('full', gulp.series(browser));
  183.  
  184. gulp.task('prod', gulp.series(production));
  185.  
  186. gulp.task('simple', gulp.series(simple));
  187. gulp.task('simplecss', gulp.series(simplecss));
  188.  
  189. gulp.task('publish', gulp.series(publish));
Add Comment
Please, Sign In to add comment