123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- 'use strict';
- var gulp = require('gulp');
- var util = require('gulp-util');
- var sass = require('gulp-sass');
- var watch = require('gulp-watch');
- var autoprefixer = require('gulp-autoprefixer');
- var jsmin = require('gulp-jsmin');
- var cssmin = require('gulp-cssmin');
- var rename = require('gulp-rename');
- var mainBowerFiles = require('main-bower-files');
- var jsonToSass = require('gulp-json-to-sass');
- var concat = require('gulp-concat');
- var through = require('through2');
- // var fs = require('fs');
- // var json2js = require('gulp-json2js');
- // var data = require('gulp-data');
- // var shared_variables = JSON.parse(fs.readFileSync('./assets/json/shared_variables.json'));
- function handleError(err) {
- console.log(err.toString());
- }
- var config = {
- assetsDir : './assets',
- production: !!util.env.production
- }
- gulp.task('vars2sass', function () {
- gulp.src('./assets/json/shared_variables.json')
- .pipe(jsonToSass({
- jsonPath: './assets/json/shared_variables.json',
- scssPath: './assets/styles/base/_shared_variables.scss'
- }));
- });
- // this one is not working, works first run but then it's like it's caching the source
- // gulp.task('variables2js', function() {
- // gulp.src('./assets/scripts/shared_variables_model.js')
- // .pipe(rename('shared_variables.js'))
- // .pipe(data(function(file) {
- // delete require.cache['./assets/json/shared_variables.json'];
- // return require('./assets/json/shared_variables.json');
- // }))
- // .pipe(json2js())
- // .pipe(gulp.dest('./assets/scripts/'));
- // });
- gulp.task('vars2js', function() {
- gulp.src('./assets/json/shared_variables.json')
- .pipe(rename('shared_variables.js'))
- .pipe(through.obj(function (file, enc, cb) {
- // console.log('file',String(file.contents));
- // small pipe to wrappe json data into a js variable
- file.contents = new Buffer("edlp_vars = "+String(file.contents).trim()+";");
- cb(null, file);
- }))
- .pipe(gulp.dest('./assets/scripts/'));
- });
- gulp.task('scripts', function () {
- gulp.src(['./assets/scripts/shared_variables.js','./assets/scripts/main.js'])
- .pipe(concat('main.js'))
- .pipe(config.production ? jsmin() : util.noop())
- .pipe(rename({suffix: '.min'}))
- .pipe(gulp.dest('./assets/dist/scripts/'));
- });
- gulp.task('styles', function () {
- gulp.src('./assets/styles/app.scss')
- .pipe(sass().on('error', sass.logError))
- .pipe(autoprefixer({
- browsers: ['last 2 versions'],
- cascade: false
- })).on('error', handleError)
- .pipe(config.production ? cssmin() : util.noop())
- .pipe(rename({suffix: '.min'}))
- .pipe(gulp.dest('./assets/dist/styles/'));
- });
- gulp.task('bower', function() {
- gulp.src(mainBowerFiles({
- "overrides":{
- "history.js":{
- "main":"./scripts/bundled/html4+html5/jquery.history.js"
- },
- "jquery":{
- "ignore":true
- },
- "overlayScrollbars":{
- "main":[
- "./js/jquery.overlayScrollbars.min.js",
- "./css/OverlayScrollbars.min.css"
- ]
- }
- }
- }))
- .pipe(gulp.dest('./assets/dist/bower/'));
- });
- // default gulp task
- gulp.task('default', ['bower', 'vars2js', 'scripts', 'vars2sass', 'styles'], function() {
- gulp.watch('./assets/json/*.json', ['vars2js', 'vars2sass', 'styles', 'scripts']);
- gulp.watch('./assets/styles/*.scss', ['styles']);
- gulp.watch('./assets/styles/base/*.scss', ['styles']);
- gulp.watch('./assets/scripts/*.js', ['scripts']);
- });
|