Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

chore: reworking CLI + import specifiers #345

Merged
merged 9 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const args = parse(Deno.args, {
string: ["src", "out", "import"],
boolean: ["help"],
default: {
import: "deno",
import: "https://deno.land/x/capi/mod.ts",
},
alias: {
src: ["s"],
Expand All @@ -25,11 +25,7 @@ if (!args.src) fail();
if (!args.out) fail();

await codegen({
importSpecifier: args.import === "npm"
? "capi"
: args.import === "deno"
? "https://deno.land/x/capi/mod.ts"
: args.import,
importSpecifier: args.import,
metadata: await getMetadata(args.src),
outDir: args.out,
}).write();
Expand Down
3 changes: 1 addition & 2 deletions codegen/codecVisitor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from "../deps/std/path.ts";
import * as M from "../frame_metadata/mod.ts";
import { Files } from "./Files.ts";
import { CodegenProps } from "./mod.ts";
Expand All @@ -18,7 +17,7 @@ export function createCodecVisitor(
"\n",
[
"import { ChainError, BitSequence, Era, $, $era, $null } from",
S.string(path.relative(props.outDir, props.importSpecifier)),
S.string(props.importSpecifier),
],
[`import type * as t from "./mod.ts"`],
...codecs,
Expand Down
3 changes: 1 addition & 2 deletions codegen/mod.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as path from "../deps/std/path.ts";
import * as M from "../frame_metadata/mod.ts";
import { createCodecVisitor } from "./codecVisitor.ts";
import { Files } from "./Files.ts";
Expand All @@ -21,7 +20,7 @@ export function codegen(props: CodegenProps): Files {
"\n",
[
"import { ChainError, BitSequence, Era, $ } from",
S.string(path.relative(props.outDir, props.importSpecifier)),
S.string(props.importSpecifier),
],
[`import * as _codec from "./codecs.ts"`],
[`export { _metadata }`],
Expand Down
5 changes: 2 additions & 3 deletions test_util/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ export function importCodegen(config: TestConfig) {
return U.getOr(memo, config, async () => {
const metadata = U.throwIfError(await C.run(C.metadata(config)));
const outDir = path.join(
path.dirname(path.fromFileUrl(import.meta.url)),
"../target/codegen/",
new URL("../target/codegen", import.meta.url).pathname,
harrysolovay marked this conversation as resolved.
Show resolved Hide resolved
config.runtimeName,
);
await gen.codegen({
importSpecifier: "./mod.ts",
importSpecifier: "../../../mod.ts",
metadata,
outDir,
}).write();
Expand Down