Add addon support

(cherry picked from commit 2191174c19958449be69adfedc83e847a2f19d6a)
This commit is contained in:
Alexey Golubev
2020-02-19 17:24:12 +03:00
committed by agolybev
parent 64aef22fa6
commit 4a62dbc8e7
3 changed files with 85 additions and 37 deletions

View File

@ -35,6 +35,8 @@
}, },
"pkg": { "pkg": {
"scripts": [ "scripts": [
"./sources/editorDataMemory.js",
"./sources/editorDataRedis.js",
"./sources/pubsubRabbitMQ.js", "./sources/pubsubRabbitMQ.js",
"../Common/sources/storage-fs.js", "../Common/sources/storage-fs.js",
"../Common/sources/storage-s3.js" "../Common/sources/storage-s3.js"

View File

@ -29,10 +29,52 @@
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode * terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
* *
*/ */
const path = require('path');
const _ = require('lodash');
var packageFile = require('./package.json'); var packageFile = require('./package.json');
module.exports = function (grunt) { module.exports = function (grunt) {
let addons = grunt.option('addon') || [];
if (!Array.isArray(addons))
addons = [addons];
addons.forEach((element,index,self) => self[index] = path.join('..', element));
addons = addons.filter(element => grunt.file.isDir(element));
function _merge(target, ...sources) {
if (!sources.length) return target;
const source = sources.shift();
for (const key in source) {
if (_.isObject(source[key])) {
if (_.isArray(source[key])) {
if (!_.isArray(target[key])){
target[key]=[];
}
target[key].push(...source[key])
}
else {
if (!target[key]) {
Object.assign(target, { [key]: {} });
}
_merge(target[key], source[key]);
}
}
else {
Object.assign(target, { [key]: source[key] });
}
}
}
addons.forEach(element => {
let _path = path.join(element, 'package.json');
if (grunt.file.exists(_path)) {
_merge(packageFile, require(_path));
grunt.log.ok('addon '.green + element + ' is merged successfully'.green);
}
});
//grunt.file.write("package-test.json", JSON.stringify(packageFile, null, 4));
var checkDependencies = {}; var checkDependencies = {};
@ -47,26 +89,9 @@ module.exports = function (grunt) {
} }
grunt.initConfig({ grunt.initConfig({
clean: { clean: packageFile.grunt.clean,
options: { mkdir: packageFile.grunt.mkdir,
force: true copy: packageFile.grunt.copy,
},
build: packageFile.build.dest
},
mkdir: {
build: {
options: {
create: [packageFile.build.dest]
},
},
},
copy: {
main: {
expand: true,
src: packageFile.build.src,
dest: packageFile.build.dest
}
},
comments: { comments: {
js: { js: {
options: { options: {

View File

@ -3,23 +3,44 @@
"version": "0.0.0", "version": "0.0.0",
"homepage": "http://www.teamlab.com", "homepage": "http://www.teamlab.com",
"private": true, "private": true,
"build": { "grunt": {
"src": [ "copy": {
"./**/sources/*.js", "server": {
"./Common/package.json", "expand": true,
"./DocService/package.json", "src": [
"./DocService/public/healthcheck.docx", "./**/sources/*.js",
"./FileConverter/package.json", "./Common/package.json",
"./FileConverter/bin/DoctRenderer.config", "./DocService/package.json",
"./Metrics/package.json", "./DocService/public/healthcheck.docx",
"./SpellChecker/package.json", "./FileConverter/package.json",
"./Common/config/*.json", "./FileConverter/bin/DoctRenderer.config",
"./Common/config/log4js/*.json", "./Metrics/package.json",
"./Common/sources/licenseKey.pem", "./SpellChecker/package.json",
"./Metrics/config/config.js" "./Common/config/*.json",
], "./Common/config/log4js/*.json",
"dest": "./build/server" "./Common/sources/licenseKey.pem",
"./Metrics/config/config.js"
],
"dest": "./build/server"
}
},
"clean": {
"options": {
"force": true
},
"server": "./build/server"
},
"mkdir": {
"server": {
"options": {
"create": [
"./build/server"
]
}
}
}
}, },
"postprocess": { "postprocess": {
"src": [ "src": [
"./build/server/**/sources/*.js" "./build/server/**/sources/*.js"