@steedos/service-package-registry 2.5.13-beta.1 → 2.5.13-beta.4

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.
@@ -1,10 +1,10 @@
1
1
  Steedos.PackageRegistry = {
2
2
  getNodes: function(){
3
- const projectNodes = Steedos.authRequest('/service/api/~packages-project-server/getProjectNodes', {async: false});
3
+ const projectNodes = Steedos.authRequest('/service/api/@steedos/service-project/getProjectNodes', {async: false});
4
4
  return projectNodes;
5
5
  },
6
6
  getNodesSelect: function(){
7
- const projectNodes = Steedos.authRequest('/service/api/~packages-project-server/getProjectNodes', {async: false});
7
+ const projectNodes = Steedos.authRequest('/service/api/@steedos/service-project/getProjectNodes', {async: false});
8
8
  let selectOptions = '';
9
9
  _.each(projectNodes, function(nodeID){
10
10
  selectOptions = selectOptions + `<option value ="${nodeID}">${nodeID}</option>`
@@ -24,27 +24,42 @@ const appendToPackagesConfig = (packageName, options)=>{
24
24
  }
25
25
  })
26
26
  }
27
- if(changeNamePackage){
28
- //如果是修改package name, 在steedos-package.yml位置保持不变
29
- const newPackages = {};
30
- _.each(packages, (info, key)=>{
31
- if(key === changeNamePackage.module){
32
- delete changeNamePackage.module
33
- newPackages[packageName] = Object.assign(changeNamePackage, options)
34
- }else{
35
- newPackages[key] = info
36
- }
37
- })
38
- packages = newPackages
39
- }else{
27
+ if(options.static){
40
28
  if(!packages[packageName]){
29
+ if(options.enable){
30
+ const packagePath = path.dirname(require.resolve(`${packageName}/package.json`))
31
+ loadPackage(packageName, packagePath);
32
+ }
41
33
  packages[packageName] = Object.assign({
42
- enable: true
34
+ enable: false
43
35
  }, options)
44
36
  }else{
45
37
  packages[packageName] = Object.assign(packages[packageName], options)
46
38
  }
39
+ }else{
40
+ if(changeNamePackage){
41
+ //如果是修改package name, 在steedos-package.yml位置保持不变
42
+ const newPackages = {};
43
+ _.each(packages, (info, key)=>{
44
+ if(key === changeNamePackage.module){
45
+ delete changeNamePackage.module
46
+ newPackages[packageName] = Object.assign(changeNamePackage, options)
47
+ }else{
48
+ newPackages[key] = info
49
+ }
50
+ })
51
+ packages = newPackages
52
+ }else{
53
+ if(!packages[packageName]){
54
+ packages[packageName] = Object.assign({
55
+ enable: true
56
+ }, options)
57
+ }else{
58
+ packages[packageName] = Object.assign(packages[packageName], options)
59
+ }
60
+ }
47
61
  }
62
+
48
63
  let data = yaml.dump(packages);
49
64
  fs.writeFileSync(packagesFilePath, data);
50
65
  }
@@ -250,9 +265,13 @@ const enablePackage = async (packageName)=>{
250
265
  packagePath = path.resolve(process.cwd(), package.path)
251
266
  }
252
267
  }else{
253
- packagePath = path.dirname(require.resolve(`${packageName}/package.json`, {
254
- paths: [path.join(userDir, 'node_modules')]
255
- }))
268
+ if(package && package.static){
269
+ packagePath = path.dirname(require.resolve(`${packageName}/package.json`))
270
+ }else{
271
+ packagePath = path.dirname(require.resolve(`${packageName}/package.json`, {
272
+ paths: [path.join(userDir, 'node_modules')]
273
+ }))
274
+ }
256
275
  }
257
276
  await loadPackage(packageName, packagePath)
258
277
 
@@ -271,6 +290,7 @@ const enablePackage = async (packageName)=>{
271
290
  }
272
291
  appendToPackagesConfig(packageName, package);
273
292
  let packageInfo = Object.assign({}, package, {name: packageName});
293
+ // console.log(`enable packageInfo`, packageInfo)
274
294
  return packageInfo;
275
295
  }
276
296
  const installPackage = async (broker, options)=>{
@@ -32,6 +32,7 @@ const getAllPackages = async ()=>{
32
32
  package.status = '';
33
33
  package.new_version = package.version
34
34
  package.local = package.local
35
+ package.static = package.static
35
36
  delete package.version
36
37
  if(installPackages[package.name]){
37
38
  package.status = installPackages[package.name].enable ? 'enable' : 'disable'
@@ -52,7 +53,8 @@ const getAllPackages = async ()=>{
52
53
  local: package.local,
53
54
  label: package.label || packageName,
54
55
  description: package.description,
55
- metadata: package.metadata
56
+ metadata: package.metadata,
57
+ static: package.static
56
58
  })
57
59
  }
58
60
  })
@@ -10,6 +10,6 @@ readonly: false
10
10
  required: false
11
11
  rows: 2
12
12
  searchable: false
13
- sort_no: 130
13
+ sort_no: 999
14
14
  sortable: false
15
15
  type: textarea
@@ -12,3 +12,4 @@ searchable: true
12
12
  sort_no: 110
13
13
  sortable: true
14
14
  type: text
15
+ visible_on: "{{false}}"
@@ -12,3 +12,4 @@ searchable: true
12
12
  sort_no: 110
13
13
  sortable: true
14
14
  type: text
15
+ visible_on: "{{false}}"
@@ -12,3 +12,4 @@ searchable: true
12
12
  sort_no: 100
13
13
  sortable: true
14
14
  type: text
15
+ visible_on: "{{false}}"
@@ -0,0 +1,4 @@
1
+ name: static
2
+ type: boolean
3
+ label: 静态(不支持卸载、升级)
4
+ visible_on: "{{false}}"
@@ -15,7 +15,7 @@ router.get('/api/nodes/install', core.requireAuthentication, async function (req
15
15
  try {
16
16
  const { module, version, label, description, nodeID} = body || {};
17
17
  let broker = schema.broker;
18
- const result = await broker.call(`~packages-project-server.installPackage`, {
18
+ const result = await broker.call(`@steedos/service-project.installPackage`, {
19
19
  module, version, label, description
20
20
  },{
21
21
  nodeID: nodeID
@@ -40,7 +40,7 @@ router.post('/api/nodes/uninstall', core.requireAuthentication, async function (
40
40
  await registry.uninstallModule(body.module)
41
41
  const { module, nodeID} = body || {};
42
42
  let broker = schema.broker;
43
- const result = await broker.call(`~packages-project-server.uninstallPackage`, {
43
+ const result = await broker.call(`@steedos/service-project.uninstallPackage`, {
44
44
  module
45
45
  },{
46
46
  nodeID: nodeID
@@ -62,7 +62,7 @@ router.post('/api/nodes/reload', core.requireAuthentication, async function (req
62
62
  try {
63
63
  const { module, nodeID} = body || {};
64
64
  let broker = schema.broker;
65
- const result = await broker.call(`~packages-project-server.reloadPackage`, {
65
+ const result = await broker.call(`@steedos/service-project.reloadPackage`, {
66
66
  module
67
67
  },{
68
68
  nodeID: nodeID
@@ -84,7 +84,7 @@ router.post('/api/nodes/disable', core.requireAuthentication, async function (re
84
84
  try {
85
85
  const { module, nodeID} = body || {};
86
86
  let broker = schema.broker;
87
- const result = await broker.call(`~packages-project-server.disablePackage`, {
87
+ const result = await broker.call(`@steedos/service-project.disablePackage`, {
88
88
  module
89
89
  },{
90
90
  nodeID: nodeID
@@ -106,7 +106,7 @@ router.post('/api/nodes/enable', core.requireAuthentication, async function (req
106
106
  try {
107
107
  const { module, nodeID} = body || {};
108
108
  let broker = schema.broker;
109
- const result = await broker.call(`~packages-project-server.enablePackage`, {
109
+ const result = await broker.call(`@steedos/service-project.enablePackage`, {
110
110
  module
111
111
  },{
112
112
  nodeID: nodeID
@@ -132,7 +132,7 @@ router.get('/api/nodes/versions', core.requireAuthentication, async function (re
132
132
  try {
133
133
 
134
134
  let broker = schema.broker;
135
- const result = await broker.call(`~packages-project-server.getPackageVersions`, {
135
+ const result = await broker.call(`@steedos/service-project.getPackageVersions`, {
136
136
  module
137
137
  })
138
138
  res.status(200).send(result); //TODO 完善返回信息
@@ -152,7 +152,7 @@ router.post('/api/nodes/upgrade', core.requireAuthentication, async function (re
152
152
  try {
153
153
  const { module, version} = body || {};
154
154
  let broker = schema.broker;
155
- const result = await broker.call(`~packages-project-server.upgradePackage`, {
155
+ const result = await broker.call(`@steedos/service-project.upgradePackage`, {
156
156
  module, version
157
157
  })
158
158
  res.status(200).send(result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steedos/service-package-registry",
3
- "version": "2.5.13-beta.1",
3
+ "version": "2.5.13-beta.4",
4
4
  "description": "",
5
5
  "main": "package.service.js",
6
6
  "scripts": {
@@ -9,11 +9,11 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
- "@steedos/auth": "2.5.13-beta.1",
13
- "@steedos/core": "2.5.13-beta.1",
14
- "@steedos/metadata-core": "2.5.13-beta.1",
15
- "@steedos/objectql": "2.5.13-beta.1",
16
- "@steedos/service-package-loader": "2.5.13-beta.1",
12
+ "@steedos/auth": "2.5.13-beta.4",
13
+ "@steedos/core": "2.5.13-beta.4",
14
+ "@steedos/metadata-core": "2.5.13-beta.4",
15
+ "@steedos/objectql": "2.5.13-beta.4",
16
+ "@steedos/service-package-loader": "2.5.13-beta.4",
17
17
  "fs-extra": "8.1.0",
18
18
  "i18next": "20.3.2",
19
19
  "json-stringify-safe": "5.0.1",
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "d2a737e3a975af170b25495dcb0d8bdd668a2da3"
34
+ "gitHead": "7b5076de3ee46290073e9b12772b297e51cd8e71"
35
35
  }
@@ -25,7 +25,7 @@ const AUTH_TYPE = 'Bearer';
25
25
  * 软件包服务启动后也需要抛出事件。
26
26
  */
27
27
  module.exports = {
28
- name: '~packages-project-server',
28
+ name: '@steedos/service-project',
29
29
  namespace: "steedos",
30
30
  /**
31
31
  * Settings
@@ -149,7 +149,10 @@ module.exports = {
149
149
  enablePackage:{
150
150
  async handler(ctx) {
151
151
  const { module } = ctx.params
152
- const packageConfig = await loader.enablePackage(module);
152
+ let packageConfig = await loader.enablePackage(module);
153
+ if(packageConfig.static){
154
+ packageConfig = Object.assign({}, packageConfig, this.getStaticPackageInfo(packageConfig.name))
155
+ }
153
156
  const metadata = await loader.getPackageMetadata(util.getPackageRelativePath(process.cwd(), packageConfig.path));
154
157
  await ctx.broker.call(`@steedos/service-packages.install`, {
155
158
  serviceInfo: Object.assign({}, packageConfig, {
@@ -275,7 +278,13 @@ module.exports = {
275
278
  async handler(ctx) {
276
279
  return await this.initialPackages();
277
280
  }
281
+ },
282
+ addPackages: {
283
+ async handler(ctx) {
284
+ return await this.addPackages(ctx);
285
+ }
278
286
  }
287
+
279
288
  },
280
289
 
281
290
  /**
@@ -544,6 +553,68 @@ module.exports = {
544
553
  }
545
554
  }
546
555
  }
556
+ },
557
+ addPackages: {
558
+ async handler(ctx){
559
+ const { packages } = ctx.params;
560
+ for(const _package of packages){
561
+ let name = null;
562
+ let options = null;
563
+ if(_.isString(_package)){
564
+ name = _package;
565
+ options = {}
566
+ }else{
567
+ const { name: _name, ..._options} = _package;
568
+ name = _name;
569
+ options = _options;
570
+ }
571
+ if(!_.has(options, 'static')){
572
+ options.static = true
573
+ }
574
+ loader.appendToPackagesConfig(name, options)
575
+ await this.installPackagesSyncToMetaData(name);
576
+ }
577
+ }
578
+ },
579
+ getStaticPackageInfo: {
580
+ handler(packageName){
581
+ const _path = path.dirname(require.resolve(`${packageName}/package.json`));
582
+ const packageJson = require(`${_path}/package.json`);
583
+ return {
584
+ path: _path,
585
+ version: packageJson.version,
586
+ description: packageJson.description
587
+ }
588
+ }
589
+ },
590
+ installPackagesSyncToMetaData:{
591
+ async handler(packageName){
592
+ //注册本地已安装的steedos packages
593
+ const installPackages = loader.loadPackagesConfig();
594
+ for (const name in installPackages) {
595
+ if (Object.hasOwnProperty.call(installPackages, name) && (packageName && packageName === name)) {
596
+ let _packageInfo = installPackages[name];
597
+ if(_packageInfo.static){
598
+ _packageInfo = Object.assign({}, _packageInfo, this.getStaticPackageInfo(name))
599
+ }
600
+ const metadata = await loader.getPackageMetadata(_packageInfo.path);
601
+ await this.broker.call(`@steedos/service-packages.install`, {
602
+ serviceInfo: {
603
+ name: name,
604
+ nodeID: this.broker.nodeID,
605
+ instanceID: this.broker.instanceID,
606
+ path: _packageInfo.path,
607
+ local: _packageInfo.local,
608
+ enable: _packageInfo.enable,
609
+ version: _packageInfo.version,
610
+ description: _packageInfo.description,
611
+ metadata: metadata,
612
+ static: _packageInfo.static
613
+ }
614
+ })
615
+ }
616
+ }
617
+ }
547
618
  }
548
619
  },
549
620
 
@@ -606,27 +677,7 @@ module.exports = {
606
677
  })
607
678
  await loader.loadPackages();
608
679
 
609
- //注册本地已安装的steedos packages
610
- const installPackages = loader.loadPackagesConfig();
611
- for (const name in installPackages) {
612
- if (Object.hasOwnProperty.call(installPackages, name)) {
613
- const _packageInfo = installPackages[name];
614
- const metadata = await loader.getPackageMetadata(_packageInfo.path);
615
- await this.broker.call(`@steedos/service-packages.install`, {
616
- serviceInfo: {
617
- name: name,
618
- nodeID: this.broker.nodeID,
619
- instanceID: this.broker.instanceID,
620
- path: _packageInfo.path,
621
- local: _packageInfo.local,
622
- enable: _packageInfo.enable,
623
- version: _packageInfo.version,
624
- description: _packageInfo.description,
625
- metadata: metadata
626
- }
627
- })
628
- }
629
- }
680
+ await this.installPackagesSyncToMetaData()
630
681
 
631
682
  },
632
683