@noldova/context 0.0.0-stage → 0.0.14

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.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +80 -2
  3. package/api/ctx.js +22 -0
  4. package/api/ctx.js.map +1 -0
  5. package/api/index.d.ts +350 -0
  6. package/api/index.js +21 -0
  7. package/api/index.js.map +1 -0
  8. package/enums/project-kind.js +13 -0
  9. package/enums/project-kind.js.map +1 -0
  10. package/exceptions/command-collision.exception.js +21 -0
  11. package/exceptions/command-collision.exception.js.map +1 -0
  12. package/exceptions/command-host.exception.js +14 -0
  13. package/exceptions/command-host.exception.js.map +1 -0
  14. package/exceptions/command-unknown.exception.js +17 -0
  15. package/exceptions/command-unknown.exception.js.map +1 -0
  16. package/exceptions/project-file.exception.js +16 -0
  17. package/exceptions/project-file.exception.js.map +1 -0
  18. package/exceptions/provider.exception.js +16 -0
  19. package/exceptions/provider.exception.js.map +1 -0
  20. package/models/command-context.js +18 -0
  21. package/models/command-context.js.map +1 -0
  22. package/models/command-output.js +10 -0
  23. package/models/command-output.js.map +1 -0
  24. package/models/command.js +10 -0
  25. package/models/command.js.map +1 -0
  26. package/models/console-output.js +19 -0
  27. package/models/console-output.js.map +1 -0
  28. package/models/project-entry-point.js +17 -0
  29. package/models/project-entry-point.js.map +1 -0
  30. package/models/project.js +91 -0
  31. package/models/project.js.map +1 -0
  32. package/package.json +28 -4
  33. package/resources.js +98 -0
  34. package/resources.js.map +1 -0
  35. package/services/command-host.js +84 -0
  36. package/services/command-host.js.map +1 -0
  37. package/services/host-locator.service.js +27 -0
  38. package/services/host-locator.service.js.map +1 -0
  39. package/services/project-file.service.js +37 -0
  40. package/services/project-file.service.js.map +1 -0
  41. package/services/provider-loader.service.js +57 -0
  42. package/services/provider-loader.service.js.map +1 -0
  43. package/types/command-class.js +9 -0
  44. package/types/command-class.js.map +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Noldova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,81 @@
1
- # Temporary Holding Version
1
+ # noldova.context
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The `ctx` command. It reads the project file (`.ctxp`), loads the command
4
+ providers the project names, and runs the command asked for. It has no command
5
+ of its own: `build`, `run` and the others come from the SDK and the tools.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install --global @noldova/context
11
+ npm install @noldova/context
12
+ ```
13
+
14
+ The first gives the `ctx` command; the second installs the host in the project,
15
+ beside the SDK and tools the project names, since they extend its `Command` and
16
+ need that copy. A global `ctx` hands each command to the host installed for the
17
+ folder it runs in, and runs the command itself only when the folder has none.
18
+
19
+ ## Use
20
+
21
+ ```bash
22
+ ctx --help
23
+ ctx --version
24
+ ctx run -- --port 8080
25
+ ```
26
+
27
+ `ctx` reads the one `.ctxp` in the folder it runs in; none or several is an
28
+ error. A command gets the project file's full path and every argument after its
29
+ name, as given. With no command, or `-h` or `--help`, it lists the commands;
30
+ `-v` or `--version` prints its version.
31
+
32
+ The project's `sdk` names the one SDK, `noldova.context.sdk` when left out, and
33
+ `tools` names the other providers:
34
+
35
+ ```json
36
+ {
37
+ "name": "noldova.context.app",
38
+ "kind": "executable",
39
+ "sdk": "noldova.context.sdk",
40
+ "tools": ["noldova.context.data.tools"],
41
+ "entry": { "source": "main.ts", "class": "Program" }
42
+ }
43
+ ```
44
+
45
+ Each provider is installed for the project as its npm package, such as
46
+ `@noldova/context.sdk`. Two providers offering a command of the same name is
47
+ an error.
48
+
49
+ `entry` tells the SDK's `run` which class's static `main` starts the app;
50
+ `source` is `main.ts` when left out, and `class` may be left out when the module
51
+ exports one class with a static `main`.
52
+
53
+ ## Write a provider
54
+
55
+ A provider exports, from its public API, classes that extend `Command`, each
56
+ with a constructor that takes no arguments:
57
+
58
+ ```ts
59
+ import { Command, type CommandContext } from "@noldova/context";
60
+
61
+ export class HelloCommand extends Command {
62
+ public override readonly name = "hello";
63
+ public override readonly description = "Says hello.";
64
+
65
+ public override async runAsync(context: CommandContext): Promise<number> {
66
+ context.output.writeLine(`Hello from ${context.projectFilePath}.`);
67
+ return 0;
68
+ }
69
+ }
70
+ ```
71
+
72
+ `ctx` reads only the first word as the command. Everything after it belongs to
73
+ the command, so subcommands at any depth and `ctx <command> --help` are its own
74
+ to handle, and `ctx --help` lists only the first words.
75
+
76
+ A failure `ctx` reports extends `CommandHostException`: its message goes to the
77
+ error output, and the exit code is 1.
78
+
79
+ ## License
80
+
81
+ MIT; see `LICENSE`.
package/api/ctx.js ADDED
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @license
4
+ * Copyright (c) Noldova.
5
+ *
6
+ * This source code is licensed under the license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ // This file uses Node APIs and will change when we replace Node.
10
+ // It writes its checks out instead of using @noldova/context.core: it runs beside the project host's copy of core
11
+ // and loads none of the context packages before it knows which copy to use.
12
+ import { fileURLToPath, pathToFileURL } from "node:url";
13
+ import { HostLocatorService } from "../services/host-locator.service.js";
14
+ const projectEntryPath = HostLocatorService.locate(process.cwd(), fileURLToPath(import.meta.url));
15
+ if (projectEntryPath === undefined) {
16
+ const { ConsoleOutput } = await import("../models/console-output.js");
17
+ const { CommandHost } = await import("../services/command-host.js");
18
+ process.exitCode = await new CommandHost(new ConsoleOutput()).runAsync(process.argv.slice(2), process.cwd());
19
+ }
20
+ else
21
+ await import(pathToFileURL(projectEntryPath).href);
22
+ //# sourceMappingURL=ctx.js.map
package/api/ctx.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ctx.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/api/ctx.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,iEAAiE;AACjE,kHAAkH;AAClH,4EAA4E;AAE5E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExD,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAEzE,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAClG,IAAI,gBAAgB,KAAK,SAAS,EAAE,CAAC;IACnC,MAAM,EAAE,aAAa,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IACtE,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC;IACpE,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,WAAW,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;AAC/G,CAAC;;IAEC,MAAM,MAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC"}
package/api/index.d.ts ADDED
@@ -0,0 +1,350 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import { Exception, type ExceptionOptions } from "@noldova/context.exceptions";
10
+
11
+ /**
12
+ * What a project produces, from its `.ctxp` `kind`.
13
+ */
14
+ export declare enum ProjectKind {
15
+ /**
16
+ * A package other projects use.
17
+ */
18
+ Library = "library",
19
+
20
+ /**
21
+ * An app, which the SDK's `run` builds and starts.
22
+ */
23
+ Executable = "executable"
24
+ }
25
+
26
+ /**
27
+ * Raised when `ctx` can't do what it was asked; every failure of this package extends it, and
28
+ * `CommandHost.runAsync` writes its message and returns 1.
29
+ */
30
+ export declare class CommandHostException extends Exception {
31
+ /**
32
+ * Initializes the exception.
33
+ *
34
+ * @param message What failed, normally a `Resources` message.
35
+ * @param options Optional options carrying the cause.
36
+ */
37
+ public constructor(message: string, options?: ExceptionOptions);
38
+ }
39
+
40
+ /**
41
+ * Raised when the project file is missing, ambiguous, unreadable or invalid.
42
+ */
43
+ export declare class ProjectFileException extends CommandHostException {
44
+ /**
45
+ * The project file, or the folder searched for one.
46
+ */
47
+ public readonly path: string;
48
+
49
+ /**
50
+ * Initializes the exception.
51
+ *
52
+ * @param path The project file, or the folder searched for one.
53
+ * @param message What failed, normally a `Resources` message.
54
+ * @param options Optional options carrying the cause, such as the JSON error.
55
+ */
56
+ public constructor(path: string, message: string, options?: ExceptionOptions);
57
+ }
58
+
59
+ /**
60
+ * Raised when a provider the project names is not installed, fails to load, or offers no
61
+ * command.
62
+ */
63
+ export declare class ProviderException extends CommandHostException {
64
+ /**
65
+ * The provider's identity, such as `noldova.context.sdk`.
66
+ */
67
+ public readonly identity: string;
68
+
69
+ /**
70
+ * Initializes the exception.
71
+ *
72
+ * @param identity The provider's identity.
73
+ * @param message What failed, normally a `Resources` message.
74
+ * @param options Optional options carrying the cause, such as the load error.
75
+ */
76
+ public constructor(identity: string, message: string, options?: ExceptionOptions);
77
+ }
78
+
79
+ /**
80
+ * Raised when two providers offer a command of the same name.
81
+ */
82
+ export declare class CommandCollisionException extends CommandHostException {
83
+ /**
84
+ * The command's name.
85
+ */
86
+ public readonly commandName: string;
87
+
88
+ /**
89
+ * The provider that offered it first: the SDK, or a tool earlier in `tools`.
90
+ */
91
+ public readonly firstProvider: string;
92
+
93
+ /**
94
+ * The provider that offered it again.
95
+ */
96
+ public readonly secondProvider: string;
97
+
98
+ /**
99
+ * Initializes the exception. The message names the command and both providers.
100
+ *
101
+ * @param commandName The command's name.
102
+ * @param firstProvider The provider that offered it first.
103
+ * @param secondProvider The provider that offered it again.
104
+ */
105
+ public constructor(commandName: string, firstProvider: string, secondProvider: string);
106
+ }
107
+
108
+ /**
109
+ * Raised when no provider of the project offers the command asked for.
110
+ */
111
+ export declare class CommandUnknownException extends CommandHostException {
112
+ /**
113
+ * The command asked for.
114
+ */
115
+ public readonly commandName: string;
116
+
117
+ /**
118
+ * Initializes the exception. The message names the command and points at `ctx --help`.
119
+ *
120
+ * @param commandName The command asked for.
121
+ */
122
+ public constructor(commandName: string);
123
+ }
124
+
125
+ /**
126
+ * Where a command writes what it reports.
127
+ */
128
+ export declare abstract class CommandOutput {
129
+ /**
130
+ * Writes one line of normal output.
131
+ *
132
+ * @param text The line, without its line break.
133
+ */
134
+ public abstract writeLine(text: string): void;
135
+
136
+ /**
137
+ * Writes one line of error output.
138
+ *
139
+ * @param text The line, without its line break.
140
+ */
141
+ public abstract writeErrorLine(text: string): void;
142
+ }
143
+
144
+ /**
145
+ * The process's standard output and standard error.
146
+ */
147
+ export declare class ConsoleOutput extends CommandOutput {
148
+ /**
149
+ * Writes the line to standard output.
150
+ *
151
+ * @param text The line, without its line break.
152
+ */
153
+ public override writeLine(text: string): void;
154
+
155
+ /**
156
+ * Writes the line to standard error.
157
+ *
158
+ * @param text The line, without its line break.
159
+ */
160
+ public override writeErrorLine(text: string): void;
161
+ }
162
+
163
+ /**
164
+ * Where an executable starts: the source and class whose static `main` the SDK's `run` calls,
165
+ * from the `.ctxp` `entry`.
166
+ */
167
+ export declare class ProjectEntryPoint {
168
+ /**
169
+ * The entry point's source, relative to the project file, such as `main.ts`, the default.
170
+ */
171
+ public readonly source: string;
172
+
173
+ /**
174
+ * The class whose static `main` starts the app, or `undefined` when the module's one class
175
+ * with a static `main` is used.
176
+ */
177
+ public readonly className: string | undefined;
178
+
179
+ private constructor();
180
+ }
181
+
182
+ /**
183
+ * A project file (`.ctxp`), as `ctx` reads it.
184
+ *
185
+ * @remarks
186
+ * `sdk` names the one SDK, `noldova.context.sdk` when left out, and `tools` the other
187
+ * providers, none when left out. Each is a package identity such as `noldova.context.sdk`,
188
+ * installed for the project as its npm package, such as `@noldova/context.sdk`.
189
+ */
190
+ export declare class Project {
191
+ /**
192
+ * The project's identity, from `name`.
193
+ */
194
+ public readonly name: string;
195
+
196
+ /**
197
+ * What the project produces, from `kind`.
198
+ */
199
+ public readonly kind: ProjectKind;
200
+
201
+ /**
202
+ * The SDK's identity.
203
+ */
204
+ public readonly sdk: string;
205
+
206
+ /**
207
+ * The other providers' identities, in their `.ctxp` order.
208
+ */
209
+ public readonly tools: readonly string[];
210
+
211
+ /**
212
+ * The executable's entry point, the default one when `entry` is left out; `undefined` for a
213
+ * library.
214
+ */
215
+ public readonly entryPoint: ProjectEntryPoint | undefined;
216
+
217
+ /**
218
+ * The project file's full path.
219
+ */
220
+ public readonly manifestPath: string;
221
+
222
+ /**
223
+ * The folder that holds the project file.
224
+ */
225
+ public readonly directory: string;
226
+
227
+ /**
228
+ * The SDK, then the tools: every provider whose commands the project uses.
229
+ */
230
+ public get providers(): readonly string[];
231
+
232
+ private constructor();
233
+
234
+ /**
235
+ * Reads a project file's text.
236
+ *
237
+ * @param text The file's JSON text.
238
+ * @param manifestPath The file's full path, which failures name.
239
+ * @param directory The folder that holds the file.
240
+ * @returns The project.
241
+ * @throws ProjectFileException when the text is not JSON, a field is missing or of the wrong
242
+ * type, `kind` is not `library` or `executable`, `sdk` or a tool is not a package identity, a
243
+ * tool is repeated or names the SDK, or `entry.source` is not a `.ts` source.
244
+ * @example
245
+ * const project = Project.parse('{ "name": "noldova.context.app", "kind": "executable" }', "/app/app.ctxp", "/app");
246
+ * project.sdk; // "noldova.context.sdk"
247
+ */
248
+ public static parse(text: string, manifestPath: string, directory: string): Project;
249
+ }
250
+
251
+ /**
252
+ * What a command is given when it runs.
253
+ */
254
+ export declare class CommandContext {
255
+ /**
256
+ * The full path of the project file the command runs for; the command reads what it needs
257
+ * from it.
258
+ */
259
+ public readonly projectFilePath: string;
260
+
261
+ /**
262
+ * The arguments after the command's name, as given.
263
+ */
264
+ public readonly arguments: readonly string[];
265
+
266
+ /**
267
+ * Where the command writes what it reports.
268
+ */
269
+ public readonly output: CommandOutput;
270
+
271
+ /**
272
+ * Initializes the context.
273
+ *
274
+ * @param projectFilePath The full path of the project file the command runs for.
275
+ * @param arguments_ The arguments after the command's name.
276
+ * @param output Where the command writes what it reports.
277
+ */
278
+ public constructor(projectFilePath: string, arguments_: readonly string[], output: CommandOutput);
279
+ }
280
+
281
+ /**
282
+ * A command `ctx` runs, such as the SDK's `build` or `run`.
283
+ *
284
+ * @remarks
285
+ * A provider is a package whose public API exports classes that extend `Command`, each with a
286
+ * constructor that takes no arguments; `ctx` makes one of each when it loads the provider.
287
+ * @example
288
+ * export class HelloCommand extends Command {
289
+ * public override readonly name = "hello";
290
+ * public override readonly description = "Says hello.";
291
+ *
292
+ * public override async runAsync(context: CommandContext): Promise<number> {
293
+ * context.output.writeLine(`Hello from ${context.projectFilePath}.`);
294
+ * return 0;
295
+ * }
296
+ * }
297
+ */
298
+ export declare abstract class Command {
299
+ /**
300
+ * The name it is run by, such as `build`.
301
+ */
302
+ public abstract readonly name: string;
303
+
304
+ /**
305
+ * One line that `ctx --help` shows beside the name.
306
+ */
307
+ public abstract readonly description: string;
308
+
309
+ /**
310
+ * Runs the command.
311
+ *
312
+ * @param context The project file's path, the arguments and the output.
313
+ * @returns The exit code, 0 when it succeeded.
314
+ */
315
+ public abstract runAsync(context: CommandContext): Promise<number>;
316
+ }
317
+
318
+ /**
319
+ * The `ctx` command host: it reads the project file, loads the providers it names and runs the
320
+ * command asked for.
321
+ *
322
+ * @remarks
323
+ * The host has no command of its own: every command, and `ctx --help` in a project's folder,
324
+ * loads the SDK and the tools, and two of them offering the same command is an error. The
325
+ * project file is the one `.ctxp` in the folder; none or several is an error; with none,
326
+ * `ctx --help` lists no command.
327
+ */
328
+ export declare class CommandHost {
329
+ /**
330
+ * Initializes the host.
331
+ *
332
+ * @param output Where the host and its commands write.
333
+ */
334
+ public constructor(output: CommandOutput);
335
+
336
+ /**
337
+ * Runs `ctx` with its arguments.
338
+ *
339
+ * @param arguments_ The arguments after `ctx`, such as `["run", "--", "--port", "80"]`; none,
340
+ * `-h` or `--help` list the project's commands, and `-v` or `--version` print the host's
341
+ * version, such as `Context 0.0.13`.
342
+ * @param directory The folder `ctx` runs in, where the project file is looked for.
343
+ * @returns The command's exit code; 1 when a `CommandHostException` was raised, whose message
344
+ * goes to the error output.
345
+ * @throws Whatever a command throws other than a `CommandHostException`.
346
+ * @example
347
+ * const exitCode = await new CommandHost(new ConsoleOutput()).runAsync(["--help"], "/app");
348
+ */
349
+ public runAsync(arguments_: readonly string[], directory: string): Promise<number>;
350
+ }
package/api/index.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export { ProjectKind } from "../enums/project-kind.js";
9
+ export { CommandCollisionException } from "../exceptions/command-collision.exception.js";
10
+ export { CommandHostException } from "../exceptions/command-host.exception.js";
11
+ export { CommandUnknownException } from "../exceptions/command-unknown.exception.js";
12
+ export { ProjectFileException } from "../exceptions/project-file.exception.js";
13
+ export { ProviderException } from "../exceptions/provider.exception.js";
14
+ export { Command } from "../models/command.js";
15
+ export { CommandContext } from "../models/command-context.js";
16
+ export { CommandOutput } from "../models/command-output.js";
17
+ export { ConsoleOutput } from "../models/console-output.js";
18
+ export { Project } from "../models/project.js";
19
+ export { ProjectEntryPoint } from "../models/project-entry-point.js";
20
+ export { CommandHost } from "../services/command-host.js";
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/api/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export var ProjectKind;
9
+ (function (ProjectKind) {
10
+ ProjectKind["Library"] = "library";
11
+ ProjectKind["Executable"] = "executable";
12
+ })(ProjectKind || (ProjectKind = {}));
13
+ //# sourceMappingURL=project-kind.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-kind.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/enums/project-kind.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,kCAAmB,CAAA;IACnB,wCAAyB,CAAA;AAC3B,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Resources } from "../resources.js";
9
+ import { CommandHostException } from "./command-host.exception.js";
10
+ export class CommandCollisionException extends CommandHostException {
11
+ commandName;
12
+ firstProvider;
13
+ secondProvider;
14
+ constructor(commandName, firstProvider, secondProvider) {
15
+ super(Resources.formatCommandCollision(commandName, firstProvider, secondProvider));
16
+ this.commandName = commandName;
17
+ this.firstProvider = firstProvider;
18
+ this.secondProvider = secondProvider;
19
+ }
20
+ }
21
+ //# sourceMappingURL=command-collision.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-collision.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/exceptions/command-collision.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,OAAO,yBAA0B,SAAQ,oBAAoB;IACjD,WAAW,CAAS;IACpB,aAAa,CAAS;IACtB,cAAc,CAAS;IAEvC,YAAmB,WAAmB,EAAE,aAAqB,EAAE,cAAsB;QACnF,KAAK,CAAC,SAAS,CAAC,sBAAsB,CAAC,WAAW,EAAE,aAAa,EAAE,cAAc,CAAC,CAAC,CAAC;QAEpF,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Exception } from "@noldova/context.exceptions";
9
+ export class CommandHostException extends Exception {
10
+ constructor(message, options) {
11
+ super(message, options);
12
+ }
13
+ }
14
+ //# sourceMappingURL=command-host.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-host.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/exceptions/command-host.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAyB,MAAM,6BAA6B,CAAC;AAE/E,MAAM,OAAO,oBAAqB,SAAQ,SAAS;IACjD,YAAmB,OAAe,EAAE,OAA0B;QAC5D,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Resources } from "../resources.js";
9
+ import { CommandHostException } from "./command-host.exception.js";
10
+ export class CommandUnknownException extends CommandHostException {
11
+ commandName;
12
+ constructor(commandName) {
13
+ super(Resources.formatCommandUnknown(commandName));
14
+ this.commandName = commandName;
15
+ }
16
+ }
17
+ //# sourceMappingURL=command-unknown.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-unknown.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/exceptions/command-unknown.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,OAAO,uBAAwB,SAAQ,oBAAoB;IAC/C,WAAW,CAAS;IAEpC,YAAmB,WAAmB;QACpC,KAAK,CAAC,SAAS,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC,CAAC;QAEnD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { CommandHostException } from "./command-host.exception.js";
9
+ export class ProjectFileException extends CommandHostException {
10
+ path;
11
+ constructor(path, message, options) {
12
+ super(message, options);
13
+ this.path = path;
14
+ }
15
+ }
16
+ //# sourceMappingURL=project-file.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-file.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/exceptions/project-file.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,OAAO,oBAAqB,SAAQ,oBAAoB;IAC5C,IAAI,CAAS;IAE7B,YAAmB,IAAY,EAAE,OAAe,EAAE,OAA0B;QAC1E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAExB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { CommandHostException } from "./command-host.exception.js";
9
+ export class ProviderException extends CommandHostException {
10
+ identity;
11
+ constructor(identity, message, options) {
12
+ super(message, options);
13
+ this.identity = identity;
14
+ }
15
+ }
16
+ //# sourceMappingURL=provider.exception.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.exception.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/exceptions/provider.exception.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,OAAO,iBAAkB,SAAQ,oBAAoB;IACzC,QAAQ,CAAS;IAEjC,YAAmB,QAAgB,EAAE,OAAe,EAAE,OAA0B;QAC9E,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAExB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class CommandContext {
9
+ projectFilePath;
10
+ arguments;
11
+ output;
12
+ constructor(projectFilePath, arguments_, output) {
13
+ this.projectFilePath = projectFilePath;
14
+ this.arguments = arguments_;
15
+ this.output = output;
16
+ }
17
+ }
18
+ //# sourceMappingURL=command-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-context.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/models/command-context.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,OAAO,cAAc;IACT,eAAe,CAAS;IACxB,SAAS,CAAoB;IAC7B,MAAM,CAAgB;IAEtC,YAAmB,eAAuB,EAAE,UAA6B,EAAE,MAAqB;QAC9F,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class CommandOutput {
9
+ }
10
+ //# sourceMappingURL=command-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-output.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/models/command-output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAgB,aAAa;CAGlC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class Command {
9
+ }
10
+ //# sourceMappingURL=command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/models/command.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,OAAgB,OAAO;CAK5B"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // This file uses Node APIs and will change when we replace Node.
9
+ import { Resources } from "../resources.js";
10
+ import { CommandOutput } from "./command-output.js";
11
+ export class ConsoleOutput extends CommandOutput {
12
+ writeLine(text) {
13
+ process.stdout.write(`${text}${Resources.lineSeparator}`);
14
+ }
15
+ writeErrorLine(text) {
16
+ process.stderr.write(`${text}${Resources.lineSeparator}`);
17
+ }
18
+ }
19
+ //# sourceMappingURL=console-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console-output.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/models/console-output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AAEjE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC9B,SAAS,CAAC,IAAY;QACpC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IAC5D,CAAC;IAEe,cAAc,CAAC,IAAY;QACzC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,aAAa,EAAE,CAAC,CAAC;IAC5D,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { Resources } from "../resources.js";
9
+ export class ProjectEntryPoint {
10
+ source;
11
+ className;
12
+ constructor(source = Resources.defaultEntrySource, className) {
13
+ this.source = source;
14
+ this.className = className;
15
+ }
16
+ }
17
+ //# sourceMappingURL=project-entry-point.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-entry-point.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/models/project-entry-point.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,iBAAiB;IACZ,MAAM,CAAS;IACf,SAAS,CAAqB;IAE9C,YAAmB,MAAM,GAAW,SAAS,CAAC,kBAAkB,EAAE,SAAkB;QAClF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import { ExceptionOptions } from "@noldova/context.exceptions";
9
+ import { JsonException, JsonReader } from "@noldova/context.json";
10
+ import { ProjectKind } from "../enums/project-kind.js";
11
+ import { ProjectFileException } from "../exceptions/project-file.exception.js";
12
+ import { Resources } from "../resources.js";
13
+ import { ProjectEntryPoint } from "./project-entry-point.js";
14
+ export class Project {
15
+ name;
16
+ kind;
17
+ sdk;
18
+ tools;
19
+ entryPoint;
20
+ manifestPath;
21
+ directory;
22
+ constructor(name, kind, sdk, tools, entryPoint, manifestPath, directory) {
23
+ this.name = name;
24
+ this.kind = kind;
25
+ this.sdk = sdk;
26
+ this.tools = tools;
27
+ this.entryPoint = entryPoint;
28
+ this.manifestPath = manifestPath;
29
+ this.directory = directory;
30
+ }
31
+ get providers() {
32
+ return [this.sdk, ...this.tools];
33
+ }
34
+ static parse(text, manifestPath, directory) {
35
+ try {
36
+ const reader = JsonReader.parse(text);
37
+ const kind = Project.readKind(reader, manifestPath);
38
+ const sdk = Project.readIdentity(reader.readOptionalString(Resources.sdkField) ?? Resources.defaultSdk, Resources.sdkField, manifestPath);
39
+ const tools = Project.readTools(reader, sdk, manifestPath);
40
+ return new Project(reader.readNonBlankString(Resources.nameField), kind, sdk, tools, Project.readEntryPoint(reader, kind, manifestPath), manifestPath, directory);
41
+ }
42
+ catch (exception) {
43
+ if (exception instanceof JsonException)
44
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, exception.message), new ExceptionOptions(exception));
45
+ throw exception;
46
+ }
47
+ }
48
+ static readKind(reader, manifestPath) {
49
+ const kind = reader.readString(Resources.kindField);
50
+ if (kind === ProjectKind.Library)
51
+ return ProjectKind.Library;
52
+ if (kind === ProjectKind.Executable)
53
+ return ProjectKind.Executable;
54
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, Resources.formatKindInvalid(kind)));
55
+ }
56
+ static readIdentity(identity, field, manifestPath) {
57
+ if (!Resources.identityPattern.test(identity))
58
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, Resources.formatIdentityInvalid(field, identity)));
59
+ return identity;
60
+ }
61
+ static readTools(reader, sdk, manifestPath) {
62
+ if (!reader.hasField(Resources.toolsField))
63
+ return [];
64
+ const seen = new Set([sdk]);
65
+ const tools = reader.readStringArray(Resources.toolsField);
66
+ for (const tool of tools) {
67
+ Project.readIdentity(tool, Resources.toolsField, manifestPath);
68
+ if (seen.has(tool))
69
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, Resources.formatToolRepeated(tool)));
70
+ seen.add(tool);
71
+ }
72
+ return tools;
73
+ }
74
+ static readEntryPoint(reader, kind, manifestPath) {
75
+ if (kind !== ProjectKind.Executable)
76
+ return undefined;
77
+ if (!reader.hasField(Resources.entryField))
78
+ return new ProjectEntryPoint();
79
+ const entry = reader.readObject(Resources.entryField);
80
+ const source = entry.readOptionalString(Resources.sourceField) ?? Resources.defaultEntrySource;
81
+ if (!source.endsWith(Resources.sourceExtension) || source.length === Resources.sourceExtension.length)
82
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, Resources.formatEntrySourceInvalid(source)));
83
+ if (Resources.outsidePathPattern.test(source))
84
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, Resources.formatEntrySourceOutside(source)));
85
+ const className = entry.readOptionalString(Resources.classField);
86
+ if (!Object.isUndefined(className) && String.isNullOrWhitespace(className))
87
+ throw new ProjectFileException(manifestPath, Resources.formatProjectInvalid(manifestPath, Resources.formatEntryClassBlank(className)));
88
+ return new ProjectEntryPoint(source, className);
89
+ }
90
+ }
91
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/models/project.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAA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/F,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,eAAe,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,eAAe,CAAC,MAAM;YACnG,MAAM,IAAI,oBAAoB,CAAC,YAAY,EAAE,SAAS,CAAC,oBAAoB,CAAC,YAAY,EAAE,SAAS,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACzI,IAAI,SAAS,CAAC,kBAAkB,CAAC,IAAI,CAAC,MAAM,CAAC;YAC3C,MAAM,IAAI,oBAAoB,CAAC,YAAY,EAAE,SAAS,CAAC,oBAAoB,CAAC,YAAY,EAAE,SAAS,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAEzI,MAAM,SAAS,GAAG,KAAK,CAAC,kBAAkB,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,kBAAkB,CAAC,SAAS,CAAC;YACxE,MAAM,IAAI,oBAAoB,CAAC,YAAY,EAAE,SAAS,CAAC,oBAAoB,CAAC,YAAY,EAAE,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAEzI,OAAO,IAAI,iBAAiB,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAClD,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,30 @@
1
1
  {
2
2
  "name": "@noldova/context",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.0.14",
4
+ "type": "module",
5
+ "main": "api/index.js",
6
+ "types": "api/index.d.ts",
7
+ "bin": {
8
+ "ctx": "api/ctx.js"
9
+ },
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/noldova-com/context.git",
14
+ "directory": "src/noldova.context"
15
+ },
16
+ "homepage": "https://github.com/noldova-com/context#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/noldova-com/context/issues"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public",
22
+ "registry": "https://registry.npmjs.org/"
23
+ },
24
+ "peerDependencies": {
25
+ "@noldova/context.core": ">=0.0.14 <0.1.0",
26
+ "@noldova/context.exceptions": ">=0.0.14 <0.1.0",
27
+ "@noldova/context.json": ">=0.0.14 <0.1.0"
28
+ },
29
+ "gitHead": "d6670c582cf942a35496df9bed0170c854f63d29"
30
+ }
package/resources.js ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class Resources {
9
+ static defaultSdk = "noldova.context.sdk";
10
+ static identityPattern = /^noldova\.context(?:\.[a-z0-9]+)+$/u;
11
+ static identityPrefix = "noldova.";
12
+ static packageScope = "@noldova/";
13
+ static hostEntryModule = "@noldova/context/api/ctx.js";
14
+ static moduleNotFoundErrorCode = "MODULE_NOT_FOUND";
15
+ static manifestExtension = ".ctxp";
16
+ static sourceExtension = ".ts";
17
+ static defaultEntrySource = "main.ts";
18
+ static helpOptions = ["-h", "--help"];
19
+ static versionOptions = ["-v", "--version"];
20
+ static hostManifestPath = "../package.json";
21
+ static versionField = "version";
22
+ static nameField = "name";
23
+ static kindField = "kind";
24
+ static sdkField = "sdk";
25
+ static toolsField = "tools";
26
+ static entryField = "entry";
27
+ static sourceField = "source";
28
+ static classField = "class";
29
+ static outsidePathPattern = /^(?:[\\/]|[A-Za-z]:)|(?:^|[\\/])\.\.(?:[\\/]|$)/u;
30
+ static listSeparator = ", ";
31
+ static lineSeparator = "\n";
32
+ static textEncoding = "utf8";
33
+ static commandColumnWidth = 12;
34
+ static usage = "Usage: ctx <command> [arguments], ctx --help or ctx --version";
35
+ static commandsHeading = "Commands:";
36
+ static noProjectNote = "No project file (.ctxp) is in this folder; the commands come from the SDK and tools a project names.";
37
+ static formatVersion(version) {
38
+ return `Context ${version}`;
39
+ }
40
+ static formatPackageName(identity) {
41
+ return `${Resources.packageScope}${identity.substring(Resources.identityPrefix.length)}`;
42
+ }
43
+ static formatCommandLine(name, description) {
44
+ return ` ${name.padEnd(Resources.commandColumnWidth)}${description}`;
45
+ }
46
+ static formatProjectNotFound(directory) {
47
+ return `No project file (.ctxp) is in "${directory}".`;
48
+ }
49
+ static formatProjectAmbiguous(directory, fileNames) {
50
+ return `"${directory}" holds ${fileNames.length} project files (${fileNames.join(Resources.listSeparator)}).`;
51
+ }
52
+ static formatProjectUnreadable(manifestPath, cause) {
53
+ return `The project file "${manifestPath}" can't be read: ${Resources.formatCause(cause)}`;
54
+ }
55
+ static formatProjectInvalid(manifestPath, reason) {
56
+ return `The project file "${manifestPath}" is invalid: ${reason}`;
57
+ }
58
+ static formatKindInvalid(kind) {
59
+ return `"kind" is "${kind}", not "library" or "executable".`;
60
+ }
61
+ static formatIdentityInvalid(field, identity) {
62
+ return `"${field}" names "${identity}", which is not a package identity such as noldova.context.sdk.`;
63
+ }
64
+ static formatToolRepeated(identity) {
65
+ return `"tools" names "${identity}" more than once, or names the SDK.`;
66
+ }
67
+ static formatEntrySourceInvalid(source) {
68
+ return `"entry.source" is "${source}", not a TypeScript source such as main.ts.`;
69
+ }
70
+ static formatEntrySourceOutside(source) {
71
+ return `"entry.source" is "${source}", which is outside the project file's folder.`;
72
+ }
73
+ static formatEntryClassBlank(className) {
74
+ return `"entry.class" is "${className}", not a class name.`;
75
+ }
76
+ static formatProviderMissing(identity, manifestPath) {
77
+ return `The project "${manifestPath}" names "${identity}", but ${Resources.formatPackageName(identity)} is not installed for it.`;
78
+ }
79
+ static formatProviderUnloadable(identity, cause) {
80
+ return `"${identity}" could not be loaded: ${Resources.formatCause(cause)}`;
81
+ }
82
+ static formatCommandUnconstructible(identity, className, cause) {
83
+ return `"${identity}" could not make its command ${className}: ${Resources.formatCause(cause)}`;
84
+ }
85
+ static formatProviderEmpty(identity) {
86
+ return `"${identity}" offers no commands: it exports no class that extends Command.`;
87
+ }
88
+ static formatCommandCollision(name, first, second) {
89
+ return `The command "${name}" is offered by both "${first}" and "${second}".`;
90
+ }
91
+ static formatCommandUnknown(name) {
92
+ return `"${name}" is not a command of this project; ctx --help lists them.`;
93
+ }
94
+ static formatCause(cause) {
95
+ return cause instanceof Error ? cause.message : String(cause);
96
+ }
97
+ }
98
+ //# sourceMappingURL=resources.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resources.js","sourceRoot":"","sources":["../../../src/noldova.context/src/resources.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,OAAO,SAAS;IACb,MAAM,CAAU,UAAU,GAAW,qBAAqB,CAAC;IAC3D,MAAM,CAAU,eAAe,GAAW,qCAAqC,CAAC;IAChF,MAAM,CAAU,cAAc,GAAW,UAAU,CAAC;IACpD,MAAM,CAAU,YAAY,GAAW,WAAW,CAAC;IACnD,MAAM,CAAU,eAAe,GAAW,6BAA6B,CAAC;IACxE,MAAM,CAAU,uBAAuB,GAAW,kBAAkB,CAAC;IACrE,MAAM,CAAU,iBAAiB,GAAW,OAAO,CAAC;IACpD,MAAM,CAAU,eAAe,GAAW,KAAK,CAAC;IAChD,MAAM,CAAU,kBAAkB,GAAW,SAAS,CAAC;IACvD,MAAM,CAAU,WAAW,GAAsB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAClE,MAAM,CAAU,cAAc,GAAsB,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACxE,MAAM,CAAU,gBAAgB,GAAW,iBAAiB,CAAC;IAC7D,MAAM,CAAU,YAAY,GAAW,SAAS,CAAC;IACjD,MAAM,CAAU,SAAS,GAAW,MAAM,CAAC;IAC3C,MAAM,CAAU,SAAS,GAAW,MAAM,CAAC;IAC3C,MAAM,CAAU,QAAQ,GAAW,KAAK,CAAC;IACzC,MAAM,CAAU,UAAU,GAAW,OAAO,CAAC;IAC7C,MAAM,CA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CAAC;IAClG,CAAC;IAEM,MAAM,CAAC,mBAAmB,CAAC,QAAgB;QAChD,OAAO,IAAI,QAAQ,iEAAiE,CAAC;IACvF,CAAC;IAEM,MAAM,CAAC,sBAAsB,CAAC,IAAY,EAAE,KAAa,EAAE,MAAc;QAC9E,OAAO,gBAAgB,IAAI,yBAAyB,KAAK,UAAU,MAAM,IAAI,CAAC;IAChF,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAC,IAAY;QAC7C,OAAO,IAAI,IAAI,4DAA4D,CAAC;IAC9E,CAAC;IAEO,MAAM,CAAC,WAAW,CAAC,KAAc;QACvC,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChE,CAAC;CACF"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // This file uses Node APIs and will change when we replace Node.
9
+ import { readFile } from "node:fs/promises";
10
+ import "@noldova/context.core";
11
+ import { JsonReader } from "@noldova/context.json";
12
+ import { CommandCollisionException } from "../exceptions/command-collision.exception.js";
13
+ import { CommandHostException } from "../exceptions/command-host.exception.js";
14
+ import { CommandUnknownException } from "../exceptions/command-unknown.exception.js";
15
+ import { ProjectFileException } from "../exceptions/project-file.exception.js";
16
+ import { CommandContext } from "../models/command-context.js";
17
+ import { Resources } from "../resources.js";
18
+ import { ProjectFileService } from "./project-file.service.js";
19
+ import { ProviderLoaderService } from "./provider-loader.service.js";
20
+ export class CommandHost {
21
+ output;
22
+ constructor(output) {
23
+ this.output = output;
24
+ }
25
+ async runAsync(arguments_, directory) {
26
+ try {
27
+ const commandName = arguments_.at(0);
28
+ if (Object.isUndefined(commandName) || Resources.helpOptions.includes(commandName))
29
+ return await this.helpAsync(directory);
30
+ if (Resources.versionOptions.includes(commandName)) {
31
+ this.output.writeLine(Resources.formatVersion(await CommandHost.readVersionAsync()));
32
+ return 0;
33
+ }
34
+ const project = await CommandHost.readProjectAsync(directory);
35
+ const command = (await this.readCommandsAsync(project)).get(commandName);
36
+ if (Object.isUndefined(command))
37
+ throw new CommandUnknownException(commandName);
38
+ return await command.runAsync(new CommandContext(project.manifestPath, arguments_.slice(1), this.output));
39
+ }
40
+ catch (exception) {
41
+ if (!(exception instanceof CommandHostException))
42
+ throw exception;
43
+ this.output.writeErrorLine(exception.message);
44
+ return 1;
45
+ }
46
+ }
47
+ async helpAsync(directory) {
48
+ const manifestPath = await ProjectFileService.findAsync(directory);
49
+ this.output.writeLine(Resources.usage);
50
+ if (Object.isUndefined(manifestPath)) {
51
+ this.output.writeLine(Resources.noProjectNote);
52
+ return 0;
53
+ }
54
+ const commands = await this.readCommandsAsync(await ProjectFileService.readAsync(manifestPath, directory));
55
+ this.output.writeLine(Resources.commandsHeading);
56
+ for (const command of [...commands.values()].sort((first, second) => Number(first.name > second.name) - Number(first.name < second.name)))
57
+ this.output.writeLine(Resources.formatCommandLine(command.name, command.description));
58
+ return 0;
59
+ }
60
+ async readCommandsAsync(project) {
61
+ const commands = new Map();
62
+ const owners = new Map();
63
+ for (const identity of project.providers)
64
+ for (const command of await ProviderLoaderService.loadAsync(project, identity)) {
65
+ const owner = owners.get(command.name);
66
+ if (!Object.isUndefined(owner))
67
+ throw new CommandCollisionException(command.name, owner, identity);
68
+ commands.set(command.name, command);
69
+ owners.set(command.name, identity);
70
+ }
71
+ return commands;
72
+ }
73
+ static async readVersionAsync() {
74
+ const text = await readFile(new URL(Resources.hostManifestPath, import.meta.url), Resources.textEncoding);
75
+ return JsonReader.parse(text).readNonBlankString(Resources.versionField);
76
+ }
77
+ static async readProjectAsync(directory) {
78
+ const manifestPath = await ProjectFileService.findAsync(directory);
79
+ if (Object.isUndefined(manifestPath))
80
+ throw new ProjectFileException(directory, Resources.formatProjectNotFound(directory));
81
+ return ProjectFileService.readAsync(manifestPath, directory);
82
+ }
83
+ }
84
+ //# sourceMappingURL=command-host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-host.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/services/command-host.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,8CAA8C,CAAC;AACzF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI9D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,MAAM,OAAO,WAAW;IACL,MAAM,CAAgB;IAEvC,YAAmB,MAAqB;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,UAA6B,EAAE,SAAiB;QACpE,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACrC,IAAI,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAChF,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;YACzC,IAAI,SAAS,CAAC,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;gB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IAAI,EAAE,QAAQ,CAAC,CAAC;YACrC,CAAC;QAEH,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,gBAAgB;QACnC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS,CAAC,YAAY,CAAC,CAAC;QAC1G,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,kBAAkB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;IAC3E,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,SAAiB;QACrD,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;QACnE,IAAI,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC;YAClC,MAAM,IAAI,oBAAoB,CAAC,SAAS,EAAE,SAAS,CAAC,qBAAqB,CAAC,SAAS,CAAC,CAAC,CAAC;QAExF,OAAO,kBAAkB,CAAC,SAAS,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IAC/D,CAAC;CACF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // This file uses Node APIs and will change when we replace Node.
9
+ // It imports none of the context packages: ctx runs it before it knows which copy of them to load.
10
+ import { realpathSync } from "node:fs";
11
+ import { createRequire } from "node:module";
12
+ import { Resources } from "../resources.js";
13
+ export class HostLocatorService {
14
+ static locate(directory, ownEntryPath) {
15
+ let entryPath;
16
+ try {
17
+ entryPath = createRequire(ownEntryPath).resolve(Resources.hostEntryModule, { paths: [directory] });
18
+ }
19
+ catch (exception) {
20
+ if (exception instanceof Error && "code" in exception && exception.code === Resources.moduleNotFoundErrorCode)
21
+ return undefined;
22
+ throw exception;
23
+ }
24
+ return realpathSync(entryPath) === realpathSync(ownEntryPath) ? undefined : entryPath;
25
+ }
26
+ }
27
+ //# sourceMappingURL=host-locator.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-locator.service.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/services/host-locator.service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AACjE,mGAAmG;AAEnG,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,kBAAkB;IACtB,MAAM,CAAC,MAAM,CAAC,SAAiB,EAAE,YAAoB;QAC1D,IAAI,SAAiB,CAAC;QACtB,IAAI,CAAC;YACH,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,eAAe,EAAE,EAAE,KAAK,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;QACrG,CAAC;QACD,OAAO,SAAkB,EAAE,CAAC;YAC1B,IAAI,SAAS,YAAY,KAAK,IAAI,MAAM,IAAI,SAAS,IAAI,SAAS,CAAC,IAAI,KAAK,SAAS,CAAC,uBAAuB;gBAC3G,OAAO,SAAS,CAAC;YAEnB,MAAM,SAAS,CAAC;QAClB,CAAC;QAED,OAAO,YAAY,CAAC,SAAS,CAAC,KAAK,YAAY,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC;IACxF,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // This file uses Node APIs and will change when we replace Node.
9
+ import { readdir, readFile } from "node:fs/promises";
10
+ import { dirname, join, resolve } from "node:path";
11
+ import "@noldova/context.core";
12
+ import { ExceptionOptions } from "@noldova/context.exceptions";
13
+ import { ProjectFileException } from "../exceptions/project-file.exception.js";
14
+ import { Project } from "../models/project.js";
15
+ import { Resources } from "../resources.js";
16
+ export class ProjectFileService {
17
+ static async findAsync(directory) {
18
+ const entries = await readdir(directory, { withFileTypes: true });
19
+ const fileNames = entries.filter(t => t.isFile() && t.name.endsWith(Resources.manifestExtension)).map(t => t.name).sort();
20
+ if (fileNames.length > 1)
21
+ throw new ProjectFileException(directory, Resources.formatProjectAmbiguous(directory, fileNames));
22
+ const fileName = fileNames.at(0);
23
+ return Object.isUndefined(fileName) ? undefined : join(directory, fileName);
24
+ }
25
+ static async readAsync(manifestPath, directory) {
26
+ const path = resolve(directory, manifestPath);
27
+ let text;
28
+ try {
29
+ text = await readFile(path, Resources.textEncoding);
30
+ }
31
+ catch (exception) {
32
+ throw new ProjectFileException(path, Resources.formatProjectUnreadable(path, exception), new ExceptionOptions(exception));
33
+ }
34
+ return Project.parse(text, path, dirname(path));
35
+ }
36
+ }
37
+ //# sourceMappingURL=project-file.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project-file.service.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/services/project-file.service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AAEjE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAC/E,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,MAAM,OAAO,kBAAkB;IACtB,MAAM,C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AC,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAClD,CAAC;CACF"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ // This file uses Node APIs and will change when we replace Node.
9
+ import { createRequire } from "node:module";
10
+ import { pathToFileURL } from "node:url";
11
+ import "@noldova/context.core";
12
+ import { ExceptionOptions } from "@noldova/context.exceptions";
13
+ import { ProviderException } from "../exceptions/provider.exception.js";
14
+ import { Command } from "../models/command.js";
15
+ import { Resources } from "../resources.js";
16
+ export class ProviderLoaderService {
17
+ static async loadAsync(project, identity) {
18
+ let modulePath;
19
+ try {
20
+ modulePath = createRequire(project.manifestPath).resolve(Resources.formatPackageName(identity));
21
+ }
22
+ catch (exception) {
23
+ throw new ProviderException(identity, Resources.formatProviderMissing(identity, project.manifestPath), new ExceptionOptions(exception));
24
+ }
25
+ let loaded;
26
+ try {
27
+ loaded = await import(pathToFileURL(modulePath).href);
28
+ }
29
+ catch (exception) {
30
+ throw new ProviderException(identity, Resources.formatProviderUnloadable(identity, exception), new ExceptionOptions(exception));
31
+ }
32
+ const commands = [];
33
+ for (const commandClass of ProviderLoaderService.readCommandClasses(loaded))
34
+ try {
35
+ commands.push(new commandClass());
36
+ }
37
+ catch (exception) {
38
+ throw new ProviderException(identity, Resources.formatCommandUnconstructible(identity, commandClass.name, exception), new ExceptionOptions(exception));
39
+ }
40
+ if (commands.length === 0)
41
+ throw new ProviderException(identity, Resources.formatProviderEmpty(identity));
42
+ return commands;
43
+ }
44
+ static readCommandClasses(loaded) {
45
+ const classes = [];
46
+ for (const name of Object.keys(loaded).sort()) {
47
+ const value = loaded[name];
48
+ if (ProviderLoaderService.isCommandClass(value))
49
+ classes.push(value);
50
+ }
51
+ return classes;
52
+ }
53
+ static isCommandClass(value) {
54
+ return Object.isFunction(value) && Command.isPrototypeOf(value);
55
+ }
56
+ }
57
+ //# sourceMappingURL=provider-loader.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider-loader.service.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/services/provider-loader.service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,iEAAiE;AAEjE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,OAAO,qBAAqB;IACzB,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAgB,EAAE,QAAgB;QAC9D,IAAI,UAAkB,CAAC;QACvB,IAAI,CAAC;YACH,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAC;QAClG,CAAC;QACD,OAAO,SAAS,EAAE,CAAC;YACjB,MAAM,IAAI,iBAAiB,CAAC,QAAQ,EAAE,SAAS,CAAC,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,YAAY,CAAC,EAAE,IAAI,gBAAgB,CAAC,SAAS,CAAC,CAAC,CAAC;QAC1I,CAAC;QAED,IAAI,MAAyC,CAAC;QAC9C,IAAI,CAAC;YACH,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,SAAS,EAAE,CAAC;YACjB,MAAM,IAAI,iBAAiB,CAAC,QAAQ,EAAE,S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F"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=command-class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command-class.js","sourceRoot":"","sources":["../../../../src/noldova.context/src/types/command-class.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}