Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Gruntify build and fix lint errors

  • Loading branch information...
commit 367eeacc451cfeb7343a096a2b6f19ed50420f70 1 parent e83ce09
@puffnfresh authored
View
3  .gitignore
@@ -7,7 +7,8 @@ examples/*.js
examples/*.js.map
lib/*.js
roy.brianmckenna.org
-bundled-roy.js
+roy.js
+roy-min.js
.DS_Store
*~
*.swp
View
18 Makefile
@@ -1,31 +1,23 @@
.PHONY: site
all:
- node src/typegrammar.js
- node src/grammar.js
+ ./node_modules/.bin/grunt
deps:
npm install
npm prune
-bundle:
- ./node_modules/interleave/bin/interleave build interleaved-roy.js
-
site: all bundle
[ -e roy.brianmckenna.org ] || mkdir roy.brianmckenna.org
cp -r site/* roy.brianmckenna.org
cp -r examples roy.brianmckenna.org
cp package.json roy.brianmckenna.org
- $(MAKE) optimise-bundle DEST=roy.brianmckenna.org/
+ cp roy-min.js roy.brianmckenna.org/
extension:
- $(MAKE) optimise-bundle DEST=misc/chrome-extension/
-
-optimise-bundle:
- closure --js dist/interleaved-roy.js --js_output_file $(DEST)bundled-roy.js 2>/dev/null || \
- (echo "Closure not available - not minimising" && cp dist/interleaved-roy.js $(DEST)bundled-roy.js)
+ cp roy-min.js misc/chrome-extension/
# Tests
-test: all
- ./node_modules/jasmine-node/bin/jasmine-node --verbose test
+test:
+ ./node_modules/.bin/grunt jasmine
View
93 grunt.js
@@ -0,0 +1,93 @@
+module.exports = function(grunt) {
+ grunt.initConfig({
+ lint: {
+ src: [
+ './src/*.js'
+ ]
+ },
+ jison: {
+ './lib/typeparser.js': './src/typegrammar.js',
+ './lib/parser.js': './src/grammar.js'
+ },
+ rigger: {
+ 'roy.js': 'rigger-roy.js'
+ },
+ jasmine: {
+ src: './test'
+ },
+ min: {
+ 'roy-min.js': 'roy.js'
+ },
+ watch: {
+ parsers: {
+ files: './src/*grammar.js',
+ tasks: 'jison'
+ },
+ jasmine: {
+ files: ['./src/*.js', './test/*Spec.js'],
+ tasks: 'jasmine'
+ }
+ }
+ });
+
+ grunt.registerMultiTask('jison', 'Parser generator by jison.', function() {
+ var Parser = require('jison').Parser,
+ grammar = require(this.data).grammar;
+ parser = new Parser(grammar, {debug: true}),
+ fs = require('fs');
+
+ fs.writeFileSync(this.target, parser.generate());
+ });
+
+ grunt.registerMultiTask('rigger', 'File concatentation by rigger.', function() {
+ var rigger = require('rigger'),
+ fs = require('fs'),
+ done = this.async(),
+ target = this.target;
+
+ rigger(this.data, function(err, output) {
+ if(err) return grunt.log.error(err);
+ fs.writeFileSync(target, output);
+ done(true);
+ });
+ });
+
+ // Watching the task doesn't work. Sadly jasmine-node
+ // executeSpecsInFolder is not idempotent
+ grunt.registerMultiTask('jasmine', 'Testing by jasmine.', function() {
+ var path = require('path'),
+ specDir = this.file.src,
+ badCache = grunt.file.expand(specDir).concat([
+ path.dirname(require.resolve("jasmine-node")),
+ ]),
+ jasmine,
+ done = this.async(),
+ key;
+
+ // Would be nice to use grunt.file.clearRequireCache
+ grunt.utils._.each(require.cache, function(v, k) {
+ var isBad = grunt.utils._.any(badCache, function(dir) {
+ return k.indexOf(path.resolve(dir)) === 0;
+ });
+ if(!isBad) return;
+ delete require.cache[k];
+ });
+
+ jasmine = require("jasmine-node");
+
+ // Not nice (necessary for jasmine-node's asyncSpecWait, etc)
+ for(key in jasmine) if(jasmine[key] instanceof Function) global[key] = jasmine[key];
+
+ function onComplete(runner) {
+ if (runner.results().failedCount > 0) {
+ grunt.log.error();
+ return;
+ }
+ done(true);
+ };
+
+ jasmine.executeSpecsInFolder(specDir, onComplete, false, true);
+ });
+
+ grunt.registerTask('default', 'jison lint jasmine rigger min');
+};
View
2  misc/chrome-extension/background.htm
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <script src="bundled-roy.js"></script>
+ <script src="roy-min.js"></script>
<script>
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
var js;
View
3  package.json
@@ -27,7 +27,8 @@
"unicode-categories": "0.9.0"
},
"devDependencies": {
- "interleave": "0.5.11",
+ "grunt": "0.3.15",
+ "rigger": "0.3.19",
"jasmine-node": "1.0.26"
}
}
View
4 interleaved-roy.js → rigger-roy.js
@@ -33,10 +33,10 @@ var roy = {};
//= src/macroexpand.js
};
load["./typeparser"] = function(exports) {
- //= src/typeparser.js
+ //= lib/typeparser.js
};
load["./parser"] = function(exports) {
- //= src/parser.js
+ //= lib/parser.js
};
load["./typeinference"] = function(exports) {
//= src/typeinference.js
View
2  site/index.htm
@@ -65,7 +65,7 @@
}
</style>
<script src="http://www.google-analytics.com/ga.js" async="async"></script>
- <script src="bundled-roy.js"></script>
+ <script src="roy-min.js"></script>
<script src="codemirror2/lib/codemirror.js"></script>
<script src="codemirror2/lib/util/runmode.js"></script>
<script src="codemirror2/mode/roy/roy.js"></script>
View
7 src/compile.js
@@ -5,9 +5,9 @@ var typecheck = require('./typeinference').typecheck,
types = require('./types'),
nodeToType = require('./typeinference').nodeToType,
nodes = require('./nodes').nodes,
- parser = require('./parser').parser,
- typeparser = require('./typeparser').parser,
lexer = require('./lexer'),
+ parser = require('../lib/parser').parser,
+ typeparser = require('../lib/typeparser').parser,
_ = require('underscore');
// Assigning the nodes to `parser.yy` allows the grammar to access the nodes from
@@ -516,7 +516,7 @@ var getFileContents = function(filename) {
}
}
- if(source == null) {
+ if(!source) {
throw new Error("File(s) not found: " + filenames.join(", "));
}
@@ -755,6 +755,7 @@ var main = function() {
return;
case "-p":
includePrelude = false;
+ /* falls through */
case "-r":
vm = require('vm');
run = true;
View
1  src/freeVariables.js
@@ -1,3 +1,4 @@
+/*jshint expr:true*/
var _ = require('underscore');
var nodes = require('./nodes');
View
10 src/grammar.js
@@ -1,6 +1,4 @@
-var sys = require('sys'),
- Parser = require('jison').Parser,
- typegrammar = require('./typegrammar').bnf;
+var typegrammar = require('./typegrammar').bnf;
var n = function(s) {
return s + "$$.lineno = yylineno;";
@@ -253,8 +251,4 @@ var grammar = {
]
}
};
-
-var parser = new Parser(grammar, {debug: true});
-
-var fs = require('fs');
-fs.writeFile('src/parser.js', parser.generate());
+exports.grammar = grammar;
View
1  src/lexer.js
@@ -278,6 +278,7 @@ var literalToken = function() {
};
exports.tokenise = function(source) {
+ /*jshint boss:true*/
indent = 0;
indents = [];
tokens = [];
View
1  src/macroexpand.js
@@ -15,6 +15,7 @@ var macroexpand = function(ast, env, opts) {
macros[n.name] = code;
},
visitCall: function() {
+ /*jshint evil:true*/
if(!macros[n.func.value]) return;
var f = new Function('var nodes = this.nodes; ' + macros[n.func.value]);
View
4 src/modules.js
@@ -1,5 +1,5 @@
var lexer = require('./lexer'),
- typeparser = require('./typeparser').parser,
+ typeparser = require('../lib/typeparser').parser,
nodes = require('./nodes').nodes,
types = require('./types'),
_ = require('underscore');
@@ -10,7 +10,7 @@ var resolveNodeModule = function(moduleName, filename) {
// node.js uses a few prefixes to decide where to load from:
// http://nodejs.org/docs/latest/api/all.html#loading_from_node_modules_Folders
var relative = _.any(['/', './', '../'], function(e) {
- return moduleName.indexOf(e) == 0;
+ return moduleName.indexOf(e) === 0;
});
if(relative) {
View
2  src/prettyprint.js
@@ -3,7 +3,7 @@ var _ = require('underscore');
var prettyPrint = function(n) {
return n.accept({
visitFunction: function() {
- return "\\" + _.map(n.args, prettyPrint).join(" ") + " -> " + _.map(n.body, prettyPrint)
+ return "\\" + _.map(n.args, prettyPrint).join(" ") + " -> " + _.map(n.body, prettyPrint);
},
visitArg: function() {
return n.name;
View
7 src/tarjan.js
@@ -41,15 +41,16 @@ function stronglyConnectedComponents(graph) {
});
if (smallestReachableIndex[vertex.id] === indices[vertex.id]) {
- var currentComponent = [];
+ var currentComponent = [],
+ popped;
do {
- var popped = stack.pop();
+ popped = stack.pop();
isInStack[popped.id] = false;
currentComponent.push(popped);
- } while (vertex.id != popped.id)
+ } while (vertex.id != popped.id);
components.push(currentComponent);
}
View
13 src/typegrammar.js
@@ -1,5 +1,3 @@
-var Parser = require('jison').Parser;
-
var bnf = {
// For type annotations
"type": [
@@ -41,7 +39,7 @@ var bnf = {
],
"dataParamList": [
["IDENTIFIER", "$$ = [new yy.Arg($1)];"],
- ["dataParamList IDENTIFIER", "$$ = $1; $1.push(new yy.Arg($2));"],
+ ["dataParamList IDENTIFIER", "$$ = $1; $1.push(new yy.Arg($2));"]
],
"optDataParamList": [
["", "$$ = [];"],
@@ -62,7 +60,6 @@ var bnf = {
["IDENTIFIER", "$$ = $1;"]
]
};
-
exports.bnf = bnf;
var grammar = {
@@ -96,10 +93,4 @@ var grammar = {
"keywordOrIdentifier": bnf.keywordOrIdentifier
}
};
-
-if(exports && !module.parent) {
- var parser = new Parser(grammar, {debug: true});
-
- var fs = require('fs');
- fs.writeFile('src/typeparser.js', parser.generate());
-}
+exports.grammar = grammar;
View
2  test/TypeInferenceSpec.js
@@ -2,7 +2,7 @@ describe('type inference', function(){
var typeinference = require('../src/typeinference'),
types = require('../src/types');
lexer = require('../src/lexer');
- parser = require('../src/parser');
+ parser = require('../lib/parser');
beforeEach(function() {
this.addMatchers({
Please sign in to comment.
Something went wrong with that request. Please try again.