forked from girder/girder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
108 lines (100 loc) · 3.38 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
/**
* Copyright 2013 Kitware Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This function takes an object like `grunt.config.get('init')` and
* returns a topologically sorted array of tasks.
*/
function sortTasks(obj) {
var toposort = require('toposort');
var _ = require('underscore');
var nodes = _.keys(obj);
var edges = _(obj).chain()
.pairs()
.map(function (o) {
return _.map(o[1].dependencies || [], function (d) {
return [d, o[0]];
});
})
.flatten(true)
.value();
return toposort.array(nodes, edges);
}
module.exports = function (grunt) {
var fs = require('fs');
var isSourceBuild = fs.existsSync('girder/__init__.py');
require('colors');
// Project configuration.
grunt.config.init({
pkg: grunt.file.readJSON('package.json'),
pluginDir: 'plugins',
staticDir: 'clients/web/static',
isSourceBuild: isSourceBuild,
init: {
setup: {}
},
default: {}
});
if (isSourceBuild) {
// We are in a source tree
grunt.config.set('girderDir', 'girder');
} else {
// We are in an installed package
grunt.config.set('girderDir', '.');
}
/**
* Load task modules inside `grunt_tasks`.
*/
grunt.loadTasks('grunt_tasks');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jade');
grunt.loadNpmTasks('grunt-contrib-stylus');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-symlink');
grunt.loadNpmTasks('grunt-gitinfo');
grunt.loadNpmTasks('grunt-file-creator');
grunt.loadNpmTasks('grunt-npm-install');
// This task should be run once manually at install time.
grunt.registerTask('setup', 'Initial install/setup tasks', function () {
// If the local config file doesn't exist, we make it
var confDir = grunt.config.get('girderDir') + '/conf';
if (!fs.existsSync(confDir + '/girder.local.cfg')) {
fs.writeFileSync(
confDir + '/girder.local.cfg',
fs.readFileSync(confDir + '/girder.dist.cfg')
);
console.log('Created local config file.');
}
});
/**
* Load `default` and `init` targets by topologically sorting the
* tasks given by keys the config object. As in:
* {
* 'init': {
* 'jade:a': {}
* 'uglify:a': {
* 'dependencies': ['jade:a']
* }
* }
* }
*
* The init task will run `jade:a` followed by `uglify:a`.
*/
grunt.registerTask('init', sortTasks(grunt.config.get('init')));
grunt.registerTask('default', sortTasks(grunt.config.get('default')));
};