@steedos/service-package-loader 2.5.20-beta.8 → 2.5.20
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/index.js +18 -12
- package/package.json +7 -6
package/index.js
CHANGED
|
@@ -10,7 +10,7 @@ const _ = require('lodash');
|
|
|
10
10
|
const fs = require("fs");
|
|
11
11
|
const metaDataCore = require('@steedos/metadata-core');
|
|
12
12
|
const { registerMetadataConfigs, loadStandardMetadata, loadRouters } = require('@steedos/metadata-registrar');
|
|
13
|
-
|
|
13
|
+
const moment = require('moment');
|
|
14
14
|
const objectMixin = require('@steedos/service-object-mixin')
|
|
15
15
|
|
|
16
16
|
const loadFlowFile = new metaDataCore.LoadFlowFile();
|
|
@@ -18,7 +18,7 @@ const loadFlowFile = new metaDataCore.LoadFlowFile();
|
|
|
18
18
|
const getPackageYmlData = (packagePath)=>{
|
|
19
19
|
let packageYmlData = {};
|
|
20
20
|
if(fs.existsSync(path.join(packagePath, 'package.service.yml'))){
|
|
21
|
-
packageYmlData = metaDataCore.loadFile(path.join(packagePath, 'package.service.yml'));
|
|
21
|
+
packageYmlData = metaDataCore.loadFile(path.join(packagePath, 'package.service.yml')) || {};
|
|
22
22
|
}
|
|
23
23
|
if(fs.existsSync(path.join(packagePath, 'README.md'))){
|
|
24
24
|
packageYmlData.readme = metaDataCore.loadFile(path.join(packagePath, 'README.md'));
|
|
@@ -77,9 +77,10 @@ module.exports = {
|
|
|
77
77
|
"space.initialized": {
|
|
78
78
|
async handler(ctx) {
|
|
79
79
|
const spaceDoc = ctx.params
|
|
80
|
+
const spaceId = spaceDoc._id
|
|
80
81
|
// 扫描main/default/data文件夹
|
|
81
|
-
await this.importData(path.join(this.settings.packageInfo.path, 'main', 'default', 'data'), false,
|
|
82
|
-
await this.loadDataOnServiceStarted();
|
|
82
|
+
await this.importData(path.join(this.settings.packageInfo.path, 'main', 'default', 'data'), false, spaceId);
|
|
83
|
+
await this.loadDataOnServiceStarted(spaceId);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
},
|
|
@@ -121,24 +122,28 @@ module.exports = {
|
|
|
121
122
|
this.broker.logger.warn(`The router.js file has been deprecated. ${filePath}`);
|
|
122
123
|
}
|
|
123
124
|
},
|
|
124
|
-
sendPackageFlowToDb: async function(packagePath, name) {
|
|
125
|
+
sendPackageFlowToDb: async function(packagePath, name, spaceId) {
|
|
125
126
|
const flows = loadFlowFile.load(path.join(packagePath, '**'));
|
|
126
127
|
for (const apiName in flows) {
|
|
127
128
|
const flow = flows[apiName];
|
|
128
129
|
const flowFilePath = flow.__filename;
|
|
129
130
|
delete flow.__filename;
|
|
130
131
|
try {
|
|
131
|
-
await this.importFlow(flow, name);
|
|
132
|
+
await this.importFlow(flow, name, spaceId);
|
|
132
133
|
} catch (error) {
|
|
133
134
|
console.error(`importFlow error`, flowFilePath, error)
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
},
|
|
137
138
|
|
|
138
|
-
importFlow: async function(flow, name) {
|
|
139
|
-
return await this.broker.call('steedos-server.importFlow', {flow, name});
|
|
139
|
+
importFlow: async function(flow, name, spaceId) {
|
|
140
|
+
return await this.broker.call('steedos-server.importFlow', {flow, name, spaceId});
|
|
140
141
|
},
|
|
141
|
-
|
|
142
|
+
/**
|
|
143
|
+
* @param {string} spaceId 非必传
|
|
144
|
+
* @returns
|
|
145
|
+
*/
|
|
146
|
+
loadDataOnServiceStarted: async function(spaceId){
|
|
142
147
|
let packageInfo = this.settings.packageInfo;
|
|
143
148
|
if (!packageInfo) {
|
|
144
149
|
return;
|
|
@@ -147,7 +152,7 @@ module.exports = {
|
|
|
147
152
|
|
|
148
153
|
this.loadPackagePublicFiles(_path);
|
|
149
154
|
if(_path){
|
|
150
|
-
this.sendPackageFlowToDb(_path)
|
|
155
|
+
this.sendPackageFlowToDb(_path, null, spaceId)
|
|
151
156
|
processLoader.sendPackageProcessToDb(_path);
|
|
152
157
|
}
|
|
153
158
|
},
|
|
@@ -253,7 +258,7 @@ module.exports = {
|
|
|
253
258
|
}
|
|
254
259
|
}
|
|
255
260
|
|
|
256
|
-
|
|
261
|
+
const startTime = moment();
|
|
257
262
|
let packageInfo = this.settings.packageInfo;
|
|
258
263
|
if (!packageInfo) {
|
|
259
264
|
return;
|
|
@@ -288,7 +293,8 @@ module.exports = {
|
|
|
288
293
|
|
|
289
294
|
// await this.loadPackagePublicFiles(_path);
|
|
290
295
|
this.started = true;
|
|
291
|
-
|
|
296
|
+
const endTime = moment();
|
|
297
|
+
console.log(`service ${this.name} started:`, `${endTime.diff(startTime, 'seconds', true)}s`);
|
|
292
298
|
if(this.afterStart){
|
|
293
299
|
try {
|
|
294
300
|
await this.afterStart();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/service-package-loader",
|
|
3
|
-
"version": "2.5.20
|
|
3
|
+
"version": "2.5.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,13 +10,14 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@steedos/metadata-core": "2.5.20
|
|
14
|
-
"@steedos/metadata-registrar": "2.5.20
|
|
15
|
-
"@steedos/router": "2.5.20
|
|
16
|
-
"@steedos/service-object-mixin": "2.5.20
|
|
13
|
+
"@steedos/metadata-core": "2.5.20",
|
|
14
|
+
"@steedos/metadata-registrar": "2.5.20",
|
|
15
|
+
"@steedos/router": "2.5.20",
|
|
16
|
+
"@steedos/service-object-mixin": "2.5.20",
|
|
17
17
|
"clone": "^2.1.2",
|
|
18
18
|
"csvtojson": "~2.0.10",
|
|
19
19
|
"moleculer": "^0.14.25",
|
|
20
|
+
"moment": "^2.24.0",
|
|
20
21
|
"node-xlsx": "^0.16.1",
|
|
21
22
|
"underscore": "^1.12.0"
|
|
22
23
|
},
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"publishConfig": {
|
|
28
29
|
"access": "public"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "1e2c9a88c8eeddc492481195d2d8c5e3519680e8"
|
|
31
32
|
}
|