-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathGruntfile.js
134 lines (122 loc) · 4.34 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
/* jshint camelcase: false */
module.exports = function(grunt) {
var chalk = require('grunt-attention/node_modules/chalk')
grunt.initConfig({
install_at: (process.env.HOME || process.evn.HOMEPATH || process.env.USERPROFILE) + '/.mongorc.js',
bower_concat: {
dist: {
dest: '.work/bower_components.js'
}
},
concat: {
dist: {
src: ['.work/*.js', 'src/**/*.js'],
dest: '.dist/mongorc.js',
options: {
process: function (content, srcpath) {
return content.replace(
'###version###', grunt.file.readJSON('package.json')['version']
)
}
}
}
},
copy: {
release: {
src: '<%= concat.dist.dest %>',
dest: '<%= copy.released.src %>'
},
builded: {
src: '<%= concat.dist.dest %>',
dest: '<%= install_at %>',
},
released: {
src: './released/mongorc.js',
dest: '<%= install_at %>',
}
},
attention: {
installed: {
options: {
borderColor: 'bgGreen',
message:
chalk.green.bold('MongoDB shell extensions installed in your home directory\n') +
chalk.green('(see <%= install_at %>) \n\n') +
chalk.green('Next time you\'ll open your mongo shell you\'ll have all the extensions automatically loaded')
}
}
},
jshint: {
options: grunt.file.readJSON('.jshintrc'),
all: ['Gruntfile.js', 'spec/**/*.js', 'src/**/*.js']
},
release: {
options: {
add: false,
bump: false,
commit: false,
tag: true,
tagName: '<%= version %>',
tagMessage: 'Release <%= version %>',
push: true,
pushTags: true,
npm: true
}
},
clean: ['.work', '.dist']
});
grunt.loadNpmTasks('grunt-bower-concat')
grunt.loadNpmTasks('grunt-contrib-concat')
grunt.loadNpmTasks('grunt-contrib-clean')
grunt.loadNpmTasks('grunt-contrib-jshint')
grunt.loadNpmTasks('grunt-contrib-copy')
grunt.loadNpmTasks('grunt-attention')
grunt.loadNpmTasks('grunt-release')
grunt.registerTask('build', ['clean', 'jshint', 'bower_concat', 'concat'])
grunt.registerTask('install-head', ['build', 'copy:builded', 'attention:installed'])
grunt.registerTask('install-released', ['copy:released', 'attention:installed'])
grunt.registerTask('spec', ['spec-on-head'])
grunt.registerTask('spec-on-head', ['build', 'run-all-specs:head'])
grunt.registerTask('spec-on-installed', ['run-all-specs:installed'])
// To do a release you need to:
// * change the version in package.json
// * execute `grunt prepare-release`
// * execute `git add --all && git commit -m "Release <version>"`
// * execute `grunt release-and-publish`
grunt.registerTask('prepare-release', ['build', 'copy:release'])
grunt.registerTask('release-and-publish', ['release'])
grunt.registerTask('default', ['spec'])
// !!! I need to automate this, but it's not easy
// How to run tests on a different MongoDB
// * start mongod on a different port with a command like
// `~/opt/mongodb-2.2.7/bin/mongod --port 3100
// --dbpath .tmp/db --logpath .tmp/log --fork
// --quiet --nojournal --noprealloc --smallfiles
// `
// * change the definition 'spec-on-head' spec to `['build', 'run-all-specs:head:3100']`
// * [optional] to use the shell shipped with the server, change the spawn to use the full path of shell executable
// * run `grunt spec`
grunt.registerTask('run-all-specs', 'Run all specs in MongoDB Shell', function(onWhat, onPort) {
var done = this.async(),
path = require('path'),
spawn = require('child_process').spawn,
fileToLoad = (onWhat || 'head') === 'head' ?
path.join(__dirname, './.dist/mongorc.js') :
grunt.config('install_at'),
portToConnectTo = (onPort ? onPort : '27017'),
commandArguments = ['--quiet', '--port', portToConnectTo, fileToLoad, '_runner.js'],
runner = spawn('mongo', commandArguments, {cwd: path.join(__dirname, 'spec')})
runner.stdout.on('data', function(data) {
grunt.log.write(data.toString())
})
runner.stderr.on('data', function(data) {
grunt.log.error(data.toString())
})
runner.on('close', function(code) {
if (code !== 0) {
grunt.util.exit(code)
}
done()
})
})
}