@voxgig/model 2.3.1 → 3.1.0
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/dist/lib/build.d.ts +9 -32
- package/dist/lib/build.js +36 -11
- package/dist/lib/build.js.map +1 -1
- package/dist/lib/builder/local.d.ts +1 -1
- package/dist/lib/builder/local.js +62 -30
- package/dist/lib/builder/local.js.map +1 -1
- package/dist/lib/builder/model.d.ts +1 -1
- package/dist/lib/builder/model.js +5 -4
- package/dist/lib/builder/model.js.map +1 -1
- package/dist/lib/config.d.ts +2 -2
- package/dist/lib/config.js +1 -6
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/types.d.ts +48 -0
- package/dist/lib/types.js +3 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/watch.d.ts +3 -2
- package/dist/lib/watch.js +24 -17
- package/dist/lib/watch.js.map +1 -1
- package/dist/model.d.ts +2 -2
- package/dist/model.js +40 -40
- package/dist/model.js.map +1 -1
- package/lib/build.ts +62 -51
- package/lib/builder/local.ts +74 -33
- package/lib/builder/model.ts +8 -6
- package/lib/config.ts +2 -13
- package/lib/types.ts +67 -0
- package/lib/watch.ts +36 -22
- package/model.ts +50 -52
- package/package.json +3 -3
package/lib/watch.ts
CHANGED
|
@@ -3,17 +3,24 @@
|
|
|
3
3
|
import Path from 'node:path'
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import { Build, BuildResult } from './
|
|
6
|
+
import type { Build, BuildResult } from './types'
|
|
7
|
+
|
|
8
|
+
import { makeBuild } from './build'
|
|
7
9
|
import { FSWatcher } from 'chokidar'
|
|
8
10
|
|
|
9
11
|
import { readFile } from 'fs/promises'
|
|
10
12
|
|
|
11
13
|
|
|
14
|
+
const print = console.log
|
|
15
|
+
const warn = console.warn
|
|
16
|
+
|
|
17
|
+
|
|
12
18
|
class Watch {
|
|
13
19
|
fsw: FSWatcher
|
|
14
20
|
spec: any
|
|
15
21
|
last?: BuildResult
|
|
16
22
|
last_change_time: number
|
|
23
|
+
build: Build | undefined
|
|
17
24
|
|
|
18
25
|
constructor(spec: any) {
|
|
19
26
|
this.spec = spec
|
|
@@ -22,9 +29,14 @@ class Watch {
|
|
|
22
29
|
|
|
23
30
|
const run = this.run.bind(this)
|
|
24
31
|
|
|
25
|
-
this.fsw.on('change', () => {
|
|
32
|
+
this.fsw.on('change', (args: any[]) => {
|
|
33
|
+
// TODO: needs a much more robust queue that checks for dups,
|
|
34
|
+
// otherwise BuildContext state will have concurrency corruptions
|
|
26
35
|
// Avoid rebuilding when, for example, TS rewrites all files in dist
|
|
27
|
-
|
|
36
|
+
const dorun = 1111 < Date.now() - this.last_change_time
|
|
37
|
+
// console.log('CHANGE', dorun, this.last_change_time, args)
|
|
38
|
+
|
|
39
|
+
if (dorun) {
|
|
28
40
|
run()
|
|
29
41
|
}
|
|
30
42
|
})
|
|
@@ -35,14 +47,11 @@ class Watch {
|
|
|
35
47
|
if (!Path.isAbsolute(file)) {
|
|
36
48
|
file = Path.join(this.spec.require, file)
|
|
37
49
|
}
|
|
38
|
-
// console.log('WATCH ADD', file)
|
|
39
50
|
this.fsw.add(file)
|
|
40
51
|
}
|
|
41
52
|
|
|
42
53
|
|
|
43
54
|
update(br: BuildResult) {
|
|
44
|
-
// console.log('BUILD RESULT', br)
|
|
45
|
-
|
|
46
55
|
let build = (br.build as Build)
|
|
47
56
|
|
|
48
57
|
let files: string[] =
|
|
@@ -62,33 +71,34 @@ class Watch {
|
|
|
62
71
|
}
|
|
63
72
|
})
|
|
64
73
|
|
|
65
|
-
// setTimeout(() => {
|
|
66
|
-
// console.log('WATCH', this.fsw.getWatched())
|
|
67
|
-
// }, 100)
|
|
68
|
-
|
|
69
74
|
}
|
|
70
75
|
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
// Returns first BuildResult
|
|
78
|
+
async start(): Promise<BuildResult> {
|
|
79
|
+
return await this.run(false)
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
|
|
77
|
-
async run(once?: boolean) {
|
|
83
|
+
async run(once?: boolean): Promise<BuildResult> {
|
|
78
84
|
this.last_change_time = Date.now()
|
|
79
|
-
|
|
85
|
+
print('\n@voxgig/model', new Date(this.last_change_time))
|
|
80
86
|
|
|
81
87
|
// TODO: build spec should not have src!
|
|
82
88
|
let src = (await readFile(this.spec.path)).toString()
|
|
83
89
|
this.spec.src = src
|
|
84
90
|
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
this.build = this.build || makeBuild(this.spec)
|
|
92
|
+
|
|
93
|
+
// TODO: better way to do this?
|
|
94
|
+
this.build.src = src
|
|
95
|
+
|
|
96
|
+
let br: BuildResult = await this.build.run()
|
|
87
97
|
|
|
88
|
-
|
|
98
|
+
print('\nFILES:\n' + this.descDeps((br as any).build.root.deps) + '\n')
|
|
89
99
|
|
|
90
100
|
if (br.ok) {
|
|
91
|
-
|
|
101
|
+
print('TOP:', Object.keys(br?.build?.model).join(', '), '\n')
|
|
92
102
|
|
|
93
103
|
if (!once) {
|
|
94
104
|
// There may be new files.
|
|
@@ -96,7 +106,7 @@ class Watch {
|
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
108
|
else {
|
|
99
|
-
|
|
109
|
+
warn('MODEL ERRORS: ' + br.err?.length)
|
|
100
110
|
this.handleErrors(br)
|
|
101
111
|
}
|
|
102
112
|
|
|
@@ -115,19 +125,23 @@ class Watch {
|
|
|
115
125
|
if (br.err) {
|
|
116
126
|
for (let be of br.err) {
|
|
117
127
|
if (be.msg) {
|
|
118
|
-
|
|
128
|
+
warn(be.msg)
|
|
119
129
|
}
|
|
120
130
|
else if (be.message) {
|
|
121
|
-
|
|
131
|
+
warn(be.message)
|
|
122
132
|
}
|
|
123
133
|
else {
|
|
124
|
-
|
|
134
|
+
warn(be)
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
137
|
}
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
descDeps(deps: Record<string, Record<string, { tar: string }>>) {
|
|
141
|
+
if (null == deps) {
|
|
142
|
+
return ''
|
|
143
|
+
}
|
|
144
|
+
|
|
131
145
|
let desc = []
|
|
132
146
|
for (let entryPath of Object.keys(deps)) {
|
|
133
147
|
desc.push(' ' + entryPath)
|
package/model.ts
CHANGED
|
@@ -3,23 +3,16 @@
|
|
|
3
3
|
// TODO: remove need for this
|
|
4
4
|
import Fs from 'fs'
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
import type { Build, BuildResult, BuildAction, BuildContext, Spec } from './lib/types'
|
|
8
|
+
|
|
9
|
+
|
|
6
10
|
import { Config } from './lib/config'
|
|
7
|
-
import { Build, BuildAction, BuildResult, Spec } from './lib/build'
|
|
8
11
|
import { Watch } from './lib/watch'
|
|
9
12
|
|
|
10
13
|
import { model_builder } from './lib/builder/model'
|
|
11
14
|
import { local_builder } from './lib/builder/local'
|
|
12
15
|
|
|
13
|
-
import {
|
|
14
|
-
dive,
|
|
15
|
-
joins,
|
|
16
|
-
get,
|
|
17
|
-
pinify,
|
|
18
|
-
camelify,
|
|
19
|
-
} from '@voxgig/util'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const intern = makeIntern()
|
|
23
16
|
|
|
24
17
|
class Model {
|
|
25
18
|
config: Config
|
|
@@ -30,33 +23,38 @@ class Model {
|
|
|
30
23
|
|
|
31
24
|
|
|
32
25
|
constructor(spec: Spec) {
|
|
26
|
+
const self = this
|
|
33
27
|
|
|
34
28
|
// Config is a special Watch to handle model config.
|
|
35
|
-
this.config =
|
|
29
|
+
this.config = makeConfig(spec, {
|
|
36
30
|
path: '/',
|
|
37
|
-
build: async (build: Build)
|
|
38
|
-
|
|
31
|
+
build: async function trigger_model(build: Build, ctx: BuildContext) {
|
|
32
|
+
if ('post' !== ctx.step) {
|
|
33
|
+
return { ok: true }
|
|
34
|
+
}
|
|
39
35
|
|
|
40
36
|
let res
|
|
41
37
|
|
|
42
|
-
|
|
38
|
+
// console.log('TRIGGER', build.id, self.trigger_model, ctx)
|
|
39
|
+
// console.log(new Error().stack)
|
|
40
|
+
|
|
41
|
+
if (self.trigger_model) {
|
|
43
42
|
|
|
44
43
|
// TODO: fix!!!
|
|
45
|
-
|
|
44
|
+
self.build.use.config.watch.last.build = build
|
|
46
45
|
|
|
47
|
-
res =
|
|
46
|
+
res = self.watch.run(true)
|
|
48
47
|
}
|
|
49
48
|
else {
|
|
50
|
-
|
|
49
|
+
self.trigger_model = true
|
|
51
50
|
res = { ok: true }
|
|
52
51
|
}
|
|
53
52
|
|
|
54
|
-
const watchmap = build.model
|
|
55
|
-
// console.log('WATCHMAP', watchmap)
|
|
53
|
+
const watchmap = build.model?.sys?.model?.watch
|
|
56
54
|
|
|
57
55
|
if (watchmap) {
|
|
58
56
|
Object.keys(watchmap).map((file: string) => {
|
|
59
|
-
|
|
57
|
+
self.watch.add(file)
|
|
60
58
|
})
|
|
61
59
|
}
|
|
62
60
|
|
|
@@ -70,7 +68,7 @@ class Model {
|
|
|
70
68
|
src: spec.src,
|
|
71
69
|
path: spec.path,
|
|
72
70
|
base: spec.base,
|
|
73
|
-
use: { config:
|
|
71
|
+
use: { config: self.config },
|
|
74
72
|
res: [
|
|
75
73
|
{
|
|
76
74
|
path: '/',
|
|
@@ -85,60 +83,60 @@ class Model {
|
|
|
85
83
|
}
|
|
86
84
|
|
|
87
85
|
|
|
88
|
-
this.watch = new Watch(
|
|
86
|
+
this.watch = new Watch(self.build)
|
|
89
87
|
}
|
|
90
88
|
|
|
89
|
+
|
|
91
90
|
async run(): Promise<BuildResult> {
|
|
92
91
|
this.trigger_model = false
|
|
93
|
-
|
|
92
|
+
const br = await this.config.run()
|
|
94
93
|
return br.ok ? this.watch.run(true) : br
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
async start() {
|
|
98
|
-
this.trigger_model = false
|
|
99
|
-
await this.config.start()
|
|
100
96
|
|
|
101
|
-
|
|
97
|
+
async start(): Promise<BuildResult> {
|
|
98
|
+
this.trigger_model = false
|
|
99
|
+
const br = await this.config.start()
|
|
100
|
+
return br.ok ? this.watch.start() : br
|
|
102
101
|
}
|
|
103
102
|
|
|
103
|
+
|
|
104
104
|
async stop() {
|
|
105
105
|
return this.watch.stop()
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
|
|
110
|
-
function
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
let cbase = spec.base + '/.model-config'
|
|
114
|
-
let cpath = cbase + '/model-config.jsonic'
|
|
115
|
-
|
|
116
|
-
// Build should load file
|
|
117
|
-
let src = Fs.readFileSync(cpath).toString()
|
|
110
|
+
function makeConfig(spec: Spec, trigger_model_build: BuildAction) {
|
|
111
|
+
let cbase = spec.base + '/.model-config'
|
|
112
|
+
let cpath = cbase + '/model-config.jsonic'
|
|
118
113
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
path: cpath,
|
|
122
|
-
base: cbase,
|
|
123
|
-
res: [
|
|
114
|
+
// Build should load file
|
|
115
|
+
let src = Fs.readFileSync(cpath).toString()
|
|
124
116
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
117
|
+
let cspec: Spec = {
|
|
118
|
+
src: src,
|
|
119
|
+
path: cpath,
|
|
120
|
+
base: cbase,
|
|
121
|
+
res: [
|
|
130
122
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
123
|
+
// Generate full config model and save as a file.
|
|
124
|
+
{
|
|
125
|
+
path: '/',
|
|
126
|
+
build: model_builder
|
|
127
|
+
},
|
|
135
128
|
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
// Trigger main model build.
|
|
130
|
+
trigger_model_build
|
|
131
|
+
],
|
|
132
|
+
require: spec.require
|
|
138
133
|
}
|
|
134
|
+
|
|
135
|
+
return new Config(cspec)
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
|
|
139
|
+
|
|
142
140
|
export {
|
|
143
141
|
Model,
|
|
144
142
|
Spec,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/model",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"main": "dist/model.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/model.d.ts",
|
|
@@ -50,9 +50,9 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/jest": "^29.5.12",
|
|
53
|
-
"@types/node": "22.
|
|
53
|
+
"@types/node": "22.5.1",
|
|
54
54
|
"es-jest": "^2.1.0",
|
|
55
|
-
"esbuild": "^0.23.
|
|
55
|
+
"esbuild": "^0.23.1",
|
|
56
56
|
"esbuild-jest": "^0.5.0",
|
|
57
57
|
"jest": "^29.7.0",
|
|
58
58
|
"typescript": "^5.5.4"
|