Skip to content

Commit f91e87c

Browse files
claude: Add --init-config flag to build-ts-extension command
Implements --init-config flag that generates a minimal deno.json with an absolute importMap path pointing to Quarto's bundled configuration. Features: - Checks if deno.json already exists and errors with helpful message - Creates minimal config with compilerOptions and absolute importMap path - Uses resourcePath() to get correct path in dev and distribution modes - Exits without building (config generation only) - Shows helpful customization guidance for users Example output: ✓ Created deno.json Import map: /usr/local/share/quarto/extension-build/import-map.json Customize as needed: - Add "quartoExtension" section for build options - Modify "compilerOptions" for type-checking behavior Generated deno.json points to Quarto's shared import-map.json which provides @quarto/types and Deno std library imports with correct versions. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0eafbb9 commit f91e87c

File tree

1 file changed

+56
-0
lines changed
  • src/command/dev-call/build-ts-extension

1 file changed

+56
-0
lines changed

src/command/dev-call/build-ts-extension/cmd.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface DenoConfig {
2929

3030
interface BuildOptions {
3131
check?: boolean;
32+
initConfig?: boolean;
3233
}
3334

3435
async function resolveConfig(): Promise<
@@ -259,6 +260,51 @@ async function bundle(
259260
info(`✓ Built ${entryPoint}${outputPath}`);
260261
}
261262

263+
async function initializeConfig(): Promise<void> {
264+
const configPath = "deno.json";
265+
266+
// Check if deno.json already exists
267+
if (existsSync(configPath)) {
268+
error("Error: deno.json already exists");
269+
error("");
270+
error("To use Quarto's default config, remove the existing deno.json.");
271+
error("Or manually add the importMap to your existing config:");
272+
const importMapPath = resourcePath("extension-build/import-map.json");
273+
info(` "importMap": "${importMapPath}"`);
274+
Deno.exit(1);
275+
}
276+
277+
// Get absolute path to Quarto's import map
278+
const importMapPath = resourcePath("extension-build/import-map.json");
279+
280+
// Create minimal config
281+
const config = {
282+
compilerOptions: {
283+
strict: true,
284+
lib: ["DOM", "ES2021"],
285+
},
286+
importMap: importMapPath,
287+
};
288+
289+
// Write deno.json
290+
Deno.writeTextFileSync(
291+
configPath,
292+
JSON.stringify(config, null, 2) + "\n",
293+
);
294+
295+
// Inform user
296+
info("✓ Created deno.json");
297+
info(` Import map: ${importMapPath}`);
298+
info("");
299+
info("Customize as needed:");
300+
info(' - Add "quartoExtension" section for build options:');
301+
info(' "entryPoint": "src/my-engine.ts"');
302+
info(' "outputFile": "_extensions/my-engine/my-engine.js"');
303+
info(' "minify": true');
304+
info(' "sourcemap": true');
305+
info(' - Modify "compilerOptions" for type-checking behavior');
306+
}
307+
262308
export const buildTsExtensionCommand = new Command()
263309
.name("build-ts-extension")
264310
.hidden()
@@ -272,8 +318,18 @@ export const buildTsExtensionCommand = new Command()
272318
" 3. src/mod.ts (if multiple .ts files exist)",
273319
)
274320
.option("--check", "Type-check only (skip bundling)")
321+
.option(
322+
"--init-config",
323+
"Generate deno.json with absolute importMap path",
324+
)
275325
.action(async (options: BuildOptions) => {
276326
try {
327+
// Handle --init-config flag first (don't build)
328+
if (options.initConfig) {
329+
await initializeConfig();
330+
return;
331+
}
332+
277333
// 1. Resolve configuration
278334
const { config, configPath } = await resolveConfig();
279335

0 commit comments

Comments
 (0)