This repository has been archived by the owner on May 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Gruntfile.js
90 lines (79 loc) · 2.65 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var fs = require('fs');
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jison: {
'./grammar/parser.js': './grammar/parser.jison'
},
jshint: {
options: {
eqeqeq: true,
globals: {
require: false,
module: true,
console: false
}
},
all: ['Gruntfile.js', 'lib/**/*.js', 'test/**.*.js']
},
browserify2: {
main: {
entry: './index.js',
compile: 'build/<%= pkg.name %>.js',
debug: true
// afterHook: uglifier()
}
},
watch: {
scripts: {
files: ['lib/**/*.js'],
tasks: ['browserify2', 'uglify']
},
gramnar: {
files: ['grammar/*.jison'],
tasks: ['jison', 'browserify2', 'uglify']
}
},
uglify: {
options: {
banner: '/**\n* <%= pkg.name %> v<%= pkg.version %>\n* https://github.com/aantthony/javascript-cas\n* \n* Copyright 2010 Anthony Foster.\n* <%= grunt.template.today("yyyy-mm-dd") %>\n*/\n'
},
build: {
src: 'build/<%= pkg.name %>.js',
dest: 'build/<%= pkg.name %>.min.js'
}
}
});
grunt.registerMultiTask('jison', 'Parser Generator', function () {
var done = this.async();
var target = this.target;
var grammar = fs.readFile(this.data, function (err, data) {
if (err) throw err;
var grammar = data.toString();
var _ = console.log;
console.log = function () {
// SHUT THE FUCK UP JISON!!!
};
var parser;
try {
var Parser = require('jison').Parser;
parser = new Parser(grammar, {debug: true});
} finally {
console.log = _;
}
if (parser) {
fs.writeFile(target, parser.generate(), function (err) {
if (err) throw err;
done(true);
});
}
});
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-browserify2');
grunt.loadNpmTasks('grunt-contrib-jshint');
// Default task(s).
grunt.registerTask('default', ['jison', 'browserify2', 'uglify']);
grunt.registerTask('live', ['default', 'watch']);
};