-
Notifications
You must be signed in to change notification settings - Fork 2
/
Gruntfile.js
230 lines (222 loc) · 6.45 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
//To build dist/concrete.js, run grunt at the command line in this directory.
//Prerequisites:
// Node Setup - nodejs.org
// Grunt Setup - npm install //reads the ./package.json and installs project dependencies
module.exports = function (grunt) {
'use strict';
var thriftPaths = grunt.file.expand({filter: "isFile"}, ["../concrete/thrift/**/*.thrift"]);
var pkg = grunt.file.readJSON('package.json');
var isFinalVersion = /^[0-9]+\.[0-9]+\.[0-9]+$/.test(pkg.version);
function createDocsIndex() {
var latestDocsPath = pkg.name + '/' + pkg.version;
grunt.file.write('docs/index.html', [
'<!DOCTYPE html>',
'<html>',
' <head>',
' <title>Redirecting to the latest concrete-js documentation ...</title>',
' <meta http-equiv="Refresh" content="0; url=\'' + latestDocsPath + '\'" />',
' </head>',
' <body>',
' <p>',
' Redirecting to <a href="' + latestDocsPath + '">the latest concrete-js documentation</a> ...',
' </p>',
' </body>',
'</html>',
].join('\n'));
}
function addNodeJSDocstrings() {
var generatedTypesPaths = grunt.file.expand({filter: "isFile"}, ["gen-nodejs/**/*_types.js"]);
generatedTypesPaths.forEach(function (path) {
var ns = 'concrete.' + path.match(/^.+\/(\w+)_types.js$/)[1];
grunt.file.write(
path,
grunt.file.read(path)
.replace(
/^/,
function(match) {
return [
'/**',
' * @namespace ' + ns,
' */',
''
].join('\n');
}
)
.replaceAll(
// Use a strict regex to reduce chance of false positives
/^const (\w+) = module\.exports\.\w+ = class \{\s*$/gm,
function(match, p1) {
return [
'',
'/**',
' * @memberof ' + ns,
' * @class ' + p1,
' * @classdesc ' + p1 + ' class generated by Thrift',
' */',
match
].join('\n');
}
)
);
});
}
grunt.initConfig({
pkg: pkg,
concat: {
options: {
separator: ';'
},
dist: {
src: [
// Services is used by other files in gen-js/
'gen-js/Service.js',
'gen-js/*.js',
// concrete.util is used by other files in src/
'src/util.js',
'src/*.js'
],
dest: 'dist/concrete.js'
}
},
uglify: {
options: {
banner: '/*! concrete <%= grunt.template.today("dd-mm-yyyy") %> */\n'
},
dist: {
files: {
'dist/concrete.min.js': ['<%= concat.dist.dest %>']
}
}
},
copy: {
dist_nodejs: {
files: [
{
expand: true,
cwd: 'gen-nodejs',
src: ['*.js', '*.ts'],
dest: 'dist_nodejs/'
},
{
expand: true,
cwd: 'src_nodejs',
src: ['**/*.js', '**/*.ts'],
dest: 'dist_nodejs/'
},
{
src: 'LICENSE.txt',
dest: 'dist_nodejs/'
},
{
src: 'package.json',
dest: 'dist_nodejs/',
},
{
src: 'README.md',
dest: 'dist_nodejs/'
}
]
},
docs: {
files: [
{
expand: true,
cwd: 'dist',
src: '*.js',
dest: 'docs/'
}
]
},
options: {
mode: true,
},
},
shell: {
DownloadThriftJS: {
command: 'curl https://raw.githubusercontent.com/apache/thrift/0.16.0/lib/js/src/thrift.js --output dist/thrift.js'
},
ThriftGen: {
// TODO: Don't hardcode location of 'concrete' repo
command: thriftPaths.map(function(path) {return 'thrift --gen js:jquery ' + path;}).join(' && '),
},
ThriftGen_nodejs: {
// TODO: Don't hardcode location of 'concrete' repo
command: thriftPaths.map(function(path) {return 'thrift --gen js:node,es6,ts ' + path;}).join(' && '),
},
VersionGen_nodejs: {
command: 'genversion --semi src_nodejs/generated_version.js'
},
},
qunit: {
dist: {
}
},
jshint: {
src: {
src: [
'examples/*.html',
'Gruntfile.js',
'gen-js/*.js',
'src/**/*.js',
'test/unit/*.js',
'test/integration/*.js'
],
options: {
extract: 'auto',
// options here to override JSHint defaults
globals: {
jQuery: true,
console: true,
module: true,
document: true
},
"-W083": true,
}
}
},
eslint: {
target: [
'gen-nodejs/**/*.js',
'gen-nodejs/**/*.ts',
'src_nodejs/**/*.js',
'src_nodejs/**/*.ts',
'test_nodejs/**/*.js',
'test_nodejs/**/*.ts'
]
},
jsdoc: {
docs: {
src: ['src_nodejs/**/*.js', 'gen-nodejs/**/*.js', 'README.md', 'package.json'],
options: {
configure: 'jsdoc.conf.json',
destination: 'docs',
},
},
"docs/js-jquery": {
src: ['src/*.js', 'README-js-jquery.md'],
options: {
configure: 'jsdoc.conf.json',
destination: 'docs/js-jquery',
},
},
},
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-eslint');
grunt.registerTask('addNodeJSDocstrings', 'Add docstrings to thrift-generated Node.js code', addNodeJSDocstrings);
grunt.registerTask('createDocsIndex', 'Creates documentation index', createDocsIndex);
grunt.registerTask('docs', [
'jsdoc:docs', 'jsdoc:docs/js-jquery', 'copy:docs'
].concat(isFinalVersion ? ['createDocsIndex'] : []));
grunt.registerTask('download', ['shell:DownloadThriftJS']);
grunt.registerTask('js', ['shell:ThriftGen', 'jshint:src', 'concat:dist', 'uglify:dist', 'download']);
grunt.registerTask('nodejs', [
'shell:ThriftGen_nodejs', 'addNodeJSDocstrings', 'shell:VersionGen_nodejs', 'eslint', 'copy:dist_nodejs'
]);
grunt.registerTask('default', ['nodejs', 'js', 'docs']);
};