@atomic-ehr/codegen 0.0.1-canary.20251006070905.fb6ed98 → 0.0.1-canary.20251006094042.7f0be72
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/dist/cli/index.js +45 -124
- package/dist/index.d.ts +2130 -62
- package/dist/index.js +5865 -84
- package/dist/index.js.map +1 -0
- package/package.json +3 -7
- package/dist/api/builder.d.ts +0 -154
- package/dist/api/builder.js +0 -341
- package/dist/api/generators/base/BaseGenerator.d.ts +0 -186
- package/dist/api/generators/base/BaseGenerator.js +0 -565
- package/dist/api/generators/base/FileManager.d.ts +0 -88
- package/dist/api/generators/base/FileManager.js +0 -202
- package/dist/api/generators/base/PythonTypeMapper.d.ts +0 -16
- package/dist/api/generators/base/PythonTypeMapper.js +0 -71
- package/dist/api/generators/base/TemplateEngine.d.ts +0 -126
- package/dist/api/generators/base/TemplateEngine.js +0 -133
- package/dist/api/generators/base/TypeMapper.d.ts +0 -129
- package/dist/api/generators/base/TypeMapper.js +0 -153
- package/dist/api/generators/base/TypeScriptTypeMapper.d.ts +0 -51
- package/dist/api/generators/base/TypeScriptTypeMapper.js +0 -232
- package/dist/api/generators/base/builders/DirectoryBuilder.d.ts +0 -99
- package/dist/api/generators/base/builders/DirectoryBuilder.js +0 -215
- package/dist/api/generators/base/builders/FileBuilder.d.ts +0 -160
- package/dist/api/generators/base/builders/FileBuilder.js +0 -406
- package/dist/api/generators/base/builders/IndexBuilder.d.ts +0 -126
- package/dist/api/generators/base/builders/IndexBuilder.js +0 -290
- package/dist/api/generators/base/enhanced-errors.d.ts +0 -84
- package/dist/api/generators/base/enhanced-errors.js +0 -259
- package/dist/api/generators/base/error-handler.d.ts +0 -89
- package/dist/api/generators/base/error-handler.js +0 -243
- package/dist/api/generators/base/errors.d.ts +0 -251
- package/dist/api/generators/base/errors.js +0 -692
- package/dist/api/generators/base/index.d.ts +0 -99
- package/dist/api/generators/base/index.js +0 -160
- package/dist/api/generators/base/types.d.ts +0 -433
- package/dist/api/generators/base/types.js +0 -12
- package/dist/api/generators/types.d.ts +0 -53
- package/dist/api/generators/types.js +0 -4
- package/dist/api/generators/typescript.d.ts +0 -190
- package/dist/api/generators/typescript.js +0 -819
- package/dist/api/index.d.ts +0 -51
- package/dist/api/index.js +0 -50
- package/dist/cli/commands/generate/typescript.d.ts +0 -10
- package/dist/cli/commands/generate/typescript.js +0 -52
- package/dist/cli/commands/generate.d.ts +0 -15
- package/dist/cli/commands/generate.js +0 -159
- package/dist/cli/commands/index.d.ts +0 -29
- package/dist/cli/commands/index.js +0 -100
- package/dist/cli/commands/typeschema/generate.d.ts +0 -19
- package/dist/cli/commands/typeschema/generate.js +0 -124
- package/dist/cli/commands/typeschema.d.ts +0 -10
- package/dist/cli/commands/typeschema.js +0 -47
- package/dist/cli/index.d.ts +0 -9
- package/dist/cli/utils/log.d.ts +0 -10
- package/dist/cli/utils/log.js +0 -23
- package/dist/cli/utils/prompts.d.ts +0 -56
- package/dist/cli/utils/prompts.js +0 -202
- package/dist/cli/utils/spinner.d.ts +0 -110
- package/dist/cli/utils/spinner.js +0 -266
- package/dist/config.d.ts +0 -217
- package/dist/config.js +0 -591
- package/dist/logger.d.ts +0 -157
- package/dist/logger.js +0 -281
- package/dist/typeschema/cache.d.ts +0 -80
- package/dist/typeschema/cache.js +0 -239
- package/dist/typeschema/core/binding.d.ts +0 -11
- package/dist/typeschema/core/binding.js +0 -143
- package/dist/typeschema/core/field-builder.d.ts +0 -12
- package/dist/typeschema/core/field-builder.js +0 -123
- package/dist/typeschema/core/identifier.d.ts +0 -13
- package/dist/typeschema/core/identifier.js +0 -94
- package/dist/typeschema/core/nested-types.d.ts +0 -9
- package/dist/typeschema/core/nested-types.js +0 -94
- package/dist/typeschema/core/transformer.d.ts +0 -11
- package/dist/typeschema/core/transformer.js +0 -235
- package/dist/typeschema/generator.d.ts +0 -43
- package/dist/typeschema/generator.js +0 -264
- package/dist/typeschema/index.d.ts +0 -15
- package/dist/typeschema/index.js +0 -15
- package/dist/typeschema/parser.d.ts +0 -79
- package/dist/typeschema/parser.js +0 -274
- package/dist/typeschema/profile/processor.d.ts +0 -14
- package/dist/typeschema/profile/processor.js +0 -262
- package/dist/typeschema/register.d.ts +0 -21
- package/dist/typeschema/register.js +0 -117
- package/dist/typeschema/types.d.ts +0 -240
- package/dist/typeschema/types.js +0 -19
- package/dist/utils/codegen-logger.d.ts +0 -102
- package/dist/utils/codegen-logger.js +0 -196
- package/dist/utils.d.ts +0 -22
- package/dist/utils.js +0 -42
package/dist/cli/index.d.ts
DELETED
package/dist/cli/utils/log.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Utilities - Re-exports from main utils with spinner support
|
|
3
|
-
*/
|
|
4
|
-
import { createSpinner } from "./spinner";
|
|
5
|
-
export { type CodegenLogger, complete, configure, createLogger, debug, dim, error, header, info, type LogOptions, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger";
|
|
6
|
-
export { createSpinner };
|
|
7
|
-
/**
|
|
8
|
-
* Run a task with a spinner
|
|
9
|
-
*/
|
|
10
|
-
export declare function withSpinner<T>(promise: Promise<T>, message: string, successMessage?: string): Promise<T>;
|
package/dist/cli/utils/log.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Utilities - Re-exports from main utils with spinner support
|
|
3
|
-
*/
|
|
4
|
-
import { createSpinner } from "./spinner";
|
|
5
|
-
// Re-export all logger functions from the main utils
|
|
6
|
-
export { complete, configure, createLogger, debug, dim, error, header, info, list, plain, progress, section, step, success, table, warn, } from "../../utils/codegen-logger";
|
|
7
|
-
// Export CLI-specific utilities
|
|
8
|
-
export { createSpinner };
|
|
9
|
-
/**
|
|
10
|
-
* Run a task with a spinner
|
|
11
|
-
*/
|
|
12
|
-
export async function withSpinner(promise, message, successMessage) {
|
|
13
|
-
const spinner = createSpinner(message).start();
|
|
14
|
-
try {
|
|
15
|
-
const result = await promise;
|
|
16
|
-
spinner.succeed(successMessage || message);
|
|
17
|
-
return result;
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
spinner.fail(`Failed: ${message}`);
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Prompts Utility
|
|
3
|
-
*
|
|
4
|
-
* Interactive prompts for better CLI user experience
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Prompt for project initialization
|
|
8
|
-
*/
|
|
9
|
-
export declare function promptInitConfig(): Promise<{
|
|
10
|
-
projectName: string;
|
|
11
|
-
description?: string;
|
|
12
|
-
outputDir: string;
|
|
13
|
-
generators: string[];
|
|
14
|
-
packageManager: "npm" | "yarn" | "pnpm" | "bun";
|
|
15
|
-
typescript: boolean;
|
|
16
|
-
}>;
|
|
17
|
-
/**
|
|
18
|
-
* Prompt for FHIR package selection
|
|
19
|
-
*/
|
|
20
|
-
export declare function promptFHIRPackage(): Promise<{
|
|
21
|
-
packageId: string;
|
|
22
|
-
version?: string;
|
|
23
|
-
profiles?: string[];
|
|
24
|
-
}>;
|
|
25
|
-
/**
|
|
26
|
-
* Prompt for generator configuration
|
|
27
|
-
*/
|
|
28
|
-
export declare function promptGeneratorConfig(generatorId: string): Promise<Record<string, any>>;
|
|
29
|
-
/**
|
|
30
|
-
* Prompt for confirmation with custom message
|
|
31
|
-
*/
|
|
32
|
-
export declare function promptConfirm(message: string, defaultValue?: boolean): Promise<boolean>;
|
|
33
|
-
/**
|
|
34
|
-
* Prompt for text input with validation
|
|
35
|
-
*/
|
|
36
|
-
export declare function promptInput(message: string, options?: {
|
|
37
|
-
default?: string;
|
|
38
|
-
validate?: (value: string) => boolean | string;
|
|
39
|
-
transform?: (value: string) => string;
|
|
40
|
-
}): Promise<string>;
|
|
41
|
-
/**
|
|
42
|
-
* Show success message
|
|
43
|
-
*/
|
|
44
|
-
export declare function showSuccess(message: string): void;
|
|
45
|
-
/**
|
|
46
|
-
* Show error message
|
|
47
|
-
*/
|
|
48
|
-
export declare function showError(message: string): void;
|
|
49
|
-
/**
|
|
50
|
-
* Show warning message
|
|
51
|
-
*/
|
|
52
|
-
export declare function showWarning(message: string): void;
|
|
53
|
-
/**
|
|
54
|
-
* Show info message
|
|
55
|
-
*/
|
|
56
|
-
export declare function showInfo(message: string): void;
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Prompts Utility
|
|
3
|
-
*
|
|
4
|
-
* Interactive prompts for better CLI user experience
|
|
5
|
-
*/
|
|
6
|
-
import { checkbox, confirm, input, select } from "@inquirer/prompts";
|
|
7
|
-
import pc from "picocolors";
|
|
8
|
-
/**
|
|
9
|
-
* Prompt for project initialization
|
|
10
|
-
*/
|
|
11
|
-
export async function promptInitConfig() {
|
|
12
|
-
console.log(pc.bold(pc.blue("\n🚀 Initialize Atomic Codegen Project\n")));
|
|
13
|
-
const projectName = await input({
|
|
14
|
-
message: "Project name:",
|
|
15
|
-
default: "my-fhir-types",
|
|
16
|
-
validate: (value) => {
|
|
17
|
-
if (!value.trim())
|
|
18
|
-
return "Project name is required";
|
|
19
|
-
if (!/^[a-z0-9-_]+$/i.test(value)) {
|
|
20
|
-
return "Project name can only contain letters, numbers, hyphens, and underscores";
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
const description = await input({
|
|
26
|
-
message: "Project description (optional):",
|
|
27
|
-
default: "",
|
|
28
|
-
});
|
|
29
|
-
const outputDir = await input({
|
|
30
|
-
message: "Output directory for generated code:",
|
|
31
|
-
default: "./generated",
|
|
32
|
-
});
|
|
33
|
-
const generators = await checkbox({
|
|
34
|
-
message: "Select generators to use:",
|
|
35
|
-
choices: [
|
|
36
|
-
{ name: "TypeScript", value: "typescript", checked: true },
|
|
37
|
-
{ name: "Python", value: "python" },
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
const packageManager = (await select({
|
|
41
|
-
message: "Package manager:",
|
|
42
|
-
choices: [
|
|
43
|
-
{ name: "Bun", value: "bun" },
|
|
44
|
-
{ name: "npm", value: "npm" },
|
|
45
|
-
{ name: "Yarn", value: "yarn" },
|
|
46
|
-
{ name: "pnpm", value: "pnpm" },
|
|
47
|
-
],
|
|
48
|
-
default: "bun",
|
|
49
|
-
}));
|
|
50
|
-
const typescript = await confirm({
|
|
51
|
-
message: "Use TypeScript for configuration?",
|
|
52
|
-
default: true,
|
|
53
|
-
});
|
|
54
|
-
return {
|
|
55
|
-
projectName,
|
|
56
|
-
description,
|
|
57
|
-
outputDir,
|
|
58
|
-
generators,
|
|
59
|
-
packageManager,
|
|
60
|
-
typescript,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Prompt for FHIR package selection
|
|
65
|
-
*/
|
|
66
|
-
export async function promptFHIRPackage() {
|
|
67
|
-
const packageId = await select({
|
|
68
|
-
message: "Select FHIR package:",
|
|
69
|
-
choices: [
|
|
70
|
-
{ name: "FHIR R4 Core", value: "hl7.fhir.r4.core" },
|
|
71
|
-
{ name: "FHIR R5 Core", value: "hl7.fhir.r5.core" },
|
|
72
|
-
{ name: "US Core", value: "hl7.fhir.us.core" },
|
|
73
|
-
{ name: "Custom package...", value: "custom" },
|
|
74
|
-
],
|
|
75
|
-
});
|
|
76
|
-
let finalPackageId = packageId;
|
|
77
|
-
let version;
|
|
78
|
-
if (packageId === "custom") {
|
|
79
|
-
finalPackageId = await input({
|
|
80
|
-
message: "Enter package ID (e.g., hl7.fhir.us.core):",
|
|
81
|
-
validate: (value) => {
|
|
82
|
-
if (!value.trim())
|
|
83
|
-
return "Package ID is required";
|
|
84
|
-
return true;
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
version = await input({
|
|
88
|
-
message: "Package version (optional):",
|
|
89
|
-
default: "",
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
const includeProfiles = await confirm({
|
|
93
|
-
message: "Include profiles in generation?",
|
|
94
|
-
default: false,
|
|
95
|
-
});
|
|
96
|
-
let profiles = [];
|
|
97
|
-
if (includeProfiles) {
|
|
98
|
-
const profileSelection = await select({
|
|
99
|
-
message: "Profile selection:",
|
|
100
|
-
choices: [
|
|
101
|
-
{ name: "All profiles", value: "all" },
|
|
102
|
-
{ name: "None", value: "none" },
|
|
103
|
-
],
|
|
104
|
-
default: "none",
|
|
105
|
-
});
|
|
106
|
-
if (profileSelection === "all") {
|
|
107
|
-
profiles = ["*"];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return {
|
|
111
|
-
packageId: finalPackageId,
|
|
112
|
-
version: version || undefined,
|
|
113
|
-
profiles,
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Prompt for generator configuration
|
|
118
|
-
*/
|
|
119
|
-
export async function promptGeneratorConfig(generatorId) {
|
|
120
|
-
const config = {};
|
|
121
|
-
switch (generatorId) {
|
|
122
|
-
case "typescript":
|
|
123
|
-
config.moduleFormat = await select({
|
|
124
|
-
message: "Module format:",
|
|
125
|
-
choices: [
|
|
126
|
-
{ name: "ESM", value: "esm" },
|
|
127
|
-
{ name: "CommonJS", value: "cjs" },
|
|
128
|
-
{ name: "Both", value: "both" },
|
|
129
|
-
],
|
|
130
|
-
default: "esm",
|
|
131
|
-
});
|
|
132
|
-
config.strict = await confirm({
|
|
133
|
-
message: "Enable strict TypeScript checks?",
|
|
134
|
-
default: true,
|
|
135
|
-
});
|
|
136
|
-
config.generateIndex = await confirm({
|
|
137
|
-
message: "Generate index files?",
|
|
138
|
-
default: true,
|
|
139
|
-
});
|
|
140
|
-
break;
|
|
141
|
-
case "python":
|
|
142
|
-
config.style = await select({
|
|
143
|
-
message: "Python style:",
|
|
144
|
-
choices: [
|
|
145
|
-
{ name: "Dataclasses", value: "dataclass" },
|
|
146
|
-
{ name: "Pydantic", value: "pydantic" },
|
|
147
|
-
{ name: "Plain classes", value: "plain" },
|
|
148
|
-
],
|
|
149
|
-
default: "dataclass",
|
|
150
|
-
});
|
|
151
|
-
config.typeHints = await confirm({
|
|
152
|
-
message: "Include type hints?",
|
|
153
|
-
default: true,
|
|
154
|
-
});
|
|
155
|
-
break;
|
|
156
|
-
}
|
|
157
|
-
return config;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Prompt for confirmation with custom message
|
|
161
|
-
*/
|
|
162
|
-
export async function promptConfirm(message, defaultValue = false) {
|
|
163
|
-
return await confirm({
|
|
164
|
-
message,
|
|
165
|
-
default: defaultValue,
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Prompt for text input with validation
|
|
170
|
-
*/
|
|
171
|
-
export async function promptInput(message, options) {
|
|
172
|
-
return await input({
|
|
173
|
-
message,
|
|
174
|
-
default: options?.default,
|
|
175
|
-
validate: options?.validate,
|
|
176
|
-
transformer: options?.transform,
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Show success message
|
|
181
|
-
*/
|
|
182
|
-
export function showSuccess(message) {
|
|
183
|
-
console.log(pc.green(`✅ ${message}`));
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Show error message
|
|
187
|
-
*/
|
|
188
|
-
export function showError(message) {
|
|
189
|
-
console.log(pc.red(`❌ ${message}`));
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Show warning message
|
|
193
|
-
*/
|
|
194
|
-
export function showWarning(message) {
|
|
195
|
-
console.log(pc.yellow(`⚠️ ${message}`));
|
|
196
|
-
}
|
|
197
|
-
/**
|
|
198
|
-
* Show info message
|
|
199
|
-
*/
|
|
200
|
-
export function showInfo(message) {
|
|
201
|
-
console.log(pc.blue(`ℹ️ ${message}`));
|
|
202
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Spinner and Progress Utilities
|
|
3
|
-
*
|
|
4
|
-
* Visual progress indicators for long-running operations
|
|
5
|
-
*/
|
|
6
|
-
/**
|
|
7
|
-
* Task progress tracker
|
|
8
|
-
*/
|
|
9
|
-
export declare class ProgressTracker {
|
|
10
|
-
private tasks;
|
|
11
|
-
private currentSpinner;
|
|
12
|
-
/**
|
|
13
|
-
* Start a new task
|
|
14
|
-
*/
|
|
15
|
-
startTask(taskId: string, message: string): void;
|
|
16
|
-
/**
|
|
17
|
-
* Update task progress
|
|
18
|
-
*/
|
|
19
|
-
updateTask(taskId: string, message: string): void;
|
|
20
|
-
/**
|
|
21
|
-
* Complete a task successfully
|
|
22
|
-
*/
|
|
23
|
-
completeTask(taskId: string, message?: string): void;
|
|
24
|
-
/**
|
|
25
|
-
* Fail a task
|
|
26
|
-
*/
|
|
27
|
-
failTask(taskId: string, error?: string): void;
|
|
28
|
-
/**
|
|
29
|
-
* Stop all spinners
|
|
30
|
-
*/
|
|
31
|
-
stop(): void;
|
|
32
|
-
/**
|
|
33
|
-
* Get task statistics
|
|
34
|
-
*/
|
|
35
|
-
getStats(): {
|
|
36
|
-
total: number;
|
|
37
|
-
completed: number;
|
|
38
|
-
failed: number;
|
|
39
|
-
running: number;
|
|
40
|
-
pending: number;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Simple spinner for single operations
|
|
45
|
-
*/
|
|
46
|
-
export declare class SimpleSpinner {
|
|
47
|
-
private spinner;
|
|
48
|
-
constructor(message: string);
|
|
49
|
-
start(message?: string): SimpleSpinner;
|
|
50
|
-
update(message: string): SimpleSpinner;
|
|
51
|
-
succeed(message?: string): void;
|
|
52
|
-
fail(message?: string): void;
|
|
53
|
-
warn(message?: string): void;
|
|
54
|
-
info(message?: string): void;
|
|
55
|
-
stop(): void;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Progress bar for batch operations
|
|
59
|
-
*/
|
|
60
|
-
export declare class ProgressBar {
|
|
61
|
-
private total;
|
|
62
|
-
private message;
|
|
63
|
-
private current;
|
|
64
|
-
private barLength;
|
|
65
|
-
private startTime;
|
|
66
|
-
constructor(total: number, message: string);
|
|
67
|
-
/**
|
|
68
|
-
* Update progress
|
|
69
|
-
*/
|
|
70
|
-
update(current: number, additionalInfo?: string): void;
|
|
71
|
-
/**
|
|
72
|
-
* Increment progress by 1
|
|
73
|
-
*/
|
|
74
|
-
increment(additionalInfo?: string): void;
|
|
75
|
-
/**
|
|
76
|
-
* Complete the progress bar
|
|
77
|
-
*/
|
|
78
|
-
complete(message?: string): void;
|
|
79
|
-
/**
|
|
80
|
-
* Render the progress bar
|
|
81
|
-
*/
|
|
82
|
-
private render;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Create a simple spinner
|
|
86
|
-
*/
|
|
87
|
-
export declare function createSpinner(message: string): SimpleSpinner;
|
|
88
|
-
/**
|
|
89
|
-
* Create a progress tracker for multiple tasks
|
|
90
|
-
*/
|
|
91
|
-
export declare function createProgressTracker(): ProgressTracker;
|
|
92
|
-
/**
|
|
93
|
-
* Create a progress bar
|
|
94
|
-
*/
|
|
95
|
-
export declare function createProgressBar(total: number, message: string): ProgressBar;
|
|
96
|
-
/**
|
|
97
|
-
* Show a spinner for a promise
|
|
98
|
-
*/
|
|
99
|
-
export declare function withSpinner<T>(promise: Promise<T>, options: {
|
|
100
|
-
start: string;
|
|
101
|
-
success?: string | ((result: T) => string);
|
|
102
|
-
fail?: string | ((error: any) => string);
|
|
103
|
-
}): Promise<T>;
|
|
104
|
-
/**
|
|
105
|
-
* Multi-step task execution with progress
|
|
106
|
-
*/
|
|
107
|
-
export declare function executeSteps<T>(steps: Array<{
|
|
108
|
-
name: string;
|
|
109
|
-
task: () => Promise<T>;
|
|
110
|
-
}>): Promise<T[]>;
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CLI Spinner and Progress Utilities
|
|
3
|
-
*
|
|
4
|
-
* Visual progress indicators for long-running operations
|
|
5
|
-
*/
|
|
6
|
-
import { performance } from "node:perf_hooks";
|
|
7
|
-
import ora from "ora";
|
|
8
|
-
import pc from "picocolors";
|
|
9
|
-
/**
|
|
10
|
-
* Task progress tracker
|
|
11
|
-
*/
|
|
12
|
-
export class ProgressTracker {
|
|
13
|
-
tasks = new Map();
|
|
14
|
-
currentSpinner = null;
|
|
15
|
-
/**
|
|
16
|
-
* Start a new task
|
|
17
|
-
*/
|
|
18
|
-
startTask(taskId, message) {
|
|
19
|
-
this.tasks.set(taskId, {
|
|
20
|
-
startTime: performance.now(),
|
|
21
|
-
status: "running",
|
|
22
|
-
});
|
|
23
|
-
if (this.currentSpinner) {
|
|
24
|
-
this.currentSpinner.stop();
|
|
25
|
-
}
|
|
26
|
-
this.currentSpinner = ora({
|
|
27
|
-
text: message,
|
|
28
|
-
spinner: "dots",
|
|
29
|
-
}).start();
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Update task progress
|
|
33
|
-
*/
|
|
34
|
-
updateTask(taskId, message) {
|
|
35
|
-
const task = this.tasks.get(taskId);
|
|
36
|
-
if (!task || task.status !== "running")
|
|
37
|
-
return;
|
|
38
|
-
if (this.currentSpinner) {
|
|
39
|
-
this.currentSpinner.text = message;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Complete a task successfully
|
|
44
|
-
*/
|
|
45
|
-
completeTask(taskId, message) {
|
|
46
|
-
const task = this.tasks.get(taskId);
|
|
47
|
-
if (!task)
|
|
48
|
-
return;
|
|
49
|
-
const duration = Math.round(performance.now() - task.startTime);
|
|
50
|
-
task.status = "completed";
|
|
51
|
-
if (this.currentSpinner) {
|
|
52
|
-
const finalMessage = message || this.currentSpinner.text;
|
|
53
|
-
this.currentSpinner.succeed(`${finalMessage} ${pc.gray(`(${duration}ms)`)}`);
|
|
54
|
-
this.currentSpinner = null;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Fail a task
|
|
59
|
-
*/
|
|
60
|
-
failTask(taskId, error) {
|
|
61
|
-
const task = this.tasks.get(taskId);
|
|
62
|
-
if (!task)
|
|
63
|
-
return;
|
|
64
|
-
task.status = "failed";
|
|
65
|
-
if (this.currentSpinner) {
|
|
66
|
-
const errorMessage = error ? `: ${error}` : "";
|
|
67
|
-
this.currentSpinner.fail(this.currentSpinner.text + errorMessage);
|
|
68
|
-
this.currentSpinner = null;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Stop all spinners
|
|
73
|
-
*/
|
|
74
|
-
stop() {
|
|
75
|
-
if (this.currentSpinner) {
|
|
76
|
-
this.currentSpinner.stop();
|
|
77
|
-
this.currentSpinner = null;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Get task statistics
|
|
82
|
-
*/
|
|
83
|
-
getStats() {
|
|
84
|
-
let completed = 0;
|
|
85
|
-
let failed = 0;
|
|
86
|
-
let running = 0;
|
|
87
|
-
let pending = 0;
|
|
88
|
-
for (const task of this.tasks.values()) {
|
|
89
|
-
switch (task.status) {
|
|
90
|
-
case "completed":
|
|
91
|
-
completed++;
|
|
92
|
-
break;
|
|
93
|
-
case "failed":
|
|
94
|
-
failed++;
|
|
95
|
-
break;
|
|
96
|
-
case "running":
|
|
97
|
-
running++;
|
|
98
|
-
break;
|
|
99
|
-
case "pending":
|
|
100
|
-
pending++;
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
total: this.tasks.size,
|
|
106
|
-
completed,
|
|
107
|
-
failed,
|
|
108
|
-
running,
|
|
109
|
-
pending,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Simple spinner for single operations
|
|
115
|
-
*/
|
|
116
|
-
export class SimpleSpinner {
|
|
117
|
-
spinner;
|
|
118
|
-
constructor(message) {
|
|
119
|
-
this.spinner = ora({
|
|
120
|
-
text: message,
|
|
121
|
-
spinner: "dots",
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
start(message) {
|
|
125
|
-
if (message) {
|
|
126
|
-
this.spinner.text = message;
|
|
127
|
-
}
|
|
128
|
-
this.spinner.start();
|
|
129
|
-
return this;
|
|
130
|
-
}
|
|
131
|
-
update(message) {
|
|
132
|
-
this.spinner.text = message;
|
|
133
|
-
return this;
|
|
134
|
-
}
|
|
135
|
-
succeed(message) {
|
|
136
|
-
this.spinner.succeed(message);
|
|
137
|
-
}
|
|
138
|
-
fail(message) {
|
|
139
|
-
this.spinner.fail(message);
|
|
140
|
-
}
|
|
141
|
-
warn(message) {
|
|
142
|
-
this.spinner.warn(message);
|
|
143
|
-
}
|
|
144
|
-
info(message) {
|
|
145
|
-
this.spinner.info(message);
|
|
146
|
-
}
|
|
147
|
-
stop() {
|
|
148
|
-
this.spinner.stop();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Progress bar for batch operations
|
|
153
|
-
*/
|
|
154
|
-
export class ProgressBar {
|
|
155
|
-
total;
|
|
156
|
-
message;
|
|
157
|
-
current = 0;
|
|
158
|
-
barLength = 30;
|
|
159
|
-
startTime = performance.now();
|
|
160
|
-
constructor(total, message) {
|
|
161
|
-
this.total = total;
|
|
162
|
-
this.message = message;
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Update progress
|
|
166
|
-
*/
|
|
167
|
-
update(current, additionalInfo) {
|
|
168
|
-
this.current = Math.min(current, this.total);
|
|
169
|
-
this.render(additionalInfo);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Increment progress by 1
|
|
173
|
-
*/
|
|
174
|
-
increment(additionalInfo) {
|
|
175
|
-
this.update(this.current + 1, additionalInfo);
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Complete the progress bar
|
|
179
|
-
*/
|
|
180
|
-
complete(message) {
|
|
181
|
-
this.current = this.total;
|
|
182
|
-
this.render();
|
|
183
|
-
const duration = Math.round(performance.now() - this.startTime);
|
|
184
|
-
console.log(pc.green(`✅ ${message || this.message} ${pc.gray(`(${duration}ms)`)}`));
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Render the progress bar
|
|
188
|
-
*/
|
|
189
|
-
render(additionalInfo) {
|
|
190
|
-
const percentage = Math.round((this.current / this.total) * 100);
|
|
191
|
-
const filled = Math.round((this.current / this.total) * this.barLength);
|
|
192
|
-
const empty = this.barLength - filled;
|
|
193
|
-
const bar = pc.green("█".repeat(filled)) + pc.gray("░".repeat(empty));
|
|
194
|
-
const progress = `${this.current}/${this.total}`;
|
|
195
|
-
const info = additionalInfo ? pc.gray(` ${additionalInfo}`) : "";
|
|
196
|
-
// Clear line and write progress
|
|
197
|
-
process.stdout.clearLine(0);
|
|
198
|
-
process.stdout.cursorTo(0);
|
|
199
|
-
process.stdout.write(`${this.message} ${bar} ${pc.cyan(progress)} ${pc.yellow(`${percentage}%`)}${info}`);
|
|
200
|
-
// Add newline when complete
|
|
201
|
-
if (this.current === this.total) {
|
|
202
|
-
process.stdout.write("\n");
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Create a simple spinner
|
|
208
|
-
*/
|
|
209
|
-
export function createSpinner(message) {
|
|
210
|
-
return new SimpleSpinner(message);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Create a progress tracker for multiple tasks
|
|
214
|
-
*/
|
|
215
|
-
export function createProgressTracker() {
|
|
216
|
-
return new ProgressTracker();
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Create a progress bar
|
|
220
|
-
*/
|
|
221
|
-
export function createProgressBar(total, message) {
|
|
222
|
-
return new ProgressBar(total, message);
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Show a spinner for a promise
|
|
226
|
-
*/
|
|
227
|
-
export async function withSpinner(promise, options) {
|
|
228
|
-
const spinner = ora({
|
|
229
|
-
text: options.start,
|
|
230
|
-
spinner: "dots",
|
|
231
|
-
}).start();
|
|
232
|
-
try {
|
|
233
|
-
const result = await promise;
|
|
234
|
-
const successMessage = typeof options.success === "function" ? options.success(result) : options.success || options.start;
|
|
235
|
-
spinner.succeed(successMessage);
|
|
236
|
-
return result;
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
const failMessage = typeof options.fail === "function" ? options.fail(error) : options.fail || `Failed: ${options.start}`;
|
|
240
|
-
spinner.fail(failMessage);
|
|
241
|
-
throw error;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Multi-step task execution with progress
|
|
246
|
-
*/
|
|
247
|
-
export async function executeSteps(steps) {
|
|
248
|
-
const results = [];
|
|
249
|
-
const progressBar = new ProgressBar(steps.length, "Executing tasks");
|
|
250
|
-
for (let i = 0; i < steps.length; i++) {
|
|
251
|
-
const step = steps[i];
|
|
252
|
-
progressBar.update(i, step?.name);
|
|
253
|
-
try {
|
|
254
|
-
const result = await step?.task();
|
|
255
|
-
if (result) {
|
|
256
|
-
results.push(result);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
progressBar.complete(`Failed at step: ${step?.name}`);
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
progressBar.complete("All tasks completed");
|
|
265
|
-
return results;
|
|
266
|
-
}
|