diff --git a/Makefile b/Makefile index a2fa2fe9..6f7c5411 100644 --- a/Makefile +++ b/Makefile @@ -10,49 +10,50 @@ ROOT = $(shell pwd) COFFEE = bin/coffee --js --bare PEGJS = node_modules/.bin/pegjs --track-line-and-column --cache MOCHA = node_modules/.bin/mocha --compilers coffee:. -u tdd -MINIFIER = node_modules/.bin/uglifyjs --no-copyright --mangle-toplevel --reserved-names require,module,exports,global,window +BROWSERIFY = node_modules/.bin/browserify +MINIFIER = node_modules/.bin/uglifyjs --no-copyright --mangle-toplevel --reserved-names require,module,exports,global,window,CoffeeScript all: $(LIB) build: all parser: lib/coffee-script/parser.js +browserify: CoffeeScriptRedux.js minify: $(LIBMIN) -# TODO: build-browser # TODO: test-browser # TODO: doc # TODO: bench + lib: mkdir lib/ - lib/coffee-script: lib mkdir -p lib/coffee-script/ - lib/coffee-script/bootstrap: lib/coffee-script mkdir -p lib/coffee-script/bootstrap + lib/coffee-script/parser.js: src/grammar.pegjs bootstraps lib/coffee-script printf %s "module.exports = " >"$(@:%=%.tmp)" - $(PEGJS) <"$<" >>"$(@:%=%.tmp)" - mv "$(@:%=%.tmp)" "$@" + $(PEGJS) <"$<" >>"$(@:%=%.tmp)" && mv "$(@:%=%.tmp)" "$@" lib/coffee-script/bootstrap/parser.js: src/grammar.pegjs lib/coffee-script/bootstrap printf %s "module.exports = " >"$@" $(PEGJS) <"$<" >>"$@" - -lib/coffee-script/%.min.js: lib/coffee-script/%.js lib/coffee-script - $(MINIFIER) <"$<" >"$@" - lib/coffee-script/bootstrap/%.js: src/%.coffee lib/coffee-script/bootstrap $(COFFEE) <"$<" >"$@" - bootstraps: $(BOOTSTRAPS) lib/coffee-script/bootstrap mv lib/coffee-script/bootstrap/* lib/coffee-script rmdir lib/coffee-script/bootstrap - - lib/coffee-script/%.js: src/%.coffee lib/coffee-script/bootstrap/%.js bootstraps lib/coffee-script $(COFFEE) <"$<" >"$(@:%=%.tmp)" && mv "$(@:%=%.tmp)" "$@" +CoffeeScriptRedux.js: $(LIB) + $(BROWSERIFY) lib/coffee-script/module.js | $(MINIFIER) > CoffeeScriptRedux.js + + +lib/coffee-script/%.min.js: lib/coffee-script/%.js lib/coffee-script + $(MINIFIER) <"$<" >"$@" + + .PHONY: test coverage install loc clean test: $(LIB) $(TESTS) diff --git a/lib/coffee-script/command.js b/lib/coffee-script/command.js index 8619c5c7..268347b2 100644 --- a/lib/coffee-script/command.js +++ b/lib/coffee-script/command.js @@ -355,7 +355,7 @@ if (options.help) { } console.log('\n\n Unless instructed otherwise (--{input,watch,cli}), `' + $0 + '` will operate on stdin/stdout.\n When none of -{-parse,p,-compile,c,-js,j,-eval,e,-cscodegen,-repl} are given\n If positional arguments were given\n * --eval is implied\n * the first positional argument is used as an input filename\n * additional positional arguments are passed as arguments to the script\n Else --repl is implied\n '); } else if (options.version) { - pkg = require(path.join(__dirname, '..', '..', 'package.json')); + pkg = require('./../../package.json'); console.log('CoffeeScript version ' + pkg.version); } else if (options.repl) { console.error('TODO: REPL'); diff --git a/lib/coffee-script/compiler.js b/lib/coffee-script/compiler.js index 8326cb1c..c93fa528 100644 --- a/lib/coffee-script/compiler.js +++ b/lib/coffee-script/compiler.js @@ -654,7 +654,7 @@ exports.Compiler = function () { } else { block = [stmt(new JS.UnaryExpression('void', new JS.CallExpression(memberAccess(new JS.FunctionExpression(null, [], new JS.BlockStatement(block)), 'call'), [new JS.ThisExpression])))]; } - pkg = require(require('path').join(__dirname, '..', '..', 'package.json')); + pkg = require('./../../package.json'); program = new JS.Program(block); program.leadingComments = [{ type: 'Line', diff --git a/lib/coffee-script/module.js b/lib/coffee-script/module.js index 4f082d8a..97ece2d5 100644 --- a/lib/coffee-script/module.js +++ b/lib/coffee-script/module.js @@ -30,7 +30,7 @@ uglifyjs = function () { } }.call(this); CoffeeScript = null; -pkg = require(path.join(__dirname, '..', '..', 'package.json')); +pkg = require('./../../package.json'); escodegenFormatDefaults = { indent: { style: ' ', diff --git a/src/command.coffee b/src/command.coffee index e6fdc932..5a2fb7b4 100644 --- a/src/command.coffee +++ b/src/command.coffee @@ -213,7 +213,7 @@ if options.help """ else if options.version - pkg = require path.join __dirname, '..', '..', 'package.json' + pkg = require './../../package.json' console.log "CoffeeScript version #{pkg.version}" else if options.repl diff --git a/src/compiler.coffee b/src/compiler.coffee index bc104748..3865eda0 100644 --- a/src/compiler.coffee +++ b/src/compiler.coffee @@ -392,7 +392,7 @@ class exports.Compiler # add a function wrapper block = [stmt new JS.UnaryExpression 'void', new JS.CallExpression (memberAccess (new JS.FunctionExpression null, [], new JS.BlockStatement block), 'call'), [new JS.ThisExpression]] # generate node - pkg = require (require 'path').join __dirname, '..', '..', 'package.json' + pkg = require './../../package.json' program = new JS.Program block program.leadingComments = [ type: 'Line' diff --git a/src/module.coffee b/src/module.coffee index ff617077..361adb70 100644 --- a/src/module.coffee +++ b/src/module.coffee @@ -13,7 +13,7 @@ uglifyjs = try require 'uglify-js' CoffeeScript = null -pkg = require path.join __dirname, '..', '..', 'package.json' +pkg = require './../../package.json' escodegenFormatDefaults = indent: