@xrmforge/cli 0.1.0
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/index.js +232 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/index.ts
|
|
4
|
+
import { readFileSync as readFileSync2 } from "fs";
|
|
5
|
+
import { dirname, join as join2 } from "path";
|
|
6
|
+
import { fileURLToPath } from "url";
|
|
7
|
+
import { Command } from "commander";
|
|
8
|
+
|
|
9
|
+
// src/config.ts
|
|
10
|
+
import { readFileSync, existsSync } from "fs";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
var CONFIG_FILENAME = "xrmforge.config.json";
|
|
13
|
+
function loadConfig(cwd = process.cwd()) {
|
|
14
|
+
const configPath = join(cwd, CONFIG_FILENAME);
|
|
15
|
+
if (!existsSync(configPath)) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const raw = readFileSync(configPath, "utf-8");
|
|
20
|
+
const config = JSON.parse(raw);
|
|
21
|
+
if (config.clientSecret) {
|
|
22
|
+
console.warn(`WARNING: clientSecret found in ${CONFIG_FILENAME}. This is a security risk.`);
|
|
23
|
+
console.warn(" Use XRMFORGE_CLIENT_SECRET environment variable instead.\n");
|
|
24
|
+
}
|
|
25
|
+
return config;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
if (error instanceof SyntaxError) {
|
|
28
|
+
throw new Error(`Invalid JSON in ${configPath}: ${error.message}`);
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function mergeWithCliOptions(config, cliOpts) {
|
|
34
|
+
const merged = { ...cliOpts };
|
|
35
|
+
if (!merged["url"] && config.url) merged["url"] = config.url;
|
|
36
|
+
if (!merged["auth"] && config.auth) merged["auth"] = config.auth;
|
|
37
|
+
if (!merged["tenantId"] && config.tenantId) merged["tenantId"] = config.tenantId;
|
|
38
|
+
if (!merged["clientId"] && config.clientId) merged["clientId"] = config.clientId;
|
|
39
|
+
if (!merged["clientSecret"] && config.clientSecret) merged["clientSecret"] = config.clientSecret;
|
|
40
|
+
if (!merged["solutions"] && config.solutions) {
|
|
41
|
+
merged["solutions"] = Array.isArray(config.solutions) ? config.solutions.join(",") : config.solutions;
|
|
42
|
+
}
|
|
43
|
+
if (!merged["output"] && config.output) merged["output"] = config.output;
|
|
44
|
+
if (!merged["entities"] && config.entities) {
|
|
45
|
+
merged["entities"] = config.entities.join(",");
|
|
46
|
+
}
|
|
47
|
+
if (!merged["labelLanguage"] && config.labelLanguage) {
|
|
48
|
+
merged["labelLanguage"] = String(config.labelLanguage);
|
|
49
|
+
}
|
|
50
|
+
if (!merged["secondaryLanguage"] && config.secondaryLanguage) {
|
|
51
|
+
merged["secondaryLanguage"] = String(config.secondaryLanguage);
|
|
52
|
+
}
|
|
53
|
+
if (merged["forms"] === void 0 && config.forms !== void 0) {
|
|
54
|
+
merged["forms"] = config.forms;
|
|
55
|
+
}
|
|
56
|
+
if (merged["optionsets"] === void 0 && config.optionsets !== void 0) {
|
|
57
|
+
merged["optionsets"] = config.optionsets;
|
|
58
|
+
}
|
|
59
|
+
return merged;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/commands/generate.ts
|
|
63
|
+
import {
|
|
64
|
+
TypeGenerationOrchestrator,
|
|
65
|
+
createCredential,
|
|
66
|
+
configureLogging,
|
|
67
|
+
ConsoleLogSink,
|
|
68
|
+
LogLevel
|
|
69
|
+
} from "@xrmforge/typegen";
|
|
70
|
+
function registerGenerateCommand(program2) {
|
|
71
|
+
program2.command("generate").description("Generate TypeScript declarations from a Dataverse environment").option("--url <url>", "Dataverse environment URL (e.g. https://myorg.crm4.dynamics.com)").option("--auth <method>", "Authentication method: client-credentials, interactive, device-code, token").option("--tenant-id <id>", "Azure AD tenant ID").option("--client-id <id>", "Azure AD application (client) ID").option("--client-secret <secret>", "Client secret (for client-credentials auth)").option("--token <token>", "Pre-acquired Bearer token (for --auth token). Prefer XRMFORGE_TOKEN env var for security.").option("--entities <list>", "Comma-separated list of entity logical names (e.g. account,contact)").option("--solutions <list>", "Comma-separated solution unique names to discover entities").option("--output <dir>", "Output directory for generated .d.ts files", "./typings").option("--label-language <code>", "Primary label language code", "1033").option("--secondary-language <code>", "Secondary label language code (for dual-language JSDoc)").option("--no-forms", "Skip form interface generation").option("--no-optionsets", "Skip OptionSet enum generation").option("-v, --verbose", "Enable verbose logging", false).action(async (opts) => {
|
|
72
|
+
try {
|
|
73
|
+
await runGenerate(opts);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if (error instanceof Error) {
|
|
76
|
+
console.error(`
|
|
77
|
+
Error: ${error.message}
|
|
78
|
+
`);
|
|
79
|
+
if (opts.verbose && error.stack) {
|
|
80
|
+
console.error(error.stack);
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
console.error("\nAn unexpected error occurred.\n");
|
|
84
|
+
}
|
|
85
|
+
process.exitCode = 1;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function runGenerate(cliOpts) {
|
|
90
|
+
const fileConfig = loadConfig();
|
|
91
|
+
const merged = mergeWithCliOptions(fileConfig, cliOpts);
|
|
92
|
+
const opts = merged;
|
|
93
|
+
configureLogging({
|
|
94
|
+
sink: new ConsoleLogSink(),
|
|
95
|
+
minLevel: opts.verbose ? LogLevel.DEBUG : LogLevel.INFO
|
|
96
|
+
});
|
|
97
|
+
if (!opts.url) {
|
|
98
|
+
throw new Error("--url is required. Set it via CLI flag or in xrmforge.config.json.");
|
|
99
|
+
}
|
|
100
|
+
if (!opts.auth) {
|
|
101
|
+
throw new Error("--auth is required. Set it via CLI flag or in xrmforge.config.json.");
|
|
102
|
+
}
|
|
103
|
+
if (!opts.entities && !opts.solutions) {
|
|
104
|
+
throw new Error("Either --entities or --solutions must be specified (CLI or xrmforge.config.json).");
|
|
105
|
+
}
|
|
106
|
+
const authConfig = buildAuthConfig(opts);
|
|
107
|
+
const credential = createCredential(authConfig);
|
|
108
|
+
const entities = opts.entities ? opts.entities.split(",").map((e) => e.trim().toLowerCase()) : [];
|
|
109
|
+
const solutionNames = opts.solutions ? opts.solutions.split(",").map((s) => s.trim()) : [];
|
|
110
|
+
if (entities.length === 0 && solutionNames.length === 0) {
|
|
111
|
+
throw new Error("No entities specified. Use --entities or --solutions.");
|
|
112
|
+
}
|
|
113
|
+
const primaryLanguage = parseInt(opts.labelLanguage, 10);
|
|
114
|
+
if (isNaN(primaryLanguage)) {
|
|
115
|
+
throw new Error(`Invalid --label-language: "${opts.labelLanguage}". Must be a numeric LCID (e.g. 1033, 1031).`);
|
|
116
|
+
}
|
|
117
|
+
let secondaryLanguage;
|
|
118
|
+
if (opts.secondaryLanguage) {
|
|
119
|
+
secondaryLanguage = parseInt(opts.secondaryLanguage, 10);
|
|
120
|
+
if (isNaN(secondaryLanguage)) {
|
|
121
|
+
throw new Error(`Invalid --secondary-language: "${opts.secondaryLanguage}". Must be a numeric LCID (e.g. 1033, 1031).`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
console.log(`
|
|
125
|
+
XrmForge Type Generator`);
|
|
126
|
+
console.log(`Environment: ${opts.url}`);
|
|
127
|
+
console.log(`Auth method: ${opts.auth}`);
|
|
128
|
+
console.log(`Entities: ${entities.length > 0 ? entities.join(", ") : "(none specified directly)"}`);
|
|
129
|
+
if (solutionNames.length > 0) {
|
|
130
|
+
console.log(`Solutions: ${solutionNames.join(", ")}`);
|
|
131
|
+
}
|
|
132
|
+
console.log(`Output: ${opts.output}`);
|
|
133
|
+
console.log(`Languages: ${primaryLanguage}${secondaryLanguage ? ` + ${secondaryLanguage}` : ""}`);
|
|
134
|
+
console.log("");
|
|
135
|
+
const orchestrator = new TypeGenerationOrchestrator(credential, {
|
|
136
|
+
environmentUrl: opts.url,
|
|
137
|
+
entities,
|
|
138
|
+
solutionNames: solutionNames.length > 0 ? solutionNames : void 0,
|
|
139
|
+
outputDir: opts.output,
|
|
140
|
+
labelConfig: { primaryLanguage, secondaryLanguage },
|
|
141
|
+
generateForms: opts.forms,
|
|
142
|
+
generateOptionSets: opts.optionsets
|
|
143
|
+
});
|
|
144
|
+
const controller = new AbortController();
|
|
145
|
+
const onSignal = () => {
|
|
146
|
+
console.log("\nAborting generation...");
|
|
147
|
+
controller.abort();
|
|
148
|
+
};
|
|
149
|
+
process.once("SIGINT", onSignal);
|
|
150
|
+
process.once("SIGTERM", onSignal);
|
|
151
|
+
const result = await orchestrator.generate({ signal: controller.signal });
|
|
152
|
+
console.log("");
|
|
153
|
+
console.log("Generation complete:");
|
|
154
|
+
console.log(` Entities: ${result.entities.length}`);
|
|
155
|
+
console.log(` Files: ${result.totalFiles}`);
|
|
156
|
+
console.log(` Warnings: ${result.totalWarnings}`);
|
|
157
|
+
console.log(` Duration: ${result.durationMs}ms`);
|
|
158
|
+
if (result.totalWarnings > 0) {
|
|
159
|
+
console.log("\nWarnings:");
|
|
160
|
+
for (const entity of result.entities) {
|
|
161
|
+
for (const warning of entity.warnings) {
|
|
162
|
+
console.log(` [${entity.entityLogicalName}] ${warning}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const failures = result.entities.filter((e) => e.files.length === 0 && e.warnings.length > 0);
|
|
167
|
+
if (failures.length > 0) {
|
|
168
|
+
console.log(`
|
|
169
|
+
${failures.length} entity/entities failed. See warnings above.`);
|
|
170
|
+
process.exitCode = 1;
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
console.log(`
|
|
174
|
+
Types written to: ${opts.output}/`);
|
|
175
|
+
}
|
|
176
|
+
function buildAuthConfig(opts) {
|
|
177
|
+
const method = opts.auth;
|
|
178
|
+
switch (method) {
|
|
179
|
+
case "client-credentials":
|
|
180
|
+
if (!opts.tenantId) throw new Error("--tenant-id is required for client-credentials auth.");
|
|
181
|
+
if (!opts.clientId) throw new Error("--client-id is required for client-credentials auth.");
|
|
182
|
+
if (!opts.clientSecret) throw new Error("--client-secret is required for client-credentials auth.");
|
|
183
|
+
return {
|
|
184
|
+
method: "client-credentials",
|
|
185
|
+
tenantId: opts.tenantId,
|
|
186
|
+
clientId: opts.clientId,
|
|
187
|
+
clientSecret: opts.clientSecret
|
|
188
|
+
};
|
|
189
|
+
case "interactive":
|
|
190
|
+
if (!opts.tenantId) throw new Error("--tenant-id is required for interactive auth.");
|
|
191
|
+
if (!opts.clientId) throw new Error("--client-id is required for interactive auth.");
|
|
192
|
+
return {
|
|
193
|
+
method: "interactive",
|
|
194
|
+
tenantId: opts.tenantId,
|
|
195
|
+
clientId: opts.clientId
|
|
196
|
+
};
|
|
197
|
+
case "device-code":
|
|
198
|
+
if (!opts.tenantId) throw new Error("--tenant-id is required for device-code auth.");
|
|
199
|
+
if (!opts.clientId) throw new Error("--client-id is required for device-code auth.");
|
|
200
|
+
return {
|
|
201
|
+
method: "device-code",
|
|
202
|
+
tenantId: opts.tenantId,
|
|
203
|
+
clientId: opts.clientId
|
|
204
|
+
};
|
|
205
|
+
case "token": {
|
|
206
|
+
const token = opts.token || process.env["XRMFORGE_TOKEN"];
|
|
207
|
+
if (!token) {
|
|
208
|
+
throw new Error(
|
|
209
|
+
"Token authentication requires a token. Set XRMFORGE_TOKEN environment variable or use --token flag."
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
if (opts.token) {
|
|
213
|
+
console.warn("WARNING: Using --token on the command line exposes the token in process list and shell history.");
|
|
214
|
+
console.warn(" Prefer setting XRMFORGE_TOKEN environment variable instead.\n");
|
|
215
|
+
}
|
|
216
|
+
return { method: "token", token };
|
|
217
|
+
}
|
|
218
|
+
default:
|
|
219
|
+
throw new Error(
|
|
220
|
+
`Unknown auth method: "${opts.auth}". Supported: client-credentials, interactive, device-code, token`
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/index.ts
|
|
226
|
+
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
227
|
+
var pkg = JSON.parse(readFileSync2(join2(__dirname, "..", "package.json"), "utf-8"));
|
|
228
|
+
var program = new Command();
|
|
229
|
+
program.name("xrmforge").description("TypeScript type generator for Dynamics 365 / Dataverse").version(pkg.version);
|
|
230
|
+
registerGenerateCommand(program);
|
|
231
|
+
program.parse();
|
|
232
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/config.ts","../src/commands/generate.ts"],"sourcesContent":["/**\n * @xrmforge/cli - Command-line interface for XrmForge\n *\n * Usage:\n * xrmforge generate --url https://myorg.crm4.dynamics.com \\\n * --auth client-credentials \\\n * --tenant <tenant-id> --client-id <app-id> --client-secret <secret> \\\n * --entities account,contact \\\n * --output ./typings\n */\n\nimport { readFileSync } from 'node:fs';\nimport { dirname, join } from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { Command } from 'commander';\nimport { registerGenerateCommand } from './commands/generate.js';\n\n// Read version from package.json (single source of truth)\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf-8'));\n\nconst program = new Command();\n\nprogram\n .name('xrmforge')\n .description('TypeScript type generator for Dynamics 365 / Dataverse')\n .version(pkg.version);\n\nregisterGenerateCommand(program);\n\nprogram.parse();\n","/**\n * @xrmforge/cli - Configuration File Support\n *\n * Reads xrmforge.config.json from the current working directory.\n * CLI flags override config file values.\n *\n * Example xrmforge.config.json:\n * ```json\n * {\n * \"url\": \"https://myorg.crm4.dynamics.com\",\n * \"auth\": \"interactive\",\n * \"tenantId\": \"your-tenant-id\",\n * \"solutions\": [\"MySolution\", \"MyOtherSolution\"],\n * \"entities\": [\"systemuser\", \"task\"],\n * \"output\": \"./typings\",\n * \"labelLanguage\": 1033,\n * \"secondaryLanguage\": 1031\n * }\n * ```\n */\n\nimport { readFileSync, existsSync } from 'node:fs';\nimport { join } from 'node:path';\n\n/** Shape of xrmforge.config.json */\nexport interface XrmForgeConfig {\n /** Dataverse environment URL */\n url?: string;\n /** Authentication method */\n auth?: string;\n /** Azure AD tenant ID */\n tenantId?: string;\n /** Azure AD application (client) ID */\n clientId?: string;\n /** Client secret (NOT recommended in config file, use env vars) */\n clientSecret?: string;\n /** Entity logical names */\n entities?: string[];\n /** Solution unique names (array or comma-separated string) */\n solutions?: string[] | string;\n /** Output directory */\n output?: string;\n /** Primary label language LCID */\n labelLanguage?: number;\n /** Secondary label language LCID */\n secondaryLanguage?: number;\n /** Generate form interfaces */\n forms?: boolean;\n /** Generate OptionSet enums */\n optionsets?: boolean;\n}\n\nconst CONFIG_FILENAME = 'xrmforge.config.json';\n\n/**\n * Load config from xrmforge.config.json in the current working directory.\n * Returns empty object if file doesn't exist.\n * Throws with clear message if file exists but is invalid JSON.\n */\nexport function loadConfig(cwd: string = process.cwd()): XrmForgeConfig {\n const configPath = join(cwd, CONFIG_FILENAME);\n\n if (!existsSync(configPath)) {\n return {};\n }\n\n try {\n const raw = readFileSync(configPath, 'utf-8');\n const config = JSON.parse(raw) as XrmForgeConfig;\n\n // Warn about secrets in config file\n if (config.clientSecret) {\n console.warn(`WARNING: clientSecret found in ${CONFIG_FILENAME}. This is a security risk.`);\n console.warn(' Use XRMFORGE_CLIENT_SECRET environment variable instead.\\n');\n }\n\n return config;\n } catch (error) {\n if (error instanceof SyntaxError) {\n throw new Error(`Invalid JSON in ${configPath}: ${error.message}`);\n }\n throw error;\n }\n}\n\n/**\n * Merge config file values with CLI options.\n * CLI flags take precedence over config file.\n */\nexport function mergeWithCliOptions(\n config: XrmForgeConfig,\n cliOpts: Record<string, unknown>,\n): Record<string, unknown> {\n const merged: Record<string, unknown> = { ...cliOpts };\n\n // Only fill in values from config that weren't set via CLI\n if (!merged['url'] && config.url) merged['url'] = config.url;\n if (!merged['auth'] && config.auth) merged['auth'] = config.auth;\n if (!merged['tenantId'] && config.tenantId) merged['tenantId'] = config.tenantId;\n if (!merged['clientId'] && config.clientId) merged['clientId'] = config.clientId;\n if (!merged['clientSecret'] && config.clientSecret) merged['clientSecret'] = config.clientSecret;\n // Solutions: CLI comma-separated string vs config array\n if (!merged['solutions'] && config.solutions) {\n merged['solutions'] = Array.isArray(config.solutions)\n ? config.solutions.join(',')\n : config.solutions;\n }\n if (!merged['output'] && config.output) merged['output'] = config.output;\n\n // Entities: CLI comma-separated string vs config array\n if (!merged['entities'] && config.entities) {\n merged['entities'] = config.entities.join(',');\n }\n\n // Label languages: config uses numbers, CLI uses strings\n if (!merged['labelLanguage'] && config.labelLanguage) {\n merged['labelLanguage'] = String(config.labelLanguage);\n }\n if (!merged['secondaryLanguage'] && config.secondaryLanguage) {\n merged['secondaryLanguage'] = String(config.secondaryLanguage);\n }\n\n // Booleans: only override if explicitly set in config\n if (merged['forms'] === undefined && config.forms !== undefined) {\n merged['forms'] = config.forms;\n }\n if (merged['optionsets'] === undefined && config.optionsets !== undefined) {\n merged['optionsets'] = config.optionsets;\n }\n\n return merged;\n}\n","/**\n * @xrmforge/cli - Generate Command\n *\n * Orchestrates type generation from a Dataverse environment.\n *\n * Usage:\n * xrmforge generate --url https://myorg.crm4.dynamics.com \\\n * --auth client-credentials \\\n * --tenant <tenant-id> --client-id <app-id> --client-secret <secret> \\\n * --entities account,contact \\\n * --output ./typings\n *\n * xrmforge generate --url https://myorg.crm4.dynamics.com \\\n * --auth interactive \\\n * --tenant <tenant-id> --client-id <app-id> \\\n * --entities account,contact,opportunity \\\n * --output ./typings \\\n * --label-language 1033 --secondary-language 1031\n */\n\nimport type { Command } from 'commander';\nimport { loadConfig, mergeWithCliOptions } from '../config.js';\nimport {\n TypeGenerationOrchestrator,\n createCredential,\n configureLogging,\n ConsoleLogSink,\n LogLevel,\n} from '@xrmforge/typegen';\nimport type { AuthConfig } from '@xrmforge/typegen';\n\n/** CLI options for the generate command */\ninterface GenerateOptions {\n url: string;\n auth: string;\n tenantId?: string;\n clientId?: string;\n clientSecret?: string;\n token?: string;\n entities?: string;\n solutions?: string;\n output: string;\n labelLanguage: string;\n secondaryLanguage?: string;\n forms: boolean;\n optionsets: boolean;\n verbose: boolean;\n}\n\n/**\n * Register the 'generate' subcommand on the CLI program.\n */\nexport function registerGenerateCommand(program: Command): void {\n program\n .command('generate')\n .description('Generate TypeScript declarations from a Dataverse environment')\n\n // Connection (can come from xrmforge.config.json)\n .option('--url <url>', 'Dataverse environment URL (e.g. https://myorg.crm4.dynamics.com)')\n .option('--auth <method>', 'Authentication method: client-credentials, interactive, device-code, token')\n\n // Auth credentials\n .option('--tenant-id <id>', 'Azure AD tenant ID')\n .option('--client-id <id>', 'Azure AD application (client) ID')\n .option('--client-secret <secret>', 'Client secret (for client-credentials auth)')\n .option('--token <token>', 'Pre-acquired Bearer token (for --auth token). Prefer XRMFORGE_TOKEN env var for security.')\n\n // Scope\n .option('--entities <list>', 'Comma-separated list of entity logical names (e.g. account,contact)')\n .option('--solutions <list>', 'Comma-separated solution unique names to discover entities')\n\n // Output\n .option('--output <dir>', 'Output directory for generated .d.ts files', './typings')\n\n // Labels\n .option('--label-language <code>', 'Primary label language code', '1033')\n .option('--secondary-language <code>', 'Secondary label language code (for dual-language JSDoc)')\n\n // Feature toggles\n .option('--no-forms', 'Skip form interface generation')\n .option('--no-optionsets', 'Skip OptionSet enum generation')\n\n // Verbosity\n .option('-v, --verbose', 'Enable verbose logging', false)\n\n .action(async (opts: GenerateOptions) => {\n try {\n await runGenerate(opts);\n } catch (error) {\n if (error instanceof Error) {\n console.error(`\\nError: ${error.message}\\n`);\n if (opts.verbose && error.stack) {\n console.error(error.stack);\n }\n } else {\n console.error('\\nAn unexpected error occurred.\\n');\n }\n process.exitCode = 1;\n }\n });\n}\n\n/**\n * Execute the generate command.\n */\nasync function runGenerate(cliOpts: GenerateOptions): Promise<void> {\n // Load config file and merge with CLI options (CLI takes precedence)\n const fileConfig = loadConfig();\n const merged = mergeWithCliOptions(fileConfig, cliOpts as unknown as Record<string, unknown>);\n const opts = merged as unknown as GenerateOptions;\n\n // Configure logging\n configureLogging({\n sink: new ConsoleLogSink(),\n minLevel: opts.verbose ? LogLevel.DEBUG : LogLevel.INFO,\n });\n\n // Validate required options (may come from config file)\n if (!opts.url) {\n throw new Error('--url is required. Set it via CLI flag or in xrmforge.config.json.');\n }\n if (!opts.auth) {\n throw new Error('--auth is required. Set it via CLI flag or in xrmforge.config.json.');\n }\n if (!opts.entities && !opts.solutions) {\n throw new Error('Either --entities or --solutions must be specified (CLI or xrmforge.config.json).');\n }\n\n // Build auth config\n const authConfig = buildAuthConfig(opts);\n const credential = createCredential(authConfig);\n\n // Parse entity list\n const entities = opts.entities\n ? opts.entities.split(',').map((e) => e.trim().toLowerCase())\n : [];\n\n // Parse solutions list\n const solutionNames = opts.solutions\n ? opts.solutions.split(',').map((s) => s.trim())\n : [];\n\n if (entities.length === 0 && solutionNames.length === 0) {\n throw new Error('No entities specified. Use --entities or --solutions.');\n }\n\n // Build label config (R8-05: validate LCID)\n const primaryLanguage = parseInt(opts.labelLanguage, 10);\n if (isNaN(primaryLanguage)) {\n throw new Error(`Invalid --label-language: \"${opts.labelLanguage}\". Must be a numeric LCID (e.g. 1033, 1031).`);\n }\n let secondaryLanguage: number | undefined;\n if (opts.secondaryLanguage) {\n secondaryLanguage = parseInt(opts.secondaryLanguage, 10);\n if (isNaN(secondaryLanguage)) {\n throw new Error(`Invalid --secondary-language: \"${opts.secondaryLanguage}\". Must be a numeric LCID (e.g. 1033, 1031).`);\n }\n }\n\n console.log(`\\nXrmForge Type Generator`);\n console.log(`Environment: ${opts.url}`);\n console.log(`Auth method: ${opts.auth}`);\n console.log(`Entities: ${entities.length > 0 ? entities.join(', ') : '(none specified directly)'}`)\n if (solutionNames.length > 0) {\n console.log(`Solutions: ${solutionNames.join(', ')}`);\n }\n console.log(`Output: ${opts.output}`);\n console.log(`Languages: ${primaryLanguage}${secondaryLanguage ? ` + ${secondaryLanguage}` : ''}`);\n console.log('');\n\n // Create orchestrator and run\n const orchestrator = new TypeGenerationOrchestrator(credential, {\n environmentUrl: opts.url,\n entities,\n solutionNames: solutionNames.length > 0 ? solutionNames : undefined,\n outputDir: opts.output,\n labelConfig: { primaryLanguage, secondaryLanguage },\n generateForms: opts.forms,\n generateOptionSets: opts.optionsets,\n });\n\n // Support Ctrl+C and SIGTERM (R8-07: Docker/K8s sends SIGTERM)\n const controller = new AbortController();\n const onSignal = () => {\n console.log('\\nAborting generation...');\n controller.abort();\n };\n process.once('SIGINT', onSignal);\n process.once('SIGTERM', onSignal);\n\n const result = await orchestrator.generate({ signal: controller.signal });\n\n // Summary\n console.log('');\n console.log('Generation complete:');\n console.log(` Entities: ${result.entities.length}`);\n console.log(` Files: ${result.totalFiles}`);\n console.log(` Warnings: ${result.totalWarnings}`);\n console.log(` Duration: ${result.durationMs}ms`);\n\n // Show warnings\n if (result.totalWarnings > 0) {\n console.log('\\nWarnings:');\n for (const entity of result.entities) {\n for (const warning of entity.warnings) {\n console.log(` [${entity.entityLogicalName}] ${warning}`);\n }\n }\n }\n\n // Show failures\n const failures = result.entities.filter((e) => e.files.length === 0 && e.warnings.length > 0);\n if (failures.length > 0) {\n console.log(`\\n${failures.length} entity/entities failed. See warnings above.`);\n process.exitCode = 1;\n return;\n }\n\n console.log(`\\nTypes written to: ${opts.output}/`);\n}\n\n/**\n * Build AuthConfig from CLI options.\n */\nfunction buildAuthConfig(opts: GenerateOptions): AuthConfig {\n const method = opts.auth as AuthConfig['method'];\n\n switch (method) {\n case 'client-credentials':\n if (!opts.tenantId) throw new Error('--tenant-id is required for client-credentials auth.');\n if (!opts.clientId) throw new Error('--client-id is required for client-credentials auth.');\n if (!opts.clientSecret) throw new Error('--client-secret is required for client-credentials auth.');\n return {\n method: 'client-credentials',\n tenantId: opts.tenantId,\n clientId: opts.clientId,\n clientSecret: opts.clientSecret,\n };\n\n case 'interactive':\n if (!opts.tenantId) throw new Error('--tenant-id is required for interactive auth.');\n if (!opts.clientId) throw new Error('--client-id is required for interactive auth.');\n return {\n method: 'interactive',\n tenantId: opts.tenantId,\n clientId: opts.clientId,\n };\n\n case 'device-code':\n if (!opts.tenantId) throw new Error('--tenant-id is required for device-code auth.');\n if (!opts.clientId) throw new Error('--client-id is required for device-code auth.');\n return {\n method: 'device-code',\n tenantId: opts.tenantId,\n clientId: opts.clientId,\n };\n\n case 'token': {\n // Token from --token flag or XRMFORGE_TOKEN environment variable\n const token = opts.token || process.env['XRMFORGE_TOKEN'];\n if (!token) {\n throw new Error(\n 'Token authentication requires a token. ' +\n 'Set XRMFORGE_TOKEN environment variable or use --token flag.',\n );\n }\n if (opts.token) {\n console.warn('WARNING: Using --token on the command line exposes the token in process list and shell history.');\n console.warn(' Prefer setting XRMFORGE_TOKEN environment variable instead.\\n');\n }\n return { method: 'token', token };\n }\n\n default:\n throw new Error(\n `Unknown auth method: \"${opts.auth}\". ` +\n `Supported: client-credentials, interactive, device-code, token`,\n );\n }\n}\n"],"mappings":";;;AAWA,SAAS,gBAAAA,qBAAoB;AAC7B,SAAS,SAAS,QAAAC,aAAY;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,eAAe;;;ACOxB,SAAS,cAAc,kBAAkB;AACzC,SAAS,YAAY;AA8BrB,IAAM,kBAAkB;AAOjB,SAAS,WAAW,MAAc,QAAQ,IAAI,GAAmB;AACtE,QAAM,aAAa,KAAK,KAAK,eAAe;AAE5C,MAAI,CAAC,WAAW,UAAU,GAAG;AAC3B,WAAO,CAAC;AAAA,EACV;AAEA,MAAI;AACF,UAAM,MAAM,aAAa,YAAY,OAAO;AAC5C,UAAM,SAAS,KAAK,MAAM,GAAG;AAG7B,QAAI,OAAO,cAAc;AACvB,cAAQ,KAAK,kCAAkC,eAAe,4BAA4B;AAC1F,cAAQ,KAAK,qEAAqE;AAAA,IACpF;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YA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AA,MACvF;AACA,aAAO,EAAE,QAAQ,SAAS,MAAM;AAAA,IAClC;AAAA,IAEA;AACE,YAAM,IAAI;AAAA,QACR,yBAAyB,KAAK,IAAI;AAAA,MAEpC;AAAA,EACJ;AACF;;;AFrQA,IAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AACxD,IAAM,MAAM,KAAK,MAAMC,cAAaC,MAAK,WAAW,MAAM,cAAc,GAAG,OAAO,CAAC;AAEnF,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,UAAU,EACf,YAAY,wDAAwD,EACpE,QAAQ,IAAI,OAAO;AAEtB,wBAAwB,OAAO;AAE/B,QAAQ,MAAM;","names":["readFileSync","join","program","readFileSync","join"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xrmforge/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "CLI for XrmForge - TypeScript type generator for Dynamics 365",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dynamics-365",
|
|
7
|
+
"typescript",
|
|
8
|
+
"xrm",
|
|
9
|
+
"dataverse",
|
|
10
|
+
"cli",
|
|
11
|
+
"code-generation"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "XrmForge Contributors",
|
|
15
|
+
"homepage": "https://github.com/juergenbeck/XrmForge/tree/main/packages/cli",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/juergenbeck/XrmForge.git",
|
|
19
|
+
"directory": "packages/cli"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/juergenbeck/XrmForge/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"bin": {
|
|
26
|
+
"xrmforge": "./dist/index.js"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist"
|
|
30
|
+
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup",
|
|
33
|
+
"dev": "tsup --watch",
|
|
34
|
+
"test": "vitest run",
|
|
35
|
+
"test:watch": "vitest",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"lint": "eslint src/",
|
|
38
|
+
"clean": "rm -rf dist"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@xrmforge/typegen": "workspace:*",
|
|
42
|
+
"commander": "^13.0.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@types/node": "^22.0.0",
|
|
46
|
+
"tsup": "^8.3.0",
|
|
47
|
+
"typescript": "^5.7.0",
|
|
48
|
+
"vitest": "^3.0.0"
|
|
49
|
+
},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=20.0.0"
|
|
52
|
+
}
|
|
53
|
+
}
|