Some updates to Node things.

This commit is contained in:
John Bintz 2015-07-05 13:14:28 -04:00
parent df984f9ebf
commit 967d656643
2 changed files with 26 additions and 53 deletions

View File

@ -1,61 +1,29 @@
gulp = require('gulp')
browserify = require('browserify')
watchify = require('watchify')
coffeeReactify = require('coffee-reactify')
glob = require('glob')
path = require('path')
source = require('vinyl-source-stream')
spawn = require('child_process').spawn
makeBrowserify = (file) ->
[sourcePath..., _, _] = file.split(path.sep)
target = sourcePath.concat(['js', 'app.js']).join(path.sep)
b = browserify({
entries: ['./' + file]
debug: true
extensions: ['.js', '.coffee', '.cjsx']
paths: [path.join(path.sep)]
cache: {}
packageCache: {}
fullPaths: true
}).transform(coffeeReactify)
bundle = b.bundle
b.bundle = ->
console.log "Browserifying #{file}..."
bundle
.call(b)
.pipe(source(path.basename(target)))
.pipe(gulp.dest(path.dirname(target)))
b
gulp.task 'watch', ->
gulp.watch './**/sass/app.scss', ['styles']
glob '**/coffee/app.coffee', (err, files) ->
files.forEach (file) ->
b = watchify(makeBrowserify(file))
b.on 'update', b.bundle
b.bundle()
gulp.task 'styles', ->
glob '**/sass/app.scss', (err, files) ->
files.forEach (file) ->
[sourcePath..., _, _] = file.split(path.sep)
appPath = sourcePath.join(path.sep)
child = spawn 'bundle', [
'exec', 'compass', 'compile',
appPath, file, '--css-dir', 'css'
]
child.stdout.pipe(process.stdout)
child.stderr.pipe(process.stderr)
webpack = require('webpack')
gulp.task 'scripts', ->
glob '**/coffee/app.coffee', (err, files) ->
glob './themes/**/coffee/app.coffee', (err, files) ->
files.forEach (file) ->
makeBrowserify(file).bundle()
parts = file.split(path.sep)
context = path.resolve(parts.slice(0, -1).join(path.sep))
entry = ['.'].concat(parts.slice(-1)).join(path.sep)
outputPath = path.resolve(parts.slice(0, -2).concat(['js']).join(path.sep))
console.log context
console.log entry
console.log outputPath
compiler = webpack(
entry: entry
context: context
output:
path: outputPath
filename: 'app.js'
)
gulp.task 'default', ['watch']

View File

@ -3,7 +3,9 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"engines": { "node": ">=0.12" },
"engines": {
"node": ">=0.12"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
@ -11,11 +13,14 @@
"license": "ISC",
"dependencies": {
"browserify": "^9.0.8",
"cjsx-loader": "^2.0.1",
"coffee-reactify": "^3.0.0",
"coffee-script": "^1.9.2",
"glob": "^5.0.5",
"gulp": "^3.8.11",
"node-libs-browser": "^0.5.2",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.2.0"
"watchify": "^3.2.0",
"webpack": "^1.9.10"
}
}