@voxgig/model 0.0.8 → 0.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/README.md +7 -1
- package/bin/voxgig-model +27 -2
- package/dist/lib/build.d.ts +40 -0
- package/dist/lib/build.js +40 -0
- package/dist/lib/build.js.map +1 -0
- package/dist/lib/builder/local.d.ts +3 -0
- package/dist/lib/builder/local.js +34 -0
- package/dist/lib/builder/local.js.map +1 -0
- package/dist/lib/builder/model.d.ts +3 -0
- package/dist/lib/builder/model.js +12 -0
- package/dist/lib/builder/model.js.map +1 -0
- package/dist/lib/config.d.ts +11 -0
- package/dist/lib/config.js +36 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/model-builder.d.ts +0 -0
- package/dist/lib/model-builder.js +2 -0
- package/dist/lib/model-builder.js.map +1 -0
- package/dist/lib/watch.d.ts +13 -0
- package/dist/lib/watch.js +60 -0
- package/dist/lib/watch.js.map +1 -0
- package/dist/model.d.ts +12 -6
- package/dist/model.js +83 -7
- package/dist/model.js.map +1 -1
- package/dist/model.min.js +83 -7
- package/lib/build.ts +99 -0
- package/lib/builder/local.ts +43 -0
- package/lib/builder/model.ts +20 -0
- package/lib/config.ts +58 -0
- package/lib/watch.ts +91 -0
- package/model/config/sys.jsonic +11 -0
- package/model/sys.jsonic +73 -0
- package/model.ts +106 -10
- package/package.json +18 -22
- package/bin/voxgig-model~ +0 -1
package/README.md
CHANGED
package/bin/voxgig-model
CHANGED
|
@@ -1,19 +1,44 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const Fs = require('fs')
|
|
4
|
+
const Path = require('path')
|
|
4
5
|
|
|
5
6
|
let { Model } = require('../dist/model.js')
|
|
6
7
|
|
|
7
8
|
let path = process.argv[2]
|
|
9
|
+
let once = '--once' === process.argv[3]
|
|
8
10
|
|
|
9
11
|
if(null == path || '' == path) {
|
|
10
12
|
console.error('ERROR: First argument should be a jsonic model file path.')
|
|
11
13
|
process.exit(1)
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
let fstats = Fs.statSync(path)
|
|
17
|
+
let base = path
|
|
18
|
+
|
|
19
|
+
if (fstats.isFile()) {
|
|
20
|
+
let basedesc = Path.parse(base)
|
|
21
|
+
base = basedesc.dir
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
path = Path.resolve(path)
|
|
25
|
+
console.log('PATH', path)
|
|
26
|
+
|
|
14
27
|
let src = Fs.readFileSync(path).toString()
|
|
15
28
|
|
|
16
|
-
let model = new Model({src,path})
|
|
29
|
+
let model = new Model({src,path,base})
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async function run() {
|
|
33
|
+
if(once) {
|
|
34
|
+
let br = await model.run()
|
|
35
|
+
console.log('OK:'+br.ok, once)
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
console.log('WATCHING...')
|
|
39
|
+
model.start()
|
|
40
|
+
}
|
|
41
|
+
}
|
|
17
42
|
|
|
18
|
-
console.log(JSON.stringify(model.get(),null,2))
|
|
19
43
|
|
|
44
|
+
run()
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Val } from 'aontu';
|
|
2
|
+
interface BuildResult {
|
|
3
|
+
ok: boolean;
|
|
4
|
+
builder?: string;
|
|
5
|
+
path?: string;
|
|
6
|
+
build?: Build;
|
|
7
|
+
builders?: BuildResult[];
|
|
8
|
+
}
|
|
9
|
+
interface BuildAction {
|
|
10
|
+
path: string;
|
|
11
|
+
build: Builder;
|
|
12
|
+
}
|
|
13
|
+
declare type Builder = (build: Build) => Promise<BuildResult>;
|
|
14
|
+
interface Spec {
|
|
15
|
+
src: string;
|
|
16
|
+
path?: string;
|
|
17
|
+
base?: string;
|
|
18
|
+
res?: BuildAction[];
|
|
19
|
+
use?: {
|
|
20
|
+
[name: string]: any;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
declare class Build {
|
|
24
|
+
src: string;
|
|
25
|
+
base: string;
|
|
26
|
+
path: string;
|
|
27
|
+
root: Val;
|
|
28
|
+
opts: {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
};
|
|
31
|
+
res: BuildAction[];
|
|
32
|
+
spec: Spec;
|
|
33
|
+
model: any;
|
|
34
|
+
use: {
|
|
35
|
+
[name: string]: any;
|
|
36
|
+
};
|
|
37
|
+
constructor(spec: Spec);
|
|
38
|
+
run(): Promise<BuildResult>;
|
|
39
|
+
}
|
|
40
|
+
export { Build, Builder, BuildResult, BuildAction, Spec, Val };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Val = exports.Build = void 0;
|
|
4
|
+
const aontu_1 = require("aontu");
|
|
5
|
+
Object.defineProperty(exports, "Val", { enumerable: true, get: function () { return aontu_1.Val; } });
|
|
6
|
+
class Build {
|
|
7
|
+
constructor(spec) {
|
|
8
|
+
this.root = aontu_1.Nil.make();
|
|
9
|
+
this.use = {};
|
|
10
|
+
this.spec = spec;
|
|
11
|
+
this.src = spec.src;
|
|
12
|
+
this.base = null == spec.base ? '' : spec.base;
|
|
13
|
+
this.path = null == spec.path ? '' : spec.path;
|
|
14
|
+
this.opts = {};
|
|
15
|
+
if (null != spec.base) {
|
|
16
|
+
this.opts.base = spec.base;
|
|
17
|
+
}
|
|
18
|
+
this.res = spec.res || [];
|
|
19
|
+
Object.assign(this.use, spec.use || {});
|
|
20
|
+
}
|
|
21
|
+
async run() {
|
|
22
|
+
console.log('BUILDING ', this.path, new Date() + ' ...');
|
|
23
|
+
this.root = (0, aontu_1.Aontu)(this.src, this.opts);
|
|
24
|
+
let nil = this.root;
|
|
25
|
+
console.log('MODEL: ' + (nil.nil ? nil.why : 'ok'));
|
|
26
|
+
console.log('MODEL ERR', this.root.err);
|
|
27
|
+
this.model = this.root.gen();
|
|
28
|
+
// TODO: only call if path value has changed
|
|
29
|
+
let brlog = [];
|
|
30
|
+
for (let builder of this.res) {
|
|
31
|
+
let br = await builder.build(this);
|
|
32
|
+
br.path = builder.path;
|
|
33
|
+
br.builder = builder.build.name;
|
|
34
|
+
brlog.push(br);
|
|
35
|
+
}
|
|
36
|
+
return { ok: true, build: this, builders: brlog };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Build = Build;
|
|
40
|
+
//# sourceMappingURL=build.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../lib/build.ts"],"names":[],"mappings":";;;AAEA,iCAAuC;AA6FrC,oFA7Fc,WAAG,OA6Fd;AA7DL,MAAM,KAAK;IAWT,YAAY,IAAU;QAPtB,SAAI,GAAQ,WAAG,CAAC,IAAI,EAAE,CAAA;QAKtB,QAAG,GAA4B,EAAE,CAAA;QAG/B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAA;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAA;QAC9C,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QAEd,IAAI,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE;YACrB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;SAC3B;QAED,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,EAAE,CAAA;QAEzB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;IACzC,CAAC;IAGD,KAAK,CAAC,GAAG;QACP,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,MAAM,CAAC,CAAA;QAExD,IAAI,CAAC,IAAI,GAAG,IAAA,aAAK,EAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAA;QAEtC,IAAI,GAAG,GAAI,IAAI,CAAC,IAAY,CAAA;QAC5B,OAAO,CAAC,GAAG,CAAC,SAAS,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;QAEnD,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEvC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAA;QAG5B,4CAA4C;QAC5C,IAAI,KAAK,GAAG,EAAE,CAAA;QACd,KAAK,IAAI,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE;YAC5B,IAAI,EAAE,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YAClC,EAAE,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;YACtB,EAAE,CAAC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;YAC/B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;SACf;QAED,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA;IACnD,CAAC;CACF;AAIC,sBAAK"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.local_builder = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const local_builder = async (build) => {
|
|
9
|
+
// TODO: need to provide project root via build
|
|
10
|
+
let root = path_1.default.resolve(build.path, '..', '..');
|
|
11
|
+
// TODO: build should do this
|
|
12
|
+
console.log('LOCAL root:', root);
|
|
13
|
+
let configbuild = build.use.config;
|
|
14
|
+
let config = configbuild.watch.last.build.model;
|
|
15
|
+
console.log('CONFIG BUILD');
|
|
16
|
+
console.dir(config, { depth: null });
|
|
17
|
+
let builders = config.sys.model.builders;
|
|
18
|
+
let ok = true;
|
|
19
|
+
let brlog = [];
|
|
20
|
+
// TODO: order by comma sep string
|
|
21
|
+
for (let name in builders) {
|
|
22
|
+
let builder = builders[name];
|
|
23
|
+
let action_path = path_1.default.join(root, builder.load);
|
|
24
|
+
// TODO: need to watch these files too, and their deps!
|
|
25
|
+
console.log('ACTION PATH', name, action_path);
|
|
26
|
+
let action = require(action_path);
|
|
27
|
+
let br = await action(build.model, build);
|
|
28
|
+
ok = ok && null != br && br.ok;
|
|
29
|
+
brlog.push(br);
|
|
30
|
+
}
|
|
31
|
+
return { ok: ok, brlog };
|
|
32
|
+
};
|
|
33
|
+
exports.local_builder = local_builder;
|
|
34
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../../lib/builder/local.ts"],"names":[],"mappings":";;;;;;AACA,gDAAuB;AAKvB,MAAM,aAAa,GAAY,KAAK,EAAE,KAAY,EAAE,EAAE;IACpD,+CAA+C;IAC/C,IAAI,IAAI,GAAG,cAAI,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;IAE/C,6BAA6B;IAC7B,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,CAAC,CAAA;IAChC,IAAI,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAA;IAElC,IAAI,MAAM,GAAG,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAA;IAC/C,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;IAC3B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IAEpC,IAAI,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAA;IAExC,IAAI,EAAE,GAAG,IAAI,CAAA;IACb,IAAI,KAAK,GAAG,EAAE,CAAA;IAEd,kCAAkC;IAClC,KAAK,IAAI,IAAI,IAAI,QAAQ,EAAE;QACzB,IAAI,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;QAC5B,IAAI,WAAW,GAAG,cAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAA;QAE/C,uDAAuD;QACvD,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAE,WAAW,CAAC,CAAA;QAE7C,IAAI,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;QACjC,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;QACzC,EAAE,GAAG,EAAE,IAAI,IAAI,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;QAC9B,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;KACf;IAED,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,CAAA;AAC1B,CAAC,CAAA;AAGC,sCAAa"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.model_builder = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const model_builder = async (build) => {
|
|
6
|
+
let json = JSON.stringify(build.root.gen(), null, 2);
|
|
7
|
+
let file = build.opts.base + '/model.json';
|
|
8
|
+
await (0, promises_1.writeFile)(file, json);
|
|
9
|
+
return { ok: true };
|
|
10
|
+
};
|
|
11
|
+
exports.model_builder = model_builder;
|
|
12
|
+
//# sourceMappingURL=model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model.js","sourceRoot":"","sources":["../../../lib/builder/model.ts"],"names":[],"mappings":";;;AACA,0CAAuC;AAKvC,MAAM,aAAa,GAAY,KAAK,EAAE,KAAY,EAAE,EAAE;IAEpD,IAAI,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAEpD,IAAI,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAE1C,MAAM,IAAA,oBAAS,EAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAE3B,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAA;AACrB,CAAC,CAAA;AAGC,sCAAa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { BuildResult, Spec } from './build';
|
|
2
|
+
import { Watch } from './watch';
|
|
3
|
+
declare class Config {
|
|
4
|
+
build: any;
|
|
5
|
+
watch: Watch;
|
|
6
|
+
constructor(spec: Spec);
|
|
7
|
+
run(): Promise<BuildResult>;
|
|
8
|
+
start(): Promise<void>;
|
|
9
|
+
stop(): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export { Config, Spec };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// load config as a model
|
|
3
|
+
// from model / config.jsonic by default
|
|
4
|
+
// config defines builders
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Config = void 0;
|
|
7
|
+
const watch_1 = require("./watch");
|
|
8
|
+
const model_1 = require("./builder/model");
|
|
9
|
+
class Config {
|
|
10
|
+
constructor(spec) {
|
|
11
|
+
this.build = {
|
|
12
|
+
src: spec.src,
|
|
13
|
+
path: spec.path,
|
|
14
|
+
base: spec.base,
|
|
15
|
+
res: [
|
|
16
|
+
{
|
|
17
|
+
path: '/',
|
|
18
|
+
build: model_1.model_builder
|
|
19
|
+
},
|
|
20
|
+
...(spec.res || [])
|
|
21
|
+
]
|
|
22
|
+
};
|
|
23
|
+
this.watch = new watch_1.Watch(this.build);
|
|
24
|
+
}
|
|
25
|
+
async run() {
|
|
26
|
+
return this.watch.run(true);
|
|
27
|
+
}
|
|
28
|
+
async start() {
|
|
29
|
+
return this.watch.start();
|
|
30
|
+
}
|
|
31
|
+
async stop() {
|
|
32
|
+
return this.watch.stop();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Config = Config;
|
|
36
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../lib/config.ts"],"names":[],"mappings":";AACA,yBAAyB;AACzB,wCAAwC;AACxC,0BAA0B;;;AAM1B,mCAA+B;AAG/B,2CAA+C;AAO/C,MAAM,MAAM;IAIV,YAAY,IAAU;QACpB,IAAI,CAAC,KAAK,GAAG;YACX,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,GAAG,EAAE;gBACH;oBACE,IAAI,EAAE,GAAG;oBACT,KAAK,EAAE,qBAAa;iBACrB;gBACD,GAAG,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC;aACpB;SACF,CAAA;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,GAAG;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC7B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IAC3B,CAAC;IAED,KAAK,CAAC,IAAI;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAA;IAC1B,CAAC;CACF;AAGQ,wBAAM"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-builder.js","sourceRoot":"","sources":["../../lib/model-builder.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BuildResult } from './build';
|
|
2
|
+
import { FSWatcher } from 'chokidar';
|
|
3
|
+
declare class Watch {
|
|
4
|
+
fsw: FSWatcher;
|
|
5
|
+
spec: any;
|
|
6
|
+
last?: BuildResult;
|
|
7
|
+
constructor(spec: any);
|
|
8
|
+
update(br: BuildResult): void;
|
|
9
|
+
start(): Promise<void>;
|
|
10
|
+
run(once: boolean): Promise<BuildResult>;
|
|
11
|
+
stop(): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export { Watch };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Watch = void 0;
|
|
4
|
+
const build_1 = require("./build");
|
|
5
|
+
const chokidar_1 = require("chokidar");
|
|
6
|
+
const promises_1 = require("fs/promises");
|
|
7
|
+
class Watch {
|
|
8
|
+
constructor(spec) {
|
|
9
|
+
this.spec = spec;
|
|
10
|
+
this.fsw = new chokidar_1.FSWatcher();
|
|
11
|
+
this.fsw.on('change', this.run.bind(this));
|
|
12
|
+
}
|
|
13
|
+
update(br) {
|
|
14
|
+
let build = br.build;
|
|
15
|
+
// TODO: remove dep map building from Aontu
|
|
16
|
+
//let depmap = (build.root as any).map
|
|
17
|
+
// console.log('DEPMAP', depmap)
|
|
18
|
+
//let files = Object.keys(depmap.url)
|
|
19
|
+
//console.log('DEP FILES', files)
|
|
20
|
+
let files = Object.keys(build.root.deps).reduce((files, target) => {
|
|
21
|
+
files = files.concat(Object.keys(build.root.deps[target]));
|
|
22
|
+
return files;
|
|
23
|
+
}, [build.path]);
|
|
24
|
+
//console.log('DEPS', build.base, files)
|
|
25
|
+
// TODO: remove deleted files
|
|
26
|
+
files.forEach((file) => {
|
|
27
|
+
if ('string' === typeof (file) &&
|
|
28
|
+
'' !== file &&
|
|
29
|
+
build.opts.base !== file) {
|
|
30
|
+
// console.log('ADD', file)
|
|
31
|
+
this.fsw.add(file);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
console.log('WATCH', this.fsw.getWatched());
|
|
36
|
+
}, 100);
|
|
37
|
+
}
|
|
38
|
+
async start() {
|
|
39
|
+
await this.run(false);
|
|
40
|
+
}
|
|
41
|
+
async run(once) {
|
|
42
|
+
// TODO: build spec should not have src!
|
|
43
|
+
let src = (await (0, promises_1.readFile)(this.spec.path)).toString();
|
|
44
|
+
this.spec.src = src;
|
|
45
|
+
let build = new build_1.Build(this.spec);
|
|
46
|
+
let br = await build.run();
|
|
47
|
+
if (!once) {
|
|
48
|
+
// There may be new files.
|
|
49
|
+
this.update(br);
|
|
50
|
+
}
|
|
51
|
+
this.last = br;
|
|
52
|
+
console.log('WATCH RUN DONE', this.spec.path, this.last.ok);
|
|
53
|
+
return br;
|
|
54
|
+
}
|
|
55
|
+
async stop() {
|
|
56
|
+
await this.fsw.close();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Watch = Watch;
|
|
60
|
+
//# sourceMappingURL=watch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"watch.js","sourceRoot":"","sources":["../../lib/watch.ts"],"names":[],"mappings":";;;AAEA,mCAA4C;AAC5C,uCAAoC;AAEpC,0CAAsC;AAGtC,MAAM,KAAK;IAKT,YAAY,IAAS;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,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AAC,CAAA;IACvB,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,IAAa;QACrB,wCAAwC;QACxC,IAAI,GAAG,GAAG,CAAC,MAAM,IAAA,mBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAA;QACrD,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QAEnB,IAAI,KAAK,GAAG,IAAI,aAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChC,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,CAAA;QAE1B,IAAI,CAAC,IAAI,EAAE;YACT,0BAA0B;YAC1B,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;SAChB;QAED,IAAI,CAAC,IAAI,GAAG,EAAE,CAAA;QACd,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QAE3D,OAAO,EAAE,CAAA;IACX,CAAC;IAGD,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;IACxB,CAAC;CACF;AAIC,sBAAK"}
|
package/dist/model.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Config } from './lib/config';
|
|
2
|
+
import { BuildResult, Spec } from './lib/build';
|
|
3
|
+
import { Watch } from './lib/watch';
|
|
2
4
|
declare class Model {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
config: Config;
|
|
6
|
+
build: any;
|
|
7
|
+
watch: Watch;
|
|
8
|
+
trigger_model: boolean;
|
|
9
|
+
constructor(spec: Spec);
|
|
10
|
+
run(): Promise<BuildResult>;
|
|
11
|
+
start(): Promise<void>;
|
|
12
|
+
stop(): Promise<void>;
|
|
7
13
|
}
|
|
8
|
-
export { Model };
|
|
14
|
+
export { Model, Spec };
|
package/dist/model.js
CHANGED
|
@@ -1,18 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* Copyright © 2021-2022 Voxgig Ltd, MIT License. */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.Model = void 0;
|
|
4
|
-
|
|
5
|
-
const
|
|
8
|
+
// TODO: remove need for this
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const config_1 = require("./lib/config");
|
|
11
|
+
const watch_1 = require("./lib/watch");
|
|
12
|
+
const model_1 = require("./lib/builder/model");
|
|
13
|
+
const local_1 = require("./lib/builder/local");
|
|
14
|
+
const intern = makeIntern();
|
|
6
15
|
class Model {
|
|
7
16
|
constructor(spec) {
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
|
|
17
|
+
this.trigger_model = false;
|
|
18
|
+
this.config = intern.makeConfig(spec, {
|
|
19
|
+
path: '/',
|
|
20
|
+
build: async (build) => {
|
|
21
|
+
console.log('TRIGGER MODEL', this.trigger_model);
|
|
22
|
+
if (this.trigger_model) {
|
|
23
|
+
console.log('CONFIG CHANGE'); //, this)
|
|
24
|
+
// console.trace()
|
|
25
|
+
// rebuild if config changes
|
|
26
|
+
// TODO: fix!!!
|
|
27
|
+
this.build.use.config.watch.last.build = build;
|
|
28
|
+
return this.watch.run(true);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.trigger_model = true;
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
11
35
|
});
|
|
36
|
+
this.build = {
|
|
37
|
+
src: spec.src,
|
|
38
|
+
path: spec.path,
|
|
39
|
+
base: spec.base,
|
|
40
|
+
use: { config: this.config },
|
|
41
|
+
res: [
|
|
42
|
+
{
|
|
43
|
+
path: '/',
|
|
44
|
+
build: model_1.model_builder
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
path: '/',
|
|
48
|
+
build: local_1.local_builder
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
this.watch = new watch_1.Watch(this.build);
|
|
12
53
|
}
|
|
13
|
-
|
|
14
|
-
|
|
54
|
+
async run() {
|
|
55
|
+
this.trigger_model = false;
|
|
56
|
+
let br = await this.config.run();
|
|
57
|
+
return br.ok ? this.watch.run(true) : br;
|
|
58
|
+
}
|
|
59
|
+
async start() {
|
|
60
|
+
console.log('MODEL START');
|
|
61
|
+
this.trigger_model = false;
|
|
62
|
+
await this.config.start();
|
|
63
|
+
return this.watch.start();
|
|
64
|
+
}
|
|
65
|
+
async stop() {
|
|
66
|
+
return this.watch.stop();
|
|
15
67
|
}
|
|
16
68
|
}
|
|
17
69
|
exports.Model = Model;
|
|
70
|
+
function makeIntern() {
|
|
71
|
+
return {
|
|
72
|
+
makeConfig(spec, trigger_model_build) {
|
|
73
|
+
let cbase = spec.base + '/config';
|
|
74
|
+
let cpath = cbase + '/config.jsonic';
|
|
75
|
+
// Build should load file
|
|
76
|
+
let src = fs_1.default.readFileSync(cpath).toString();
|
|
77
|
+
let cspec = {
|
|
78
|
+
src: src,
|
|
79
|
+
path: cpath,
|
|
80
|
+
base: cbase,
|
|
81
|
+
res: [
|
|
82
|
+
// Generate full config model and save as a file.
|
|
83
|
+
{
|
|
84
|
+
path: '/',
|
|
85
|
+
build: model_1.model_builder
|
|
86
|
+
},
|
|
87
|
+
trigger_model_build
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
return new config_1.Config(cspec);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
18
94
|
//# sourceMappingURL=model.js.map
|
package/dist/model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model.js","sourceRoot":"","sources":["../model.ts"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wBACE,IAAI,EAAE,GAAG;wBACT,KAAK,EAAE,qBAAa;qBACrB;oBAED,mBAAmB;iBACpB;aACF,CAAA;YACD,OAAO,IAAI,eAAM,CAAC,KAAK,CAAC,CAAA;QAC1B,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/dist/model.min.js
CHANGED
|
@@ -1,18 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/* Copyright © 2021-2022 Voxgig Ltd, MIT License. */
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.Model = void 0;
|
|
4
|
-
|
|
5
|
-
const
|
|
8
|
+
// TODO: remove need for this
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const config_1 = require("./lib/config");
|
|
11
|
+
const watch_1 = require("./lib/watch");
|
|
12
|
+
const model_1 = require("./lib/builder/model");
|
|
13
|
+
const local_1 = require("./lib/builder/local");
|
|
14
|
+
const intern = makeIntern();
|
|
6
15
|
class Model {
|
|
7
16
|
constructor(spec) {
|
|
8
|
-
this.
|
|
9
|
-
this.
|
|
10
|
-
|
|
17
|
+
this.trigger_model = false;
|
|
18
|
+
this.config = intern.makeConfig(spec, {
|
|
19
|
+
path: '/',
|
|
20
|
+
build: async (build) => {
|
|
21
|
+
console.log('TRIGGER MODEL', this.trigger_model);
|
|
22
|
+
if (this.trigger_model) {
|
|
23
|
+
console.log('CONFIG CHANGE'); //, this)
|
|
24
|
+
// console.trace()
|
|
25
|
+
// rebuild if config changes
|
|
26
|
+
// TODO: fix!!!
|
|
27
|
+
this.build.use.config.watch.last.build = build;
|
|
28
|
+
return this.watch.run(true);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.trigger_model = true;
|
|
32
|
+
return { ok: true };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
11
35
|
});
|
|
36
|
+
this.build = {
|
|
37
|
+
src: spec.src,
|
|
38
|
+
path: spec.path,
|
|
39
|
+
base: spec.base,
|
|
40
|
+
use: { config: this.config },
|
|
41
|
+
res: [
|
|
42
|
+
{
|
|
43
|
+
path: '/',
|
|
44
|
+
build: model_1.model_builder
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
path: '/',
|
|
48
|
+
build: local_1.local_builder
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
};
|
|
52
|
+
this.watch = new watch_1.Watch(this.build);
|
|
12
53
|
}
|
|
13
|
-
|
|
14
|
-
|
|
54
|
+
async run() {
|
|
55
|
+
this.trigger_model = false;
|
|
56
|
+
let br = await this.config.run();
|
|
57
|
+
return br.ok ? this.watch.run(true) : br;
|
|
58
|
+
}
|
|
59
|
+
async start() {
|
|
60
|
+
console.log('MODEL START');
|
|
61
|
+
this.trigger_model = false;
|
|
62
|
+
await this.config.start();
|
|
63
|
+
return this.watch.start();
|
|
64
|
+
}
|
|
65
|
+
async stop() {
|
|
66
|
+
return this.watch.stop();
|
|
15
67
|
}
|
|
16
68
|
}
|
|
17
69
|
exports.Model = Model;
|
|
70
|
+
function makeIntern() {
|
|
71
|
+
return {
|
|
72
|
+
makeConfig(spec, trigger_model_build) {
|
|
73
|
+
let cbase = spec.base + '/config';
|
|
74
|
+
let cpath = cbase + '/config.jsonic';
|
|
75
|
+
// Build should load file
|
|
76
|
+
let src = fs_1.default.readFileSync(cpath).toString();
|
|
77
|
+
let cspec = {
|
|
78
|
+
src: src,
|
|
79
|
+
path: cpath,
|
|
80
|
+
base: cbase,
|
|
81
|
+
res: [
|
|
82
|
+
// Generate full config model and save as a file.
|
|
83
|
+
{
|
|
84
|
+
path: '/',
|
|
85
|
+
build: model_1.model_builder
|
|
86
|
+
},
|
|
87
|
+
trigger_model_build
|
|
88
|
+
]
|
|
89
|
+
};
|
|
90
|
+
return new config_1.Config(cspec);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
18
94
|
//# sourceMappingURL=model.js.map
|
package/lib/build.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { Aontu, Val, Nil } from 'aontu'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
interface BuildResult {
|
|
7
|
+
ok: boolean
|
|
8
|
+
builder?: string
|
|
9
|
+
path?: string
|
|
10
|
+
build?: Build
|
|
11
|
+
builders?: BuildResult[]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface BuildAction {
|
|
15
|
+
path: string
|
|
16
|
+
build: Builder
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type Builder = (
|
|
20
|
+
build: Build
|
|
21
|
+
) => Promise<BuildResult>
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
interface Spec {
|
|
25
|
+
src: string
|
|
26
|
+
path?: string
|
|
27
|
+
base?: string
|
|
28
|
+
res?: BuildAction[]
|
|
29
|
+
use?: { [name: string]: any }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Build {
|
|
36
|
+
src: string
|
|
37
|
+
base: string
|
|
38
|
+
path: string
|
|
39
|
+
root: Val = Nil.make()
|
|
40
|
+
opts: { [key: string]: any }
|
|
41
|
+
res: BuildAction[]
|
|
42
|
+
spec: Spec
|
|
43
|
+
model: any
|
|
44
|
+
use: { [name: string]: any } = {}
|
|
45
|
+
|
|
46
|
+
constructor(spec: Spec) {
|
|
47
|
+
this.spec = spec
|
|
48
|
+
this.src = spec.src
|
|
49
|
+
this.base = null == spec.base ? '' : spec.base
|
|
50
|
+
this.path = null == spec.path ? '' : spec.path
|
|
51
|
+
this.opts = {}
|
|
52
|
+
|
|
53
|
+
if (null != spec.base) {
|
|
54
|
+
this.opts.base = spec.base
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.res = spec.res || []
|
|
58
|
+
|
|
59
|
+
Object.assign(this.use, spec.use || {})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
async run(): Promise<BuildResult> {
|
|
64
|
+
console.log('BUILDING ', this.path, new Date() + ' ...')
|
|
65
|
+
|
|
66
|
+
this.root = Aontu(this.src, this.opts)
|
|
67
|
+
|
|
68
|
+
let nil = (this.root as Nil)
|
|
69
|
+
console.log('MODEL: ' + (nil.nil ? nil.why : 'ok'))
|
|
70
|
+
|
|
71
|
+
console.log('MODEL ERR', this.root.err)
|
|
72
|
+
|
|
73
|
+
this.model = this.root.gen()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// TODO: only call if path value has changed
|
|
77
|
+
let brlog = []
|
|
78
|
+
for (let builder of this.res) {
|
|
79
|
+
let br = await builder.build(this)
|
|
80
|
+
br.path = builder.path
|
|
81
|
+
br.builder = builder.build.name
|
|
82
|
+
brlog.push(br)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return { ok: true, build: this, builders: brlog }
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
export {
|
|
91
|
+
Build,
|
|
92
|
+
Builder,
|
|
93
|
+
BuildResult,
|
|
94
|
+
BuildAction,
|
|
95
|
+
Spec,
|
|
96
|
+
Val
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
|
|
2
|
+
import Path from 'path'
|
|
3
|
+
|
|
4
|
+
import { Build, Builder } from '../build'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const local_builder: Builder = async (build: Build) => {
|
|
8
|
+
// TODO: need to provide project root via build
|
|
9
|
+
let root = Path.resolve(build.path, '..', '..')
|
|
10
|
+
|
|
11
|
+
// TODO: build should do this
|
|
12
|
+
console.log('LOCAL root:', root)
|
|
13
|
+
let configbuild = build.use.config
|
|
14
|
+
|
|
15
|
+
let config = configbuild.watch.last.build.model
|
|
16
|
+
console.log('CONFIG BUILD')
|
|
17
|
+
console.dir(config, { depth: null })
|
|
18
|
+
|
|
19
|
+
let builders = config.sys.model.builders
|
|
20
|
+
|
|
21
|
+
let ok = true
|
|
22
|
+
let brlog = []
|
|
23
|
+
|
|
24
|
+
// TODO: order by comma sep string
|
|
25
|
+
for (let name in builders) {
|
|
26
|
+
let builder = builders[name]
|
|
27
|
+
let action_path = Path.join(root, builder.load)
|
|
28
|
+
|
|
29
|
+
// TODO: need to watch these files too, and their deps!
|
|
30
|
+
console.log('ACTION PATH', name, action_path)
|
|
31
|
+
|
|
32
|
+
let action = require(action_path)
|
|
33
|
+
let br = await action(build.model, build)
|
|
34
|
+
ok = ok && null != br && br.ok
|
|
35
|
+
brlog.push(br)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { ok: ok, brlog }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export {
|
|
42
|
+
local_builder
|
|
43
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
|
|
2
|
+
import { writeFile } from 'fs/promises'
|
|
3
|
+
|
|
4
|
+
import { Build, Builder } from '../build'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const model_builder: Builder = async (build: Build) => {
|
|
8
|
+
|
|
9
|
+
let json = JSON.stringify(build.root.gen(), null, 2)
|
|
10
|
+
|
|
11
|
+
let file = build.opts.base + '/model.json'
|
|
12
|
+
|
|
13
|
+
await writeFile(file, json)
|
|
14
|
+
|
|
15
|
+
return { ok: true }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
model_builder
|
|
20
|
+
}
|
package/lib/config.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
// load config as a model
|
|
3
|
+
// from model / config.jsonic by default
|
|
4
|
+
// config defines builders
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import { BuildResult, Spec } from './build'
|
|
10
|
+
import { Watch } from './watch'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
import { model_builder } from './builder/model'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Config {
|
|
21
|
+
build: any
|
|
22
|
+
watch: Watch
|
|
23
|
+
|
|
24
|
+
constructor(spec: Spec) {
|
|
25
|
+
this.build = {
|
|
26
|
+
src: spec.src,
|
|
27
|
+
path: spec.path,
|
|
28
|
+
base: spec.base,
|
|
29
|
+
res: [
|
|
30
|
+
{
|
|
31
|
+
path: '/',
|
|
32
|
+
build: model_builder
|
|
33
|
+
},
|
|
34
|
+
...(spec.res || [])
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
this.watch = new Watch(this.build)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async run(): Promise<BuildResult> {
|
|
42
|
+
return this.watch.run(true)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async start() {
|
|
46
|
+
return this.watch.start()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async stop() {
|
|
50
|
+
return this.watch.stop()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
export { Config, Spec }
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
package/lib/watch.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import { Build, BuildResult } from './build'
|
|
4
|
+
import { FSWatcher } from 'chokidar'
|
|
5
|
+
|
|
6
|
+
import { readFile } from 'fs/promises'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Watch {
|
|
10
|
+
fsw: FSWatcher
|
|
11
|
+
spec: any
|
|
12
|
+
last?: BuildResult
|
|
13
|
+
|
|
14
|
+
constructor(spec: any) {
|
|
15
|
+
this.spec = spec
|
|
16
|
+
this.fsw = new FSWatcher()
|
|
17
|
+
this.fsw.on('change', this.run.bind(this))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
update(br: BuildResult) {
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
let build = (br.build as Build)
|
|
24
|
+
|
|
25
|
+
// TODO: remove dep map building from Aontu
|
|
26
|
+
//let depmap = (build.root as any).map
|
|
27
|
+
|
|
28
|
+
// console.log('DEPMAP', depmap)
|
|
29
|
+
|
|
30
|
+
//let files = Object.keys(depmap.url)
|
|
31
|
+
//console.log('DEP FILES', files)
|
|
32
|
+
|
|
33
|
+
let files: string[] =
|
|
34
|
+
Object.keys(build.root.deps).reduce((files: string[], target: any) => {
|
|
35
|
+
files = files.concat(Object.keys(build.root.deps[target]))
|
|
36
|
+
return files
|
|
37
|
+
}, [build.path])
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
//console.log('DEPS', build.base, files)
|
|
41
|
+
|
|
42
|
+
// TODO: remove deleted files
|
|
43
|
+
files.forEach((file: string) => {
|
|
44
|
+
if ('string' === typeof (file) &&
|
|
45
|
+
'' !== file &&
|
|
46
|
+
build.opts.base !== file
|
|
47
|
+
) {
|
|
48
|
+
// console.log('ADD', file)
|
|
49
|
+
this.fsw.add(file)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
setTimeout(() => {
|
|
54
|
+
console.log('WATCH', this.fsw.getWatched())
|
|
55
|
+
}, 100)
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async start() {
|
|
60
|
+
await this.run(false)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async run(once: boolean) {
|
|
64
|
+
// TODO: build spec should not have src!
|
|
65
|
+
let src = (await readFile(this.spec.path)).toString()
|
|
66
|
+
this.spec.src = src
|
|
67
|
+
|
|
68
|
+
let build = new Build(this.spec)
|
|
69
|
+
let br = await build.run()
|
|
70
|
+
|
|
71
|
+
if (!once) {
|
|
72
|
+
// There may be new files.
|
|
73
|
+
this.update(br)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.last = br
|
|
77
|
+
console.log('WATCH RUN DONE', this.spec.path, this.last.ok)
|
|
78
|
+
|
|
79
|
+
return br
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
async stop() {
|
|
84
|
+
await this.fsw.close()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
export {
|
|
90
|
+
Watch
|
|
91
|
+
}
|
package/model/sys.jsonic
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
shape: srv: {
|
|
3
|
+
env: {
|
|
4
|
+
lambda: boolean
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# shape: app: {
|
|
13
|
+
# name: string
|
|
14
|
+
# layout: string
|
|
15
|
+
# # parts: {
|
|
16
|
+
# # &={
|
|
17
|
+
# # part: string
|
|
18
|
+
# # active: boolean
|
|
19
|
+
# # # active: *true | boolean
|
|
20
|
+
# # }
|
|
21
|
+
# # }
|
|
22
|
+
# }
|
|
23
|
+
|
|
24
|
+
# shape: part: img: {
|
|
25
|
+
# src: string
|
|
26
|
+
# svg: string
|
|
27
|
+
# }
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# app: web: basic: /sys/shape/app
|
|
31
|
+
|
|
32
|
+
# app: web: basic: {
|
|
33
|
+
# name: basic
|
|
34
|
+
# layout: BasicAdmin
|
|
35
|
+
# }
|
|
36
|
+
|
|
37
|
+
# app: web: basic: parts: {
|
|
38
|
+
# head: {
|
|
39
|
+
# part: BasicHead
|
|
40
|
+
# }
|
|
41
|
+
|
|
42
|
+
# side: {
|
|
43
|
+
# part: BasicSide
|
|
44
|
+
# }
|
|
45
|
+
|
|
46
|
+
# main: {
|
|
47
|
+
# part: BasicMain
|
|
48
|
+
# }
|
|
49
|
+
|
|
50
|
+
# foot: {
|
|
51
|
+
# part: BasicFoot
|
|
52
|
+
# }
|
|
53
|
+
# }
|
|
54
|
+
|
|
55
|
+
# #app: web: basic: parts: head: {
|
|
56
|
+
# # part: BasicHead
|
|
57
|
+
# # logo: /sys/shape/part/img
|
|
58
|
+
# #}
|
|
59
|
+
|
|
60
|
+
# # app: web: basic: parts: side: {
|
|
61
|
+
# # # part: BasicSide
|
|
62
|
+
# # # # menu: /shape/part/menu
|
|
63
|
+
# # }
|
|
64
|
+
|
|
65
|
+
# # app: web: basic: parts: main: {
|
|
66
|
+
# # part: BasicMain
|
|
67
|
+
# # }
|
|
68
|
+
|
|
69
|
+
# # app: web: basic: parts: foot: {
|
|
70
|
+
# # part: BasicFoot
|
|
71
|
+
# # }
|
|
72
|
+
|
|
73
|
+
|
package/model.ts
CHANGED
|
@@ -1,27 +1,123 @@
|
|
|
1
|
+
/* Copyright © 2021-2022 Voxgig Ltd, MIT License. */
|
|
1
2
|
|
|
3
|
+
// TODO: remove need for this
|
|
4
|
+
import Fs from 'fs'
|
|
2
5
|
|
|
3
|
-
import {
|
|
6
|
+
import { Config } from './lib/config'
|
|
7
|
+
import { Build, BuildAction, BuildResult, Spec } from './lib/build'
|
|
8
|
+
import { Watch } from './lib/watch'
|
|
4
9
|
|
|
5
|
-
import {
|
|
10
|
+
import { model_builder } from './lib/builder/model'
|
|
11
|
+
import { local_builder } from './lib/builder/local'
|
|
6
12
|
|
|
7
13
|
|
|
14
|
+
const intern = makeIntern()
|
|
15
|
+
|
|
8
16
|
class Model {
|
|
9
|
-
|
|
17
|
+
config: Config
|
|
18
|
+
build: any
|
|
19
|
+
watch: Watch
|
|
20
|
+
|
|
21
|
+
trigger_model = false
|
|
22
|
+
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
constructor(spec: Spec) {
|
|
25
|
+
this.config = intern.makeConfig(spec, {
|
|
26
|
+
path: '/',
|
|
27
|
+
build: async (build: Build) => {
|
|
28
|
+
console.log('TRIGGER MODEL', this.trigger_model)
|
|
12
29
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
30
|
+
if (this.trigger_model) {
|
|
31
|
+
console.log('CONFIG CHANGE')//, this)
|
|
32
|
+
// console.trace()
|
|
33
|
+
// rebuild if config changes
|
|
34
|
+
|
|
35
|
+
// TODO: fix!!!
|
|
36
|
+
this.build.use.config.watch.last.build = build
|
|
37
|
+
|
|
38
|
+
return this.watch.run(true)
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.trigger_model = true
|
|
42
|
+
return { ok: true }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
16
45
|
})
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
this.build = {
|
|
50
|
+
src: spec.src,
|
|
51
|
+
path: spec.path,
|
|
52
|
+
base: spec.base,
|
|
53
|
+
use: { config: this.config },
|
|
54
|
+
res: [
|
|
55
|
+
{
|
|
56
|
+
path: '/',
|
|
57
|
+
build: model_builder
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
{
|
|
62
|
+
path: '/',
|
|
63
|
+
build: local_builder
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
this.watch = new Watch(this.build)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async run(): Promise<BuildResult> {
|
|
72
|
+
this.trigger_model = false
|
|
73
|
+
let br = await this.config.run()
|
|
74
|
+
return br.ok ? this.watch.run(true) : br
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async start() {
|
|
78
|
+
console.log('MODEL START')
|
|
79
|
+
this.trigger_model = false
|
|
80
|
+
await this.config.start()
|
|
81
|
+
|
|
82
|
+
return this.watch.start()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async stop() {
|
|
86
|
+
return this.watch.stop()
|
|
17
87
|
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
function makeIntern() {
|
|
92
|
+
return {
|
|
93
|
+
makeConfig(spec: Spec, trigger_model_build: BuildAction) {
|
|
94
|
+
let cbase = spec.base + '/config'
|
|
95
|
+
let cpath = cbase + '/config.jsonic'
|
|
96
|
+
|
|
97
|
+
// Build should load file
|
|
98
|
+
let src = Fs.readFileSync(cpath).toString()
|
|
99
|
+
|
|
100
|
+
let cspec: Spec = {
|
|
101
|
+
src: src,
|
|
102
|
+
path: cpath,
|
|
103
|
+
base: cbase,
|
|
104
|
+
res: [
|
|
105
|
+
|
|
106
|
+
// Generate full config model and save as a file.
|
|
107
|
+
{
|
|
108
|
+
path: '/',
|
|
109
|
+
build: model_builder
|
|
110
|
+
},
|
|
18
111
|
|
|
19
|
-
|
|
20
|
-
|
|
112
|
+
trigger_model_build
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
return new Config(cspec)
|
|
116
|
+
}
|
|
21
117
|
}
|
|
22
118
|
}
|
|
23
119
|
|
|
24
120
|
|
|
25
|
-
export { Model }
|
|
121
|
+
export { Model, Spec }
|
|
26
122
|
|
|
27
123
|
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/model",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"main": "dist/model.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
|
-
"browser": "dist/model.min.js",
|
|
7
6
|
"types": "dist/model.d.ts",
|
|
8
7
|
"bin": {
|
|
9
8
|
"voxgig-model": "bin/voxgig-model"
|
|
10
9
|
},
|
|
11
|
-
"description": "Model.",
|
|
10
|
+
"description": "Voxgig Model.",
|
|
12
11
|
"homepage": "https://github.com/voxgig/model",
|
|
13
12
|
"keywords": [
|
|
13
|
+
"voxgig",
|
|
14
14
|
"model"
|
|
15
15
|
],
|
|
16
16
|
"author": "Richard Rodger (http://richardrodger.com)",
|
|
@@ -19,19 +19,17 @@
|
|
|
19
19
|
"url": "git://github.com/voxgig/model.git"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
+
"test": "jest --coverage",
|
|
23
|
+
"test-pure": "jest --coverage --config jest.config.pure.js",
|
|
24
|
+
"test-some": "jest -t",
|
|
25
|
+
"test-watch": "jest --coverage --watchAll",
|
|
22
26
|
"watch": "tsc -w -d",
|
|
23
|
-
"
|
|
24
|
-
"test-some": "lab -v -P test --sourcemaps --transform node_modules/lab-transform-typescript -g",
|
|
25
|
-
"test-jest": "jest --coverage",
|
|
26
|
-
"test-web": "echo no-test-web",
|
|
27
|
-
"test-web-x": "browserify -o test-web/test-web.js -e test/model.test.js -s Model -im -i assert -i @hapi/lab && open test-web/index.html",
|
|
28
|
-
"build-x": "tsc -d && cp dist/model.js dist/model.min.js && browserify -o dist/model.min.js -e dist/model.js -s Model -im -i assert -p tinyify",
|
|
29
|
-
"build": "tsc -d && cp dist/model.js dist/model.min.js",
|
|
27
|
+
"build": "tsc -d",
|
|
30
28
|
"clean": "rm -rf node_modules yarn.lock package-lock.json",
|
|
31
29
|
"reset": "npm run clean && npm i && npm run build && npm test",
|
|
32
30
|
"repo-tag": "REPO_VERSION=`node -e \"console.log(require('./package').version)\"` && echo TAG: v$REPO_VERSION && git commit -a -m v$REPO_VERSION && git push && git tag v$REPO_VERSION && git push --tags;",
|
|
33
31
|
"repo-publish": "npm run clean && npm i && npm run repo-publish-quick",
|
|
34
|
-
"repo-publish-quick": "npm run build && npm run test && npm run repo-tag && npm publish --registry
|
|
32
|
+
"repo-publish-quick": "npm run build && npm run test && npm run repo-tag && npm publish --registry https://registry.npmjs.org --access=public"
|
|
35
33
|
},
|
|
36
34
|
"license": "MIT",
|
|
37
35
|
"files": [
|
|
@@ -39,21 +37,19 @@
|
|
|
39
37
|
"lib",
|
|
40
38
|
"dist",
|
|
41
39
|
"bin",
|
|
40
|
+
"model",
|
|
42
41
|
"LICENSE"
|
|
43
42
|
],
|
|
44
43
|
"dependencies": {
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"jsonic": "jsonicjs/jsonic#nextgen"
|
|
44
|
+
"aontu": "rjrodger/aontu",
|
|
45
|
+
"chokidar": "^3.5.3"
|
|
48
46
|
},
|
|
49
47
|
"devDependencies": {
|
|
50
|
-
"@types/jest": "^
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"@hapi/lab": "^24.2.0",
|
|
57
|
-
"lab-transform-typescript": "^3.0.1"
|
|
48
|
+
"@types/jest": "^27.5.1",
|
|
49
|
+
"esbuild": "^0.14.39",
|
|
50
|
+
"esbuild-jest": "^0.5.0",
|
|
51
|
+
"jest": "^28.1.0",
|
|
52
|
+
"ts-jest": "^28.0.2",
|
|
53
|
+
"typescript": "^4.6.4"
|
|
58
54
|
}
|
|
59
55
|
}
|
package/bin/voxgig-model~
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|