@hagicode/hagiscript 0.1.5 → 0.1.6-dev.37.1.2e654a6

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -1
  3. package/bin/runtime +16 -0
  4. package/dist/cli.js +2 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/npm-sync-commands.js +2 -0
  7. package/dist/commands/npm-sync-commands.js.map +1 -1
  8. package/dist/commands/runtime-commands.d.ts +2 -0
  9. package/dist/commands/runtime-commands.js +136 -0
  10. package/dist/commands/runtime-commands.js.map +1 -0
  11. package/dist/index.d.ts +4 -0
  12. package/dist/index.js +4 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/runtime/command-launch.js +1 -0
  15. package/dist/runtime/command-launch.js.map +1 -1
  16. package/dist/runtime/npm-sync.d.ts +5 -1
  17. package/dist/runtime/npm-sync.js +6 -3
  18. package/dist/runtime/npm-sync.js.map +1 -1
  19. package/dist/runtime/runtime-executor.d.ts +27 -0
  20. package/dist/runtime/runtime-executor.js +86 -0
  21. package/dist/runtime/runtime-executor.js.map +1 -0
  22. package/dist/runtime/runtime-manager.d.ts +68 -0
  23. package/dist/runtime/runtime-manager.js +553 -0
  24. package/dist/runtime/runtime-manager.js.map +1 -0
  25. package/dist/runtime/runtime-manifest.d.ts +63 -0
  26. package/dist/runtime/runtime-manifest.js +231 -0
  27. package/dist/runtime/runtime-manifest.js.map +1 -0
  28. package/dist/runtime/runtime-paths.d.ts +24 -0
  29. package/dist/runtime/runtime-paths.js +62 -0
  30. package/dist/runtime/runtime-paths.js.map +1 -0
  31. package/dist/runtime/runtime-state.d.ts +43 -0
  32. package/dist/runtime/runtime-state.js +82 -0
  33. package/dist/runtime/runtime-state.js.map +1 -0
  34. package/package.json +9 -3
  35. package/runtime/lib/runtime-script-lib.mjs +103 -0
  36. package/runtime/manifest.yaml +122 -0
  37. package/runtime/scripts/configure-code-server.mjs +14 -0
  38. package/runtime/scripts/configure-omniroute.mjs +16 -0
  39. package/runtime/scripts/install-code-server.mjs +32 -0
  40. package/runtime/scripts/install-dotnet.mjs +24 -0
  41. package/runtime/scripts/install-node.mjs +4 -0
  42. package/runtime/scripts/install-npm-packages.mjs +4 -0
  43. package/runtime/scripts/install-omniroute.mjs +34 -0
  44. package/runtime/scripts/remove-npm-packages.mjs +4 -0
  45. package/runtime/scripts/update-npm-packages.mjs +4 -0
  46. package/runtime/scripts/verify-dotnet.mjs +10 -0
  47. package/runtime/scripts/verify-node.mjs +4 -0
  48. package/runtime/templates/code-server-config.yaml +5 -0
  49. package/runtime/templates/omniroute-config.yaml +4 -0
@@ -0,0 +1,86 @@
1
+ import { appendFile, mkdir } from "node:fs/promises";
2
+ import { basename, dirname, extname } from "node:path";
3
+ import process from "node:process";
4
+ import { runCommand } from "./command-launch.js";
5
+ export async function executeRuntimeScript(scriptPath, context) {
6
+ const runner = context.runner ?? runCommand;
7
+ const { command, args } = getRuntimeScriptLaunch(scriptPath);
8
+ const result = await runner(command, args, {
9
+ cwd: context.manifest.manifestDir,
10
+ env: buildRuntimeScriptEnvironment(context),
11
+ maxBuffer: 10 * 1024 * 1024
12
+ });
13
+ if (context.logFilePath) {
14
+ await writeRuntimeLog(context.logFilePath, [
15
+ `# ${context.phase}:${context.component.name}`,
16
+ `$ ${command} ${args.join(" ")}`,
17
+ result.stdout ? `stdout:\n${result.stdout}` : "",
18
+ result.stderr ? `stderr:\n${result.stderr}` : ""
19
+ ]
20
+ .filter(Boolean)
21
+ .join("\n"));
22
+ }
23
+ return {
24
+ command,
25
+ args,
26
+ stdout: result.stdout,
27
+ stderr: result.stderr
28
+ };
29
+ }
30
+ export async function writeRuntimeLog(logFilePath, content) {
31
+ await mkdir(dirname(logFilePath), { recursive: true });
32
+ await appendFile(logFilePath, `${content}\n`, "utf8");
33
+ }
34
+ export function getRuntimeScriptLaunch(scriptPath) {
35
+ const extension = extname(scriptPath).toLowerCase();
36
+ if (extension === ".mjs" || extension === ".js" || extension === ".cjs") {
37
+ return {
38
+ command: process.execPath,
39
+ args: [scriptPath]
40
+ };
41
+ }
42
+ return {
43
+ command: scriptPath,
44
+ args: []
45
+ };
46
+ }
47
+ function buildRuntimeScriptEnvironment(context) {
48
+ return withManagedBinPath({
49
+ ...process.env,
50
+ HAGISCRIPT_RUNTIME_ROOT: context.paths.root,
51
+ HAGISCRIPT_RUNTIME_BIN_DIR: context.paths.bin,
52
+ HAGISCRIPT_RUNTIME_CONFIG_DIR: context.paths.config,
53
+ HAGISCRIPT_RUNTIME_LOGS_DIR: context.paths.logs,
54
+ HAGISCRIPT_RUNTIME_DATA_DIR: context.paths.data,
55
+ HAGISCRIPT_RUNTIME_STATE_PATH: context.paths.stateFile,
56
+ HAGISCRIPT_RUNTIME_TEMPLATE_DIR: `${context.manifest.manifestDir}/templates`,
57
+ HAGISCRIPT_RUNTIME_COMPONENT_NAME: context.component.name,
58
+ HAGISCRIPT_RUNTIME_COMPONENT_TYPE: context.component.type,
59
+ HAGISCRIPT_RUNTIME_COMPONENT_VERSION: context.component.version ?? "",
60
+ HAGISCRIPT_RUNTIME_COMPONENT_ROOT: context.componentRoot,
61
+ HAGISCRIPT_RUNTIME_COMPONENT_CONFIG_DIR: context.componentConfigDir,
62
+ HAGISCRIPT_RUNTIME_PHASE: context.phase,
63
+ HAGISCRIPT_RUNTIME_PURGE: context.purge ? "1" : "0",
64
+ HAGISCRIPT_RUNTIME_VERBOSE: context.verbose ? "1" : "0",
65
+ HAGISCRIPT_RUNTIME_SCRIPT_BASENAME: basename(scriptPathForEnv(context.component, context.phase))
66
+ }, context.paths.bin);
67
+ }
68
+ function withManagedBinPath(env, binPath) {
69
+ const pathKey = process.platform === "win32" ? "Path" : "PATH";
70
+ const currentPath = env[pathKey] ?? env.PATH ?? "";
71
+ return {
72
+ ...env,
73
+ [pathKey]: [binPath, currentPath].filter(Boolean).join(process.platform === "win32" ? ";" : ":")
74
+ };
75
+ }
76
+ function scriptPathForEnv(component, phase) {
77
+ switch (phase) {
78
+ case "install":
79
+ return component.scripts.install;
80
+ case "remove":
81
+ return component.scripts.remove ?? component.scripts.install;
82
+ case "update":
83
+ return component.scripts.update ?? component.scripts.install;
84
+ }
85
+ }
86
+ //# sourceMappingURL=runtime-executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-executor.js","sourceRoot":"","sources":["../../src/runtime/runtime-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACpD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACtD,OAAO,OAAO,MAAM,cAAc,CAAA;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AA4BhD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,UAAkB,EAClB,OAAsC;IAEtC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,UAAU,CAAA;IAC3C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,sBAAsB,CAAC,UAAU,CAAC,CAAA;IAC5D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE;QACzC,GAAG,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW;QACjC,GAAG,EAAE,6BAA6B,CAAC,OAAO,CAAC;QAC3C,SAAS,EAAE,EAAE,GAAG,IAAI,GAAG,IAAI;KAC5B,CAAC,CAAA;IAEF,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;QACxB,MAAM,eAAe,CACnB,OAAO,CAAC,WAAW,EACnB;YACE,KAAK,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE;YAC9C,KAAK,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAChC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,M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AC,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;KACjG,CAAA;AACH,CAAC;AAED,SAAS,gBAAgB,CACvB,SAAqC,EACrC,KAA4B;IAE5B,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,SAAS,CAAC,OAAO,CAAC,OAAO,CAAA;QAClC,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAA;QAC9D,KAAK,QAAQ;YACX,OAAO,SAAS,CAAC,OAAO,CAAC,MAAM,IAAI,SAAS,CAAC,OAAO,CAAC,OAAO,CAAA;IAChE,CAAC;AACH,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { type LoadedRuntimeManifest, type RuntimeLifecyclePhase } from "./runtime-manifest.js";
2
+ import { type ResolvedRuntimePaths } from "./runtime-paths.js";
3
+ import { type RuntimeComponentStatus, type RuntimeState } from "./runtime-state.js";
4
+ export interface RuntimeLifecycleOptions {
5
+ manifestPath?: string;
6
+ runtimeRoot?: string;
7
+ components?: readonly string[];
8
+ dryRun?: boolean;
9
+ force?: boolean;
10
+ purge?: boolean;
11
+ checkOnly?: boolean;
12
+ verbose?: boolean;
13
+ logger?: (message: string) => void;
14
+ now?: () => Date;
15
+ }
16
+ export interface RuntimePlannedAction {
17
+ componentName: string;
18
+ phase: RuntimeLifecyclePhase;
19
+ strategy: "builtin" | "script" | "fallback-install" | "fallback-cleanup";
20
+ scriptPath?: string;
21
+ reason?: string;
22
+ }
23
+ export interface RuntimeLifecycleResult {
24
+ manifest: LoadedRuntimeManifest;
25
+ paths: ResolvedRuntimePaths;
26
+ state: RuntimeState;
27
+ plan: RuntimePlannedAction[];
28
+ skipped: {
29
+ componentName: string;
30
+ reason: string;
31
+ }[];
32
+ changedComponents: string[];
33
+ logFilePath?: string;
34
+ }
35
+ export interface RuntimeStateReport {
36
+ runtime: {
37
+ name: string;
38
+ version: string;
39
+ manifestPath: string;
40
+ };
41
+ managedRoot: string;
42
+ managedPaths: ResolvedRuntimePaths;
43
+ ready: boolean;
44
+ components: Array<{
45
+ name: string;
46
+ type: string;
47
+ status: RuntimeComponentStatus;
48
+ version: string | null;
49
+ managedPaths: string[];
50
+ }>;
51
+ lastOperation: RuntimeState["lastOperation"];
52
+ }
53
+ export declare class RuntimeLifecycleError extends Error {
54
+ constructor(message: string, options?: ErrorOptions);
55
+ }
56
+ export declare function installRuntime(options?: RuntimeLifecycleOptions): Promise<RuntimeLifecycleResult>;
57
+ export declare function removeRuntime(options?: RuntimeLifecycleOptions): Promise<RuntimeLifecycleResult>;
58
+ export declare function updateRuntime(options?: RuntimeLifecycleOptions): Promise<RuntimeLifecycleResult>;
59
+ export declare function runRuntimeLifecycle(phase: RuntimeLifecyclePhase, options?: RuntimeLifecycleOptions): Promise<RuntimeLifecycleResult>;
60
+ export declare function queryRuntimeState(options: Pick<RuntimeLifecycleOptions, "manifestPath" | "runtimeRoot">): Promise<RuntimeStateReport>;
61
+ export declare function renderRuntimeStateText(report: RuntimeStateReport): string;
62
+ export declare function planRuntimeLifecycle(phase: RuntimeLifecyclePhase, manifest: LoadedRuntimeManifest, state: RuntimeState, options?: RuntimeLifecycleOptions): {
63
+ plan: RuntimePlannedAction[];
64
+ skipped: {
65
+ componentName: string;
66
+ reason: string;
67
+ }[];
68
+ };