Add the following code to your Gruntfile.js
.
grunt.registerTask('default', [
'clean',
'ts',
'build',
'cleanTs',
'lint'
]);
The code creates the default task, which runs when you choose Build.
Here is the entire Gruntfile.js
code:
module.exports = function(grunt) {
"use strict";
var webAppDir = "webapp";
var config = {
ts: {
default: {
src: ["**/*.ts", "!node_modules/**"]
}
},
copy: {
copyToTmp: {
files: [{
expand: true,
src: '**/*.js',
dest: '<%= dir.tmpDir %>',
cwd: '<%= dir.webapp %>',
filter: function(filepath) {
// prevent js from localService to be copied
return !filepath.match(new RegExp('<%= dir.webapp %>' + '(\\/|\\\\)localService', 'gi'));
}
}, {
expand: true,
src: '**/*.css',
dest: '<%= dir.tmpDir %>',
cwd: '<%= dir.webapp %>'
},
{
expand: true,
src: 'localService/metadata.xml',
dest: '<%= dir.tmpDir %>',
cwd: '<%= dir.webapp %>'
}, {
expand: true,
src: '**/*',
dest: '<%= dir.tmpDir %>',
cwd: '<%= dir.webapp %>',
filter: function(filepath) {
// prevent js and css files and contents of webapp/test from being copied
return !filepath.match(new RegExp("(" + webAppDir +
"(\\/|\\\\)test|${webAppDir}(\\/|\\\\)localService|\\.js$|\\.css$|\\.ts$|\\test.html$)", "gi"));
}
}
]
}
}
};
grunt.loadNpmTasks("@sap/grunt-sapui5-bestpractice-build");
grunt.config.merge(config);
grunt.loadNpmTasks("grunt-ts");
grunt.registerTask('cleanTs', 'Clean type script build result', function() {
grunt.file.expand({
cwd: grunt.config.data.dir.webapp
}, '**/*.ts').forEach(function(file) {
var jsFile = grunt.config.data.dir.webapp + '/' + file.replace(/[^\\/:*?"<>|\r\n]ts$/, ".js");
if (grunt.file.exists(jsFile)) {
grunt.file.delete(jsFile, {
force: true
});
}
var mapFile = grunt.config.data.dir.webapp + '/' + file.replace(/[^\\/:*?"<>|\r\n]ts$/, ".js.map");
if (grunt.file.exists(mapFile)) {
grunt.file.delete(mapFile, {
force: true
});
}
});
});
grunt.registerTask('default', [
'clean',
'ts',
'build',
'cleanTs',
'lint'
]);
};