web-apps/build/deploy/grunt.js

597 lines
21 KiB
JavaScript
Raw Normal View History

2016-03-11 00:48:53 +00:00
module.exports = function(grunt) {
var defaultConfig, packageFile, deployConfig, deployFile;
grunt.loadNpmTasks('grunt-contrib');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-replace');
grunt.registerTask('sdk-init', function() {
grunt.initConfig({
clean: packageFile['sdk']['clean'],
copy: {
sdk: {
files: packageFile['sdk']['copy']
}
}
});
});
grunt.registerTask('api-init', function() {
grunt.initConfig({
clean: packageFile['api']['clean'],
copy: {
api: {
files: packageFile['api']['copy']
}
}
});
});
grunt.registerTask('bootstrap-init', function() {
grunt.initConfig({
clean: packageFile['bootstrap']['clean'],
copy: {
script: {
files: packageFile['bootstrap']["copy"]["script"]
},
css: {
files: packageFile['bootstrap']["copy"]["css"]
},
images: {
files: packageFile['bootstrap']["copy"]["images"]
}
}
});
});
grunt.registerTask('extjs-init', function() {
grunt.initConfig({
clean: packageFile['extjs']['clean'],
copy: {
script: {
files: packageFile['extjs']["copy"]["script"]
},
css: {
files: packageFile['extjs']["copy"]["css"]
},
images: {
files: packageFile['extjs']["copy"]["images"]
}
}
});
});
grunt.registerTask('megapixel-init', function() {
grunt.initConfig({
clean: packageFile['megapixel']['clean'],
copy: {
script: {
files: packageFile['megapixel']["copy"]["script"]
}
}
});
});
grunt.registerTask('jquery-init', function() {
grunt.initConfig({
clean: packageFile['jquery']['clean'],
copy: {
scripts: {
files: packageFile['jquery']["copy"]["script"]
}
}
});
});
grunt.registerTask('sockjs-init', function() {
grunt.initConfig({
clean: packageFile['sockjs']['clean'],
copy: {
script: {
files: packageFile['sockjs']["copy"]["script"]
}
}
});
});
grunt.registerTask('xregexp-init', function() {
grunt.initConfig({
clean: packageFile['xregexp']['clean'],
copy: {
script: {
files: packageFile['xregexp']["copy"]["script"]
}
}
});
});
grunt.registerTask('underscore-init', function() {
grunt.initConfig({
clean: packageFile['underscore']['clean'],
copy: {
script: {
files: packageFile['underscore']["copy"]["script"]
}
}
});
});
grunt.registerTask('zeroclipboard-init', function() {
grunt.initConfig({
clean: packageFile['zeroclipboard']['clean'],
copy: {
script: {
files: packageFile['zeroclipboard']["copy"]["script"]
}
}
});
});
grunt.registerTask('main-app-init', function() {
grunt.initConfig({
pkg: '<json:' + defaultConfig + '>',
clean: packageFile['main']['clean'],
meta: {
banner: '/*\n' +
' * Copyright (c) Ascensio System SIA <%= grunt.template.today("yyyy") %>. All rights reserved\n' +
' *\n' +
' * <%= pkg.homepage %> \n' +
' *\n' +
' * Version: <%= pkg.version %> (build:<%= pkg.build %>)\n' +
' */'
},
min: {
scriptsview: {
src: ['<banner:meta.banner>'].concat(packageFile['main']["js"]['srcview']),
dest: packageFile['main']["js"]['destview']
},
scriptsedit: {
src: ['<banner:meta.banner>'].concat(packageFile['main']["js"]['srcedit']),
dest: packageFile['main']["js"]['destedit']
}
},
mincss: {
styles: {
files: {
"<%= pkg.main.css.destview %>" : packageFile['main']["css"]['srcview']
,"<%= pkg.main.css.destedit %>" : packageFile['main']["css"]['srcedit']
}
}
},
copy: {
localization: {
files: packageFile['main']['copy']["localization"]
},
help: {
files: packageFile['main']['copy']["help"]
},
'index-page': {
files: packageFile['main']['copy']["index-page"]
},
'images-app': {
files: packageFile['main']['copy']["images-app"]
},
'images-common': {
files: packageFile['main']['copy']["images-common"]
}
}
});
});
grunt.registerTask('mobile-app-init', function() {
grunt.initConfig({
pkg: '<json:' + defaultConfig + '>',
clean: packageFile['mobile']['clean'],
meta: {
banner: '/*\n' +
' * Copyright (c) Ascensio System SIA <%= grunt.template.today("yyyy") %>. All rights reserved\n' +
' *\n' +
' * <%= pkg.homepage %>\n' +
' *\n' +
' * Version: <%= pkg.version %> (build:<%= pkg.build %>)\n' +
' */'
},
min: {
scrips: {
src: ['<banner:meta.banner>'].concat(packageFile['mobile']["js"]['src']),
dest: packageFile['mobile']["js"]['dist']
}
},
mincss: {
styles: {
files: {
"<%= pkg.mobile.css.normal.dist %>" : packageFile['mobile']["css"]['normal']['src'],
"<%= pkg.mobile.css.retina.dist %>" : packageFile['mobile']["css"]['retina']['src']
}
}
},
copy: {
localization: {
files: packageFile['mobile']['copy']["localization"]
},
'index-page': {
files: packageFile['mobile']['copy']["index-page"]
},
'images-app': {
files: packageFile['mobile']['copy']["images-app"]
}
}
});
});
grunt.registerTask('embed-app-init', function() {
grunt.initConfig({
pkg: '<json:' + defaultConfig + '>',
clean: packageFile['embed']['clean'],
meta: {
banner: '/*\n' +
' * Copyright (c) Ascensio System SIA <%= grunt.template.today("yyyy") %>. All rights reserved\n' +
' *\n' +
' * <%= pkg.homepage %>\n' +
' *\n' +
' * Version: <%= pkg.version %> (build:<%= pkg.build %>)\n' +
' */'
},
min: {
scrips: {
src: ['<banner:meta.banner>'].concat(packageFile['embed']["js"]['src']),
dest: packageFile['embed']["js"]['dist']
}
},
mincss: {
styles: {
files: {
"<%= pkg.embed.css.dist %>" : packageFile['embed']["css"]['src']
}
}
},
copy: {
'index-page': {
files: packageFile['embed']['copy']["index-page"]
},
'images-app': {
files: packageFile['embed']['copy']["images-app"]
}
}
});
});
grunt.registerTask('increment-build', function() {
var pkg = grunt.file.readJSON(defaultConfig);
pkg.build = parseInt(pkg.build) + 1;
grunt.file.write(defaultConfig, JSON.stringify(pkg, null, 4));
});
grunt.registerTask('deploy-api', 'api-init clean copy');
grunt.registerTask('deploy-sdk', 'sdk-init clean copy');
grunt.registerTask('deploy-3rdparty-bootstrap', 'bootstrap-init clean copy');
grunt.registerTask('deploy-3rdparty-extjs', 'extjs-init clean copy');
grunt.registerTask('deploy-3rdparty-megapixel', 'megapixel-init clean copy');
grunt.registerTask('deploy-3rdparty-jquery', 'jquery-init clean copy');
grunt.registerTask('deploy-3rdparty-sockjs', 'sockjs-init clean copy');
grunt.registerTask('deploy-3rdparty-xregexp', 'xregexp-init clean copy');
grunt.registerTask('deploy-3rdparty-underscore', 'underscore-init clean copy');
grunt.registerTask('deploy-3rdparty-zeroclipboard', 'zeroclipboard-init clean copy');
grunt.registerTask('deploy-app-main', 'main-app-init clean min mincss copy');
grunt.registerTask('deploy-app-mobile', 'mobile-app-init clean min mincss copy');
grunt.registerTask('deploy-app-embed', 'embed-app-init clean min mincss copy');
grunt.registerTask('init-build-documenteditor', 'Initialize build DocumentEditor.', function(){
defaultConfig = 'documenteditor.json';
packageFile = require('./' + defaultConfig);
if (packageFile)
grunt.log.ok('DocumentEditor config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
grunt.registerTask('init-build-spreadsheeteditor', 'Initialize build SpreadsheetEditor.', function(){
defaultConfig = 'spreadsheeteditor.json';
packageFile = require('./' + defaultConfig);
if (packageFile)
grunt.log.ok('SpreadsheetEditor config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
grunt.registerTask('init-build-presentationeditor', 'Initialize build PresentationEditor.', function(){
defaultConfig = 'presentationeditor.json';
packageFile = require('./' + defaultConfig);
if (packageFile)
grunt.log.ok('PresentationEditor config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
grunt.registerTask('deploy-app', 'Deploy application.', function(){
if (packageFile) {
if (packageFile['tasks']['deploy'])
grunt.task.run(packageFile['tasks']['deploy']);
else
grunt.log.error().writeln('Not found "deploy" task in configure'.red);
} else {
grunt.log.error().writeln('Is not load configure file.'.red);
}
});
grunt.registerTask('init-obfuscate-app', 'Obfuscate application.', function(){
grunt.initConfig({
exec: {
obfuscate_string: {
command: function() {
var exec_string = '.\\bin\\ObfuscateStrings.exe';
exec_string += ' -api ' + packageFile['obf']['api'];
exec_string += ' -pat ' + packageFile['obf']['pat'];
exec_string += ' ' + packageFile['obf']['keys'];
for(var i in packageFile['obf']['apply']){
exec_string += ' -apply ' + packageFile['obf']['apply'][i] + ' ' + packageFile['obf']['apply'][i];
}
return exec_string;
},
stdout: false
}
}
});
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-obfuscate-api', 'Obfuscate api.', function(){
grunt.initConfig({
exec: {
obfuscate_api: {
command: function() {
var exec_string = '.\\bin\\ObfuscateJSApi.exe -verbose';
exec_string += ' -ccvars ' + packageFile['obf_api']['ccvars'];
exec_string += ' -ccprops ' + packageFile['obf_api']['ccprops'];
exec_string += ' -api ' + packageFile['obf_api']['api'];
for(var i in packageFile['obf_api']['clientjs']){
exec_string += ' -clientjs ' + packageFile['obf_api']['clientjs'][i] + ' ' + packageFile['obf_api']['clientjs'][i];
}
exec_string += ' -ccres ' + packageFile['obf_api']['ccres'] + ' ' + packageFile['obf_api']['ccres'];
return exec_string;
},
stdout: false
}
}
});
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('obfuscate-api', 'init-obfuscate-api exec');
grunt.registerTask('obfuscate-app', 'init-obfuscate-app exec');
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('deploy-documenteditor', 'init-build-documenteditor deploy-app');
grunt.registerTask('deploy-spreadsheeteditor', 'init-build-spreadsheeteditor deploy-app');
grunt.registerTask('deploy-presentationeditor', 'init-build-presentationeditor deploy-app');
grunt.registerTask('obfuscate-documenteditor', 'deploy-documenteditor obfuscate-api obfuscate-app');
grunt.registerTask('obfuscate-spreadsheeteditor', 'deploy-spreadsheeteditor obfuscate-app');
grunt.registerTask('obfuscate-presentationeditor', 'deploy-presentationeditor obfuscate-api obfuscate-app');
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('obfuscate-all', 'obfuscate-documenteditor obfuscate-spreadsheeteditor obfuscate-presentationeditor');
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-isa209', 'Initialize deploy to isa209.', function(){
deployConfig = 'isa209.json';
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
deployFile = require('./' + deployConfig);
2016-11-21 13:00:09 +00:00
if (deployFile)
2016-03-11 00:48:53 +00:00
grunt.log.ok('isa209 config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-testserver', 'Initialize deploy to testserver.', function(){
deployConfig = 'testserver.json';
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
deployFile = require('./' + deployConfig);
2016-11-21 13:00:09 +00:00
if (deployFile)
2016-03-11 00:48:53 +00:00
grunt.log.ok('testserver config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-com', 'Initialize deploy to com.', function(){
deployConfig = 'com.json';
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
deployFile = require('./' + deployConfig);
2016-11-21 13:00:09 +00:00
if (deployFile)
2016-03-11 00:48:53 +00:00
grunt.log.ok('com config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-com.eu', 'Initialize deploy to com.', function(){
deployConfig = 'com.eu.json';
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
deployFile = require('./' + deployConfig);
2016-11-21 13:00:09 +00:00
if (deployFile)
2016-03-11 00:48:53 +00:00
grunt.log.ok('com config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-nct', 'Initialize deploy to nct.', function(){
deployConfig = 'nct.json';
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
deployFile = require('./' + deployConfig);
2016-11-21 13:00:09 +00:00
if (deployFile)
2016-03-11 00:48:53 +00:00
grunt.log.ok('nct config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
grunt.registerTask('init-deploy-doc-test', 'Initialize deploy to doc-test.', function(){
deployConfig = 'doc-test.json';
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
deployFile = require('./' + deployConfig);
2016-11-21 13:00:09 +00:00
if (deployFile)
2016-03-11 00:48:53 +00:00
grunt.log.ok('doc-test config loaded successfully'.green);
else
grunt.log.error().writeln('Could not load config file'.red);
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('run-deploy-task', 'Run deploy task.', function(){
if (deployFile) {
if (deployFile['tasks']['deploy'])
grunt.task.run(deployFile['tasks']['deploy']);
else
grunt.log.error().writeln('Not found "deploy" task in configure'.red);
} else {
grunt.log.error().writeln('Is not load configure file.'.red);
}
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('insert-version-to-url', function() {
var dst_folder = 'v' + deployFile['version']['major'] + '.' + deployFile['version']['minor'];
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
if(undefined !== process.env['BUILD_NUMBER'])
{
2016-11-21 13:00:09 +00:00
grunt.log.ok('Use Jenkins build number as minor version!'.yellow);
2016-03-11 00:48:53 +00:00
dst_folder = 'v' + deployFile['version']['major'] + '.' + process.env['BUILD_NUMBER'];
}
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
//change current config:
//set version's named folder as rootDir for archived sources
if(undefined !== deployFile['compress'])
deployFile['compress']['dist']['options']['rootDir'] = dst_folder;
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
if(undefined !== deployFile['dst'])
deployFile['dst'] = deployFile['dst'] + '/' + dst_folder;
//add version's named folder to full path url
var full_url = deployFile['replace']['url']['options']['variables'];
2016-11-21 13:00:09 +00:00
for(var i in full_url){
2016-03-11 00:48:53 +00:00
full_url[i] = full_url[i] + dst_folder + '/';
}
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('increment-deploy-version', function() {
var pkg = grunt.file.readJSON(deployConfig);
pkg.version.minor = parseInt(pkg.version.minor) + 1;
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
//write changes
grunt.file.write(deployConfig, JSON.stringify(pkg, null, 4));
});
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-compress', function(){
grunt.initConfig({
pkg: '<json:' + deployConfig + '>',
compress: deployFile['compress']
});
});
2016-11-21 13:00:09 +00:00
grunt.registerTask('deploy-compress-all', 'init-deploy-compress');
2016-03-11 00:48:53 +00:00
grunt.registerTask('init-deploy-configure', 'Init configure task.', function(){
var replace_path_array = {};
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
if(deployFile['path']){
//Generate structure for the replace tasks
//for each pattern
for(var i in deployFile['path']['pattern']){
//and for each file
for(var j in deployFile['path']['src_path']){
var replace_task_name = 'path_subtask_' + i + j;
2016-11-21 13:00:09 +00:00
replace_path_array[replace_task_name] = {};
2016-03-11 00:48:53 +00:00
replace_path_array[replace_task_name]['options'] = {};
var find = deployFile['path']['pattern'][i];
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
var replace = '';
//find the count of slash
var start_index = 0;
while(true){
start_index = deployFile['path']['src_path'][j].indexOf('/', start_index + 1);
//add up folder to replace string per each slash
if(start_index != -1)
replace = replace + '../';
else
break;
}
//find the begin of file name
var last_slash = deployFile['path']['src_path'][j].lastIndexOf('/');
//and add path to file to replace string whithout file name
if(last_slash != -1)
replace = replace + deployFile['path']['src_path'][j].substring(0, last_slash + 1);
replace = replace + find;
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
replace_path_array[replace_task_name]['options']['variables'] = {};
replace_path_array[replace_task_name]['options']['variables'][find] = replace;
replace_path_array[replace_task_name]['options']['prefix'] = "";
var file = deployFile['path']['base_path'] + '/' + deployFile['path']['src_path'][j];
replace_path_array[replace_task_name]['files'] = {};
replace_path_array[replace_task_name]['files'][file] = file;
2016-11-21 13:00:09 +00:00
grunt.log.ok(JSON.stringify(replace_path_array[replace_task_name], null, 4).green);
2016-03-11 00:48:53 +00:00
}
}
}
//Copy replace task from configuration file
for(var i in deployFile['replace']){
replace_path_array[i] = deployFile['replace'][i];
}
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.initConfig({
pkg: deployFile,
pkg_origin: '<json:' + deployConfig + '>',
clean: [ '<%= pkg_origin.dst %>/' ],
copy: {
all: {
files: {
'<%= pkg.dst %>/': '<%= pkg.src %>/**'
}
}
},
2016-11-21 13:00:09 +00:00
replace: replace_path_array
2016-03-11 00:48:53 +00:00
});
});
2016-11-21 13:00:09 +00:00
grunt.registerTask('deploy-configure-all', 'init-deploy-configure clean copy replace');
2016-03-11 00:48:53 +00:00
grunt.registerTask('deploy-to-isa209', 'init-deploy-isa209 run-deploy-task');
grunt.registerTask('deploy-to-testserver', 'init-deploy-testserver run-deploy-task');
grunt.registerTask('deploy-to-com', 'init-deploy-com run-deploy-task');
grunt.registerTask('deploy-to-com.eu', 'init-deploy-com.eu run-deploy-task');
grunt.registerTask('deploy-to-nct', 'init-deploy-nct run-deploy-task');
grunt.registerTask('deploy-to-doc-test', 'init-deploy-doc-test run-deploy-task');
grunt.registerTask('deploy-to-all', 'deploy-to-isa209 deploy-to-testserver deploy-to-com deploy-to-com.eu deploy-to-nct deploy-to-doc-test');
2016-11-21 13:00:09 +00:00
2016-03-11 00:48:53 +00:00
grunt.registerTask('default', 'deploy-documenteditor deploy-spreadsheeteditor deploy-presentationeditor');
};