@codenotch/codenotch.cli 1.0.40 → 1.0.42
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 +78 -28
- package/dist/commands/generate/app.js +6 -0
- package/dist/commands/generate/app.js.map +1 -1
- package/dist/commands/generate/appmanifest.js +5 -0
- package/dist/commands/generate/appmanifest.js.map +1 -1
- package/dist/commands/generate/dbcontext.js +6 -2
- package/dist/commands/generate/dbcontext.js.map +1 -1
- package/dist/commands/generate/i18n.js +5 -0
- package/dist/commands/generate/i18n.js.map +1 -1
- package/dist/commands/generate/index.js +8 -1
- package/dist/commands/generate/index.js.map +1 -1
- package/dist/commands/generate/manifest.js +4 -0
- package/dist/commands/generate/manifest.js.map +1 -1
- package/dist/commands/generate/openapi.js +5 -1
- package/dist/commands/generate/openapi.js.map +1 -1
- package/dist/commands/generate/pkg.js +4 -0
- package/dist/commands/generate/pkg.js.map +1 -1
- package/dist/commands/generate/process.js +6 -0
- package/dist/commands/generate/process.js.map +1 -1
- package/dist/commands/project/deploy.js +9 -2
- package/dist/commands/project/deploy.js.map +1 -1
- package/dist/commands/project/index.js +8 -1
- package/dist/commands/project/index.js.map +1 -1
- package/dist/commands/project/inspect.js +65 -1
- package/dist/commands/project/inspect.js.map +1 -1
- package/dist/commands/project/new.js +7 -1
- package/dist/commands/project/new.js.map +1 -1
- package/dist/commands/project/remove.js +6 -1
- package/dist/commands/project/remove.js.map +1 -1
- package/dist/commands/react/build.js +22 -1
- package/dist/commands/react/build.js.map +1 -1
- package/dist/commands/react/clean.js +7 -2
- package/dist/commands/react/clean.js.map +1 -1
- package/dist/commands/react/dev.js +6 -0
- package/dist/commands/react/dev.js.map +1 -1
- package/dist/commands/react/index.js +11 -1
- package/dist/commands/react/index.js.map +1 -1
- package/dist/commands/react/package.d.ts +2 -0
- package/dist/commands/react/package.js +47 -0
- package/dist/commands/react/package.js.map +1 -0
- package/dist/commands/react/serve.js +5 -0
- package/dist/commands/react/serve.js.map +1 -1
- package/dist/commands/runtime/clear.js +5 -0
- package/dist/commands/runtime/clear.js.map +1 -1
- package/dist/commands/runtime/index.js +8 -1
- package/dist/commands/runtime/index.js.map +1 -1
- package/dist/commands/system/docs.d.ts +2 -0
- package/dist/commands/system/docs.js +57 -0
- package/dist/commands/system/docs.js.map +1 -0
- package/dist/commands/system/index.js +2 -0
- package/dist/commands/system/index.js.map +1 -1
- package/dist/commands/system/read.js +2 -1
- package/dist/commands/system/read.js.map +1 -1
- package/dist/commands/validation/files/ScriptValidator.js +9 -8
- package/dist/commands/validation/files/ScriptValidator.js.map +1 -1
- package/dist/commands/validation/validate.js +4 -13
- package/dist/commands/validation/validate.js.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/dist/utils/BuildUtils.d.ts +53 -5
- package/dist/utils/BuildUtils.js +233 -21
- package/dist/utils/BuildUtils.js.map +1 -1
- package/dist/utils/ConsoleUtils.d.ts +0 -2
- package/dist/utils/ConsoleUtils.js +0 -8
- package/dist/utils/ConsoleUtils.js.map +1 -1
- package/dist/utils/DbSchemaUtils.d.ts +16 -10
- package/dist/utils/DbSchemaUtils.js +82 -30
- package/dist/utils/DbSchemaUtils.js.map +1 -1
- package/dist/utils/DocsUtils.d.ts +34 -0
- package/dist/utils/DocsUtils.js +76 -0
- package/dist/utils/DocsUtils.js.map +1 -0
- package/dist/utils/OsUtils.d.ts +6 -0
- package/dist/utils/OsUtils.js +26 -0
- package/dist/utils/OsUtils.js.map +1 -1
- package/dist/utils/PackageUtils.d.ts +101 -0
- package/dist/utils/PackageUtils.js +538 -0
- package/dist/utils/PackageUtils.js.map +1 -0
- package/dist/utils/ProcessBundlerUtils.d.ts +103 -0
- package/dist/utils/ProcessBundlerUtils.js +336 -0
- package/dist/utils/ProcessBundlerUtils.js.map +1 -0
- package/dist/utils/ProjectCompilationUtils.d.ts +14 -2
- package/dist/utils/ProjectCompilationUtils.js +75 -3
- package/dist/utils/ProjectCompilationUtils.js.map +1 -1
- package/dist/utils/ProjectGeneratorUtils.d.ts +2 -1
- package/dist/utils/ProjectGeneratorUtils.js +21 -14
- package/dist/utils/ProjectGeneratorUtils.js.map +1 -1
- package/dist/utils/ProjectTemplates.d.ts +2 -2
- package/dist/utils/ProjectTemplates.js +12 -6
- package/dist/utils/ProjectTemplates.js.map +1 -1
- package/dist/utils/ProjectUtils.d.ts +18 -1
- package/dist/utils/ProjectUtils.js +33 -28
- package/dist/utils/ProjectUtils.js.map +1 -1
- package/dist/utils/ServeUtils.js +1 -2
- package/dist/utils/ServeUtils.js.map +1 -1
- package/dist/utils/TemplateUtils.d.ts +29 -0
- package/dist/utils/TemplateUtils.js +96 -3
- package/dist/utils/TemplateUtils.js.map +1 -1
- package/package.json +78 -71
- package/resources/docs/apps.md +109 -0
- package/resources/docs/i18n.md +51 -0
- package/resources/docs/processes.md +87 -0
- package/resources/docs/project.md +101 -0
- package/resources/docs/queries.md +54 -0
- package/resources/docs/tables.md +97 -0
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { IProcessTrigger } from './ProjectUtils';
|
|
2
|
+
import { IJsonSchema } from './TypeSchemaUtils';
|
|
3
|
+
/** One entry of 'compiled/processes.json': everything the runtime needs to route and execute a process */
|
|
4
|
+
export interface IProcessArtifact {
|
|
5
|
+
id: string;
|
|
6
|
+
/** Path of the bundle, relative to the root of the package, posix separators, e.g. 'compiled/CreateBook.js' */
|
|
7
|
+
file: string;
|
|
8
|
+
/** Content hash of the bundle, 'sha256:<hex>', meant as the key of the V8 code cache of the runtime */
|
|
9
|
+
hash: string;
|
|
10
|
+
/** Declaration site, relative to the root of the package, e.g. 'processes/products.ts:5' */
|
|
11
|
+
source: string;
|
|
12
|
+
/** How the process is started, undefined when it is only reachable through ctx.call */
|
|
13
|
+
trigger?: IProcessTrigger;
|
|
14
|
+
auth?: {
|
|
15
|
+
scope: string;
|
|
16
|
+
};
|
|
17
|
+
description?: string;
|
|
18
|
+
/** True when 'run' declares an input parameter */
|
|
19
|
+
takesInput: boolean;
|
|
20
|
+
/** Schema of the input of 'run', when its parameter carries a type annotation */
|
|
21
|
+
input?: IJsonSchema;
|
|
22
|
+
/** Schema of the return type of 'run', Promise unwrapped, when it carries one */
|
|
23
|
+
output?: IJsonSchema;
|
|
24
|
+
}
|
|
25
|
+
export interface IProcessBundleResult {
|
|
26
|
+
/** One artifact per bundled process, sorted by id so the index is deterministic */
|
|
27
|
+
artifacts: IProcessArtifact[];
|
|
28
|
+
/** Path of the written 'processes.json', undefined when the bundling failed before writing it */
|
|
29
|
+
indexPath?: string;
|
|
30
|
+
/** Skipped declarations and bundler warnings, already worded for the console */
|
|
31
|
+
warnings: string[];
|
|
32
|
+
/** Bundling failures. When non-empty the artifacts list is empty */
|
|
33
|
+
errors: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Bundles every process of a project into its own self-contained .js artifact, executable by the
|
|
37
|
+
* C# runtime in a bare V8 engine (ClearScript). The full contract between these artifacts and the
|
|
38
|
+
* runtime is documented in docs/PROCESS-RUNTIME-CONTRACT.md — keep both in sync.
|
|
39
|
+
*
|
|
40
|
+
* In short, one artifact:
|
|
41
|
+
* - is an IIFE with no import left: the code of the process and every workspace file or npm
|
|
42
|
+
* package it reaches are inlined (each artifact is independent, duplication is accepted);
|
|
43
|
+
* - reads the '@codenotch/*' modules from `globalThis.__codenotch.modules`, injected by the
|
|
44
|
+
* runtime before the script is evaluated — they are never bundled;
|
|
45
|
+
* - registers itself into `globalThis.__cn_processes[id] = { id, run }`, where `run(ctx, input)`
|
|
46
|
+
* returns a Promise. Registration makes the artifacts host-agnostic: one engine per process
|
|
47
|
+
* and one shared engine per service both work.
|
|
48
|
+
*
|
|
49
|
+
* Next to the artifacts, 'processes.json' indexes them with their trigger, auth and input/output
|
|
50
|
+
* schemas, so the runtime routes and validates without ever reading TypeScript.
|
|
51
|
+
*
|
|
52
|
+
* esbuild only strips the types, it does not check them: typechecking is the job of the caller
|
|
53
|
+
* (see ProjectCompilationUtils.compileProject, which validates the scripts first).
|
|
54
|
+
*/
|
|
55
|
+
export default abstract class ProcessBundlerUtils {
|
|
56
|
+
/** Folder of the artifacts, relative to the root of the package */
|
|
57
|
+
static readonly OUTPUT_FOLDER_NAME = "compiled";
|
|
58
|
+
/** Name of the index written next to the artifacts */
|
|
59
|
+
static readonly INDEX_FILE_NAME = "processes.json";
|
|
60
|
+
/** Global the runtime fills with the '@codenotch/*' implementations before evaluating an artifact */
|
|
61
|
+
private static readonly MODULES_GLOBAL;
|
|
62
|
+
/** Global registry an artifact writes itself into when evaluated */
|
|
63
|
+
private static readonly REGISTRY_GLOBAL;
|
|
64
|
+
/** Bare specifiers of the Node standard library, which does not exist in the V8 of the runtime */
|
|
65
|
+
private static readonly NODE_BUILTINS;
|
|
66
|
+
/**
|
|
67
|
+
* Discovers the processes of `projectPath` and bundles each of them into
|
|
68
|
+
* `outDir` (default: '<projectPath>/compiled'), plus a 'processes.json' index.
|
|
69
|
+
*
|
|
70
|
+
* A declaration that cannot be bundled (id missing or built at runtime, variable not
|
|
71
|
+
* exported, duplicated id) is skipped with a warning rather than failing the build.
|
|
72
|
+
* Nothing is thrown for bundling failures either: they are returned as errors.
|
|
73
|
+
*
|
|
74
|
+
* @param projectPath root of the project, where the sources and 'node_modules' live
|
|
75
|
+
* @param outDir where the artifacts are written; its previous content is replaced when it
|
|
76
|
+
* looks like an earlier compilation output (empty, or holding the index)
|
|
77
|
+
*/
|
|
78
|
+
static bundleProcesses(projectPath: string, outDir?: string): Promise<IProcessBundleResult>;
|
|
79
|
+
/** Keeps the declarations that can become an artifact, one warning per skipped one */
|
|
80
|
+
private static selectBundlable;
|
|
81
|
+
/**
|
|
82
|
+
* One output file name per process id. Ids are sanitized for the file system and deduplicated
|
|
83
|
+
* case-insensitively (Windows), so the index 'file' field is the only reliable mapping.
|
|
84
|
+
*/
|
|
85
|
+
private static assignFileNames;
|
|
86
|
+
/** The three resolution rules of a bundle: synthetic entries, runtime-provided modules, no Node builtin */
|
|
87
|
+
private static createPlugin;
|
|
88
|
+
/** Source of the synthetic entry module of one process */
|
|
89
|
+
private static createEntrySource;
|
|
90
|
+
/** Source of the stand-in module of a runtime-provided '@codenotch/*' package */
|
|
91
|
+
private static createRuntimeModuleSource;
|
|
92
|
+
/** Index entries of the written bundles, hashing each artifact for the code cache of the runtime */
|
|
93
|
+
private static createArtifacts;
|
|
94
|
+
/**
|
|
95
|
+
* Empties the previous output, but refuses to wipe a folder that does not look like an
|
|
96
|
+
* earlier compilation (no index): losing user files is worse than a stale artifact.
|
|
97
|
+
*/
|
|
98
|
+
private static prepareOutputFolder;
|
|
99
|
+
/** 'processes/products.ts:5' — declaration site relative to the project, for messages and the index */
|
|
100
|
+
private static formatSource;
|
|
101
|
+
/** One console line out of an esbuild diagnostic, with its location when it has one */
|
|
102
|
+
private static formatEsbuildMessage;
|
|
103
|
+
}
|
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
const fs_1 = __importDefault(require("fs"));
|
|
40
|
+
const path_1 = __importDefault(require("path"));
|
|
41
|
+
const crypto_1 = require("crypto");
|
|
42
|
+
const module_1 = require("module");
|
|
43
|
+
const esbuild = __importStar(require("esbuild"));
|
|
44
|
+
const ProjectUtils_1 = __importDefault(require("./ProjectUtils"));
|
|
45
|
+
const FileUtils_1 = __importDefault(require("./FileUtils"));
|
|
46
|
+
/**
|
|
47
|
+
* Bundles every process of a project into its own self-contained .js artifact, executable by the
|
|
48
|
+
* C# runtime in a bare V8 engine (ClearScript). The full contract between these artifacts and the
|
|
49
|
+
* runtime is documented in docs/PROCESS-RUNTIME-CONTRACT.md — keep both in sync.
|
|
50
|
+
*
|
|
51
|
+
* In short, one artifact:
|
|
52
|
+
* - is an IIFE with no import left: the code of the process and every workspace file or npm
|
|
53
|
+
* package it reaches are inlined (each artifact is independent, duplication is accepted);
|
|
54
|
+
* - reads the '@codenotch/*' modules from `globalThis.__codenotch.modules`, injected by the
|
|
55
|
+
* runtime before the script is evaluated — they are never bundled;
|
|
56
|
+
* - registers itself into `globalThis.__cn_processes[id] = { id, run }`, where `run(ctx, input)`
|
|
57
|
+
* returns a Promise. Registration makes the artifacts host-agnostic: one engine per process
|
|
58
|
+
* and one shared engine per service both work.
|
|
59
|
+
*
|
|
60
|
+
* Next to the artifacts, 'processes.json' indexes them with their trigger, auth and input/output
|
|
61
|
+
* schemas, so the runtime routes and validates without ever reading TypeScript.
|
|
62
|
+
*
|
|
63
|
+
* esbuild only strips the types, it does not check them: typechecking is the job of the caller
|
|
64
|
+
* (see ProjectCompilationUtils.compileProject, which validates the scripts first).
|
|
65
|
+
*/
|
|
66
|
+
class ProcessBundlerUtils {
|
|
67
|
+
/** Folder of the artifacts, relative to the root of the package */
|
|
68
|
+
static OUTPUT_FOLDER_NAME = 'compiled';
|
|
69
|
+
/** Name of the index written next to the artifacts */
|
|
70
|
+
static INDEX_FILE_NAME = 'processes.json';
|
|
71
|
+
/** Global the runtime fills with the '@codenotch/*' implementations before evaluating an artifact */
|
|
72
|
+
static MODULES_GLOBAL = 'globalThis.__codenotch.modules';
|
|
73
|
+
/** Global registry an artifact writes itself into when evaluated */
|
|
74
|
+
static REGISTRY_GLOBAL = 'globalThis.__cn_processes';
|
|
75
|
+
/** Bare specifiers of the Node standard library, which does not exist in the V8 of the runtime */
|
|
76
|
+
static NODE_BUILTINS = new Set(module_1.builtinModules);
|
|
77
|
+
/**
|
|
78
|
+
* Discovers the processes of `projectPath` and bundles each of them into
|
|
79
|
+
* `outDir` (default: '<projectPath>/compiled'), plus a 'processes.json' index.
|
|
80
|
+
*
|
|
81
|
+
* A declaration that cannot be bundled (id missing or built at runtime, variable not
|
|
82
|
+
* exported, duplicated id) is skipped with a warning rather than failing the build.
|
|
83
|
+
* Nothing is thrown for bundling failures either: they are returned as errors.
|
|
84
|
+
*
|
|
85
|
+
* @param projectPath root of the project, where the sources and 'node_modules' live
|
|
86
|
+
* @param outDir where the artifacts are written; its previous content is replaced when it
|
|
87
|
+
* looks like an earlier compilation output (empty, or holding the index)
|
|
88
|
+
*/
|
|
89
|
+
static async bundleProcesses(projectPath, outDir) {
|
|
90
|
+
projectPath = path_1.default.resolve(projectPath);
|
|
91
|
+
outDir = path_1.default.resolve(outDir ?? path_1.default.join(projectPath, this.OUTPUT_FOLDER_NAME));
|
|
92
|
+
const warnings = [];
|
|
93
|
+
const errors = [];
|
|
94
|
+
const discovered = await ProjectUtils_1.default.discoverProcessFiles(projectPath);
|
|
95
|
+
const selected = this.selectBundlable(discovered, projectPath, warnings);
|
|
96
|
+
this.prepareOutputFolder(outDir, warnings);
|
|
97
|
+
const fileNames = this.assignFileNames(selected);
|
|
98
|
+
if (selected.length > 0) {
|
|
99
|
+
const entryPoints = {};
|
|
100
|
+
for (const process of selected) {
|
|
101
|
+
entryPoints[fileNames.get(process.id)] = `cn-process-entry:${process.id}`;
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
const result = await esbuild.build({
|
|
105
|
+
entryPoints,
|
|
106
|
+
bundle: true,
|
|
107
|
+
write: true,
|
|
108
|
+
outdir: outDir,
|
|
109
|
+
format: 'iife',
|
|
110
|
+
platform: 'neutral',
|
|
111
|
+
// 'neutral' resolves nothing by default, so packages without an 'exports' map would not be found
|
|
112
|
+
mainFields: ['module', 'main'],
|
|
113
|
+
target: 'es2022',
|
|
114
|
+
sourcemap: true,
|
|
115
|
+
sourcesContent: true,
|
|
116
|
+
charset: 'utf8',
|
|
117
|
+
legalComments: 'none',
|
|
118
|
+
logLevel: 'silent',
|
|
119
|
+
absWorkingDir: projectPath,
|
|
120
|
+
plugins: [this.createPlugin(new Map(selected.map(process => [process.id, process])))]
|
|
121
|
+
});
|
|
122
|
+
warnings.push(...result.warnings.map(message => this.formatEsbuildMessage(message)));
|
|
123
|
+
}
|
|
124
|
+
catch (failure) {
|
|
125
|
+
const bundleErrors = failure.errors;
|
|
126
|
+
const bundleWarnings = failure.warnings;
|
|
127
|
+
if (Array.isArray(bundleErrors) && bundleErrors.length > 0) {
|
|
128
|
+
errors.push(...bundleErrors.map(message => this.formatEsbuildMessage(message)));
|
|
129
|
+
warnings.push(...(bundleWarnings ?? []).map(message => this.formatEsbuildMessage(message)));
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
errors.push(`Process bundling failed: ${failure instanceof Error ? failure.message : String(failure)}`);
|
|
133
|
+
}
|
|
134
|
+
return { artifacts: [], warnings, errors };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// The index is written even when empty: it tells the runtime 'no process' apart from
|
|
138
|
+
// 'packaged by a cli that did not bundle processes yet'
|
|
139
|
+
const artifacts = this.createArtifacts(selected, fileNames, projectPath, outDir, errors);
|
|
140
|
+
const index = {
|
|
141
|
+
version: 1,
|
|
142
|
+
processes: artifacts
|
|
143
|
+
};
|
|
144
|
+
const indexPath = path_1.default.join(outDir, this.INDEX_FILE_NAME);
|
|
145
|
+
if (!FileUtils_1.default.writeFileSync(indexPath, JSON.stringify(index, null, 4) + '\n')) {
|
|
146
|
+
errors.push(`Could not write '${indexPath}'.`);
|
|
147
|
+
return { artifacts, warnings, errors };
|
|
148
|
+
}
|
|
149
|
+
return { artifacts, indexPath, warnings, errors };
|
|
150
|
+
}
|
|
151
|
+
/** Keeps the declarations that can become an artifact, one warning per skipped one */
|
|
152
|
+
static selectBundlable(discovered, projectPath, warnings) {
|
|
153
|
+
const selected = [];
|
|
154
|
+
const byId = new Map();
|
|
155
|
+
for (const process of discovered) {
|
|
156
|
+
const at = this.formatSource(process, projectPath);
|
|
157
|
+
const name = process.variableName !== undefined ? `'${process.variableName}'` : '(anonymous)';
|
|
158
|
+
if (!process.isIdStatic) {
|
|
159
|
+
warnings.push(`${at}: the id of process ${name} is built at runtime — skipped, a bundled process needs a static string id`);
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (process.id === undefined) {
|
|
163
|
+
warnings.push(`${at}: process ${name} has no 'id' — skipped`);
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
if (process.variableName === undefined) {
|
|
167
|
+
warnings.push(`${at}: process '${process.id}' is not assigned to a variable — skipped, the bundle entry needs an export to reach it`);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (!process.isExported) {
|
|
171
|
+
warnings.push(`${at}: process '${process.id}' is assigned to ${name} which is not exported — skipped`);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const existing = byId.get(process.id);
|
|
175
|
+
if (existing) {
|
|
176
|
+
warnings.push(`${at}: duplicate process id '${process.id}', already declared at ${this.formatSource(existing, projectPath)} — skipped, the first declaration wins`);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
byId.set(process.id, process);
|
|
180
|
+
selected.push(process);
|
|
181
|
+
}
|
|
182
|
+
return selected;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* One output file name per process id. Ids are sanitized for the file system and deduplicated
|
|
186
|
+
* case-insensitively (Windows), so the index 'file' field is the only reliable mapping.
|
|
187
|
+
*/
|
|
188
|
+
static assignFileNames(selected) {
|
|
189
|
+
const names = new Map();
|
|
190
|
+
const taken = new Set();
|
|
191
|
+
for (const process of selected) {
|
|
192
|
+
let base = process.id.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
193
|
+
if (base === '' || base === '.' || base === '..') {
|
|
194
|
+
base = 'process';
|
|
195
|
+
}
|
|
196
|
+
let name = base;
|
|
197
|
+
for (let suffix = 2; taken.has(name.toLowerCase()); suffix++) {
|
|
198
|
+
name = `${base}_${suffix}`;
|
|
199
|
+
}
|
|
200
|
+
taken.add(name.toLowerCase());
|
|
201
|
+
names.set(process.id, name);
|
|
202
|
+
}
|
|
203
|
+
return names;
|
|
204
|
+
}
|
|
205
|
+
/** The three resolution rules of a bundle: synthetic entries, runtime-provided modules, no Node builtin */
|
|
206
|
+
static createPlugin(processesById) {
|
|
207
|
+
const self = this;
|
|
208
|
+
return {
|
|
209
|
+
name: 'codenotch-processes',
|
|
210
|
+
setup(build) {
|
|
211
|
+
// Synthetic entry of each process: imports its variable and registers its run
|
|
212
|
+
build.onResolve({ filter: /^cn-process-entry:/ }, args => ({
|
|
213
|
+
path: args.path.substring('cn-process-entry:'.length),
|
|
214
|
+
namespace: 'cn-process-entry'
|
|
215
|
+
}));
|
|
216
|
+
build.onLoad({ filter: /.*/, namespace: 'cn-process-entry' }, args => {
|
|
217
|
+
const process = processesById.get(args.path);
|
|
218
|
+
return {
|
|
219
|
+
contents: self.createEntrySource(process),
|
|
220
|
+
resolveDir: path_1.default.dirname(process.filePath),
|
|
221
|
+
loader: 'js'
|
|
222
|
+
};
|
|
223
|
+
});
|
|
224
|
+
// '@codenotch/*' is provided by the runtime, never bundled: the import becomes a
|
|
225
|
+
// lookup in the modules global. sideEffects false lets a type-only import vanish.
|
|
226
|
+
build.onResolve({ filter: /^@codenotch\// }, args => ({
|
|
227
|
+
path: args.path,
|
|
228
|
+
namespace: 'cn-runtime-module',
|
|
229
|
+
sideEffects: false
|
|
230
|
+
}));
|
|
231
|
+
build.onLoad({ filter: /.*/, namespace: 'cn-runtime-module' }, args => ({
|
|
232
|
+
contents: self.createRuntimeModuleSource(args.path),
|
|
233
|
+
loader: 'js'
|
|
234
|
+
}));
|
|
235
|
+
// The Node standard library does not exist in the V8 of the runtime: failing here
|
|
236
|
+
// with a clear message beats an exotic failure inside the runtime months later
|
|
237
|
+
const blockBuiltin = (specifier) => ({
|
|
238
|
+
errors: [{ text: `'${specifier}' is part of the Node.js standard library, which does not exist in the V8 engine of the Codenotch runtime. A process cannot use it.` }]
|
|
239
|
+
});
|
|
240
|
+
build.onResolve({ filter: /^node:/ }, args => blockBuiltin(args.path));
|
|
241
|
+
build.onResolve({ filter: /^[^./]/ }, args => self.NODE_BUILTINS.has(args.path) ? blockBuiltin(args.path) : undefined);
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/** Source of the synthetic entry module of one process */
|
|
246
|
+
static createEntrySource(process) {
|
|
247
|
+
const idJson = JSON.stringify(process.id);
|
|
248
|
+
// esbuild accepts absolute import paths; forward slashes keep the source identical across platforms
|
|
249
|
+
const importPath = JSON.stringify(process.filePath.replaceAll('\\', '/'));
|
|
250
|
+
return [
|
|
251
|
+
`import { ${process.variableName} as __cnProcess } from ${importPath};`,
|
|
252
|
+
``,
|
|
253
|
+
`// The runtime looks the process up in this registry after evaluating the bundle`,
|
|
254
|
+
`const __cnRegistry = ${this.REGISTRY_GLOBAL} || (${this.REGISTRY_GLOBAL} = {});`,
|
|
255
|
+
`__cnRegistry[${idJson}] = {`,
|
|
256
|
+
` id: ${idJson},`,
|
|
257
|
+
` run: (ctx, input) => __cnProcess.run(ctx, input)`,
|
|
258
|
+
`};`,
|
|
259
|
+
``
|
|
260
|
+
].join('\n');
|
|
261
|
+
}
|
|
262
|
+
/** Source of the stand-in module of a runtime-provided '@codenotch/*' package */
|
|
263
|
+
static createRuntimeModuleSource(moduleName) {
|
|
264
|
+
const nameJson = JSON.stringify(moduleName);
|
|
265
|
+
return [
|
|
266
|
+
`var __cnModules = globalThis.__codenotch && ${this.MODULES_GLOBAL};`,
|
|
267
|
+
`var __cnProvided = __cnModules && __cnModules[${nameJson}];`,
|
|
268
|
+
`if (!__cnProvided) {`,
|
|
269
|
+
` throw new Error("The runtime did not provide " + ${nameJson} + ": it must be set in ${this.MODULES_GLOBAL} before this script is evaluated.");`,
|
|
270
|
+
`}`,
|
|
271
|
+
`module.exports = __cnProvided;`,
|
|
272
|
+
``
|
|
273
|
+
].join('\n');
|
|
274
|
+
}
|
|
275
|
+
/** Index entries of the written bundles, hashing each artifact for the code cache of the runtime */
|
|
276
|
+
static createArtifacts(selected, fileNames, projectPath, outDir, errors) {
|
|
277
|
+
// 'file' is relative to the root of the package, which is the parent of the output folder —
|
|
278
|
+
// not to projectPath: when packaging, the sources and the package are two different trees
|
|
279
|
+
const outFolderRelative = path_1.default.basename(outDir);
|
|
280
|
+
const artifacts = [];
|
|
281
|
+
for (const process of selected) {
|
|
282
|
+
const fileName = `${fileNames.get(process.id)}.js`;
|
|
283
|
+
const filePath = path_1.default.join(outDir, fileName);
|
|
284
|
+
let content;
|
|
285
|
+
try {
|
|
286
|
+
content = fs_1.default.readFileSync(filePath);
|
|
287
|
+
}
|
|
288
|
+
catch {
|
|
289
|
+
errors.push(`The bundle of process '${process.id}' was not written at '${filePath}'.`);
|
|
290
|
+
continue;
|
|
291
|
+
}
|
|
292
|
+
artifacts.push({
|
|
293
|
+
id: process.id,
|
|
294
|
+
file: `${outFolderRelative}/${fileName}`,
|
|
295
|
+
hash: `sha256:${(0, crypto_1.createHash)('sha256').update(content).digest('hex')}`,
|
|
296
|
+
source: this.formatSource(process, projectPath),
|
|
297
|
+
trigger: process.trigger,
|
|
298
|
+
auth: process.scope !== undefined ? { scope: process.scope } : undefined,
|
|
299
|
+
description: process.description,
|
|
300
|
+
takesInput: process.takesInput,
|
|
301
|
+
input: process.input,
|
|
302
|
+
output: process.output
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
// Deterministic order: the same project always produces the same index
|
|
306
|
+
return artifacts.sort((a, b) => a.id.localeCompare(b.id));
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Empties the previous output, but refuses to wipe a folder that does not look like an
|
|
310
|
+
* earlier compilation (no index): losing user files is worse than a stale artifact.
|
|
311
|
+
*/
|
|
312
|
+
static prepareOutputFolder(outDir, warnings) {
|
|
313
|
+
if (!fs_1.default.existsSync(outDir)) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const entries = fs_1.default.readdirSync(outDir);
|
|
317
|
+
if (entries.length > 0 && !entries.includes(this.INDEX_FILE_NAME)) {
|
|
318
|
+
warnings.push(`'${outDir}' already exists and does not hold a '${this.INDEX_FILE_NAME}': its files are kept and the new artifacts are written next to them.`);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
FileUtils_1.default.deleteRecursively(outDir);
|
|
322
|
+
}
|
|
323
|
+
/** 'processes/products.ts:5' — declaration site relative to the project, for messages and the index */
|
|
324
|
+
static formatSource(process, projectPath) {
|
|
325
|
+
return `${path_1.default.relative(projectPath, process.filePath).replaceAll('\\', '/')}:${process.line}`;
|
|
326
|
+
}
|
|
327
|
+
/** One console line out of an esbuild diagnostic, with its location when it has one */
|
|
328
|
+
static formatEsbuildMessage(message) {
|
|
329
|
+
if (message.location) {
|
|
330
|
+
return `${message.location.file.replaceAll('\\', '/')}:${message.location.line}: ${message.text}`;
|
|
331
|
+
}
|
|
332
|
+
return message.text;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
exports.default = ProcessBundlerUtils;
|
|
336
|
+
//# sourceMappingURL=ProcessBundlerUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessBundlerUtils.js","sourceRoot":"","sources":["../../src/utils/ProcessBundlerUtils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,mCAAoC;AACpC,mCAAwC;AACxC,iDAAmC;AACnC,kEAAmF;AACnF,4DAAoC;AAmCpC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAA8B,mBAAmB;IAE7C,mEAAmE;IACnE,MAAM,CAAU,kBAAkB,GAAG,UAAU,CAAC;IAEhD,sDAAsD;IACtD,MAAM,CAAU,eAAe,GAAG,gBAAgB,CAAC;IAEnD,qGAAqG;IAC7F,MAAM,CAAU,cAAc,GAAG,gCAAgC,CAAC;IAE1E,oEAAoE;IAC5D,MAAM,CAAU,eAAe,GAAG,2BAA2B,CAAC;IAEtE,kGAAkG;IAC1F,MAAM,CAAU,aAAa,GAAG,IAAI,GAAG,CAAC,uBAAc,CAAC,CAAC;IAEhE;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,WAAmB,EAAE,MAAe;QAE7D,WAAW,GAAG,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACxC,MAAM,GAAG,c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;OAGG;IACK,MAAM,CAAC,mBAAmB,CAAC,MAAc,EAAE,QAAkB;QAEjE,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YACzB,OAAO;QACX,CAAC;QAED,MAAM,OAAO,GAAG,YAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QACvC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,EAAE,CAAC;YAChE,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,yCAAyC,IAAI,CAAC,eAAe,uEAAuE,CAAC,CAAC;YAC9J,OAAO;QACX,CAAC;QAED,mBAAS,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,uGAAuG;IAC/F,MAAM,CAAC,YAAY,CAAC,OAA2B,EAAE,WAAmB;QACxE,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IACnG,CAAC;IAED,uFAAuF;IAC/E,MAAM,CAAC,oBAAoB,CAAC,OAAwB;QACxD,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;YACnB,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC;QACtG,CAAC;QACD,OAAO,OAAO,CAAC,IAAI,CAAC;IACxB,CAAC;;AA7TL,sCA8TC"}
|
|
@@ -16,10 +16,22 @@ export default abstract class ProjectCompilationUtils {
|
|
|
16
16
|
* We have to compile the project because some files need to be modified a bit in order to work when deployed
|
|
17
17
|
* In-place compilation, the files in the source folder will be modified/deleted and the output will be generated in the same folder
|
|
18
18
|
* /!\Warning/!\ This will modify/delete files in the source folder, make sure to know what you are doing !!!
|
|
19
|
-
* @param
|
|
19
|
+
* @param targetPath folder receiving the compiled output (and holding the sources, when compiling in place)
|
|
20
|
+
* @param options `sourcePath`: where the original sources and their 'node_modules' live, when
|
|
21
|
+
* `targetPath` is a stripped copy (packaging copies without 'node_modules', so
|
|
22
|
+
* typechecking and bundling would not resolve a single import there). The
|
|
23
|
+
* scripts are read from it, the outputs still land in `targetPath`.
|
|
20
24
|
* @returns the path to the compiled project
|
|
21
25
|
*/
|
|
22
|
-
static compileProject(targetPath: string
|
|
26
|
+
static compileProject(targetPath: string, options?: {
|
|
27
|
+
sourcePath?: string;
|
|
28
|
+
}): Promise<CompilationResult>;
|
|
29
|
+
/**
|
|
30
|
+
* Typechecks every .ts/.tsx of the project with a single TypeScript program, feeding the
|
|
31
|
+
* errors and warnings into the compilation context. Scripts are read from `sourcePath`, where
|
|
32
|
+
* 'node_modules' lives, so the imports resolve.
|
|
33
|
+
*/
|
|
34
|
+
private static validateScripts;
|
|
23
35
|
/**
|
|
24
36
|
* Execute the compilation step needed for the tests to execute properly, skipping steps that are not needed for tests (like building React apps)
|
|
25
37
|
*
|
|
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const path_1 = __importDefault(require("path"));
|
|
7
7
|
const FileUtils_1 = __importDefault(require("./FileUtils"));
|
|
8
8
|
const ConsoleUtils_1 = __importDefault(require("./ConsoleUtils"));
|
|
9
|
+
const codenotch_core_1 = require("@codenotch/codenotch.core");
|
|
9
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const ProcessBundlerUtils_1 = __importDefault(require("./ProcessBundlerUtils"));
|
|
12
|
+
const ScriptValidator_1 = __importDefault(require("../commands/validation/files/ScriptValidator"));
|
|
10
13
|
const MANIFEST_FILE_NAME = "manifest.json";
|
|
11
14
|
const DB_SCHEMA_FILE_NAME = "db-schema.xml";
|
|
12
15
|
class ProjectCompilationUtils {
|
|
@@ -15,17 +18,22 @@ class ProjectCompilationUtils {
|
|
|
15
18
|
* We have to compile the project because some files need to be modified a bit in order to work when deployed
|
|
16
19
|
* In-place compilation, the files in the source folder will be modified/deleted and the output will be generated in the same folder
|
|
17
20
|
* /!\Warning/!\ This will modify/delete files in the source folder, make sure to know what you are doing !!!
|
|
18
|
-
* @param
|
|
21
|
+
* @param targetPath folder receiving the compiled output (and holding the sources, when compiling in place)
|
|
22
|
+
* @param options `sourcePath`: where the original sources and their 'node_modules' live, when
|
|
23
|
+
* `targetPath` is a stripped copy (packaging copies without 'node_modules', so
|
|
24
|
+
* typechecking and bundling would not resolve a single import there). The
|
|
25
|
+
* scripts are read from it, the outputs still land in `targetPath`.
|
|
19
26
|
* @returns the path to the compiled project
|
|
20
27
|
*/
|
|
21
|
-
static async compileProject(targetPath) {
|
|
28
|
+
static async compileProject(targetPath, options = {}) {
|
|
22
29
|
// TODO: Generate kinda DB schema (read all .ts/.js files that declare a table)
|
|
23
30
|
// TODO: Generate openapi.json (read all .ts/.js files that declare a process)
|
|
24
31
|
// TODO: Generate ts files for i18n (one per *.i18n.csv)
|
|
32
|
+
const sourcePath = options.sourcePath ?? targetPath;
|
|
25
33
|
const context = {
|
|
26
34
|
targetPath: targetPath,
|
|
27
35
|
files: FileUtils_1.default.listFilesRecursively(targetPath, {
|
|
28
|
-
ignoredFolderNames: ['node_modules', '.codenotch', '.git', 'dist', 'build', 'out', '.github']
|
|
36
|
+
ignoredFolderNames: ['node_modules', '.codenotch', '.git', 'dist', 'build', 'out', '.github', ProcessBundlerUtils_1.default.OUTPUT_FOLDER_NAME]
|
|
29
37
|
}),
|
|
30
38
|
errors: [],
|
|
31
39
|
warnings: []
|
|
@@ -36,6 +44,26 @@ class ProjectCompilationUtils {
|
|
|
36
44
|
ConsoleUtils_1.default.check(`Manifest generated`);
|
|
37
45
|
// Overwrite manifest
|
|
38
46
|
FileUtils_1.default.writeFileSync(path_1.default.join(targetPath, MANIFEST_FILE_NAME), JSON.stringify(context.manifest, null, 4));
|
|
47
|
+
// Typecheck the scripts before bundling them: esbuild strips the types without checking
|
|
48
|
+
// them, and a project that does not compile must fail here, not on the runtime
|
|
49
|
+
await this.validateScripts(sourcePath, context);
|
|
50
|
+
// One self-contained .js per process, ready for the V8 of the runtime (see ProcessBundlerUtils)
|
|
51
|
+
console.log(chalk_1.default.cyan('→') + ' Bundling processes...');
|
|
52
|
+
const bundling = await ProcessBundlerUtils_1.default.bundleProcesses(sourcePath, path_1.default.join(targetPath, ProcessBundlerUtils_1.default.OUTPUT_FOLDER_NAME));
|
|
53
|
+
for (const warning of bundling.warnings) {
|
|
54
|
+
context.warnings.push(warning);
|
|
55
|
+
console.log(chalk_1.default.yellow(` ${warning}`));
|
|
56
|
+
}
|
|
57
|
+
for (const error of bundling.errors) {
|
|
58
|
+
context.errors.push(error);
|
|
59
|
+
console.log(chalk_1.default.red(` ${error}`));
|
|
60
|
+
}
|
|
61
|
+
if (bundling.artifacts.length === 0) {
|
|
62
|
+
ConsoleUtils_1.default.check('No process to bundle');
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
ConsoleUtils_1.default.check(`${bundling.artifacts.length} process(es) bundled into '${ProcessBundlerUtils_1.default.OUTPUT_FOLDER_NAME}/'`);
|
|
66
|
+
}
|
|
39
67
|
// Remove .npmrc if exists, we don't want to expose it
|
|
40
68
|
FileUtils_1.default.deleteRecursively(path_1.default.join(targetPath, '.npmrc'));
|
|
41
69
|
if (context.errors.length > 0) {
|
|
@@ -49,6 +77,50 @@ class ProjectCompilationUtils {
|
|
|
49
77
|
warnings: context.warnings
|
|
50
78
|
};
|
|
51
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Typechecks every .ts/.tsx of the project with a single TypeScript program, feeding the
|
|
82
|
+
* errors and warnings into the compilation context. Scripts are read from `sourcePath`, where
|
|
83
|
+
* 'node_modules' lives, so the imports resolve.
|
|
84
|
+
*/
|
|
85
|
+
static async validateScripts(sourcePath, context) {
|
|
86
|
+
console.log(chalk_1.default.cyan('→') + ' Typechecking scripts...');
|
|
87
|
+
// The generated .d.ts (db-schema) joins the program as an ambient declaration through the
|
|
88
|
+
// tsconfig, requesting it explicitly would report its diagnostics twice
|
|
89
|
+
const ignoredFolders = await FileUtils_1.default.getIgnoredFolderPaths(sourcePath);
|
|
90
|
+
const scriptPaths = FileUtils_1.default.listFilesRecursively(sourcePath, {
|
|
91
|
+
ignoredFolderPaths: ignoredFolders,
|
|
92
|
+
fileExtensions: ['.ts', '.tsx']
|
|
93
|
+
}).filter(filePath => !filePath.endsWith('.d.ts'));
|
|
94
|
+
if (scriptPaths.length === 0) {
|
|
95
|
+
ConsoleUtils_1.default.check('No script to typecheck');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const messages = await ScriptValidator_1.default.validateMany(scriptPaths);
|
|
99
|
+
let errorCount = 0;
|
|
100
|
+
for (const message of messages) {
|
|
101
|
+
// '@codenotch/*' is provided by the runtime: an unresolved one only means its typings
|
|
102
|
+
// are not published yet (@codenotch/orm today), which must not block the packaging
|
|
103
|
+
if (message.code === 'TS2307' && message.message.includes(`'@codenotch/`)) {
|
|
104
|
+
message.severity = 'warning';
|
|
105
|
+
}
|
|
106
|
+
const line = (0, codenotch_core_1.formatCompilationMessage)(message);
|
|
107
|
+
if (message.severity === 'error') {
|
|
108
|
+
errorCount++;
|
|
109
|
+
context.errors.push(line);
|
|
110
|
+
console.log(chalk_1.default.red(` ${line}`));
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
context.warnings.push(line);
|
|
114
|
+
console.log(chalk_1.default.yellow(` ${line}`));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (errorCount === 0) {
|
|
118
|
+
ConsoleUtils_1.default.check(`${scriptPaths.length} script(s) typechecked`);
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.log(chalk_1.default.red(`Typecheck failed with ${errorCount} error(s)`));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
52
124
|
/**
|
|
53
125
|
* Execute the compilation step needed for the tests to execute properly, skipping steps that are not needed for tests (like building React apps)
|
|
54
126
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProjectCompilationUtils.js","sourceRoot":"","sources":["../../src/utils/ProjectCompilationUtils.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;
|
|
1
|
+
{"version":3,"file":"ProjectCompilationUtils.js","sourceRoot":"","sources":["../../src/utils/ProjectCompilationUtils.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,4DAAoC;AACpC,kEAA0C;AAC1C,8DAAgG;AAChG,kDAA0B;AAC1B,gFAAwD;AACxD,mGAA2E;AAmB3E,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAC3C,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAC5C,MAA8B,uBAAuB;IAEjD;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,UAAkB,EAAE,UAAmC,EAAE;QAExF,+EAA+E;QAC/E,8EAA8E;QAC9E,wDAAwD;QAExD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,UAAU,CAAC;QAEpD,MAAM,OAAO,GAAuB;YAChC,UAAU,EAAE,UAAU;YACtB,KAAK,EAAE,mBAAS,CAAC,oBAAoB,CAAC,UAAU,EAAE;gBAC9C,kBAAkB,EAAE,CAAC,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,6BAAmB,CAAC,kBAAkB,CAAC;aACxI,CACA;YACD,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACf,CAAC;QAGF,qFAAqF;QACrF,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,yBAAyB,CAAC,CAAC;QACzD,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,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;QAC5B,QAAQ,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC;QAC9C,QAAQ,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;QAGtC,4BAA4B;QAC5B,IAAI,CAAC,QAAQ,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACzC,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;QAC/B,CAAC;QAED,qCAAqC;QACrC,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,KAAK,SAAS,EAAE,CAAC;YAChF,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,KAAK;gBACX,WAAW,EAAE,4BAA4B;aAC5C,CAAC,CAAC;QACP,CAAC;QACD,IAAI,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,OAAO;gBACb,WAAW,EAAE,+BAA+B;aAC/C,CAAC,CAAC;QACP,CAAC;QAED,qDAAqD;QACrD,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAClC,QAAQ,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,CAAA;QAC/B,CAAC;QAGD,OAAO,QAAQ,CAAC;IACpB,CAAC;CAKJ;AAxND,0CAwNC"}
|
|
@@ -14,9 +14,10 @@ export interface IGenerationResult {
|
|
|
14
14
|
* Every generator reports rather than prints: the command decides how to show the outcome.
|
|
15
15
|
*/
|
|
16
16
|
export default abstract class ProjectGeneratorUtils {
|
|
17
|
-
/** 'db-schema.xml' and 'db-schema.ts' from the 'defineEntity' declarations of the project */
|
|
17
|
+
/** 'db-schema.xml' and 'db-schema.d.ts' from the 'defineEntity' and 'defineDocument' declarations of the project */
|
|
18
18
|
static generateDbContext(projectPath: string): Promise<IGenerationResult & {
|
|
19
19
|
tableCount: number;
|
|
20
|
+
documentCount: number;
|
|
20
21
|
}>;
|
|
21
22
|
/** 'openapi.json' from the processes triggered by an api call */
|
|
22
23
|
static generateOpenApi(projectPath: string): Promise<IGenerationResult & {
|