This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
139 lines (125 loc) · 3.61 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
'use strict';
const path = require('path');
const childProcess = require('child_process');
// wrapper function for grunt configuration
module.exports = function(grunt) {
grunt.initConfig({
// read in the package information
pkg: grunt.file.readJSON('package.json'),
// grunt-antlr4 plugin configuration (generate parser)
antlr4: {
generate: {
grammar: 'src/grammar/Document.g4',
options: {
grammarLevel: {
language: 'JavaScript'
},
flags: [
'Werror',
'Xlog',
'listener',
'visitor'
]
}
}
},
// grunt-eslint plugin configuration (lint for JS)
eslint: {
options: {
},
target: [
'Gruntfile.js',
'src/**/*.js',
'test/**/*.js'
]
},
// grunt-contrib-clean plugin configuration (clean up files)
clean: {
generate: [
'*.log',
'src/grammar/DocumentLexer.js',
'src/grammar/DocumentParser.js',
'src/grammar/DocumentListener.js',
'src/grammar/DocumentVisitor.js',
'src/grammar/*.interp',
'src/grammar/*.tokens'
],
build: [
'dist/*'
],
options: {
force: true
}
},
// grunt-mocha-test plugin configuration (unit testing)
mochaTest: {
test: {
options: {
reporter: 'spec',
timeout: 20000
},
src: [
'test/**/*.js'
]
}
},
// grunt-webpack plugin configuration (concatenates and removes whitespace)
webpack: {
clientConfig: {
target: 'web',
mode: 'development',
resolve: {
fallback: {
"os": false,
"fs": false,
"path": false,
"url": false,
"crypto": false
}
},
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'lib-web.js',
library: 'vm'
}
},
serverConfig: {
target: 'node',
mode: 'development',
entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'lib-node.js',
library: 'vm'
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-webpack');
grunt.registerTask('generate', 'Generate the parser code.', ['clean:generate', 'antlr4']);
grunt.registerTask('build', 'Build the module.', ['clean:build', 'eslint', 'mochaTest']);
grunt.registerTask('package', 'Package the libraries.', ['clean:build', 'eslint', 'webpack']);
grunt.registerTask('default', 'Default targets.', ['generate', 'build']);
grunt.registerMultiTask('antlr4', 'Task for antlr4 parser/lexer generation in JS', function () {
var commandLine = ['-jar', 'lib/antlr-4.8-complete.jar'];
var options = this.options();
if (options.flags) options.flags.forEach(function (flag) {
commandLine.push('-' + flag);
});
delete options.flags;
if (options.grammarLevel) Object.keys(options.grammarLevel).forEach(function (optionKey) {
commandLine.push('-D' + optionKey + '=' + options.grammarLevel[optionKey]);
});
delete options.grammarLevel;
Object.keys(options).forEach(function (optionKey) {
commandLine.push('-' + optionKey);
commandLine.push(options[optionKey]);
});
commandLine.push(this.data.grammar);
childProcess.spawnSync('java', commandLine, {stdio: 'inherit'});
});
};