zorin-e
5/5/2017 - 1:57 PM

Builder based on gulp

Builder based on gulp

{
  "name": "adminpaygpay",
  "version": "0.0.0",
  "description": "",
  "main": "gulpfile.js",
  "devDependencies": {
    "browser-sync": "^2.9.11",
    "fs": "0.0.2",
    "gulp": "^3.9.0",
    "gulp-autoprefixer": "^3.1.0",
    "gulp-changed": "^2.0.0",
    "gulp-clean": "^0.3.2",
    "gulp-concat": "^2.6.0",
    "gulp-connect-php": "0.0.8",
    "gulp-css-globbing": "^0.1.8",
    "gulp-cssmin": "^0.1.7",
    "gulp-if": "^2.0.2",
    "gulp-plumber": "^1.0.1",
    "gulp-rename": "^1.2.2",
    "gulp-sass": "^3.0.0",
    "gulp-sourcemaps": "^2.6.0",
    "gulp-uglify": "^2.1.2",
    "gulp-watch": "^4.3.11"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "webdude"
}
'use strict';

const gulp = require('gulp'),
	  concat = require('gulp-concat'),
	  cssmin = require('gulp-cssmin'),
	  plumber = require('gulp-plumber'),
	  browserSync = require('browser-sync'),
	  reload = browserSync.reload,
	  sass = require('gulp-sass'),
	  autoprefixer = require('gulp-autoprefixer'),
	  clean = require('gulp-clean'),
	  globbing = require('gulp-css-globbing'),
	  fs = require('fs'),
	  watch = require('gulp-watch'),
	  rename = require('gulp-rename'),
	  connect = require('gulp-connect-php'),
	  gulpif = require('gulp-if'),
	  uglify = require('gulp-uglify'),
	  sourcemaps = require('gulp-sourcemaps'),
	  changed = require('gulp-changed');

/**
 *
 * settings
 *
 */

let path, app, min;

min = {
	css: true,
	cssVendors: true,
	js: true
};

app = {
	entry: './app/',
	build: '../www_php/static/'
};

path = {
	host: 'https://admin.paygpay',
	// templateDir: '../smarty/templates_new/**/*.tpl',

	scss: app.entry + 'scss/base.scss',
	scssWatch: [app.entry + 'scss/**/*.scss', '!' + app.entry + 'scss/additional/**'],

	scssVendors: app.entry + 'scss/additional/vendors.scss',
	scssWatchVendors: [app.entry + 'scss/additional/**/*.scss'],

	js: app.entry + 'js/*.js',

	fonts: app.entry  + 'fonts/**/*{.woff,.ttf,woff2,.svg}',

	create: [
	]
};


/**
 *
 * tasks
 *
 */

// js
gulp.task('js', () => {
	gulp.src(path.js)
		.pipe(plumber())
		.pipe(changed(app.build + 'js'))
		.pipe(sourcemaps.init({loadMaps: true}))
		.pipe(gulpif(min.js, uglify()))
		.pipe(sourcemaps.write('./maps'))
		.pipe(gulp.dest(app.build + 'js'));
});

// scss
gulp.task('scss', () => {
	gulp.src(path.scss)
		.pipe(plumber())
		.pipe(globbing({
        	extensions: ['.scss']
    	}))
    	.pipe(sourcemaps.init({loadMaps: true}))
		.pipe(sass())
		.pipe(autoprefixer({
			browsers: ['last 2 versions'],
			cascade: true
		}))
		.pipe(concat('custom.css'))
		.pipe(gulpif(min.css, cssmin()))
		.pipe(sourcemaps.write('./maps'))
		.pipe(gulp.dest(app.build + 'css'));
		// .pipe(reload({stream:true}));
});

// scss vendors
gulp.task('scssVendors', () => {
	gulp.src(path.scssVendors)
		.pipe(plumber())
		.pipe(globbing({
        	extensions: ['.scss']
    	}))
		.pipe(sass())
		.pipe(autoprefixer({
			browsers: ['last 2 versions'],
			cascade: true
		}))
		.pipe(concat('vendors.css'))
		.pipe(gulpif(min.cssVendors, cssmin()))
		.pipe(gulp.dest(app.build + 'css'));
		// .pipe(reload({stream:true}));
});

// fonts
gulp.task('fonts', () => {
	gulp.src(path.fonts)
		.pipe(gulp.dest(app.build + 'fonts'));
		// .pipe(reload({stream:true}));
});

// watchers
gulp.task('watcher', () => {
	// tpl
	// watch(path.templateDir, () => {
	// 	 browserSync.reload
 //  	});
 	// js
  	watch(path.js, () => {
  		gulp.start('js');
  	});

  	// scss
  	watch(path.scssWatch, () => {
  		gulp.start('scss');
  	});

  	// scss vendors
  	watch(path.scssWatchVendors, () => {
  		gulp.start('scssVendors');
  	});

	// fonts
  	watch(path.fonts, () => {
  		gulp.start('fonts');
  	});
});


// connect to php
gulp.task('connect', () => {
	  connect.server({
	    bin: 'C:/xampp/php/php.exe',
	    ini: 'C:/xampp/php/php.ini',
	    port: 8001,
	    base: '../www_php'
	  }, () => {
		browserSync({
			proxy: path.host,
			port: 7009,
			open: false
		});
	  });	
});

// default
gulp.task('default', ['watcher']);