This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Gruntfile.js
60 lines (49 loc) · 1.53 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
module.exports = function(grunt) {
grunt.initConfig({
mochaTest: {
test: {
src: 'test/**/*.js'
}
}
});
var aliases = [
'fn',
'fun',
'func',
'lam'
];
grunt.registerTask('build', function() {
var macro = grunt.file.read('./src/macro.js');
var regex = /MACRO_NAME/gm;
grunt.file.write('./macros/index.js', macro.replace(regex, 'λ'));
aliases.forEach(function(name) {
grunt.file.write('./macros/' + name + '/index.js', macro.replace(regex, name));
});
});
grunt.registerTask('alias', function(name, file) {
var macro = grunt.file.read('./src/macro.js');
var regex = /MACRO_NAME/gm;
grunt.file.write(file, macro.replace(regex, name));
});
grunt.registerTask('build-test', function() {
grunt.file.write('./test/tests.js', compileFile('./test/tests.sjs', true));
});
grunt.registerTask('compile', function(fileName) {
console.log(compileFile(fileName));
});
var moduleCtx;
function compileFile(fileName, isTest) {
var macro = grunt.file.read('./macros/index.js');
var test = isTest ? grunt.file.read('./test/macros.sjs') : '';
var file = grunt.file.read(fileName);
var sweet = require('sweet.js');
if (!moduleCtx) moduleCtx = sweet.loadModule(macro);
return sweet.compile(test + file, {
modules: [moduleCtx],
readableNames: true,
}).code;
}
grunt.registerTask('default', ['build']);
grunt.registerTask('test', ['build', 'build-test', 'mochaTest']);
grunt.loadNpmTasks('grunt-mocha-test');
};