Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v1.0.0 #122

Merged
merged 28 commits into from
Jan 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b426d88
Adds support for Browserify
vbwx Jun 22, 2015
41c2961
Fixes file path
kennethormandy Jun 26, 2015
5773ce7
Merge branch 'master' of https://github.com/sintaxi/terraform into ko…
kennethormandy Sep 10, 2015
bcd9bd2
Updates Browserify and Through
kennethormandy Sep 10, 2015
a6b9787
Merge branch 'master' of https://github.com/sintaxi/terraform into ko…
kennethormandy Sep 27, 2015
3ce0970
Restores and updates Through
kennethormandy Sep 27, 2015
b7072dd
bump jade version... cross fingers
lunelson Oct 22, 2015
92071fc
Merge branch 'master' into ko-browserify-personal
kennethormandy Oct 25, 2015
5474861
Adds minifying to Browserify step
kennethormandy Oct 25, 2015
db3c8b1
Updates Node-sass
kennethormandy Oct 29, 2015
afd3949
Add a failing test for using a `_data.js` file.
johnboxall Nov 7, 2015
423822e
Use `require` to resolve data files rather than `fs.readFileSync`.
johnboxall Nov 7, 2015
08cc2c3
Test that actually tests the change.
johnboxall Nov 7, 2015
fd59926
Don't load `_data` from cache.
johnboxall Nov 8, 2015
6fe0e6a
Merge branch 'master' of https://github.com/sintaxi/terraform into ko…
kennethormandy Dec 6, 2015
f5f2024
Updates Browserify
kennethormandy Dec 6, 2015
adceba0
Merge branch 'johnboxall-dynamic-data' into ko-browserify-and-data
kennethormandy Dec 15, 2015
dd47162
Merge branch 'ko-browserify-and-data' of https://github.com/kennethor…
kennethormandy Jan 6, 2016
373e537
Fixes package.json formatting for use with the CLI
kennethormandy Jan 6, 2016
b2340c4
Updates Jade to v.1.11.0, breaking change
kennethormandy Jan 6, 2016
909e280
Updates dependencies
kennethormandy Jan 6, 2016
38e9561
Merge branch 'update-jade' of https://github.com/lunelson/terraform i…
kennethormandy Jan 6, 2016
d36e86b
Updates contributor list
kennethormandy Jan 6, 2016
c602ae8
Updates Mocha
kennethormandy Jan 6, 2016
22cfb6e
Updates Browserify step to preprocess .js instead of .es
kennethormandy Jun 23, 2015
77ad9a5
Removes old comment
kennethormandy Jun 23, 2015
3c197b6
Adds additional test for Browserify-ing .js files
kennethormandy Jun 24, 2015
dd4279d
Removes debug Browserify extension logging
kennethormandy Jan 6, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/helpers/memoized.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ exports.walkData = helpers.walkData
exports.isTemplate = helpers.isTemplate
exports.isStylesheet = helpers.isStylesheet
exports.isJavaScript = helpers.isJavaScript

exports.needsBrowserify = helpers.needsBrowserify
27 changes: 19 additions & 8 deletions lib/helpers/raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var TerraformError = exports.TerraformError = require("../error").TerraformError
var processors = exports.processors = {
"html": ["jade", "ejs", "md"],
"css" : ["styl", "less", "scss", "sass"],
"js" : ["coffee"]
"js" : ["js", "coffee"]
}


Expand Down Expand Up @@ -219,18 +219,18 @@ var dataTree = exports.dataTree = function (filename) {
obj._contents = []

try{
var dataPath = path.resolve(dirPath, "_data.json")
var fileData = fs.readFileSync(dataPath)
obj._data = JSON.parse(fileData)
var dataPath = path.resolve(dirPath, "_data")
obj._data = require(dataPath)
delete require.cache[require.resolve(dataPath)]
}catch(e){
if(e.code && e.code === "ENOENT"){
if(e.code && e.code === "MODULE_NOT_FOUND"){
// data file failed or does not exist
}else{
e.source = "Data"
e.dest = "Globals"
e.lineno = -1
e.filename = dataPath
e.stack = fileData.toString()
e.filename = require.resolve(dataPath)
e.stack = fs.readFileSync(e.filename)
throw new TerraformError(e)
}
//console.log(e.code)
Expand Down Expand Up @@ -362,7 +362,7 @@ var outputPath = exports.outputPath = function(source, allowAlternateExtensions)
for(var targetExtension in processors){ // .html, .css, .js
if (processors.hasOwnProperty(targetExtension)) {
processors[targetExtension].forEach(function(sourceExtension){ // .jade, .ejs, .md
if (allowAlternateExtensions) {
if (allowAlternateExtensions && targetExtension !== sourceExtension) { // Don’t bother if it’s .js to .js
// Search for a alternate extension before the known source extension e.g. foobar.bar.jade
var alternateFileExtension = new RegExp("^.*\\.(\\w{3,4})\\." + sourceExtension + "$")
var match = alternateFileExtension.exec(source)
Expand Down Expand Up @@ -496,3 +496,14 @@ exports.isJavaScript = function(filePath){

return processors["js"].indexOf(ext) !== -1
}

/**
* needsBrowserify
*
* returns true if the code uses require, exports or module but doesn't declare them
*/

exports.needsBrowserify = function(source) {
return /^[^#\/'"*]*(require|module|exports)\b/m.test(source)
&& !(/\b(function|var|global) +(require|module|exports)\b|\b(module|require) *=[^=]/.test(source))
}
79 changes: 63 additions & 16 deletions lib/javascript/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var path = require("path")
var fs = require("fs")
var helpers = require('../helpers')
var path = require("path")
var fs = require("fs")
var helpers = require('../helpers')
var minify = require('harp-minify')
var browserify = require('browserify')
var through = require('through')

/**
* Build Processor list for javascripts.
Expand All @@ -13,15 +15,20 @@ var minify = require('harp-minify')
* }
*
*/
var processors = {}
var extensions = [], processors = {}
helpers.processors["js"].forEach(function(sourceType){
extensions.push('.' + sourceType)
processors[sourceType] = require("./processors/" + sourceType)
})

module.exports = function(root, filePath, callback){

var srcPath = path.resolve(root, filePath)
var ext = path.extname(srcPath).replace(/^\./, '')
var minifyOpts = {
compress: false,
mangle: false
}

fs.readFile(srcPath, function(err, data){

Expand All @@ -41,18 +48,58 @@ module.exports = function(root, filePath, callback){
* Lookup Directories
*/

var render = processors[ext].compile(srcPath, data, function(err, js) {
if (err) return callback(err);

/**
* Consistently minify
*/
var post = minify.js(js, {
compress: false,
mangle: true
});
callback(null, post);
})
var render = function(ext, data, cb) {
processors[ext].compile(srcPath, data, function(err, js) {
if (err) return cb(err)

/**
* Consistently minify
*/
cb(null, minify.js(js, minifyOpts))
})
}

if(helpers.needsBrowserify(data.toString())) {
var post = '', success = true

var exceptionHandler = function(err) {
success = false
console.log(err.message)
render(ext, data, callback)
}

process.once('uncaughtException', exceptionHandler)
browserify(srcPath, {extensions: extensions}).transform(function(file) {
var result = ''
return through(write, end)

function write(buf) {
result += buf
}
function end() {
if(success) {
var that = this
render(path.extname(file).replace(/^\./, '').toLowerCase(), result, function(err, data) {
that.queue(data)
that.queue(null)
})
}
}
}).on('error', exceptionHandler).bundle()
.on('data', function(buf) {
if (success) {
post += buf
}
}).on('end', function() {
if (success) {
process.removeListener('uncaughtException', exceptionHandler)
callback(null, minify.js(post, minifyOpts))
}
})
}
else {
render(ext, data, callback)
}

})

Expand Down
3 changes: 3 additions & 0 deletions lib/javascript/processors/js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.compile = function(filePath, fileContents, callback){
callback(null, fileContents.toString())
}
2 changes: 1 addition & 1 deletion lib/template/processors/jade.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var jade = require('harp-jade')
var jade = require('jade')
var TerraformError = require("../../error").TerraformError

module.exports = function(fileContents, options){
Expand Down
57 changes: 35 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,50 @@
},
"author": "Brock Whitten <[email protected]>",
"contributors": [
{ "name": "Brock Whitten", "email": "[email protected]" },
{ "name": "Brian Donovan", "email": "[email protected]" },
{ "name": "Kenneth Ormandy", "email": "[email protected]" },
{ "name": "Zhang Yichao", "email": "[email protected]" },
{ "name": "Carlos Rodriguez" },
{ "name": "Zeke Sikelianos", "email": "[email protected]" },
{ "name": "Guilherme Rodrigues", "email": "[email protected]" },
{ "name": "Radu Brehar", "email": "[email protected]" },
{ "name": "Glen Maddern", "email": "[email protected]" },
{ "name": "Jed Foster", "email": "[email protected]" },
{ "name": "Sehrope Sarkuni", "email": "[email protected]" },
{ "name": "Keiichiro Matsumoto", "email": "[email protected]" },
{ "name": "Najam Khn", "email": "[email protected]" }
"Brock Whitten <[email protected]>",
"Brian Donovan <[email protected]>",
"Kenneth Ormandy <[email protected]>",
"Zhang Yichao <[email protected]>",
"Carlos Rodriguez",
"Zeke Sikelianos <[email protected]>",
"Guilherme Rodrigues <[email protected]>",
"Radu Brehar <[email protected]>",
"Glen Maddern <[email protected]>",
"Jed Foster <[email protected]>",
"Sehrope Sarkuni <[email protected]>",
"Keiichiro Matsumoto <[email protected]>",
"Najam Khn <[email protected]>",
"Eric Drechsel",
"Najam Khan",
"Zhang Yichao <[email protected]>",
"Dave Jensen",
"Ryan Lewis",
"Julian Duque <[email protected]>",
"Lu Nelson <[email protected]>",
"Stephen Way",
"Pierre Spring <[email protected]>",
"John Boxall <[email protected]>",
"TJ Nicolaides <[email protected]>"
],
"license": "MIT",
"dependencies": {
"lru-cache": "2.7.0",
"harp-jade": "1.9.3-bc.4",
"autoprefixer": "6.2.3",
"browserify": "12.0.1",
"coffee-script": "1.10.0",
"node-sass": "3.4.2",
"ejs": "2.3.4",
"marked": "0.3.5",
"lodash": "3.10.1",
"harp-minify": "0.4.0",
"jade": "1.11.0",
"less": "2.5.3",
"lodash": "3.10.1",
"lru-cache": "4.0.0",
"marked": "0.3.5",
"node-sass": "3.4.2",
"postcss": "5.0.14",
"stylus": "0.53.0",
"harp-minify": "0.3.3",
"autoprefixer": "6.1.0",
"postcss": "5.0.12"
"through": "2.3.8"
},
"devDependencies": {
"mocha": "1.8.2",
"mocha": "2.3.4",
"should": "1.2.2"
}
}
12 changes: 12 additions & 0 deletions test/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,16 @@ describe("data", function(){
})
})

describe("dynamic", function(){
it("should return public object", function(done){
var root = __dirname + "/fixtures/data/dynamic"
var poly = polymer.root(root)
poly.render("pub.json.jade", { "layout": false }, function(err, result){
var pub = JSON.parse(result)
should.exist(pub["articles"]["_data"]["hello-world"])
should.not.exist(pub[".foo"])
done()
})
})
})
})
1 change: 1 addition & 0 deletions test/fixtures/data/dynamic/.foo/placeholder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is here to test ignoring directories that begin with a dot (".")
3 changes: 3 additions & 0 deletions test/fixtures/data/dynamic/_layout.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
h1 My Articles
h5.feature= public.articles._data['hello-world'].title
!= yield
6 changes: 6 additions & 0 deletions test/fixtures/data/dynamic/articles/_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
"hello-world": {
"title" : "Earth people, New York to California",
"author": "Brock Whitten"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/data/dynamic/articles/hello-world.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
h3= title
h4= author

p Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
6 changes: 6 additions & 0 deletions test/fixtures/data/dynamic/index.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
h2 Home

h3 Articles

for article, slug in public.articles._data
!= partial('articles/' + slug + '.jade', { author: "Kool Keith" })
1 change: 1 addition & 0 deletions test/fixtures/data/dynamic/pub.json.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!= JSON.stringify(public)
4 changes: 4 additions & 0 deletions test/fixtures/javascripts/browserify/Math.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Let's see if we can mix .coffee & .es

exports.pow = (num) ->
num * num
5 changes: 5 additions & 0 deletions test/fixtures/javascripts/browserify/Math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Let's see if we can mix .es & .js

exports.pow = function(num) {
return num * num;
};
3 changes: 3 additions & 0 deletions test/fixtures/javascripts/browserify/comment.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# pow = require('./Math').pow;

console.log(pow(4));
5 changes: 5 additions & 0 deletions test/fixtures/javascripts/browserify/comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*
* pow = require('./Math').pow;
*/

console.log(pow(4));
6 changes: 6 additions & 0 deletions test/fixtures/javascripts/browserify/declared.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require = (file) ->
# custom implementation

pow = require('./Math').pow

console.log pow(4)
7 changes: 7 additions & 0 deletions test/fixtures/javascripts/browserify/declared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var require = function(file) {
// custom implementation
};

var pow = require('./Math').pow;

console.log(pow(4));
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pow = require('./../../../../Math.js').pow

console.log pow(4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var pow = require('./../../../../Math.js').pow;

console.log(pow(4));
3 changes: 3 additions & 0 deletions test/fixtures/javascripts/browserify/require_coffee.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pow = require('./Math.coffee').pow

console.log pow(4)
3 changes: 3 additions & 0 deletions test/fixtures/javascripts/browserify/require_coffee.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var pow = require('./Math.coffee').pow;

console.log(pow(4));
3 changes: 3 additions & 0 deletions test/fixtures/javascripts/browserify/require_js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pow = require('./Math.js').pow

console.log pow(4)
3 changes: 3 additions & 0 deletions test/fixtures/javascripts/browserify/require_js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var pow = require('./Math.js').pow;

console.log(pow(4));
22 changes: 22 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ describe("helpers", function(){
done()
})

it('should return all possible file names for js ordered by priority.', function(done){
var list = polymer.helpers.buildPriorityList('/js/bundle.js')
list.should.be.an.instanceOf(Array)
list.should.have.lengthOf(4)
var plist = "js/bundle.js, js/bundle.coffee, js/bundle.js.js, js/bundle.js.coffee".split(', ')
list.should.eql(plist)
done()
})


it('should build priority list assuming template file when unknown.', function(done){
var list = polymer.helpers.buildPriorityList('feed.xml')
list.should.be.an.instanceOf(Array)
Expand Down Expand Up @@ -257,6 +267,18 @@ describe("helpers", function(){
done()
})

it('should return true if javascript file.', function(done){
polymer.helpers.isJavaScript(path.join('foo.js')).should.be.true
polymer.helpers.isJavaScript(path.join('foo', 'bar', 'baz.js')).should.be.true
done()
})

it('should return true if minified javascript file.', function(done){
polymer.helpers.isJavaScript(path.join('foo.min.js')).should.be.true
polymer.helpers.isJavaScript(path.join('foo', 'bar', 'bas.min.js')).should.be.true
done()
})

it('should return false if less file.', function(done){
polymer.helpers.isStylesheet(path.join('foo.less')).should.be.true
polymer.helpers.isStylesheet(path.join('foo', 'bar', 'baz.less')).should.be.true
Expand Down
Loading