Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: convert output to default to the source root #1579

Merged
merged 14 commits into from
Aug 22, 2024
2 changes: 1 addition & 1 deletion docs/convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This will output something like:
<span class="muted">│</span>
<span class="muted">└</span> 1 notebook converted; 2 files written</code></pre>

The `convert` command generates files in the current working directory. The command above generates two files: <code>zoomable-sunburst.md</code>, a Markdown file representing the converted notebook; and <code>flare-2.json</code>, an attached JSON file. You can change the output directory using the <code>--output</code> command-line flag.
The `convert` command generates files in the source root of the current project by default (typically `src`); you can change the output directory using the `--output` command-line flag. The command above generates two files: `zoomable-sunburst.md`, a Markdown file representing the converted notebook; and `flare-2.json`, an attached JSON file.

Due to differences between Observable Framework and Observable notebooks, the `convert` command typically won’t produce a working Markdown page out of the box; you’ll often need to make further edits to the generated Markdown. We describe these differences below, along with examples of manual conversion.

Expand Down
22 changes: 19 additions & 3 deletions src/bin/observable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env node
import {join} from "node:path/posix";
import type {ParseArgsConfig} from "node:util";
import {parseArgs} from "node:util";
import * as clack from "@clack/prompts";
Expand Down Expand Up @@ -199,12 +200,27 @@ try {
case "convert": {
const {
positionals,
values: {output, force}
values: {config, root, output: out, force}
} = helpArgs(command, {
options: {output: {type: "string", default: "."}, force: {type: "boolean", short: "f"}},
options: {
output: {
type: "string",
short: "o",
description: "Output directory (defaults to the source root)"
},
force: {
type: "boolean",
short: "f",
description: "If true, overwrite existing resources"
},
...CONFIG_OPTION
},
allowPositionals: true
});
await import("../convert.js").then((convert) => convert.convert(positionals, {output: output!, force}));
// The --output command-line option is relative to the cwd, but the root
// config option (typically "src") is relative to the project root.
const output = out ?? join(root ?? ".", (await readConfig(config, root)).root);
await import("../convert.js").then((convert) => convert.convert(positionals, {output, force}));
break;
}
default: {
Expand Down