Skip to content

Commit

Permalink
Merge branch 'master' into ccprog-patch-compile
Browse files Browse the repository at this point in the history
  • Loading branch information
ccprog committed Oct 22, 2018
2 parents ecdbf69 + 33518de commit 4ec315a
Show file tree
Hide file tree
Showing 12 changed files with 4,678 additions and 391 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM node:6-alpine
ENTRYPOINT [ "harp" ]
WORKDIR /app
COPY . /opt/harp
RUN npm install -g /opt/harp
4 changes: 2 additions & 2 deletions bin/harp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ program
var port = program.port || 9000
harp.multihost(projectPath, { port: port }, function(){
if(port == "80"){
var loc = "http://harp.nu"
var loc = "http://lvh.me"
}else{
var loc = "http://harp.nu:" + port
var loc = "http://lvh.me:" + port
}
output("Your server is hosting multiple projects at " + loc)
})
Expand Down
84 changes: 82 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ var mime = require('mime')
var helpers = require('./helpers')
var middleware = require('./middleware')
var pkg = require('../package.json')
var browserify = require('browserify')
var watchify = require('watchify')
var url = require("url")




/**
Expand All @@ -17,17 +22,69 @@ var pkg = require('../package.json')
*/

exports.server = function(dirPath, options, callback){
var cjs = {}
var app = connect()
app.use(middleware.regProjectFinder(dirPath))
app.use(middleware.setup)
app.use(middleware.basicAuth)
app.use(middleware.underscore)

app.use(function(req, rsp, next){
var pathname = url.parse(req.url).pathname.replace(/^\/|\/$/g, '')
if (cjs.hasOwnProperty(pathname)){
rsp.statusCode = 200
rsp.end(cjs[pathname])
} else {
return next()
}
})

app.use(middleware.mwl)
app.use(middleware.static)
app.use(middleware.poly)
app.use(middleware.process)
app.use(middleware.fallback)

try {
var setup = helpers.setup(dirPath)
} catch(e) {
var setup = { publicPath: dirPath }
}


var b = browserify({
entries: [setup.publicPath + "/bundle.cjs"],
cache: {},
packageCache: {},
plugin: [watchify]
})

var update = function(info){
//b.bundle().pipe(fs.createWriteStream(dirPath + "/bundle.js"))
var chunks = []
var stream = b.bundle()

stream.on("data", function(chunk){
chunks.push(chunk)
})

stream.on("end", function(){
cjs["bundle.js"] = Buffer.concat(chunks)
})

}

b.on('update', update)

update()

// function bundle() {
// console.log(dirPath + "/bundle.cjs")
// b.bundle()
// //_stdout.write(util.format.apply(this, arguments) + '\n')
// //b.bundle().pipe(fs.createWriteStream('output.js'));
// }

return app.listen(options.port || 9966, options.ip, function(){
app.projectPath = dirPath
callback.apply(app, arguments)
Expand Down Expand Up @@ -214,7 +271,30 @@ exports.compile = function(projectPath, outputPath, callback){
fs.writeFile(dest, body, done)
})
}else{
done()
if (file === "bundle.cjs"){

var b = browserify({
entries: [path.resolve(setup.publicPath, "bundle.cjs")],
cache: {},
packageCache: {},
plugin: []
})

var dest = path.resolve(outputPath, "bundle.js")
var chunks = []
var stream = b.bundle()

stream.on("data", function(chunk){
chunks.push(chunk)
})

stream.on("end", function(){
fs.writeFile(dest, Buffer.concat(chunks), done)
})

} else {
done()
}
}
}
})
Expand All @@ -229,7 +309,7 @@ exports.compile = function(projectPath, outputPath, callback){
*/
var copyFile = function(file, done){
var ext = path.extname(file)
if(!terraform.helpers.shouldIgnore(file) && [".jade", ".ejs", ".md", ".styl", ".less", ".scss", ".sass", ".coffee"].indexOf(ext) === -1){
if(!terraform.helpers.shouldIgnore(file) && [".jade", ".ejs", ".md", ".styl", ".less", ".scss", ".sass", ".coffee", ".cjs"].indexOf(ext) === -1){
var localPath = path.resolve(outputPath, file)
fs.mkdirp(path.dirname(localPath), function(err){
fs.copy(path.resolve(setup.publicPath, file), localPath, done)
Expand Down
4 changes: 2 additions & 2 deletions lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ exports.notMultihostURL = function(req, rsp, next){

if(hostname == "127.0.0.1" || hostname == "localhost"){
rsp.statusCode = 307
rsp.setHeader('Location', 'http://harp.nu' + port)
rsp.end("redirecting you to http://harp.nu" + port)
rsp.setHeader('Location', 'http://lvh.me' + port)
rsp.end("redirecting you to http://lvh.me" + port)
}else if(arr.length == 4){
arr.pop()
arr.push('io')
Expand Down
Loading

0 comments on commit 4ec315a

Please sign in to comment.