Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

First!

  • Loading branch information...
commit 01578119e4457ea6731016fa9aa9c46c7f1cff95 0 parents
@GulinSS authored
9 .npmignore
@@ -0,0 +1,9 @@
+.lock-wscript
+.svn/
+.hg/
+.git/
+CVS/
+*~
+*.bak
+.DS_Store
+npm-debug.log
2  build.bat
@@ -0,0 +1,2 @@
+rd /s /q lib
+coffee -wo lib/ src/
32 package.json
@@ -0,0 +1,32 @@
+{
+ "name": "bower-javascript-brunch",
+ "version": "0.0.1",
+ "description": "Adds Bower support to Brunch for javascript files",
+ "author": {
+ "name": "Gulin Serge",
+ "url": "http://gulin.pro/"
+ },
+ "homepage": "https://github.com/GulinSS/bower-javascript-brunch.git",
+ "repository": {
+ "type": "git",
+ "url": "git@github.com:GulinSS/bower-javascript-brunch.git"
+ },
+ "main": "./lib/index",
+ "scripts": {
+ "prepublish": "coffee -o lib/ src/",
+ "postinstall": "node setup.js postinstall"
+ },
+ "engines": {
+ "node": "~0.6.10 || 0.8 || 0.9"
+ },
+ "dependencies": {
+ "coffee-script": "1.3.3",
+ "underscore": "~1.4.4",
+ "q": "~0.8.12",
+ "bower": "~0.7.0"
+ },
+ "devDependencies": {
+ "mocha": "1.2.2",
+ "chai": "1.1.0"
+ }
+}
28 setup.js
@@ -0,0 +1,28 @@
+var exec = require('child_process').exec;
+var sysPath = require('path');
+var fs = require('fs');
+
+var mode = process.argv[2];
+
+var fsExists = fs.exists || sysPath.exists;
+
+var execute = function(pathParts, params, callback) {
+ if (callback == null) callback = function() {};
+ var path = sysPath.join.apply(null, pathParts);
+ var command = 'node ' + path + ' ' + params;
+ console.log('Executing', command);
+ exec(command, function(error, stdout, stderr) {
+ if (error != null) return process.stderr.write(stderr.toString());
+ console.log(stdout.toString());
+ });
+};
+
+if (mode === 'postinstall') {
+ fsExists(sysPath.join(__dirname, 'lib'), function(exists) {
+ if (exists) return;
+ execute(['node_modules', 'coffee-script', 'bin', 'coffee'], '-o lib/ src/');
+ });
+} else if (mode === 'test') {
+ execute(['node_modules', 'mocha', 'bin', 'mocha'],
+ '--require test/common.js --colors');
+}
62 src/index.coffee
@@ -0,0 +1,62 @@
+sysPath = require 'path'
+_ = require 'underscore'
+Q = require 'q'
+fs = require 'fs'
+bowerList = require 'bower/lib/commands/list'
+
+helper =
+ monkeyPatchPaths: (bowerListResult) ->
+ fixPath = (path) ->
+ path.split('/').join sysPath.sep
+
+ result = {}
+
+ _.each bowerListResult, (v, k) ->
+ if _.isArray v
+ resultv = []
+ _.each v, (vv, i) ->
+ resultv[i] = fixPath vv
+ result[k] = resultv
+ else result[k] = fixPath v
+ return result
+
+module.exports = class BowerJSIncluder
+ brunchPlugin: yes
+ type: 'javascript'
+ extension: 'js'
+
+ constructor: (config) ->
+ pathsDefered = Q.defer()
+ mergedPathDefered = Q.defer()
+ @public = config.paths?.public
+ include = config.plugins?.bower?.extend
+
+ pathsDefered.promise.then (paths) ->
+ include = helper.monkeyPatchPaths include
+ merged = _.extend {}, paths, include
+ resolveResult = []
+
+ _.each merged, (v, k) ->
+ if _.isArray v
+ _.each v, (vv, i) ->
+ resolveResult.push vv
+ else resolveResult.push v
+
+ mergedPathDefered.resolve resolveResult
+
+ @pathsPromise = mergedPathDefered.promise
+ bowerList({paths: true}).on 'data', (paths) ->
+ pathsDefered.resolve paths
+
+ compile: (data, path, callback) ->
+ @pathsPromise.then (paths) ->
+ if path.indexOf('app') is 0
+ callback null, data
+
+ # скобки нужны
+ if paths.indexOf(path) >= 0
+ callback null, data
+ else callback null, ""
+
+ onCompile: (compiled) ->
+ #console.log compiled

0 comments on commit 0157811

Please sign in to comment.
Something went wrong with that request. Please try again.