-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
159 lines (145 loc) · 4.29 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
"use strict";
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint: {
target: ['src/**/*.js']
},
clean: ['doc', 'dist', 'temp'],
jsdoc: {
doc: {
src: ['src/**/*.js', 'README.md'],
options: {
destination: 'doc',
template: 'node_modules/ink-docstrap/template',
configure: 'jsdoc.conf.json'
}
}
},
babel: {
options: {
sourceMap: true,
presets: ['es2015']
},
babel_out: {
files: [{
expand: true,
cwd: 'src/control',
src: ['**/*.js'],
dest: 'temp/babel_out/control',
ext: '.js'
}]
}
},
copy: {
files: {
cwd: 'src',
src: '**/*.xml',
dest: 'dist',
expand: true
}
},
uglify: {
dist: {
files: [{
expand: true,
cwd: 'temp/babel_out',
src: ['**/*.js'],
dest: 'dist',
}]
}
}
});
// Load grunt plugin tasks from pre-installed npm packages
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-jsdoc');
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-openui5');
// Local task: Copy README
grunt.registerTask(
'create_readme',
'Copy README to package dist',
function () {
grunt.file.copy('README.md', 'dist/README.md');
grunt.log.ok('Copied README to package dist.');
}
);
// Local task: Create meteor package file
grunt.registerTask(
'create_package_js',
'Create meteor package file',
function () {
// TODO rather than just copy package.js, build list of files for
// api.addFiles() method based on current UI5 files
grunt.file.copy('src/package.js', 'dist/package.js');
grunt.log.ok('Meteor package.js copied from src/.');
}
);
// Local task: Create UI5 debug files
grunt.registerTask(
'create_ui5_debug_files',
'Create UI5 debug files ("-dbg")',
function () {
// TODO move this into outside function so the grunt file is easier to
// to follow. I tried but couldn't get a reference to the grunt object
let debugFilesCreated = 0;
let sourceMapsCopied = 0;
// Recurse babel output directory copying unminfied javascript to dist
// directory but with '-dbg' in the name before the first dot.
grunt.file.recurse(
'temp/babel_out',
function (abspath, root, subdir, filename) {
// Ignore root directory
if (subdir) {
// Only create -dbg versions of javascript files
if (filename.endsWith('.js')) {
// Source file is absolute path
var sourceFile = abspath;
// Destination file name has '-dbg' in the filename before first period
var firstPeriod = filename.indexOf('.');
var destFileName = [
filename.slice(0, firstPeriod),
'-dbg',
filename.slice(firstPeriod)
].join('');
// Destination is in 'dist' directory
const destFile = 'dist/' + subdir + '/' + destFileName;
// Copy file
grunt.file.copy(sourceFile, destFile);
debugFilesCreated++;
} else if (filename.endsWith('.map') || filename.endsWith('.xml')) {
// Just copy source maps, xml templates as is.
var sourceFile = abspath;
// Destination is in 'dist' directory
var destFile = 'dist/' + subdir + '/' + filename;
// Copy file
grunt.file.copy(sourceFile, destFile);
sourceMapsCopied++;
}
}
}
);
// Finished
grunt.log.ok(
debugFilesCreated + ' debug files created. ' +
sourceMapsCopied + ' source maps copied.'
);
}
);
// Complete, combined build task
grunt.registerTask('build', [
'eslint',
'clean',
'jsdoc',
'babel',
'uglify',
'copy',
'create_package_js',
'create_ui5_debug_files',
'create_readme'
]);
};