Created
October 22, 2015 05:50
-
-
Save bhill77/d07a5e986906b614fef2 to your computer and use it in GitHub Desktop.
bower laravel elixir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var gulp = require('gulp'), | |
| file = require('gulp-file'), | |
| filenames = require('gulp-filenames'), | |
| gulpif = require('gulp-if'), | |
| imagemin = require('gulp-imagemin'), | |
| beautify = require('gulp-jsbeautify'), | |
| rename = require('gulp-rename'), | |
| uglify = require('gulp-uglify'), | |
| Elixir = require('laravel-elixir'), | |
| merge = require('merge-stream'), | |
| path = require('path'), | |
| exists = require('path-exists').sync, | |
| sequence = require('run-sequence'), | |
| config = Elixir.config; | |
| /** | |
| * Publish javascript main files into another folder | |
| * @param {string|object} outputDir The destination folder or an options object | |
| * @param {object} options Options object passed to bower-files | |
| */ | |
| Elixir.extend('bowerJs', function(outputDir, options) { | |
| // Options were provided on the outputDir parameter | |
| if (typeof outputDir == 'object') { | |
| options = outputDir; | |
| outputDir = null; | |
| } | |
| options = typeof options == 'undefined' ? {camelCase: false} : options; | |
| var paths = new Elixir.GulpPaths() | |
| .output(outputDir || config.get('assets.js.folder') + '/vendor'); | |
| new Elixir.Task('bowerJs', function () { | |
| var bower_components = require('bower-files')(options); | |
| var getMinifiedScripts = function (path, index, arr) { | |
| var newPath = path.replace(/.([^.]+)$/g, '.min.$1'); | |
| return exists( newPath ) ? newPath : path; | |
| }, | |
| isNotMinified = function(file) { | |
| var filename = file.history[file.history.length - 1]; | |
| return !(/\.min\.js$/.test(filename)); | |
| }, | |
| uglifyScripts = function(file) { | |
| return isNotMinified(file) && config.production; | |
| }, | |
| jsfiles = bower_components.ext('js').deps, | |
| tasks = [], | |
| createFolder; | |
| for (var packageName in jsfiles) { | |
| if (jsfiles[packageName].length) { | |
| jsfiles[packageName].map(getMinifiedScripts); | |
| createFolder = jsfiles[packageName].length > 1; | |
| tasks.push( | |
| gulp.src(jsfiles[packageName]) | |
| .pipe(gulpif(uglifyScripts, uglify())) | |
| .pipe(gulpif(createFolder, rename({dirname: packageName.replace(/\.js$/, '')}))) | |
| .pipe(gulpif(!createFolder, rename({basename: packageName.replace(/\.js$/, '')}))) | |
| .pipe(filenames(packageName.replace(/\.js$/, ''))) | |
| .pipe(gulp.dest(paths.output.path)) | |
| ); | |
| } | |
| } | |
| return merge.apply(this, tasks); | |
| }); | |
| }); | |
| /** | |
| * Generate a requirejs main file from the proccessed files | |
| * @param {string} filename The filename of the main file | |
| * @param {object} shim The requirejs shim definitions | |
| * @param {object} outputDir Options object passed to bower-files | |
| */ | |
| Elixir.extend('bowerRequireMain', function(filename, shim, outputDir) { | |
| var paths = new Elixir.GulpPaths() | |
| .output(outputDir || config.get('assets.js.folder')); | |
| new Elixir.Task('bowerRequireMain', function() { | |
| var main = {paths: {}, baseUrl: 'js', shim: (shim || {})}; | |
| var files = filenames.get("all"), | |
| packages = []; | |
| for (var packageName in files) { | |
| packages.push(packageName); | |
| } | |
| packages = packages.sort() | |
| for (var i in packages) { | |
| main.paths[packages[i]] = 'vendor/' + packages[i]; | |
| } | |
| var main_str = 'require.config(' + JSON.stringify(main) + ');'; | |
| return file(filename, main_str) | |
| .pipe(beautify({indentSize: 4})) | |
| .pipe(gulp.dest(paths.output.path)); | |
| }); | |
| }); | |
| /** | |
| * Publish font main files into another folder | |
| * @param {string|object} outputDir The destination folder or an options object | |
| * @param {object} options Options object passed to bower-files | |
| */ | |
| Elixir.extend('bowerFonts', function(outputDir, options) { | |
| // Options were provided on the outputDir parameter | |
| if (typeof outputDir == 'object') { | |
| options = outputDir; | |
| outputDir = null; | |
| } | |
| options = typeof options == 'undefined' ? {camelCase: false} : options; | |
| var paths = new Elixir.GulpPaths() | |
| .output(outputDir || config.publicPath + '/fonts'); | |
| new Elixir.Task('bowerFonts', function() { | |
| var bower_components = require('bower-files')(options); | |
| var fonts = bower_components.ext(['eot', 'woff', 'woff2', 'ttf', 'svg']).deps, | |
| tasks = []; | |
| for (var packageName in fonts) { | |
| if (fonts[packageName].length) { | |
| tasks.push( | |
| gulp.src(fonts[packageName]) | |
| .pipe(gulp.dest(paths.output.path + '/' + packageName)) | |
| ); | |
| } | |
| } | |
| return merge.apply(this, tasks); | |
| }); | |
| }); | |
| /** | |
| * Publish image main files into another folder | |
| * @param {string|object} outputDir The destination folder or an options object | |
| * @param {object} options Options object passed to bower-files | |
| */ | |
| Elixir.extend('bowerImages', function(outputDir, options) { | |
| // Options were provided on the outputDir parameter | |
| if (typeof outputDir == 'object') { | |
| options = outputDir; | |
| outputDir = null; | |
| } | |
| options = typeof options == 'undefined' ? {camelCase: false} : options; | |
| var paths = new Elixir.GulpPaths() | |
| .output(outputDir || config.publicPath + '/img/vendor'); | |
| new Elixir.Task('bowerImages', function() { | |
| var bower_components = require('bower-files')(options); | |
| var images = bower_components.ext(['png', 'jpg', 'gif', 'jpeg']).deps, | |
| tasks = []; | |
| for (var packageName in images) { | |
| if (images[packageName].length) { | |
| tasks.push( | |
| gulp.src(images[packageName]) | |
| .pipe(imagemin()) | |
| .pipe(gulp.dest(paths.output.path + '/' + packageName)) | |
| ); | |
| } | |
| } | |
| return merge.apply(this, tasks); | |
| }); | |
| }); | |
| ///testing | |
| Elixir.extend('bowerCss', function(outputDir, options) { | |
| // Options were provided on the outputDir parameter | |
| if (typeof outputDir == 'object') { | |
| options = outputDir; | |
| outputDir = null; | |
| } | |
| options = typeof options == 'undefined' ? {camelCase: false} : options; | |
| var paths = new Elixir.GulpPaths() | |
| .output(outputDir || config.get('assets.css.folder') + '/vendor'); | |
| new Elixir.Task('bowerCss', function () { | |
| var bower_components = require('bower-files')(options); | |
| var getMinifiedScripts = function (path, index, arr) { | |
| var newPath = path.replace(/.([^.]+)$/g, '.min.$1'); | |
| return exists( newPath ) ? newPath : path; | |
| }, | |
| isNotMinified = function(file) { | |
| var filename = file.history[file.history.length - 1]; | |
| return !(/\.min\.css$/.test(filename)); | |
| }, | |
| uglifyScripts = function(file) { | |
| return isNotMinified(file) && config.production; | |
| }, | |
| jsfiles = bower_components.ext('css').deps, | |
| tasks = [], | |
| createFolder; | |
| for (var packageName in jsfiles) { | |
| if (jsfiles[packageName].length) { | |
| jsfiles[packageName].map(getMinifiedScripts); | |
| createFolder = jsfiles[packageName].length > 1; | |
| tasks.push( | |
| gulp.src(jsfiles[packageName]) | |
| .pipe(gulpif(uglifyScripts, uglify())) | |
| .pipe(gulpif(createFolder, rename({dirname: packageName.replace(/\.css$/, '')}))) | |
| .pipe(gulpif(!createFolder, rename({basename: packageName.replace(/\.css$/, '')}))) | |
| .pipe(filenames(packageName.replace(/\.css$/, ''))) | |
| .pipe(gulp.dest(paths.output.path)) | |
| ); | |
| } | |
| } | |
| return merge.apply(this, tasks); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "laravel-elixir-bower-files", | |
| "version": "1.0.4", | |
| "description": "Publish you bower components main files", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "author": { | |
| "name": "Gerardo Gómez", | |
| "email": "[email protected]" | |
| }, | |
| "license": "MIT", | |
| "dependencies": { | |
| "bower-files": "~3.8.0", | |
| "gulp": "^3.8.8", | |
| "gulp-file": "^0.2.0", | |
| "gulp-filenames": "^1.3.0", | |
| "gulp-if": "^1.2.5", | |
| "gulp-imagemin": "^2.3.0", | |
| "gulp-jsbeautify": "^0.1.1", | |
| "gulp-rename": "^1.2.2", | |
| "gulp-uglify": "^1.2.0", | |
| "merge-stream": "^1.0.0", | |
| "path-exists": "^1.0.0", | |
| "run-sequence": "^1.1.2" | |
| }, | |
| "repository": { | |
| "type": "git", | |
| "url": "git+https://github.com/ruysu/laravel-elixir-bower-files.git" | |
| }, | |
| "keywords": [ | |
| "laravel", | |
| "elixir", | |
| "bower", | |
| "laravel-elixir-bower" | |
| ], | |
| "gitHead": "c1bf1308e7cf64f178bc91dfd0ecd8dde95200af", | |
| "bugs": { | |
| "url": "https://github.com/ruysu/laravel-elixir-bower-files/issues" | |
| }, | |
| "homepage": "https://github.com/ruysu/laravel-elixir-bower-files", | |
| "_id": "[email protected]", | |
| "_shasum": "47e503b9ad89e90332b41dd714c0c91e8d7920ed", | |
| "_from": "laravel-elixir-bower-files@*", | |
| "_npmVersion": "1.4.28", | |
| "_npmUser": { | |
| "name": "ruysu", | |
| "email": "[email protected]" | |
| }, | |
| "maintainers": [ | |
| { | |
| "name": "ruysu", | |
| "email": "[email protected]" | |
| } | |
| ], | |
| "dist": { | |
| "shasum": "47e503b9ad89e90332b41dd714c0c91e8d7920ed", | |
| "tarball": "http://registry.npmjs.org/laravel-elixir-bower-files/-/laravel-elixir-bower-files-1.0.4.tgz" | |
| }, | |
| "directories": {}, | |
| "_resolved": "https://registry.npmjs.org/laravel-elixir-bower-files/-/laravel-elixir-bower-files-1.0.4.tgz", | |
| "readme": "ERROR: No README data found!" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment