Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Rey committed Aug 28, 2014
1 parent c1b0759 commit 6a3d7f7
Show file tree
Hide file tree
Showing 10 changed files with 684 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2014 Elao <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Elao - Assets - Gulp

Handle your project's assets with style ! (and gulp)
244 changes: 244 additions & 0 deletions assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
// Modules
var
util = require('gulp-util');

// Assets
var
Assets = function() {

// Options
this.options = {
groups: [
// Assets
{
name: 'assets',
pattern: 'assets'
},
// Symfony - App
{
name: 'app',
pattern: 'app/Resources/assets'
},
// Symfony - Bundles
{
name: function(path) {
return path
.replace(/^src\//, '')
.replace(/\/Resources\/assets(.*)$/, '')
.replace(/Bundle/g, '')
.replace(/\//g, '') + 'Bundle';
},
pattern: 'src/**/*Bundle/Resources/assets'
}
],
includes: [
'bower_components',
'node_modules'
],
dest: 'web/assets',
header: false,
assets: {
js: {
glob: '/**/*.js',
src: '/js',
dest: '/js',
vendor: {}
},
sass: {
glob: '/**/*.scss',
src: '/sass',
dest: '/css',
vendor: {}
},
images: {
glob: '/**',
src: '/images',
dest: '/images',
vendor: {}
},
fonts: {
glob: '/**',
src: '/fonts',
dest: '/fonts',
vendor: {}
}
}
};

// Assets
this.assets = {};

// Header Meta
this.headerMeta = null;

// Current asset group
this.group = util.env.group || null;
};

// Merges two (or more) objects,
// giving the last one precedence
function merge(target, source) {
if (typeof target !== 'object') {
target = {};
}
for (var property in source) {
if (source.hasOwnProperty(property)) {
var
sourceProperty = source[property];

if (typeof sourceProperty === 'object') {
target[property] = merge(target[property], sourceProperty);
continue;
}

target[property] = sourceProperty;
}
}

for (var a = 2, l = arguments.length; a < l; a++) {
merge(target, arguments[a]);
}

return target;
};

Assets.prototype = {

// Configuration
config: function(options) {
this.options = merge(this.options, options);
},

// Get assets
get: function(assetType) {
var
glob = require('glob'),
path = require('path');

if (this.assets[assetType] === undefined) {

// Initialize assets object
this.assets[assetType] = {};

// Search assets groups
this.options.groups.forEach(function(group) {

glob.sync(group.pattern + this.options.assets[assetType].src).forEach(function(assetGroupPath) {
var
assetGroup = (typeof(group.name) == 'function') ? group.name(assetGroupPath) : group.name;

this.assets[assetType][assetGroup] = {
src: path.resolve(assetGroupPath + this.options.assets[assetType].glob),
dest: this.getDest(assetType)
};

if (util.env.verbose) {
util.log(
'Found', "'" + util.colors.cyan(assetGroup) + "'",
'group', "'" + util.colors.grey(assetType) + "'",
'at', util.colors.magenta(assetGroupPath + this.options.assets[assetType].glob)
);
}
}.bind(this));
}.bind(this));

// Add vendors
Object.keys(this.options.assets[assetType].vendor).forEach(function(assetGroup) {

var
assetGroupSrc = [this.options.assets[assetType].vendor[assetGroup].src];

this.options.includes.forEach(function(include) {
assetGroupSrc.push(include + '/' + assetGroupSrc[0]);
});

assetGroupSrc.forEach(function(src) {
if (glob.sync(src).length) {

this.assets[assetType][assetGroup] = {
src: path.resolve(src),
dest: this.getDest(assetType) + (this.options.assets[assetType].vendor[assetGroup].dest ? this.options.assets[assetType].vendor[assetGroup].dest : '')
};

if (util.env.verbose) {
util.log(
'Vendor', "'" + util.colors.cyan(assetGroup) + "'",
'group', "'" + util.colors.grey(assetType) + "'",
'at', util.colors.magenta(src)
);
}
}
}.bind(this));
}.bind(this));
}

// Filter on current asset group
if (this.group) {
var
assets = {};

Object.keys(this.assets[assetType]).forEach(function(assetGroup) {
if (assetGroup == this.group) {
assets[assetGroup] = this.assets[assetType][assetGroup];
}
}.bind(this));

return assets;
}

return this.assets[assetType];
},

// Set current asset group
setGroup: function(group) {
this.group = group;
},

// Find asset group by asset type and path
findGroup: function(assetType, path) {
var
minimatch = require('minimatch'),
group = null;

Object.keys(this.assets[assetType]).forEach(function(assetGroup) {
if (minimatch(path, this.assets[assetType][assetGroup].src)) {
group = assetGroup;
}
}.bind(this));

return group;
},

// Get sources
getSrc: function(assetType) {
var
src = [];

Object.keys(this.get(assetType)).forEach(function(assetGroup) {
src.push(this.get(assetType)[assetGroup].src);
}.bind(this));

return src;
},

// Get destination
getDest: function(assetType) {
return this.options.dest + this.options.assets[assetType].dest;
},

// Get header
getHeader: function() {
return this.options.header;
},

getHeaderMeta: function() {
if (this.headerMeta === null) {
this.headerMeta = require('../../package.json');
this.headerMeta.date = new Date();
}

return this.headerMeta;
}
};

module.exports = new Assets();
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Assets
var
assets = require('./assets');

module.exports = assets;

// Tasks
require('require-dir')('./tasks');
66 changes: 66 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "elao-assets-gulp",
"description": "Handle your project's assets with style ! (and gulp)",
"version": "0.1.0",
"homepage": "https://github.com/Elao/node-module-assets-gulp",
"repository": {
"type": "git",
"url": "https://github.com/Elao/node-module-assets-gulp"
},
"bugs": {
"url": "https://github.com/Elao/node-module-assets-gulp/issues"
},
"author": {
"name": "Elao",
"email": "[email protected]",
"url": "http://www.elao.com/"
},
"tags": [
"tool",
"asset",
"gulp",
"symfony"
],
"files": [
"index.js",
"assets.js",
"tasks"
],
"dependencies": {
"gulp-util": "3.0.*",
"gulp-load-plugins": "0.6.*",
"gulp-plumber": "0.6.*",
"gulp-streamify": "0.0.*",
"gulp-if": "1.2.*",
"gulp-changed": "1.0.*",
"gulp-size": "1.0.*",
"gulp-notify": "1.5.*",
"gulp-header": "1.0.*",
"require-dir": "0.1.*",
"event-stream": "3.1.*",
"through2": "0.6.*",
"glob": "4.0.*",
"glob2base": "0.0.*",
"vinyl-source-stream": "0.1.*",
"minimatch": "1.0.*",
"rimraf": "2.2.*",

"gulp-sass": "0.7.*",
"gulp-scss-lint": "0.1.*",

"gulp-imagemin": "1.0.*",

"browserify": "5.10.*",
"watchify": "1.0.*",
"gulp-uglify": "0.3.*",
"gulp-jshint": "1.8.*",
"jshint-stylish": "0.4.*",
"gulp-jscs": "1.1.*"
},
"licenses": [
{
"type": "MIT",
"url": "https://raw.githubusercontent.com/Elao/node-module-assets-gulp/master/LICENSE"
}
]
}
Loading

0 comments on commit 6a3d7f7

Please sign in to comment.