Skip to content

Commit

Permalink
support coffeescript v1 on older node versions
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Mar 7, 2018
1 parent 5cf1df1 commit f16296e
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 6 deletions.
3 changes: 1 addition & 2 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# History

## v2.7.0 2018 March 7
- Now uses CoffeeScript v2 for compilation
- Now uses CoffeeScript v2 for compilation for node versions which support it (at time of testing that is node v6 and above), otherwise uses CoffeeScript v1
- Now compiled with CoffeeScript v2
- Updated base files
- Minimum node version is now Node v6, as that is the earliest node version that CoffeeScript v2 supports

## v2.6.0 2017 April 17
- Updated dependencies
Expand Down
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"url": "https://github.com/docpad/docpad-plugin-coffeescript.git"
},
"engines": {
"node": ">=6"
"node": ">=0.8"
},
"editions": [
{
Expand Down Expand Up @@ -91,6 +91,7 @@
],
"main": "index.js",
"dependencies": {
"coffee-script": "^1.12.7",
"coffeescript": "^2.2.2",
"editions": "^1.3.4"
},
Expand Down
8 changes: 6 additions & 2 deletions source/coffeescript.plugin.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Import
coffee = require('coffeescript')

# Export Plugin
module.exports = (BasePlugin) ->
Expand All @@ -19,6 +17,12 @@ module.exports = (BasePlugin) ->
{inExtension,outExtension,file} = opts
literate = false

# Import
try
coffee = require('coffeescript')
catch
coffee = require('coffee-script')

# CoffeeScript to JavaScript
if (inExtension in ['coffee','litcoffee'] and outExtension in ['js',null]) or (inExtension in ['md','markdown'] and outExtension is 'js' and literate = true)
# Prepare
Expand Down
8 changes: 8 additions & 0 deletions source/coffeescript.test.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Determine CoffeeScript version
try
require('coffeescript')
coffeescriptVersion = 2
catch
coffeescriptVersion = 1

# Test our plugin using DocPad's Testers
require('docpad').require('testers').test({
pluginPath: __dirname+'/..'
testerClass: 'RendererTester'
outExpectedPath: __dirname+"/../test/out-expected-v#{coffeescriptVersion}"
})
File renamed without changes.
6 changes: 6 additions & 0 deletions test/out-expected-v1/litcoffee-to-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(function() {
var a;

a = require('./helpers');

}).call(this);
6 changes: 6 additions & 0 deletions test/out-expected-v1/md-to-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(function() {
var a;

a = require('./helpers');

}).call(this);
10 changes: 10 additions & 0 deletions test/out-expected-v2/coffee-to-js.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
(function() {
var greet;

greet = function(arg) {
if (arg === 'Hello') {
return console.log('Goodbye');
}
};

}).call(this);
File renamed without changes.
File renamed without changes.

0 comments on commit f16296e

Please sign in to comment.