@docbrasil/api-systemmanager 1.0.94 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/admin/doctypes.js +76 -76
- package/api/admin/document.js +332 -332
- package/api/admin/form.js +151 -151
- package/api/admin/index.js +46 -46
- package/api/admin/list.js +133 -133
- package/api/admin/message.js +194 -194
- package/api/admin/notification.js +233 -233
- package/api/admin/organization.js +124 -124
- package/api/admin/plugin.js +116 -116
- package/api/admin/policy.js +78 -78
- package/api/admin/processes.js +370 -370
- package/api/admin/task.js +125 -125
- package/api/admin/user.js +185 -185
- package/api/dispatch.js +101 -101
- package/api/general/geoLocation.js +88 -88
- package/api/general/index.js +23 -23
- package/api/login.js +267 -267
- package/api/session.js +85 -85
- package/api/user/datasource.js +144 -144
- package/api/user/document.js +730 -730
- package/api/user/index.js +39 -39
- package/api/user/notification.js +101 -101
- package/api/user/organization.js +230 -230
- package/api/user/process.js +191 -191
- package/api/user/register.js +205 -205
- package/api/user/task.js +201 -201
- package/api/user/task_available.js +135 -135
- package/api/user/user.js +287 -287
- package/api/utils/cypher.js +37 -37
- package/api/utils/promises.js +118 -118
- package/bundleRollup.js +158 -158
- package/dist/bundle.cjs +4875 -4875
- package/dist/bundle.mjs +1 -1
- package/doc/api.md +675 -337
- package/doc.md +653 -653
- package/helper/boom.js +487 -487
- package/helper/cryptojs.js +6067 -6067
- package/index.js +85 -85
- package/package-lock.json +4635 -4635
- package/package.json +68 -68
- package/readme.md +25 -25
- package/tests/admin/document.spec.js +45 -45
- package/tests/admin/form.spec.js +74 -74
- package/tests/admin/list.spec.js +86 -86
- package/tests/admin/message.js +92 -92
- package/tests/admin/notification.spec.js +174 -174
- package/tests/admin/pluginspec..js +71 -71
- package/tests/admin/policy.spec.js +71 -71
- package/tests/admin/processes.spec.js +119 -119
- package/tests/admin/users.spec.js +127 -127
- package/tests/documents.spec.js +164 -164
- package/tests/login.spec.js +91 -91
- package/tests/session.spec..js +58 -58
- package/tests/user/documents.js +164 -164
- package/tests/user/organization.js +122 -122
- package/tests/user/process.js +71 -71
- package/tests/user/task_available.js +75 -75
- package/tests/user/user.js +88 -88
package/api/utils/promises.js
CHANGED
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import _ from 'lodash';
|
|
2
|
-
import Boom from '@hapi/boom';
|
|
3
|
-
|
|
4
|
-
class ThePromise {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @description Logger call api professional
|
|
8
|
-
* @param {object} context Process or Domain
|
|
9
|
-
* @param {string} message Message to log
|
|
10
|
-
* @param {object} data Object to show log
|
|
11
|
-
* @private
|
|
12
|
-
*/
|
|
13
|
-
_logger({context = null, message, data}) {
|
|
14
|
-
try {
|
|
15
|
-
|
|
16
|
-
if (context) {
|
|
17
|
-
data = _.isObject(data) ? data : {data};
|
|
18
|
-
|
|
19
|
-
const logSystemMager = _.hasIn(context, 'logger')
|
|
20
|
-
&& _.isFunction(context.logger)
|
|
21
|
-
&& _.hasIn(context.logger(), 'trace')
|
|
22
|
-
&& _.isFunction(context.logger().trace);
|
|
23
|
-
|
|
24
|
-
const logMicroservices = _.hasIn(context, 'log')
|
|
25
|
-
&& _.isFunction(context.log)
|
|
26
|
-
&& _.hasIn(context.log(), 'info')
|
|
27
|
-
&& _.isFunction(context.log().info);
|
|
28
|
-
|
|
29
|
-
if (logSystemMager) {
|
|
30
|
-
context.logger().trace(message, data);
|
|
31
|
-
} else if (logMicroservices) {
|
|
32
|
-
context.log().info(message, data);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
} catch (ex) {
|
|
36
|
-
const message = _.hasIn(ex, 'message') ? ex.message : `Fail logger action: ${message}`;
|
|
37
|
-
throw new Error(message);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* @description Clean process, when call API in process
|
|
43
|
-
* @param {object} params
|
|
44
|
-
* @private
|
|
45
|
-
*/
|
|
46
|
-
_cleanParams(params) {
|
|
47
|
-
if (_.hasIn(params, 'process')) {
|
|
48
|
-
delete params.process;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* @description Calls to execute a promise or a callback, so we can support promises and callbacks at the same time
|
|
54
|
-
* NOTE: This promise is focused on the process area.
|
|
55
|
-
* @param {object} options
|
|
56
|
-
* - process || domain (optional): if you want to log into the process || Domain
|
|
57
|
-
* - funcName (optional): the name of the function you are calling
|
|
58
|
-
* - params (optional): parameters to log
|
|
59
|
-
* - cb (optional): the callback, if we have one
|
|
60
|
-
* - debug: Show or hide debug
|
|
61
|
-
* @param func: the function to call to execute
|
|
62
|
-
* @return {*}
|
|
63
|
-
*/
|
|
64
|
-
exec(options, func) {
|
|
65
|
-
const self = this;
|
|
66
|
-
|
|
67
|
-
return new Promise(async (resolve, reject) => {
|
|
68
|
-
const {debug, cb, context, funcName, params} = options || {};
|
|
69
|
-
const {success: debugForSuccess, error: debugForError} = debug;
|
|
70
|
-
|
|
71
|
-
let err;
|
|
72
|
-
let retData;
|
|
73
|
-
|
|
74
|
-
// Ensure we remove it, since we do not have it. It can cause circular referenfe on JSON stringify.
|
|
75
|
-
self._cleanParams(params);
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
if (debugForSuccess) {
|
|
79
|
-
self._logger({context, message: `START: ${funcName} executed successfully`, data: params});
|
|
80
|
-
}
|
|
81
|
-
retData = await func();
|
|
82
|
-
} catch (ex) {
|
|
83
|
-
err = ex;
|
|
84
|
-
|
|
85
|
-
} finally {
|
|
86
|
-
|
|
87
|
-
if (retData === null) {
|
|
88
|
-
err = Boom.notFound(`ERROR: ${funcName} cannot find item`);
|
|
89
|
-
if (debugForError) {
|
|
90
|
-
self._logger({context, message: `ERROR: ${funcName} cannot find item`, data: params});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (_.isFunction(cb)) {
|
|
94
|
-
|
|
95
|
-
if (debugForError) {
|
|
96
|
-
self._logger({context, message: `ERROR: ${funcName}`, data: params});
|
|
97
|
-
}
|
|
98
|
-
cb(err, retData);
|
|
99
|
-
}
|
|
100
|
-
if (err) {
|
|
101
|
-
if (debugForError) {
|
|
102
|
-
self._logger({context, message: `ERROR: ${funcName}`, data: params});
|
|
103
|
-
}
|
|
104
|
-
reject(err);
|
|
105
|
-
} else {
|
|
106
|
-
if (debugForSuccess) {
|
|
107
|
-
self._logger({context, message: `END: ${funcName} executed successfully`, data: {params, retData}});
|
|
108
|
-
}
|
|
109
|
-
resolve(retData);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const thePromise = new ThePromise();
|
|
117
|
-
|
|
118
|
-
export default thePromise;
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
import Boom from '@hapi/boom';
|
|
3
|
+
|
|
4
|
+
class ThePromise {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description Logger call api professional
|
|
8
|
+
* @param {object} context Process or Domain
|
|
9
|
+
* @param {string} message Message to log
|
|
10
|
+
* @param {object} data Object to show log
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
_logger({context = null, message, data}) {
|
|
14
|
+
try {
|
|
15
|
+
|
|
16
|
+
if (context) {
|
|
17
|
+
data = _.isObject(data) ? data : {data};
|
|
18
|
+
|
|
19
|
+
const logSystemMager = _.hasIn(context, 'logger')
|
|
20
|
+
&& _.isFunction(context.logger)
|
|
21
|
+
&& _.hasIn(context.logger(), 'trace')
|
|
22
|
+
&& _.isFunction(context.logger().trace);
|
|
23
|
+
|
|
24
|
+
const logMicroservices = _.hasIn(context, 'log')
|
|
25
|
+
&& _.isFunction(context.log)
|
|
26
|
+
&& _.hasIn(context.log(), 'info')
|
|
27
|
+
&& _.isFunction(context.log().info);
|
|
28
|
+
|
|
29
|
+
if (logSystemMager) {
|
|
30
|
+
context.logger().trace(message, data);
|
|
31
|
+
} else if (logMicroservices) {
|
|
32
|
+
context.log().info(message, data);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} catch (ex) {
|
|
36
|
+
const message = _.hasIn(ex, 'message') ? ex.message : `Fail logger action: ${message}`;
|
|
37
|
+
throw new Error(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @description Clean process, when call API in process
|
|
43
|
+
* @param {object} params
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
_cleanParams(params) {
|
|
47
|
+
if (_.hasIn(params, 'process')) {
|
|
48
|
+
delete params.process;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @description Calls to execute a promise or a callback, so we can support promises and callbacks at the same time
|
|
54
|
+
* NOTE: This promise is focused on the process area.
|
|
55
|
+
* @param {object} options
|
|
56
|
+
* - process || domain (optional): if you want to log into the process || Domain
|
|
57
|
+
* - funcName (optional): the name of the function you are calling
|
|
58
|
+
* - params (optional): parameters to log
|
|
59
|
+
* - cb (optional): the callback, if we have one
|
|
60
|
+
* - debug: Show or hide debug
|
|
61
|
+
* @param func: the function to call to execute
|
|
62
|
+
* @return {*}
|
|
63
|
+
*/
|
|
64
|
+
exec(options, func) {
|
|
65
|
+
const self = this;
|
|
66
|
+
|
|
67
|
+
return new Promise(async (resolve, reject) => {
|
|
68
|
+
const {debug, cb, context, funcName, params} = options || {};
|
|
69
|
+
const {success: debugForSuccess, error: debugForError} = debug;
|
|
70
|
+
|
|
71
|
+
let err;
|
|
72
|
+
let retData;
|
|
73
|
+
|
|
74
|
+
// Ensure we remove it, since we do not have it. It can cause circular referenfe on JSON stringify.
|
|
75
|
+
self._cleanParams(params);
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
if (debugForSuccess) {
|
|
79
|
+
self._logger({context, message: `START: ${funcName} executed successfully`, data: params});
|
|
80
|
+
}
|
|
81
|
+
retData = await func();
|
|
82
|
+
} catch (ex) {
|
|
83
|
+
err = ex;
|
|
84
|
+
|
|
85
|
+
} finally {
|
|
86
|
+
|
|
87
|
+
if (retData === null) {
|
|
88
|
+
err = Boom.notFound(`ERROR: ${funcName} cannot find item`);
|
|
89
|
+
if (debugForError) {
|
|
90
|
+
self._logger({context, message: `ERROR: ${funcName} cannot find item`, data: params});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (_.isFunction(cb)) {
|
|
94
|
+
|
|
95
|
+
if (debugForError) {
|
|
96
|
+
self._logger({context, message: `ERROR: ${funcName}`, data: params});
|
|
97
|
+
}
|
|
98
|
+
cb(err, retData);
|
|
99
|
+
}
|
|
100
|
+
if (err) {
|
|
101
|
+
if (debugForError) {
|
|
102
|
+
self._logger({context, message: `ERROR: ${funcName}`, data: params});
|
|
103
|
+
}
|
|
104
|
+
reject(err);
|
|
105
|
+
} else {
|
|
106
|
+
if (debugForSuccess) {
|
|
107
|
+
self._logger({context, message: `END: ${funcName} executed successfully`, data: {params, retData}});
|
|
108
|
+
}
|
|
109
|
+
resolve(retData);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const thePromise = new ThePromise();
|
|
117
|
+
|
|
118
|
+
export default thePromise;
|
package/bundleRollup.js
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
import * as rollup from 'rollup';
|
|
2
|
-
|
|
3
|
-
import nodePolyfills from 'rollup-plugin-node-polyfills';
|
|
4
|
-
import cleanup from 'rollup-plugin-cleanup';
|
|
5
|
-
import {uglify} from "rollup-plugin-uglify";
|
|
6
|
-
|
|
7
|
-
import json from '@rollup/plugin-json';
|
|
8
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
9
|
-
import alias from '@rollup/plugin-alias';
|
|
10
|
-
import {nodeResolve} from '@rollup/plugin-node-resolve';
|
|
11
|
-
|
|
12
|
-
import moment from 'moment';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @description Class to bukld munti file type (CJS and MJS)
|
|
16
|
-
*/
|
|
17
|
-
class BuildRollup {
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @description Alist to change modules to esm for use in frontend
|
|
21
|
-
* @type {({find: string, replacement: string}|{find: string, replacement: string}|{find: string, replacement: string}|{find: string, replacement: string})[]}
|
|
22
|
-
*/
|
|
23
|
-
#aliasList = [
|
|
24
|
-
{
|
|
25
|
-
find: 'lodash',
|
|
26
|
-
replacement: 'lodash-es'
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
find: 'moment',
|
|
30
|
-
replacement: 'dayjs/esm'
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
find: 'axios',
|
|
34
|
-
replacement: 'axios-esm'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
find: 'joi',
|
|
38
|
-
replacement: 'joi/dist/joi-browser.min.js'
|
|
39
|
-
}
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @description Not add in bundle bellow module, install external to use.
|
|
44
|
-
* @type {string[]}
|
|
45
|
-
*/
|
|
46
|
-
#externalPlugins = ['lodash', 'axios', '@hapi/boom', 'joi', 'moment'];
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @description Mount list of plugin backend and frontend
|
|
50
|
-
* @type {{mjs: (*)[], cjs: [*, *, *, *]}}
|
|
51
|
-
*/
|
|
52
|
-
#pluginList = {
|
|
53
|
-
cjs: [
|
|
54
|
-
commonjs(),
|
|
55
|
-
nodePolyfills(),
|
|
56
|
-
json(),
|
|
57
|
-
nodeResolve(),
|
|
58
|
-
],
|
|
59
|
-
|
|
60
|
-
mjs: [
|
|
61
|
-
alias({entries: this.#aliasList}),
|
|
62
|
-
|
|
63
|
-
commonjs(),
|
|
64
|
-
nodePolyfills(),
|
|
65
|
-
json(),
|
|
66
|
-
nodeResolve(),
|
|
67
|
-
cleanup(),
|
|
68
|
-
uglify()
|
|
69
|
-
]
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @description Mount configuration to build
|
|
74
|
-
* @type {{mjs: {output: {file: string, format: string}, entry: {input: string, plugins: *[]}}, cjs: {output: {file: string, format: string}, entry: {input: string, external: [], plugins: (*)[]}}}}
|
|
75
|
-
*/
|
|
76
|
-
#rollupConfig = {
|
|
77
|
-
cjs: {
|
|
78
|
-
entry: {
|
|
79
|
-
input: './index.js',
|
|
80
|
-
external: this.#externalPlugins,
|
|
81
|
-
plugins: this.#pluginList.cjs,
|
|
82
|
-
},
|
|
83
|
-
output: {
|
|
84
|
-
file: 'dist/bundle.cjs',
|
|
85
|
-
format: 'cjs'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
mjs: {
|
|
90
|
-
entry: {
|
|
91
|
-
input: './index.js',
|
|
92
|
-
plugins: this.#pluginList.mjs,
|
|
93
|
-
},
|
|
94
|
-
output: {
|
|
95
|
-
file: 'dist/bundle.mjs',
|
|
96
|
-
format: 'esm'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @see https://rollupjs.org/guide/en/#rolluprollup
|
|
103
|
-
* @description Build all types (CJS backend 'require' | MJS Frontend 'import')
|
|
104
|
-
*/
|
|
105
|
-
async #rollupBuild(config) {
|
|
106
|
-
const self = this;
|
|
107
|
-
|
|
108
|
-
try {
|
|
109
|
-
const bundle = await rollup.rollup(config.entry);
|
|
110
|
-
self.log('Bundle generated');
|
|
111
|
-
|
|
112
|
-
await bundle.write(config.output);
|
|
113
|
-
self.log('Bundle writen');
|
|
114
|
-
|
|
115
|
-
await bundle.close();
|
|
116
|
-
self.log('Bundle finished\n');
|
|
117
|
-
|
|
118
|
-
} catch (ex) {
|
|
119
|
-
throw ex;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* @description Log in terminal process
|
|
125
|
-
* @param {string} text - text to log in terminal
|
|
126
|
-
*/
|
|
127
|
-
log(text, type = 'log') {
|
|
128
|
-
const dateNow = moment().format('DD/MM/YYYY HH:mm:ss');
|
|
129
|
-
console[type](`${dateNow}\t ${text}`);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
async init() {
|
|
133
|
-
const self = this;
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
self.log('Start process to bundle files');
|
|
137
|
-
|
|
138
|
-
for await (const bundleType of Object.keys(self.#rollupConfig)) {
|
|
139
|
-
self.log(`Start process to bundle type ${bundleType}`);
|
|
140
|
-
|
|
141
|
-
const bundleConfig = self.#rollupConfig[bundleType];
|
|
142
|
-
await self.#rollupBuild(bundleConfig);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
self.log('Done! All to bundle generated with success');
|
|
146
|
-
|
|
147
|
-
} catch (ex) {
|
|
148
|
-
throw ex;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// ------------ //
|
|
154
|
-
// START BUNDLE //
|
|
155
|
-
// ------------ //
|
|
156
|
-
|
|
157
|
-
const buildRollup = new BuildRollup();
|
|
158
|
-
buildRollup.init();
|
|
1
|
+
import * as rollup from 'rollup';
|
|
2
|
+
|
|
3
|
+
import nodePolyfills from 'rollup-plugin-node-polyfills';
|
|
4
|
+
import cleanup from 'rollup-plugin-cleanup';
|
|
5
|
+
import {uglify} from "rollup-plugin-uglify";
|
|
6
|
+
|
|
7
|
+
import json from '@rollup/plugin-json';
|
|
8
|
+
import commonjs from '@rollup/plugin-commonjs';
|
|
9
|
+
import alias from '@rollup/plugin-alias';
|
|
10
|
+
import {nodeResolve} from '@rollup/plugin-node-resolve';
|
|
11
|
+
|
|
12
|
+
import moment from 'moment';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @description Class to bukld munti file type (CJS and MJS)
|
|
16
|
+
*/
|
|
17
|
+
class BuildRollup {
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description Alist to change modules to esm for use in frontend
|
|
21
|
+
* @type {({find: string, replacement: string}|{find: string, replacement: string}|{find: string, replacement: string}|{find: string, replacement: string})[]}
|
|
22
|
+
*/
|
|
23
|
+
#aliasList = [
|
|
24
|
+
{
|
|
25
|
+
find: 'lodash',
|
|
26
|
+
replacement: 'lodash-es'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
find: 'moment',
|
|
30
|
+
replacement: 'dayjs/esm'
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
find: 'axios',
|
|
34
|
+
replacement: 'axios-esm'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
find: 'joi',
|
|
38
|
+
replacement: 'joi/dist/joi-browser.min.js'
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @description Not add in bundle bellow module, install external to use.
|
|
44
|
+
* @type {string[]}
|
|
45
|
+
*/
|
|
46
|
+
#externalPlugins = ['lodash', 'axios', '@hapi/boom', 'joi', 'moment'];
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @description Mount list of plugin backend and frontend
|
|
50
|
+
* @type {{mjs: (*)[], cjs: [*, *, *, *]}}
|
|
51
|
+
*/
|
|
52
|
+
#pluginList = {
|
|
53
|
+
cjs: [
|
|
54
|
+
commonjs(),
|
|
55
|
+
nodePolyfills(),
|
|
56
|
+
json(),
|
|
57
|
+
nodeResolve(),
|
|
58
|
+
],
|
|
59
|
+
|
|
60
|
+
mjs: [
|
|
61
|
+
alias({entries: this.#aliasList}),
|
|
62
|
+
|
|
63
|
+
commonjs(),
|
|
64
|
+
nodePolyfills(),
|
|
65
|
+
json(),
|
|
66
|
+
nodeResolve(),
|
|
67
|
+
cleanup(),
|
|
68
|
+
uglify()
|
|
69
|
+
]
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @description Mount configuration to build
|
|
74
|
+
* @type {{mjs: {output: {file: string, format: string}, entry: {input: string, plugins: *[]}}, cjs: {output: {file: string, format: string}, entry: {input: string, external: [], plugins: (*)[]}}}}
|
|
75
|
+
*/
|
|
76
|
+
#rollupConfig = {
|
|
77
|
+
cjs: {
|
|
78
|
+
entry: {
|
|
79
|
+
input: './index.js',
|
|
80
|
+
external: this.#externalPlugins,
|
|
81
|
+
plugins: this.#pluginList.cjs,
|
|
82
|
+
},
|
|
83
|
+
output: {
|
|
84
|
+
file: 'dist/bundle.cjs',
|
|
85
|
+
format: 'cjs'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
mjs: {
|
|
90
|
+
entry: {
|
|
91
|
+
input: './index.js',
|
|
92
|
+
plugins: this.#pluginList.mjs,
|
|
93
|
+
},
|
|
94
|
+
output: {
|
|
95
|
+
file: 'dist/bundle.mjs',
|
|
96
|
+
format: 'esm'
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @see https://rollupjs.org/guide/en/#rolluprollup
|
|
103
|
+
* @description Build all types (CJS backend 'require' | MJS Frontend 'import')
|
|
104
|
+
*/
|
|
105
|
+
async #rollupBuild(config) {
|
|
106
|
+
const self = this;
|
|
107
|
+
|
|
108
|
+
try {
|
|
109
|
+
const bundle = await rollup.rollup(config.entry);
|
|
110
|
+
self.log('Bundle generated');
|
|
111
|
+
|
|
112
|
+
await bundle.write(config.output);
|
|
113
|
+
self.log('Bundle writen');
|
|
114
|
+
|
|
115
|
+
await bundle.close();
|
|
116
|
+
self.log('Bundle finished\n');
|
|
117
|
+
|
|
118
|
+
} catch (ex) {
|
|
119
|
+
throw ex;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @description Log in terminal process
|
|
125
|
+
* @param {string} text - text to log in terminal
|
|
126
|
+
*/
|
|
127
|
+
log(text, type = 'log') {
|
|
128
|
+
const dateNow = moment().format('DD/MM/YYYY HH:mm:ss');
|
|
129
|
+
console[type](`${dateNow}\t ${text}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async init() {
|
|
133
|
+
const self = this;
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
self.log('Start process to bundle files');
|
|
137
|
+
|
|
138
|
+
for await (const bundleType of Object.keys(self.#rollupConfig)) {
|
|
139
|
+
self.log(`Start process to bundle type ${bundleType}`);
|
|
140
|
+
|
|
141
|
+
const bundleConfig = self.#rollupConfig[bundleType];
|
|
142
|
+
await self.#rollupBuild(bundleConfig);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
self.log('Done! All to bundle generated with success');
|
|
146
|
+
|
|
147
|
+
} catch (ex) {
|
|
148
|
+
throw ex;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ------------ //
|
|
154
|
+
// START BUNDLE //
|
|
155
|
+
// ------------ //
|
|
156
|
+
|
|
157
|
+
const buildRollup = new BuildRollup();
|
|
158
|
+
buildRollup.init();
|