nesoi 3.1.7 → 3.2.1
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/lib/compiler/apps/distributed/distributed_compiler.d.ts +31 -0
- package/lib/compiler/apps/distributed/distributed_compiler.js +121 -0
- package/lib/compiler/apps/distributed/stages/1_mkdir_stage.d.ts +15 -0
- package/lib/compiler/apps/distributed/stages/1_mkdir_stage.js +96 -0
- package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.d.ts +15 -0
- package/lib/compiler/apps/distributed/stages/2_build_typescript_stage.js +174 -0
- package/lib/compiler/apps/distributed/stages/3_copy_types_stage.d.ts +15 -0
- package/lib/compiler/apps/distributed/stages/3_copy_types_stage.js +82 -0
- package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.d.ts +16 -0
- package/lib/compiler/apps/distributed/stages/4_dump_modules_stage.js +182 -0
- package/lib/compiler/apps/distributed/stages/5_copy_static_stage.d.ts +0 -0
- package/lib/compiler/apps/distributed/stages/5_copy_static_stage.js +31 -0
- package/lib/compiler/apps/distributed/stages/6_dump_cli_stage.d.ts +0 -0
- package/lib/compiler/apps/distributed/stages/6_dump_cli_stage.js +34 -0
- package/lib/compiler/apps/distributed/stages/7_dump_package_json_stage.d.ts +0 -0
- package/lib/compiler/apps/distributed/stages/7_dump_package_json_stage.js +45 -0
- package/lib/compiler/elements/element.js +2 -2
- package/lib/compiler/index.d.ts +1 -0
- package/lib/compiler/index.js +3 -1
- package/lib/elements/blocks/block.builder.d.ts +1 -0
- package/lib/elements/blocks/block.builder.js +16 -1
- package/lib/elements/blocks/block.schema.d.ts +4 -1
- package/lib/elements/blocks/job/job.builder.d.ts +1 -0
- package/lib/elements/blocks/job/job.builder.js +2 -1
- package/lib/elements/entities/bucket/bucket.d.ts +2 -2
- package/lib/elements/entities/bucket/bucket.js +30 -16
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.d.ts +1 -1
- package/lib/elements/entities/bucket/model/bucket_model_field.builder.js +1 -0
- package/lib/engine/apps/app.config.d.ts +24 -30
- package/lib/engine/apps/app.config.js +11 -21
- package/lib/engine/apps/app.d.ts +6 -5
- package/lib/engine/apps/app.js +1 -1
- package/lib/engine/apps/distributed/distributed.app.config.d.ts +44 -0
- package/lib/engine/apps/distributed/distributed.app.config.js +36 -0
- package/lib/engine/apps/distributed/distributed.app.d.ts +30 -0
- package/lib/engine/apps/distributed/distributed.app.js +52 -0
- package/lib/engine/apps/distributed/distributed_node.app.d.ts +67 -0
- package/lib/engine/apps/distributed/distributed_node.app.js +191 -0
- package/lib/engine/apps/distributed/elements/distributed_job.d.ts +7 -0
- package/lib/engine/apps/distributed/elements/distributed_job.js +11 -0
- package/lib/engine/apps/distributed/inc/inc.client.d.ts +17 -0
- package/lib/engine/apps/distributed/inc/inc.client.js +105 -0
- package/lib/engine/apps/distributed/inc/inc.server.d.ts +19 -0
- package/lib/engine/apps/distributed/inc/inc.server.js +174 -0
- package/lib/engine/apps/distributed/inc/test.d.ts +1 -0
- package/lib/engine/apps/distributed/inc/test.js +24 -0
- package/lib/engine/apps/inline.app.d.ts +7 -2
- package/lib/engine/apps/inline.app.js +18 -2
- package/lib/engine/apps/monolyth/monolyth.app.d.ts +2 -2
- package/lib/engine/apps/monolyth/monolyth.app.js +1 -1
- package/lib/engine/module.d.ts +11 -1
- package/lib/engine/module.js +17 -4
- package/lib/engine/util/crypto.d.ts +4 -13
- package/lib/engine/util/crypto.js +26 -37
- package/lib/engine/util/log.d.ts +1 -1
- package/lib/engine/util/log.js +2 -0
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Compiler } from "../../compiler";
|
|
2
|
+
import { AnyApp } from "../../../engine/apps/app";
|
|
3
|
+
import { DistributedApp } from "../../../engine/apps/distributed/distributed.app";
|
|
4
|
+
export type DistributedCompilerConfig = {
|
|
5
|
+
libPaths?: string[];
|
|
6
|
+
staticPaths?: string[];
|
|
7
|
+
scripts?: Record<string, string>;
|
|
8
|
+
nesoiPath?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare class DistributedCompiler {
|
|
11
|
+
compiler: Compiler;
|
|
12
|
+
appPath: string;
|
|
13
|
+
config: DistributedCompilerConfig;
|
|
14
|
+
dirs: {
|
|
15
|
+
build: string;
|
|
16
|
+
nodes: {
|
|
17
|
+
[name: string]: {
|
|
18
|
+
build: string;
|
|
19
|
+
build_modules: string;
|
|
20
|
+
build_externals: string;
|
|
21
|
+
build_types: string;
|
|
22
|
+
build_bin: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
constructor(compiler: Compiler, appPath: string, config?: DistributedCompilerConfig);
|
|
27
|
+
run(): Promise<void>;
|
|
28
|
+
mergeServicePaths(app: AnyApp): void;
|
|
29
|
+
expandLibPaths(): void;
|
|
30
|
+
static scanAll(dir: string): Promise<DistributedApp<any, any, {}>[] | undefined>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.DistributedCompiler = void 0;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const space_1 = require("../../../engine/space");
|
|
43
|
+
const console_1 = __importDefault(require("../../../engine/util/console"));
|
|
44
|
+
const _1_mkdir_stage_1 = require("./stages/1_mkdir_stage");
|
|
45
|
+
const _2_build_typescript_stage_1 = require("./stages/2_build_typescript_stage");
|
|
46
|
+
const _3_copy_types_stage_1 = require("./stages/3_copy_types_stage");
|
|
47
|
+
const _4_dump_modules_stage_1 = require("./stages/4_dump_modules_stage");
|
|
48
|
+
// import { CopyStaticStage } from './stages/5_copy_static_stage';
|
|
49
|
+
// import { DumpCLIStage } from './stages/6_dump_cli_stage';
|
|
50
|
+
// import { DumpPackageJsonStage } from './stages/7_dump_package_json_stage';
|
|
51
|
+
const log_1 = require("../../../engine/util/log");
|
|
52
|
+
const app_1 = require("../../../engine/apps/app");
|
|
53
|
+
const distributed_app_1 = require("../../../engine/apps/distributed/distributed.app");
|
|
54
|
+
const path_1 = require("../../../engine/util/path");
|
|
55
|
+
class DistributedCompiler {
|
|
56
|
+
constructor(compiler, appPath, config = {}) {
|
|
57
|
+
this.compiler = compiler;
|
|
58
|
+
this.appPath = appPath;
|
|
59
|
+
this.config = config;
|
|
60
|
+
this.dirs = {};
|
|
61
|
+
}
|
|
62
|
+
async run() {
|
|
63
|
+
console_1.default.header('Distributed Compiler');
|
|
64
|
+
log_1.Log.info('compiler', 'distributed', `Importing the Distributed definition from ${this.appPath}`);
|
|
65
|
+
const appFile = space_1.Space.path(this.compiler.space, this.appPath);
|
|
66
|
+
const app = (await Promise.resolve(`${appFile}`).then(s => __importStar(require(s)))).default;
|
|
67
|
+
this.config = Object.assign({}, app_1.App.getInfo(app).config?.compiler || {}, this.config);
|
|
68
|
+
this.mergeServicePaths(app);
|
|
69
|
+
this.expandLibPaths();
|
|
70
|
+
try {
|
|
71
|
+
await new _1_mkdir_stage_1.MkdirStage(this, app).run();
|
|
72
|
+
await new _2_build_typescript_stage_1.BuildTypescriptStage(this, app).run();
|
|
73
|
+
await new _3_copy_types_stage_1.CopyTypesStage(this, app).run();
|
|
74
|
+
await new _4_dump_modules_stage_1.DumpModulesStage(this, app).run();
|
|
75
|
+
// await new CopyStaticStage(this, app).run();
|
|
76
|
+
// await new DumpCLIStage(this, app).run();
|
|
77
|
+
// await new DumpPackageJsonStage(this, app).run();
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
log_1.Log.error('compiler', 'distributed', e.toString(), { stack: e.stack });
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
mergeServicePaths(app) {
|
|
85
|
+
var _a;
|
|
86
|
+
const services = app_1.App.getServices(app);
|
|
87
|
+
for (const name in services) {
|
|
88
|
+
const service = services[name];
|
|
89
|
+
if (!service.libPaths)
|
|
90
|
+
continue;
|
|
91
|
+
(_a = this.config).libPaths ?? (_a.libPaths = []);
|
|
92
|
+
this.config.libPaths.push(...service.libPaths);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
expandLibPaths() {
|
|
96
|
+
var _a;
|
|
97
|
+
const expandedPaths = [];
|
|
98
|
+
(_a = this.config).libPaths ?? (_a.libPaths = []);
|
|
99
|
+
for (const path of this.config.libPaths) {
|
|
100
|
+
const expanded = path_1.Path.expandWildcard(path);
|
|
101
|
+
expandedPaths.push(...expanded);
|
|
102
|
+
}
|
|
103
|
+
this.config.libPaths = expandedPaths;
|
|
104
|
+
}
|
|
105
|
+
static async scanAll(dir) {
|
|
106
|
+
const apps = [];
|
|
107
|
+
const nodes = fs.readdirSync(dir, { withFileTypes: true });
|
|
108
|
+
for (const node of nodes) {
|
|
109
|
+
const nodePath = path.resolve(dir, node.name);
|
|
110
|
+
if (!nodePath.endsWith('.ts')) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const exported = (await Promise.resolve(`${nodePath}`).then(s => __importStar(require(s))))?.default;
|
|
114
|
+
if (exported instanceof distributed_app_1.DistributedApp) {
|
|
115
|
+
apps.push(exported);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return apps;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.DistributedCompiler = DistributedCompiler;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DistributedApp } from "../../../../engine/apps/distributed/distributed.app";
|
|
2
|
+
import { DistributedCompiler } from '../distributed_compiler';
|
|
3
|
+
/**
|
|
4
|
+
* [Distributed Compiler Stage #1]
|
|
5
|
+
* Create the directory structure
|
|
6
|
+
*
|
|
7
|
+
* @category Distributed Compiler
|
|
8
|
+
* @subcategory Stages
|
|
9
|
+
*/
|
|
10
|
+
export declare class MkdirStage {
|
|
11
|
+
private distributed;
|
|
12
|
+
private app;
|
|
13
|
+
constructor(distributed: DistributedCompiler, app: DistributedApp<any, any>);
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.MkdirStage = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const space_1 = require("../../../../engine/space");
|
|
40
|
+
const log_1 = require("../../../../engine/util/log");
|
|
41
|
+
/**
|
|
42
|
+
* [Distributed Compiler Stage #1]
|
|
43
|
+
* Create the directory structure
|
|
44
|
+
*
|
|
45
|
+
* @category Distributed Compiler
|
|
46
|
+
* @subcategory Stages
|
|
47
|
+
*/
|
|
48
|
+
class MkdirStage {
|
|
49
|
+
constructor(distributed, app) {
|
|
50
|
+
this.distributed = distributed;
|
|
51
|
+
this.app = app;
|
|
52
|
+
}
|
|
53
|
+
async run() {
|
|
54
|
+
log_1.Log.info('compiler', 'distributed', 'Creating build directory tree');
|
|
55
|
+
const dirs = this.distributed.dirs;
|
|
56
|
+
dirs.build = space_1.Space.path(this.distributed.compiler.space, 'build', this.app.name);
|
|
57
|
+
// Remove build folder
|
|
58
|
+
log_1.Log.debug('compiler', 'distributed', `Removing folder ${dirs.build}`);
|
|
59
|
+
fs.rmSync(dirs.build, { recursive: true, force: true });
|
|
60
|
+
// Create build folder
|
|
61
|
+
log_1.Log.debug('compiler', 'distributed', `Creating folder ${dirs.build}`);
|
|
62
|
+
fs.mkdirSync(dirs.build, { recursive: true });
|
|
63
|
+
dirs.nodes = {};
|
|
64
|
+
for (const name in this.app.nodes) {
|
|
65
|
+
dirs.nodes[name] = {
|
|
66
|
+
build: path.resolve(dirs.build, name),
|
|
67
|
+
build_modules: path.resolve(dirs.build, name, 'modules'),
|
|
68
|
+
build_externals: path.resolve(dirs.build, name, 'externals'),
|
|
69
|
+
build_types: path.resolve(dirs.build, name, 'types'),
|
|
70
|
+
build_bin: path.resolve(dirs.build, name, 'bin'),
|
|
71
|
+
};
|
|
72
|
+
const nodeDirs = dirs.nodes[name];
|
|
73
|
+
// Create build/<node>/modules folder
|
|
74
|
+
log_1.Log.debug('compiler', 'distributed', `Creating folder ${nodeDirs.build_modules}`);
|
|
75
|
+
if (!fs.existsSync(nodeDirs.build_modules)) {
|
|
76
|
+
fs.mkdirSync(nodeDirs.build_modules, { recursive: true });
|
|
77
|
+
}
|
|
78
|
+
// Create build/<node>/externals folder
|
|
79
|
+
log_1.Log.debug('compiler', 'distributed', `Creating folder ${nodeDirs.build_externals}`);
|
|
80
|
+
if (!fs.existsSync(nodeDirs.build_externals)) {
|
|
81
|
+
fs.mkdirSync(nodeDirs.build_externals, { recursive: true });
|
|
82
|
+
}
|
|
83
|
+
// Create build/<node>/types folder
|
|
84
|
+
log_1.Log.debug('compiler', 'distributed', `Creating folder ${nodeDirs.build_types}`);
|
|
85
|
+
if (!fs.existsSync(nodeDirs.build_types)) {
|
|
86
|
+
fs.mkdirSync(nodeDirs.build_types, { recursive: true });
|
|
87
|
+
}
|
|
88
|
+
// Create build/<node>/bin folder
|
|
89
|
+
log_1.Log.debug('compiler', 'distributed', `Creating folder ${nodeDirs.build_bin}`);
|
|
90
|
+
if (!fs.existsSync(nodeDirs.build_bin)) {
|
|
91
|
+
fs.mkdirSync(nodeDirs.build_bin, { recursive: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.MkdirStage = MkdirStage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DistributedApp } from "../../../../engine/apps/distributed/distributed.app";
|
|
2
|
+
import { DistributedCompiler } from '../distributed_compiler';
|
|
3
|
+
/**
|
|
4
|
+
* [Distributed Compiler Stage #2]
|
|
5
|
+
* Build typescript files to build folder
|
|
6
|
+
*
|
|
7
|
+
* @category Distributed Compiler
|
|
8
|
+
* @subcategory Stages
|
|
9
|
+
*/
|
|
10
|
+
export declare class BuildTypescriptStage {
|
|
11
|
+
private distributed;
|
|
12
|
+
private app;
|
|
13
|
+
constructor(distributed: DistributedCompiler, app: DistributedApp<any, any>);
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.BuildTypescriptStage = void 0;
|
|
37
|
+
const ts = __importStar(require("typescript"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const space_1 = require("../../../../engine/space");
|
|
40
|
+
const log_1 = require("../../../../engine/util/log");
|
|
41
|
+
const typescript_compiler_1 = require("../../../typescript/typescript_compiler");
|
|
42
|
+
const app_1 = require("../../../../engine/apps/app");
|
|
43
|
+
/**
|
|
44
|
+
* [Distributed Compiler Stage #2]
|
|
45
|
+
* Build typescript files to build folder
|
|
46
|
+
*
|
|
47
|
+
* @category Distributed Compiler
|
|
48
|
+
* @subcategory Stages
|
|
49
|
+
*/
|
|
50
|
+
class BuildTypescriptStage {
|
|
51
|
+
constructor(distributed, app) {
|
|
52
|
+
this.distributed = distributed;
|
|
53
|
+
this.app = app;
|
|
54
|
+
}
|
|
55
|
+
async run() {
|
|
56
|
+
const { config, compiler, dirs: _dirs, appPath } = this.distributed;
|
|
57
|
+
for (const name in this.app.nodes) {
|
|
58
|
+
log_1.Log.info('compiler', 'distributed', `[${name}] Building TypeScript files...`);
|
|
59
|
+
const node = this.app.nodes[name];
|
|
60
|
+
const dirs = _dirs.nodes[name];
|
|
61
|
+
const libPaths = (config.libPaths || []).map(path => {
|
|
62
|
+
return space_1.Space.path(compiler.space, path);
|
|
63
|
+
});
|
|
64
|
+
const binFiles = Object.values(config.scripts || {}).map(path => {
|
|
65
|
+
return space_1.Space.path(compiler.space, path);
|
|
66
|
+
});
|
|
67
|
+
const info = app_1.App.getInfo(node);
|
|
68
|
+
const modulePaths = [];
|
|
69
|
+
space_1.Space.scan(compiler.space, (name) => {
|
|
70
|
+
if (info.spaceModules.includes(name)) {
|
|
71
|
+
modulePaths.push(space_1.Space.path(compiler.space, '.nesoi', name));
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
const space = compiler.space;
|
|
75
|
+
const spacePath = space_1.Space.path(space);
|
|
76
|
+
const libFiles = typescript_compiler_1.TypeScriptCompiler.allFiles(libPaths);
|
|
77
|
+
const appFile = space_1.Space.path(space, appPath);
|
|
78
|
+
const nesoiFile = space_1.Space.path(space, 'nesoi.ts');
|
|
79
|
+
const moduleFiles = typescript_compiler_1.TypeScriptCompiler.allFiles(modulePaths);
|
|
80
|
+
const replacePaths = {
|
|
81
|
+
[nesoiFile]: { __remove: true },
|
|
82
|
+
'$': { __remove: true },
|
|
83
|
+
[appFile]: path.resolve(dirs.build, 'app.js'),
|
|
84
|
+
'.nesoi': path.resolve(dirs.build, 'types'),
|
|
85
|
+
};
|
|
86
|
+
const tsPaths = {
|
|
87
|
+
'$': [nesoiFile]
|
|
88
|
+
};
|
|
89
|
+
if (config.nesoiPath) {
|
|
90
|
+
tsPaths['nesoi/*'] = [`${config.nesoiPath}/*`];
|
|
91
|
+
}
|
|
92
|
+
const moduleDirs = Object.values(compiler.modules).map(mod => [mod.module.name, space_1.Space.path(compiler.space, 'modules', ...mod.module.subdir, mod.module.name)]);
|
|
93
|
+
libFiles.forEach(lib => {
|
|
94
|
+
let libModule;
|
|
95
|
+
for (const [module, modulePath] of moduleDirs) {
|
|
96
|
+
if (lib.startsWith(modulePath)) {
|
|
97
|
+
libModule = { name: module, path: modulePath };
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
let outPath;
|
|
102
|
+
if (!libModule) {
|
|
103
|
+
lib = space_1.Space.relPath(compiler.space, lib);
|
|
104
|
+
outPath = path.resolve(dirs.build, lib);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const rel = path.relative(libModule.path, lib);
|
|
108
|
+
outPath = path.resolve(dirs.build, 'modules', libModule.name, rel);
|
|
109
|
+
}
|
|
110
|
+
replacePaths[lib] = path.resolve(dirs.build, outPath);
|
|
111
|
+
});
|
|
112
|
+
libPaths.forEach(lib => {
|
|
113
|
+
let libModule;
|
|
114
|
+
for (const [module, modulePath] of moduleDirs) {
|
|
115
|
+
if (lib.startsWith(modulePath)) {
|
|
116
|
+
libModule = { name: module, path: modulePath };
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
let outPath;
|
|
121
|
+
if (!libModule) {
|
|
122
|
+
lib = space_1.Space.relPath(compiler.space, lib);
|
|
123
|
+
outPath = path.resolve(dirs.build, lib);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const rel = path.relative(libModule.path, lib);
|
|
127
|
+
outPath = path.resolve(dirs.build, 'modules', libModule.name, rel);
|
|
128
|
+
}
|
|
129
|
+
replacePaths[lib] = path.resolve(dirs.build, outPath);
|
|
130
|
+
tsPaths[lib + '/*'] = [space_1.Space.path(compiler.space, lib) + '/*'];
|
|
131
|
+
});
|
|
132
|
+
tsPaths['.nesoi/*'] = [space_1.Space.path(compiler.space, '.nesoi') + '/*'];
|
|
133
|
+
const dotNesoiPath = space_1.Space.path(compiler.space, '.nesoi');
|
|
134
|
+
moduleFiles.forEach(moduleFile => {
|
|
135
|
+
const module = moduleFile.replace(dotNesoiPath, '').split(path.sep)[1];
|
|
136
|
+
if (!module?.length) {
|
|
137
|
+
throw new Error(`Unable to find module name from path ${moduleFile}`);
|
|
138
|
+
}
|
|
139
|
+
const filename = path.basename(moduleFile).replace(/\.ts$/, '.js');
|
|
140
|
+
replacePaths[moduleFile] = path.resolve(dirs.build, 'modules', module, filename);
|
|
141
|
+
});
|
|
142
|
+
binFiles.forEach(binFile => {
|
|
143
|
+
const filename = path.basename(binFile).replace(/\.ts$/, '.js');
|
|
144
|
+
replacePaths[binFile] = path.resolve(dirs.build, 'bin', filename);
|
|
145
|
+
});
|
|
146
|
+
const emitCode = typescript_compiler_1.TypeScriptCompiler.compileApp(info.spaceModules, [
|
|
147
|
+
appFile,
|
|
148
|
+
...libFiles,
|
|
149
|
+
...binFiles,
|
|
150
|
+
...moduleFiles
|
|
151
|
+
], {
|
|
152
|
+
target: ts.ScriptTarget.ES2020,
|
|
153
|
+
module: ts.ModuleKind.CommonJS,
|
|
154
|
+
moduleResolution: ts.ModuleResolutionKind.Node10,
|
|
155
|
+
noEmitOnError: true,
|
|
156
|
+
declaration: true,
|
|
157
|
+
strict: true,
|
|
158
|
+
esModuleInterop: true,
|
|
159
|
+
paths: {
|
|
160
|
+
...tsPaths
|
|
161
|
+
},
|
|
162
|
+
rootDir: space_1.Space.path(space),
|
|
163
|
+
outDir: dirs.build,
|
|
164
|
+
// Built methods don't carry all the typings, so we disable this check
|
|
165
|
+
// However, this has been checked before Compiler built them
|
|
166
|
+
noImplicitAny: false,
|
|
167
|
+
}, spacePath, dirs.build, replacePaths);
|
|
168
|
+
if (emitCode !== 0) {
|
|
169
|
+
throw new Error('One or more TypeScript files contains errors.');
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.BuildTypescriptStage = BuildTypescriptStage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { DistributedApp } from "../../../../engine/apps/distributed/distributed.app";
|
|
2
|
+
import { DistributedCompiler } from '../distributed_compiler';
|
|
3
|
+
/**
|
|
4
|
+
* [distributed Compiler Stage #3]
|
|
5
|
+
* Copy type declarations to build/types folder
|
|
6
|
+
*
|
|
7
|
+
* @category distributed Compiler
|
|
8
|
+
* @subcategory Stages
|
|
9
|
+
*/
|
|
10
|
+
export declare class CopyTypesStage {
|
|
11
|
+
private distributed;
|
|
12
|
+
private app;
|
|
13
|
+
constructor(distributed: DistributedCompiler, app: DistributedApp<any, any>);
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.CopyTypesStage = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const space_1 = require("../../../../engine/space");
|
|
40
|
+
const log_1 = require("../../../../engine/util/log");
|
|
41
|
+
const name_helpers_1 = require("../../../helpers/name_helpers");
|
|
42
|
+
const app_1 = require("../../../../engine/apps/app");
|
|
43
|
+
/**
|
|
44
|
+
* [distributed Compiler Stage #3]
|
|
45
|
+
* Copy type declarations to build/types folder
|
|
46
|
+
*
|
|
47
|
+
* @category distributed Compiler
|
|
48
|
+
* @subcategory Stages
|
|
49
|
+
*/
|
|
50
|
+
class CopyTypesStage {
|
|
51
|
+
constructor(distributed, app) {
|
|
52
|
+
this.distributed = distributed;
|
|
53
|
+
this.app = app;
|
|
54
|
+
}
|
|
55
|
+
async run() {
|
|
56
|
+
const { compiler, dirs: _dirs } = this.distributed;
|
|
57
|
+
for (const name in this.app.nodes) {
|
|
58
|
+
log_1.Log.info('compiler', 'distributed', `[${name}] Copying module and space types from .nesoi to build/types folder...`);
|
|
59
|
+
const node = this.app.nodes[name];
|
|
60
|
+
const dirs = _dirs.nodes[name];
|
|
61
|
+
const info = app_1.App.getInfo(node);
|
|
62
|
+
// Copy module types to types folder
|
|
63
|
+
for (const name of info.spaceModules) {
|
|
64
|
+
const module = compiler.modules[name];
|
|
65
|
+
const from = space_1.Space.path(compiler.space, '.nesoi', module.lowName + '.module.ts');
|
|
66
|
+
const to = path.resolve(dirs.build_types, module.lowName + '.module.ts');
|
|
67
|
+
log_1.Log.debug('compiler', 'distributed', `Copying module types from ${from} to ${to}`);
|
|
68
|
+
fs.cpSync(from, to, { recursive: true });
|
|
69
|
+
}
|
|
70
|
+
// Copy space type to types folder
|
|
71
|
+
{
|
|
72
|
+
const space = compiler.space._name;
|
|
73
|
+
const spaceLow = name_helpers_1.NameHelpers.nameHighToLow(space);
|
|
74
|
+
const from = space_1.Space.path(compiler.space, '.nesoi', spaceLow + '.ts');
|
|
75
|
+
const to = path.resolve(dirs.build_types, spaceLow + '.ts');
|
|
76
|
+
log_1.Log.debug('compiler', 'distributed', `Copying space types from ${from} to ${to}`);
|
|
77
|
+
fs.cpSync(from, to, { recursive: true });
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.CopyTypesStage = CopyTypesStage;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DistributedApp } from "../../../../engine/apps/distributed/distributed.app";
|
|
2
|
+
import { DistributedCompiler } from '../distributed_compiler';
|
|
3
|
+
/**
|
|
4
|
+
* [distributed Compiler Stage #4]
|
|
5
|
+
* Dump modules to build/modules folder.
|
|
6
|
+
*
|
|
7
|
+
* @category distributed Compiler
|
|
8
|
+
* @subcategory Stages
|
|
9
|
+
*/
|
|
10
|
+
export declare class DumpModulesStage {
|
|
11
|
+
private distributed;
|
|
12
|
+
private app;
|
|
13
|
+
constructor(distributed: DistributedCompiler, app: DistributedApp<any, any>);
|
|
14
|
+
run(): Promise<void>;
|
|
15
|
+
private dumpModule;
|
|
16
|
+
}
|