-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
149 lines (139 loc) · 5.39 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
var jwtAuthenticationMiddleware = require('./lib/server/http/jwt-auth-middleware');
var jwtAuthenticationServer = require('./index').server;
module.exports = function(grunt) {
// Long stack traces for q
process.env.Q_DEBUG = 1;
// Polyfill so we can run without ES6 promises
if (!global.Promise) {
global.Promise = require('q').Promise;
}
var addJWTMiddleware = function(middlewares, validator, validIssuers, basePath) {
var jwtMiddleware = jwtAuthenticationMiddleware.create(validator, validIssuers);
middlewares.unshift(function(req, res, next) {
if (req.url !== basePath) return next();
jwtMiddleware(req, res, next);
});
middlewares.push(function(req, res, next) {
if (req.url === basePath) {
res.end('Ok');
}
next();
});
};
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jasmine_nodejs: {
options: {
specNameSuffix: 'spec.js', // also accepts an array
stopOnFailure: false,
reporters: {
console: {
colors: true,
cleanStack: 1, // (0|false)|(1|true)|2|3
verbosity: 4, // (0|false)|1|2|3|(4|true)
listStyle: 'indent', // 'flat'|'indent'
activity: false
}
}
},
unit: {
specs: ['test/unit/**/*']
},
integration: {
specs: ['test/integration/**/*']
}
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
source: {
files: {
src: ['lib/**/*.js', 'test/**/*.js']
}
}
},
connect: {
server: {
options: {
base: 'test/integration/key-server',
middleware: function(connect, options, middlewares) {
var validator = jwtAuthenticationServer.create({
resourceServerAudience: 'an-audience',
publicKeyBaseUrl: 'http://localhost:8000/'
});
addJWTMiddleware(middlewares, validator, ['an-issuer'], '/needs/auth');
addJWTMiddleware(middlewares, validator, ['different-issuer'], '/different/issuer');
return middlewares;
}
}
}
},
'grunt-contrib-watch': {
options: {
atBegin: true
},
unit: {
files: ['lib/**/*', 'test/unit/**/*'],
tasks: ['unitTest']
},
integration: {
files: ['lib/**/*', 'test/integration/**/*'],
tasks: ['integrationTest']
}
},
changelog: {
options: {
commitLink: function(commitHash) {
var shortCommitHash = commitHash.substring(0, 8);
var commitUrl = grunt.config.get('pkg.repository.url') + '/commits/' + commitHash;
return '[' + shortCommitHash + '](' + commitUrl + ')';
},
issueLink: function(issueId) {
var issueUrl = grunt.config.get('pkg.repository.url') + '/issue/' + issueId;
return '[' + issueId + '](' + issueUrl + ')';
},
file: 'docs/CHANGELOG.md'
}
},
bump: {
options: {
commit: true,
commitMessage: 'chore: Release v%VERSION%',
commitFiles: ['package.json', 'docs/CHANGELOG.md', 'docs/API.md'],
pushTo: 'origin',
updateConfigs: ['pkg'],
tagName: '%VERSION%'
}
},
jsdoc2md: {
api: {
src: "lib/**/*.js",
dest: "docs/API.md"
}
}
});
grunt.loadNpmTasks('grunt-jasmine-nodejs');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-npm');
grunt.loadNpmTasks("grunt-jsdoc-to-markdown");
grunt.renameTask('watch', 'grunt-contrib-watch');
grunt.registerTask('unitTest', ['jasmine_nodejs:unit']);
grunt.registerTask('integrationTest', ['connect:server', 'jasmine_nodejs:integration']);
grunt.registerTask('buildAndTest', ['jshint:source', 'unitTest', 'integrationTest']);
grunt.registerTask('docs', ['changelog', 'jsdoc2md']);
grunt.registerTask('release', function(type) {
if (!type) {
grunt.fail.fatal('No release type specified. You must specify patch, minor or major. For example "grunt release:patch".');
}
grunt.task.run(['buildAndTest', 'bump-only:' + type, 'docs', 'bump-commit', 'npm-publish']);
});
grunt.registerTask('default', ['buildAndTest']);
grunt.registerTask('watch', ['grunt-contrib-watch:unit']);
grunt.registerTask('watchIntegrationTest', ['grunt-contrib-watch:integration']);
};