forked from jsbin/jsbin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
159 lines (147 loc) · 4.23 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
'use strict';
/*global module:false*/
module.exports = function (grunt) {
var fs = require('fs'),
path = require('path'),
exec = require('child_process').exec,
scripts = require('./scripts.json');
// Runs JSBin with local config file.
//
// Config file defaults to config.node.json but can be provided as an
// additional argument. Will also use nodemon if installed otherwise
// falls back to using node.
//
// Example:
//
// $ grunt run:config.local.json
grunt.registerTask('run', 'Runs JSBin for local development', function (config) {
var done = this.async(),
filepath = path.join(__dirname, config || 'config.node.json'),
cmd = '[ -e "`which nodemon`" ] && nodemon --debug . || node --debug .',
child;
// Set the config for the node app.
try {
if (fs.statSync(filepath).isFile() && !process.env.JSBIN_CONFIG) {
process.env.JSBIN_CONFIG = filepath;
}
} catch (error) {
// Ignore if file wasn't found.
if (error.errno !== 34 /* ENOENT */) {
throw error;
}
}
child = exec(cmd, function (err) {
if (err) {
grunt.log.writeln(err.message);
process.exit(err.code);
}
done();
});
child.stdout.on('data', process.stdout.write.bind(process.stdout));
child.stderr.on('data', process.stderr.write.bind(process.stderr));
});
var pkg = grunt.file.readJSON('package.json');
var distpaths = {
script: 'public/js/prod/<%= pkg.name %>-<%= pkg.version %>.js',
// map: 'public/js/prod/<%= pkg.name %>.map.json', // don't version this so we overwrite
min: 'public/js/prod/<%= pkg.name %>-<%= pkg.version %>.min.js',
runner: 'public/js/prod/runner-<%= pkg.version %>.js',
runnermin: 'public/js/prod/runner-<%= pkg.version %>.min.js'
};
var config = {
pkg: pkg,
scriptsRelative: scripts.app.map(function (script) {
return 'public' + script;
}),
runnerScripts: scripts.runner.map(function (script) {
return 'public' + script;
}),
addonsRelative: (function(addon) {
var relative = [];
for (var prop in addon) {
if (addon.hasOwnProperty(prop)) {
var src = addon[prop].map(function(script) {
return 'public' + script;
});
relative.push({
src: src,
dest: 'public/js/prod/addon-' + prop + '-<%= pkg.version %>.min.js'
});
}
}
return relative;
})(scripts.addons),
jshint: {
dist: {
files: {
src: ['grunt.js', 'lib/**/*.js']
}
},
build: {
files: {
src: '<%= scriptsRelative %>'
}
}
},
concat: {
options: {
separator: ';'
},
dist: {
src: [
'public/js/intro-start.js',
'<%= scriptsRelative %>',
'public/js/outro-start.js'
],
dest: distpaths.script
},
runner: {
src: [
'public/js/intro.js',
'<%= runnerScripts %>',
'public/js/outro.js'
],
dest: distpaths.runner
}
},
uglify: {
options: {
compress: { unsafe: false },
},
dist: {
options: {
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */\n',
// sourceMap: distpaths.map,
// sourceMappingURL: '/js/prod/jsbin.map.json',
// sourceMapPrefix: 2,
// sourceMapRoot: '/js',
},
src: distpaths.script, //'<%= scriptsRelative %>',
dest: distpaths.min
},
runner: {
options: {},
src: distpaths.runner,
dest: distpaths.runnermin
},
addons: {
files: '<%= addonsRelative %>'
}
},
watch: {
files: '<%= lint.files %>',
tasks: 'lint'
},
run: {}
};
// Project configuration.
grunt.initConfig(config);
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
// Default task.
grunt.registerTask('build', ['concat', 'uglify']);
grunt.registerTask('addons', ['uglify:addons']);
grunt.registerTask('default', ['jshint']);
};