forked from stealjs/steal
/
Gruntfile.js
68 lines (62 loc) · 1.83 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
var fs = require('fs');
var Promise = require('node-promise/promise');
var readFile_promise = Promise.convertNodeAsyncFunction(fs.readFile);
module.exports = function (grunt) {
var codestyle = {
options : {
indentSize : 1,
indentChar : "\t"
}
};
grunt.registerTask("build", function() {
var done = this.async();
fs.readFile(grunt.config('build').file, 'utf8', function (err, core) {
var promises = [];
if (err) {
return console.log('An error occured while reading core/core.js file')
}
var matches = core.match(/\/\*#\s+(.*?)\s+#\*\//g);
matches.forEach(function (file) {
promises.push(readFile_promise("core/" + file.slice(3, -3).trim()));
});
Promise.all(promises).then(function (results) {
var out = grunt.config('build').out;
for (var i = 0; i < results.length; i++) {
core = core.replace(matches[i], results[i]);
console.log("-- Adding core/" + matches[i].slice(3, -3).trim())
}
fs.writeFile(out, core, function (err) {
if (err) {
return console.log('There was an error with writing ' + out)
}
console.log(out + ' was successfully built.')
done();
})
})
});
});
grunt.initConfig({
pkg : '<json:package.json>',
meta : {
banner : '/*! <%= pkg.title || pkg.name %> - <%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\n" : "" %>' +
'* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */'
},
out : 'steal.js',
build : {
file : 'core/core.js',
out : '<%= out %>'
},
uglify: {
steal: {
files: {
'steal.production.js': ['steal.js']
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('default', ['build', 'uglify']);
};