@servable/tools 1.6.0 → 1.6.2

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "source": "src/index.js",
5
5
  "main": "src/index.js",
6
- "version": "1.6.0",
6
+ "version": "1.6.2",
7
7
  "description": "Servable tools is a utility that builds a protocol's manifest and documents it.",
8
8
  "author": "Servable Community",
9
9
  "license": "ISC",
@@ -316,6 +316,20 @@ export default class ProtocolLoaderV1_0_0 extends BaseClass {
316
316
  return this._importJSDefault({ path, })
317
317
  }
318
318
 
319
+ async beforeEnd() {
320
+ const cacheKey = 'beforeEnd'
321
+ if (this._valueInCache(cacheKey)) {
322
+ return this._valueInCache(cacheKey)
323
+ }
324
+
325
+ const path = `${this.path}/beforeEnd/index.js`
326
+ if (!(await checkFileExists(path))) {
327
+ return null
328
+ }
329
+
330
+ return this._importJSDefault({ path, })
331
+ }
332
+
319
333
  configFolder() {
320
334
  return `${this.path}/config`
321
335
  }
@@ -301,6 +301,11 @@ export default class ProtocolLoaderV1_1_0 extends BaseClass {
301
301
  return main ? main.beforeInit : null
302
302
  }
303
303
 
304
+ async beforeEnd() {
305
+ const main = await this.main()
306
+ return main ? main.beforeEnd : null
307
+ }
308
+
304
309
  async main() {
305
310
 
306
311
  const path = `${this.path}/main.js`
@@ -32,8 +32,8 @@ const perform = async ({
32
32
  let adaptedClassesStructs = []
33
33
  let classesProtocols = []
34
34
 
35
- await Promise.all(classesSchemas.map(async classSchema => {
36
- // const classSchema = classesSchemas[i]
35
+ for (var i in classesSchemas) {
36
+ const classSchema = classesSchemas[i]
37
37
  const adaptedClassStruct = await classStruct({
38
38
  protocol,
39
39
  classSchema,
@@ -47,7 +47,7 @@ const perform = async ({
47
47
 
48
48
  let { protocolsPayloads } = adaptedClassStruct
49
49
  if (!protocolsPayloads || !protocolsPayloads.length) {
50
- return
50
+ continue
51
51
  }
52
52
 
53
53
  protocolsPayloads = protocolsPayloads.filter(a => (a && a.id !== protocol.id))
@@ -68,7 +68,7 @@ const perform = async ({
68
68
  extractProtocol: perform
69
69
  })
70
70
  classesProtocols = classesProtocols.concat(classProtocols)
71
- }))
71
+ }
72
72
 
73
73
  await updateProtocolsExcerpt({ adaptedClassesStructs })
74
74
  let ownClasses = adaptedClassesStructs.map(i => i.classSchema).filter(a => a)
@@ -0,0 +1,119 @@
1
+ import classStruct from './classStruct/index.js'
2
+ import _ from 'underscore'
3
+ import extractClassesProtocol from './extractClassesProtocol.js'
4
+
5
+ const perform = async ({
6
+ protocolFactory,
7
+ protocol,
8
+ updateProtocolsExcerpt,
9
+ instancesPathId = []
10
+ }) => {
11
+
12
+ const defaultResult = [
13
+ protocol
14
+ ]
15
+
16
+ //#TODO: protocol.loader
17
+ if (!(await protocol.loader.isValid())) {
18
+ console.log('protocol not valid', protocol.id, protocol.loader.path)
19
+ return defaultResult
20
+ }
21
+
22
+ //#TODO: protocol.loader
23
+ const classesSchemas = await protocol.loader.classesSchemas()
24
+ if (!classesSchemas) {
25
+ return defaultResult
26
+ }
27
+
28
+ if (protocol.id === 'app') {
29
+ await Servable.engine.formatAppClassesSchemas({ classesSchemas })
30
+ }
31
+
32
+ let adaptedClassesStructs = []
33
+ let classesProtocols = []
34
+
35
+ await Promise.all(classesSchemas.map(async classSchema => {
36
+ // const classSchema = classesSchemas[i]
37
+ const adaptedClassStruct = await classStruct({
38
+ protocol,
39
+ classSchema,
40
+ protocolFactory,
41
+ instancesPathId: [
42
+ ...instancesPathId,
43
+ { type: 'class', value: { className: classSchema.className } }
44
+ ]
45
+ })
46
+ adaptedClassesStructs = adaptedClassesStructs.concat(adaptedClassStruct)
47
+
48
+ let { protocolsPayloads } = adaptedClassStruct
49
+ if (!protocolsPayloads || !protocolsPayloads.length) {
50
+ return
51
+ }
52
+
53
+ protocolsPayloads = protocolsPayloads.filter(a => (a && a.id !== protocol.id))
54
+ //#TODO Move from uniq to cleanprotocols
55
+ protocolsPayloads = _.uniq(protocolsPayloads, a => a.id)
56
+
57
+ const classProtocols = await extractClassesProtocol({
58
+ protocolsPayloads,
59
+ protocolFactory,
60
+ updateProtocolsExcerpt,
61
+ instancesPathId: [
62
+ ...instancesPathId,
63
+ {
64
+ type: 'class',
65
+ value: { className: classSchema.className }
66
+ }
67
+ ],
68
+ extractProtocol: perform
69
+ })
70
+ classesProtocols = classesProtocols.concat(classProtocols)
71
+ }))
72
+
73
+ await updateProtocolsExcerpt({ adaptedClassesStructs })
74
+ let ownClasses = adaptedClassesStructs.map(i => i.classSchema).filter(a => a)
75
+ let jsClasses = adaptedClassesStructs.map(i => i._class).filter(a => a)
76
+
77
+
78
+ classesProtocols = _.uniq(classesProtocols, a => a.id)
79
+ if (!classesProtocols.length) {
80
+ //#TODO: protocol.schema
81
+ protocol.schema = {
82
+ ...protocol.schema,
83
+ classes: {
84
+ managed: ownClasses,
85
+ all: ownClasses
86
+ },
87
+ jsClasses
88
+ }
89
+ return [protocol]
90
+ }
91
+
92
+ //#TODO: protocol.schema
93
+ let all = [...ownClasses]
94
+ classesProtocols.forEach(element => {
95
+ const { classes: { managed: _own = [], all: _all = [] } = {} } = element.schema
96
+ all = [...all, ..._all]
97
+ all = _.uniq(all, 'className')
98
+ })
99
+
100
+ //#TODO: protocol.schema
101
+ protocol.schema = {
102
+ ...protocol.schema,
103
+ classes: {
104
+ managed: ownClasses,
105
+ all
106
+ },
107
+ jsClasses
108
+ }
109
+
110
+ protocol.extractionStatus = 2
111
+
112
+ return [
113
+ protocol,
114
+ ...classesProtocols
115
+ ]
116
+ }
117
+
118
+ export default perform
119
+