@voxgig/model 2.3.0 → 3.0.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 +35 -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 -32
- 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 +21 -16
- 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 +60 -50
- package/lib/builder/local.ts +73 -35
- package/lib/builder/model.ts +8 -6
- package/lib/config.ts +2 -13
- package/lib/types.ts +67 -0
- package/lib/watch.ts +33 -21
- package/model.ts +50 -52
- package/package.json +3 -3
package/dist/model.js
CHANGED
|
@@ -11,31 +11,34 @@ const config_1 = require("./lib/config");
|
|
|
11
11
|
const watch_1 = require("./lib/watch");
|
|
12
12
|
const model_1 = require("./lib/builder/model");
|
|
13
13
|
const local_1 = require("./lib/builder/local");
|
|
14
|
-
const intern = makeIntern();
|
|
15
14
|
class Model {
|
|
16
15
|
constructor(spec) {
|
|
17
16
|
this.trigger_model = false;
|
|
17
|
+
const self = this;
|
|
18
18
|
// Config is a special Watch to handle model config.
|
|
19
|
-
this.config =
|
|
19
|
+
this.config = makeConfig(spec, {
|
|
20
20
|
path: '/',
|
|
21
|
-
build: async (build)
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
build: async function trigger_model(build, ctx) {
|
|
22
|
+
var _a, _b, _c;
|
|
23
|
+
if ('post' !== ctx.step) {
|
|
24
|
+
return { ok: true };
|
|
25
|
+
}
|
|
24
26
|
let res;
|
|
25
|
-
|
|
27
|
+
// console.log('TRIGGER', build.id, self.trigger_model, ctx)
|
|
28
|
+
// console.log(new Error().stack)
|
|
29
|
+
if (self.trigger_model) {
|
|
26
30
|
// TODO: fix!!!
|
|
27
|
-
|
|
28
|
-
res =
|
|
31
|
+
self.build.use.config.watch.last.build = build;
|
|
32
|
+
res = self.watch.run(true);
|
|
29
33
|
}
|
|
30
34
|
else {
|
|
31
|
-
|
|
35
|
+
self.trigger_model = true;
|
|
32
36
|
res = { ok: true };
|
|
33
37
|
}
|
|
34
|
-
const watchmap = (_b = (_a = build.model
|
|
35
|
-
// console.log('WATCHMAP', watchmap)
|
|
38
|
+
const watchmap = (_c = (_b = (_a = build.model) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.model) === null || _c === void 0 ? void 0 : _c.watch;
|
|
36
39
|
if (watchmap) {
|
|
37
40
|
Object.keys(watchmap).map((file) => {
|
|
38
|
-
|
|
41
|
+
self.watch.add(file);
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
return res;
|
|
@@ -46,7 +49,7 @@ class Model {
|
|
|
46
49
|
src: spec.src,
|
|
47
50
|
path: spec.path,
|
|
48
51
|
base: spec.base,
|
|
49
|
-
use: { config:
|
|
52
|
+
use: { config: self.config },
|
|
50
53
|
res: [
|
|
51
54
|
{
|
|
52
55
|
path: '/',
|
|
@@ -59,46 +62,43 @@ class Model {
|
|
|
59
62
|
],
|
|
60
63
|
require: spec.require
|
|
61
64
|
};
|
|
62
|
-
this.watch = new watch_1.Watch(
|
|
65
|
+
this.watch = new watch_1.Watch(self.build);
|
|
63
66
|
}
|
|
64
67
|
async run() {
|
|
65
68
|
this.trigger_model = false;
|
|
66
|
-
|
|
69
|
+
const br = await this.config.run();
|
|
67
70
|
return br.ok ? this.watch.run(true) : br;
|
|
68
71
|
}
|
|
69
72
|
async start() {
|
|
70
73
|
this.trigger_model = false;
|
|
71
|
-
await this.config.start();
|
|
72
|
-
return this.watch.start();
|
|
74
|
+
const br = await this.config.start();
|
|
75
|
+
return br.ok ? this.watch.start() : br;
|
|
73
76
|
}
|
|
74
77
|
async stop() {
|
|
75
78
|
return this.watch.stop();
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
exports.Model = Model;
|
|
79
|
-
function
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
require: spec.require
|
|
99
|
-
};
|
|
100
|
-
return new config_1.Config(cspec);
|
|
101
|
-
}
|
|
82
|
+
function makeConfig(spec, trigger_model_build) {
|
|
83
|
+
let cbase = spec.base + '/.model-config';
|
|
84
|
+
let cpath = cbase + '/model-config.jsonic';
|
|
85
|
+
// Build should load file
|
|
86
|
+
let src = fs_1.default.readFileSync(cpath).toString();
|
|
87
|
+
let cspec = {
|
|
88
|
+
src: src,
|
|
89
|
+
path: cpath,
|
|
90
|
+
base: cbase,
|
|
91
|
+
res: [
|
|
92
|
+
// Generate full config model and save as a file.
|
|
93
|
+
{
|
|
94
|
+
path: '/',
|
|
95
|
+
build: model_1.model_builder
|
|
96
|
+
},
|
|
97
|
+
// Trigger main model build.
|
|
98
|
+
trigger_model_build
|
|
99
|
+
],
|
|
100
|
+
require: spec.require
|
|
102
101
|
};
|
|
102
|
+
return new config_1.Config(cspec);
|
|
103
103
|
}
|
|
104
104
|
//# sourceMappingURL=model.js.map
|
package/dist/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../model.ts"],"names":[],"mappings":";AAAA,o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AAC,IAAI;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;IAC1B,CAAC;CACF;AAkCC,sBAAK;AA/BP,SAAS,UAAU,CAAC,IAAU,EAAE,mBAAgC;IAC9D,IAAI,KAAK,GAAG,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAA;IACxC,IAAI,KAAK,GAAG,KAAK,GAAG,sBAAsB,CAAA;IAE1C,yBAAyB;IACzB,IAAI,GAAG,GAAG,YAAE,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAA;IAE3C,IAAI,KAAK,GAAS;QAChB,GAAG,EAAE,GAAG;QACR,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,KAAK;QACX,GAAG,EAAE;YAEH,iDAAiD;YACjD;gBACE,IAAI,EAAE,GAAG;gBACT,KAAK,EAAE,qBAAa;aACrB;YAED,4BAA4B;YAC5B,mBAAmB;SACpB;QACD,OAAO,EAAE,IAAI,CAAC,OAAO;KACtB,CAAA;IAED,OAAO,IAAI,eAAM,CAAC,KAAK,CAAC,CAAA;AAC1B,CAAC"}
|
package/lib/build.ts
CHANGED
|
@@ -4,56 +4,42 @@
|
|
|
4
4
|
import { Aontu, Val, Nil, Context } from 'aontu'
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
interface BuildAction {
|
|
17
|
-
path: string
|
|
18
|
-
build: Builder
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
type Builder = (
|
|
22
|
-
build: Build
|
|
23
|
-
) => Promise<BuildResult>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
interface Spec {
|
|
27
|
-
src: string
|
|
28
|
-
path?: string
|
|
29
|
-
base?: string
|
|
30
|
-
res?: BuildAction[]
|
|
31
|
-
require?: any
|
|
32
|
-
use?: { [name: string]: any }
|
|
33
|
-
}
|
|
7
|
+
import type {
|
|
8
|
+
Build,
|
|
9
|
+
BuildResult,
|
|
10
|
+
BuildAction,
|
|
11
|
+
Builder,
|
|
12
|
+
BuildContext,
|
|
13
|
+
Spec,
|
|
14
|
+
} from './types'
|
|
34
15
|
|
|
35
16
|
|
|
36
17
|
|
|
37
18
|
|
|
38
|
-
class Build {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
class BuildImpl implements Build {
|
|
20
|
+
id
|
|
21
|
+
src
|
|
22
|
+
base
|
|
23
|
+
path
|
|
24
|
+
root: any = Nil.make()
|
|
25
|
+
opts: any
|
|
26
|
+
res
|
|
27
|
+
spec
|
|
46
28
|
model: any
|
|
47
|
-
use
|
|
29
|
+
use = {}
|
|
48
30
|
err: any[] = []
|
|
31
|
+
ctx: BuildContext
|
|
49
32
|
|
|
50
33
|
|
|
51
34
|
constructor(spec: Spec) {
|
|
35
|
+
this.id = String(Math.random()).substring(3, 15)
|
|
36
|
+
|
|
52
37
|
this.spec = spec
|
|
53
38
|
this.src = spec.src
|
|
54
39
|
this.base = null == spec.base ? '' : spec.base
|
|
55
40
|
this.path = null == spec.path ? '' : spec.path
|
|
56
41
|
this.opts = {}
|
|
42
|
+
this.ctx = { step: 'pre', state: {} }
|
|
57
43
|
|
|
58
44
|
if (null != spec.base) {
|
|
59
45
|
this.opts.base = spec.base
|
|
@@ -71,19 +57,36 @@ class Build {
|
|
|
71
57
|
|
|
72
58
|
|
|
73
59
|
async run(): Promise<BuildResult> {
|
|
74
|
-
// console.log('BUILD RUN', this.path)
|
|
75
|
-
|
|
76
60
|
let hasErr = false
|
|
77
61
|
|
|
78
|
-
this.
|
|
79
|
-
|
|
62
|
+
this.ctx.step = 'pre'
|
|
63
|
+
const brlog = []
|
|
80
64
|
|
|
81
|
-
|
|
82
|
-
|
|
65
|
+
for (let builder of this.res) {
|
|
66
|
+
try {
|
|
67
|
+
let br = await builder.build(this, this.ctx)
|
|
68
|
+
br.step = this.ctx.step
|
|
69
|
+
br.path = builder.path
|
|
70
|
+
br.builder = builder.build.name
|
|
71
|
+
brlog.push(br)
|
|
72
|
+
}
|
|
73
|
+
catch (e: any) {
|
|
74
|
+
this.err.push(e)
|
|
75
|
+
hasErr = true
|
|
76
|
+
break
|
|
77
|
+
}
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
|
|
86
|
-
|
|
81
|
+
if (!hasErr) {
|
|
82
|
+
this.root = Aontu(this.src, this.opts)
|
|
83
|
+
hasErr = this.root.err && 0 < this.root.err.length
|
|
84
|
+
|
|
85
|
+
if (hasErr) {
|
|
86
|
+
this.err.push(...this.root.err)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
87
90
|
|
|
88
91
|
if (!hasErr) {
|
|
89
92
|
let genctx = new Context({ root: this.root })
|
|
@@ -94,32 +97,39 @@ class Build {
|
|
|
94
97
|
this.err.push(...genctx.err)
|
|
95
98
|
}
|
|
96
99
|
else {
|
|
97
|
-
|
|
98
100
|
// TODO: only call if path value has changed
|
|
101
|
+
|
|
102
|
+
this.ctx.step = 'post'
|
|
103
|
+
|
|
99
104
|
for (let builder of this.res) {
|
|
100
105
|
try {
|
|
101
|
-
let br = await builder.build(this)
|
|
106
|
+
let br = await builder.build(this, this.ctx)
|
|
107
|
+
br.step = this.ctx.step
|
|
102
108
|
br.path = builder.path
|
|
103
109
|
br.builder = builder.build.name
|
|
104
110
|
brlog.push(br)
|
|
105
111
|
}
|
|
106
112
|
catch (e: any) {
|
|
107
113
|
this.err.push(e)
|
|
114
|
+
break
|
|
108
115
|
}
|
|
109
116
|
}
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
|
|
120
|
+
const br = { ok: !hasErr, build: this, builders: brlog, err: this.err }
|
|
121
|
+
|
|
122
|
+
return br
|
|
114
123
|
}
|
|
115
124
|
}
|
|
116
125
|
|
|
117
126
|
|
|
127
|
+
function makeBuild(spec: Spec) {
|
|
128
|
+
return new BuildImpl(spec)
|
|
129
|
+
}
|
|
130
|
+
|
|
118
131
|
export {
|
|
119
|
-
|
|
120
|
-
Builder,
|
|
121
|
-
BuildResult,
|
|
122
|
-
BuildAction,
|
|
132
|
+
makeBuild,
|
|
123
133
|
Spec,
|
|
124
134
|
Val
|
|
125
135
|
}
|
package/lib/builder/local.ts
CHANGED
|
@@ -1,64 +1,104 @@
|
|
|
1
1
|
|
|
2
2
|
import Path from 'path'
|
|
3
3
|
|
|
4
|
-
import { Build, Builder } from '../
|
|
4
|
+
import type { Build, Builder, BuildContext } from '../types'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
// Runs any builders local to the repo.
|
|
8
|
-
const local_builder: Builder = async (build: Build) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let root = Path.resolve(build.path, '..', '..')
|
|
8
|
+
const local_builder: Builder = async (build: Build, ctx: BuildContext) => {
|
|
9
|
+
ctx.state.local = (ctx.state.local || {})
|
|
10
|
+
let actionDefs = ctx.state.local.actionDefs
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
if (null == actionDefs) {
|
|
13
|
+
try {
|
|
14
|
+
actionDefs = ctx.state.local.actionDefs = []
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
// console.dir(config, { depth: null })
|
|
16
|
+
// TODO: need to provide project root via build
|
|
17
|
+
let root = Path.resolve(build.path, '..', '..')
|
|
20
18
|
|
|
21
|
-
let builders = config.sys.model.builders
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
// TODO: build should do this
|
|
21
|
+
let configbuild = build.use.config
|
|
25
22
|
|
|
26
|
-
|
|
27
|
-
for (let name in builders) {
|
|
28
|
-
// console.log('LOCAL BUILDER', name)
|
|
23
|
+
let config = configbuild.watch.last.build.model
|
|
29
24
|
|
|
30
|
-
let
|
|
31
|
-
let action_path = Path.join(root, builder.load)
|
|
25
|
+
let builders = config.sys.model.builders
|
|
32
26
|
|
|
33
|
-
// TODO:
|
|
34
|
-
|
|
27
|
+
// TODO: order by comma sep string
|
|
28
|
+
// Load builders
|
|
29
|
+
for (let name in builders) {
|
|
30
|
+
let builder = builders[name]
|
|
31
|
+
let action_path = Path.join(root, builder.load)
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
clear(action_path)
|
|
34
|
+
let action = require(action_path)
|
|
35
|
+
|
|
36
|
+
if (action instanceof Promise) {
|
|
37
|
+
action = await action
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const step = action.step || 'post'
|
|
41
|
+
|
|
42
|
+
actionDefs.push({ name, builder, action, step })
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (e: any) {
|
|
46
|
+
throw e
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if ('pre' === ctx.step) {
|
|
52
|
+
try {
|
|
53
|
+
let ok = true
|
|
54
|
+
let brlog = []
|
|
55
|
+
|
|
56
|
+
for (let actionDef of actionDefs) {
|
|
57
|
+
if ('pre' === actionDef.step || 'all' === actionDef.step) {
|
|
58
|
+
let br = await actionDef.action(build.model, build)
|
|
59
|
+
ok = ok && null != br && br.ok
|
|
60
|
+
brlog.push(br)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return { ok: true, step: ctx.step, active: true }
|
|
65
|
+
}
|
|
66
|
+
catch (e: any) {
|
|
67
|
+
throw e
|
|
41
68
|
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
else if ('post' === ctx.step) {
|
|
72
|
+
try {
|
|
73
|
+
let ok = true
|
|
74
|
+
let brlog = []
|
|
75
|
+
|
|
76
|
+
for (let actionDef of actionDefs) {
|
|
77
|
+
if ('post' === actionDef.step || 'all' === actionDef.step) {
|
|
78
|
+
let br = await actionDef.action(build.model, build)
|
|
79
|
+
ok = ok && null != br && br.ok
|
|
80
|
+
brlog.push(br)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
42
83
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
84
|
+
return { ok: true, step: ctx.step, active: true }
|
|
85
|
+
}
|
|
86
|
+
catch (e: any) {
|
|
87
|
+
throw e
|
|
88
|
+
}
|
|
47
89
|
}
|
|
48
90
|
|
|
91
|
+
return { ok: false, why: 'bad-step', step: ctx.step, active: false }
|
|
49
92
|
}
|
|
50
93
|
|
|
51
94
|
|
|
52
95
|
// Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
|
|
53
96
|
function clear(path: string) {
|
|
54
97
|
let filePath = require.resolve(path)
|
|
55
|
-
// console.log('CM fp', filePath)
|
|
56
98
|
|
|
57
99
|
if (require.cache[filePath]) {
|
|
58
100
|
const children = require.cache[filePath].children.map(child => child.id)
|
|
59
101
|
|
|
60
|
-
// console.log('CM-B', filePath, children)
|
|
61
|
-
|
|
62
102
|
// Delete module from cache
|
|
63
103
|
delete require.cache[filePath]
|
|
64
104
|
|
|
@@ -71,8 +111,6 @@ function clear(path: string) {
|
|
|
71
111
|
if (require.cache[filePath] && require.cache[filePath].parent) {
|
|
72
112
|
let i = require.cache[filePath].parent.children.length
|
|
73
113
|
|
|
74
|
-
// console.log('CM-A', filePath, require.cache[filePath].parent.children)
|
|
75
|
-
|
|
76
114
|
while (i--) {
|
|
77
115
|
if (require.cache[filePath].parent.children[i].id === filePath) {
|
|
78
116
|
require.cache[filePath].parent.children.splice(i, 1)
|
package/lib/builder/model.ts
CHANGED
|
@@ -3,11 +3,14 @@ import Path from 'path'
|
|
|
3
3
|
|
|
4
4
|
import { writeFile } from 'fs/promises'
|
|
5
5
|
|
|
6
|
-
import { Build, Builder } from '../
|
|
6
|
+
import type { Build, Builder, BuildContext } from '../types'
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
// Builds the main model file, after unification.
|
|
10
|
-
const model_builder: Builder = async (build: Build) => {
|
|
10
|
+
const model_builder: Builder = async (build: Build, ctx: BuildContext) => {
|
|
11
|
+
if ('post' !== ctx.step) {
|
|
12
|
+
return { ok: true, step: ctx.step, active: false }
|
|
13
|
+
}
|
|
11
14
|
|
|
12
15
|
try {
|
|
13
16
|
let json = JSON.stringify(build.root.gen(), null, 2)
|
|
@@ -20,12 +23,11 @@ const model_builder: Builder = async (build: Build) => {
|
|
|
20
23
|
|
|
21
24
|
let file = build.opts.base + '/' + filename + '.json'
|
|
22
25
|
|
|
23
|
-
// console.log('MODEL BUILDER', file)
|
|
24
26
|
await writeFile(file, json)
|
|
25
27
|
|
|
26
|
-
return { ok: true }
|
|
27
|
-
}
|
|
28
|
-
|
|
28
|
+
return { ok: true, step: ctx.step, active: true }
|
|
29
|
+
}
|
|
30
|
+
catch (e: any) {
|
|
29
31
|
throw e
|
|
30
32
|
}
|
|
31
33
|
}
|
package/lib/config.ts
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
/* Copyright © 2021-
|
|
1
|
+
/* Copyright © 2021-2024 Voxgig Ltd, MIT License. */
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
// from model / config.jsonic by default
|
|
6
|
-
// config defines builders
|
|
4
|
+
import type { BuildResult, Spec } from './types'
|
|
7
5
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { BuildResult, Spec } from './build'
|
|
12
6
|
import { Watch } from './watch'
|
|
13
7
|
|
|
14
|
-
|
|
15
8
|
import { model_builder } from './builder/model'
|
|
16
9
|
|
|
17
10
|
|
|
@@ -29,10 +22,6 @@ class Config {
|
|
|
29
22
|
path: spec.path,
|
|
30
23
|
base: spec.base,
|
|
31
24
|
res: [
|
|
32
|
-
{
|
|
33
|
-
path: '/',
|
|
34
|
-
build: model_builder
|
|
35
|
-
},
|
|
36
25
|
...(spec.res || [])
|
|
37
26
|
],
|
|
38
27
|
require: spec.require
|
package/lib/types.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface Build {
|
|
5
|
+
id: string
|
|
6
|
+
src: string
|
|
7
|
+
base: string
|
|
8
|
+
path: string
|
|
9
|
+
root: any
|
|
10
|
+
opts: { [key: string]: any }
|
|
11
|
+
res: BuildAction[]
|
|
12
|
+
spec: Spec
|
|
13
|
+
model: any
|
|
14
|
+
use: { [name: string]: any }
|
|
15
|
+
err: any[]
|
|
16
|
+
ctx: BuildContext
|
|
17
|
+
|
|
18
|
+
run: () => Promise<BuildResult>
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
interface BuildResult {
|
|
23
|
+
ok: boolean
|
|
24
|
+
builder?: string
|
|
25
|
+
path?: string
|
|
26
|
+
build?: Build
|
|
27
|
+
builders?: BuildResult[]
|
|
28
|
+
step?: string
|
|
29
|
+
err?: any[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface BuildAction {
|
|
33
|
+
path: string
|
|
34
|
+
build: Builder
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
interface BuildContext {
|
|
39
|
+
step: 'pre' | 'post'
|
|
40
|
+
state: Record<string, any>
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type Builder = (
|
|
44
|
+
build: Build,
|
|
45
|
+
ctx: BuildContext,
|
|
46
|
+
) => Promise<BuildResult>
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
interface Spec {
|
|
50
|
+
src: string
|
|
51
|
+
path?: string
|
|
52
|
+
base?: string
|
|
53
|
+
res?: BuildAction[]
|
|
54
|
+
require?: any
|
|
55
|
+
use?: { [name: string]: any }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
export type {
|
|
61
|
+
Build,
|
|
62
|
+
BuildResult,
|
|
63
|
+
BuildAction,
|
|
64
|
+
Builder,
|
|
65
|
+
BuildContext,
|
|
66
|
+
Spec,
|
|
67
|
+
}
|