This repository has been archived by the owner on Aug 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Gruntfile.js
104 lines (88 loc) · 2.51 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
'use strict';
module.exports = function (grunt) {
// Load build dependencies
var gruntConfig = require('./gruntconfig')(grunt),
config = gruntConfig.config,
child_process = require('child_process'),
path = require('path'),
fs = require('fs');
// check if being run as another project's dependency:
// when npm installs as another projects dependency, npm doesn't reinstall
// shared (used by parent) dependencies locally, so they must be loaded
// from parent node modules directory instead.
var loadNpmTasks = grunt.loadNpmTasks,
cwd = process.cwd(),
localModules = cwd + path.sep + 'node_modules',
parentModules = path.dirname(cwd);
if (path.basename(parentModules) === 'node_modules') {
var parentDir = path.dirname(parentModules);
loadNpmTasks = function (name) {
if (!fs.existsSync(localModules + path.sep + name)) {
process.chdir(parentDir);
grunt.loadNpmTasks(name);
process.chdir(cwd);
} else {
grunt.loadNpmTasks(name);
}
};
}
gruntConfig.tasks.forEach(loadNpmTasks);
grunt.initConfig(gruntConfig);
grunt.event.on('watch', function (action, filepath) {
// Only lint the file that actually changed
grunt.config(['jshint', 'scripts'], filepath);
});
grunt.registerTask('runpreinstall', function (dir) {
var done = this.async();
child_process.exec('php ' + dir + '/lib/pre-install.php',
function (error, stdout, stderr) {
if (error !== null) {
grunt.log.error(error);
grunt.log.error(stdout);
grunt.log.error(stderr);
done(false);
} else {
grunt.log.write(stdout);
done();
}
});
});
// build for dev
grunt.registerTask('build', [
'clean',
'copy:build',
'postcss:build',
'jshint:scripts',
'concat:scripts',
'runpreinstall:' + config.build + '/' + config.src
]);
// build distribution
grunt.registerTask('builddist', [
'build',
'copy:dist',
'postcss:dist',
'uglify:dist',
'runpreinstall:' + config.dist
]);
// preview the distribution
grunt.registerTask('dist', [
'builddist',
'configureRewriteRules',
'connect:dist:keepalive'
]);
// develop
grunt.registerTask('default', [
'build',
'configureRewriteRules',
'test',
'connect:dev',
'watch'
]);
grunt.registerTask('test', [
'browserify:test',
'concat:bundle',
'copy:test',
'connect:test',
'mocha_phantomjs'
]);
};