asphodelos 0.5.0 → 0.5.1
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.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
|
4
4
|
import { Console, Effect, FileSystem, Option, Path, Ref, Stream } from "effect";
|
|
5
5
|
import { CliError, Command, Flag } from "effect/cli";
|
|
6
6
|
// package.json
|
|
7
|
-
var version = "0.5.
|
|
7
|
+
var version = "0.5.1";
|
|
8
8
|
var description = "Asphodelos is a code generator from OpenAPI to Elysia";
|
|
9
9
|
// src/cli/index.ts
|
|
10
10
|
const COMMAND_NAME = "asphodelos";
|
|
@@ -48,7 +48,7 @@ function runJobs(config) {
|
|
|
48
48
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob }] = yield* Effect.promise(() => Promise.all([
|
|
49
49
|
import("./openapi-4yNuDK_n.mjs").then((n) => n.t),
|
|
50
50
|
import("./format-DC258z--.mjs").then((n) => n.r),
|
|
51
|
-
import("./shared-
|
|
51
|
+
import("./shared-CQsoa7gV.mjs").then((n) => n.s)
|
|
52
52
|
]));
|
|
53
53
|
const jobs = makeJob(yield* parseOpenAPI(config.input), config);
|
|
54
54
|
yield* cleanSplitOutputs(jobs);
|
|
@@ -86,7 +86,7 @@ function reportJobs(config, previous) {
|
|
|
86
86
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
87
87
|
onSuccess: (report) => Console.log(report)
|
|
88
88
|
}));
|
|
89
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
89
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-CQsoa7gV.mjs").then((n) => n.s));
|
|
90
90
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
91
91
|
return {
|
|
92
92
|
inputDirectory,
|
|
@@ -1669,6 +1669,23 @@ function makeModuleSpec(fromFile, target) {
|
|
|
1669
1669
|
const stripped = path.relative(path.dirname(fromFile), target.output).replaceAll("\\", "/").replace(/\.ts$/u, "").replace(/(^|\/)index$/u, "");
|
|
1670
1670
|
return stripped === "" ? "." : stripped.startsWith(".") ? stripped : `./${stripped}`;
|
|
1671
1671
|
}
|
|
1672
|
+
/**
|
|
1673
|
+
* The path `from` imports the generated file `target` by.
|
|
1674
|
+
*
|
|
1675
|
+
* Through the alias when the config names one and `target` sits under the app entry's directory —
|
|
1676
|
+
* `@/` stands for that directory, so `src/client.ts` is `@/client` from anywhere — and relative to
|
|
1677
|
+
* `from` otherwise. The extension goes. A barrel is imported by its directory; any other file
|
|
1678
|
+
* keeps its `index`, so an entry is named rather than left to directory resolution.
|
|
1679
|
+
*/
|
|
1680
|
+
function makeImportPath(from, target, alias, kind = "file") {
|
|
1681
|
+
const module = posix.normalize(target).replace(kind === "barrel" ? /(?:\/index)?\.ts$/u : /\.ts$/u, "");
|
|
1682
|
+
if (alias !== void 0) {
|
|
1683
|
+
const inside = posix.relative(alias.directory, module);
|
|
1684
|
+
if (inside !== "" && !inside.startsWith("..")) return `${alias.prefix}/${inside}`;
|
|
1685
|
+
}
|
|
1686
|
+
const relative = posix.relative(posix.dirname(posix.normalize(from)), module);
|
|
1687
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
1688
|
+
}
|
|
1672
1689
|
function makeBarrel(value) {
|
|
1673
1690
|
return `${Object.keys(value).toSorted().map((k) => `export * from './${k.charAt(0).toLowerCase() + k.slice(1)}'`).join("\n")}\n`;
|
|
1674
1691
|
}
|
|
@@ -4314,23 +4331,6 @@ var shared_exports = /* @__PURE__ */ __exportAll({
|
|
|
4314
4331
|
outsideSources: () => outsideSources
|
|
4315
4332
|
});
|
|
4316
4333
|
/**
|
|
4317
|
-
* The specifier `from` imports the generated file `target` by.
|
|
4318
|
-
*
|
|
4319
|
-
* Through the alias when the config names one and `target` sits under the app entry's directory —
|
|
4320
|
-
* `@/` stands for that directory, so `src/client.ts` is `@/client` from anywhere — and relative to
|
|
4321
|
-
* `from` otherwise. The extension goes. A barrel is imported by its directory; any other file
|
|
4322
|
-
* keeps its `index`, so an entry is named rather than left to directory resolution.
|
|
4323
|
-
*/
|
|
4324
|
-
function importSpecifier(from, target, alias, kind = "file") {
|
|
4325
|
-
const module = posix.normalize(target).replace(kind === "barrel" ? /(?:\/index)?\.ts$/u : /\.ts$/u, "");
|
|
4326
|
-
if (alias !== void 0) {
|
|
4327
|
-
const inside = posix.relative(alias.directory, module);
|
|
4328
|
-
if (inside !== "" && !inside.startsWith("..")) return `${alias.prefix}/${inside}`;
|
|
4329
|
-
}
|
|
4330
|
-
const relative = posix.relative(posix.dirname(posix.normalize(from)), module);
|
|
4331
|
-
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
4332
|
-
}
|
|
4333
|
-
/**
|
|
4334
4334
|
* The directory of the nearest `package.json` at or above `dir`, or `undefined` when there is
|
|
4335
4335
|
* none: the package a file belongs to, read from where it sits and nothing else.
|
|
4336
4336
|
*/
|
|
@@ -4409,7 +4409,7 @@ function settleTarget(from, target, pathAlias) {
|
|
|
4409
4409
|
import: target.package
|
|
4410
4410
|
};
|
|
4411
4411
|
if (pathAlias === void 0) return target;
|
|
4412
|
-
const specifier =
|
|
4412
|
+
const specifier = makeImportPath(from, target.output, pathAlias, "barrel");
|
|
4413
4413
|
return specifier.startsWith(".") ? target : {
|
|
4414
4414
|
...target,
|
|
4415
4415
|
import: specifier
|
|
@@ -4451,7 +4451,7 @@ function makeJob(openAPI, config) {
|
|
|
4451
4451
|
const clientImport = (field, output) => {
|
|
4452
4452
|
if (clientConfig === void 0) return Effect.fail(new GenerateError({ message: `${field} needs the top-level client it imports` }));
|
|
4453
4453
|
const isBeside = posix.dirname(posix.normalize(output)) === posix.dirname(clientConfig.output);
|
|
4454
|
-
return packageImport(output, clientConfig.output, isBeside || clientBarrel === void 0 ?
|
|
4454
|
+
return packageImport(output, clientConfig.output, isBeside || clientBarrel === void 0 ? makeImportPath(output, clientConfig.output, pathAlias) : makeImportPath(output, clientBarrel, pathAlias, "barrel"), clientConfig.package, `${field}.output is in another package than the client: name the package the client is published as, client.package, for the file to import it by.`);
|
|
4455
4455
|
};
|
|
4456
4456
|
const { output: componentsOutput, package: componentsPackage, ...componentTargets } = config.components ?? {};
|
|
4457
4457
|
const targetOf = (kind) => componentTargets[kind] ?? { output: `${baseDir}/components/${kind}.ts` };
|
|
@@ -4491,7 +4491,7 @@ function makeJob(openAPI, config) {
|
|
|
4491
4491
|
name: "client",
|
|
4492
4492
|
output: clientConfig.output,
|
|
4493
4493
|
split: false,
|
|
4494
|
-
run: (output) => clientRun(output, packageImport(output, appOutput,
|
|
4494
|
+
run: (output) => clientRun(output, packageImport(output, appOutput, makeImportPath(output, appOutput, pathAlias), config.package, "client.output is in another package than the app entry: name the package the app is published as, the top-level package, for the client to import it by."), {
|
|
4495
4495
|
baseUrl: clientConfig.baseUrl,
|
|
4496
4496
|
sameOrigin: clientConfig.sameOrigin === true,
|
|
4497
4497
|
barrel: clientBarrel
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { INPUT_EXTENSIONS, parseConfig } from "../index.mjs";
|
|
2
2
|
import { t as FormatOptions } from "../format-DC258z--.mjs";
|
|
3
|
-
import { a as makeJob, c as fileSystemLayer, i as jobTargets, n as isInsideDirectory, o as outsideSources, r as isUserCodeJob, t as cleanSplitOutputs } from "../shared-
|
|
3
|
+
import { a as makeJob, c as fileSystemLayer, i as jobTargets, n as isInsideDirectory, o as outsideSources, r as isUserCodeJob, t as cleanSplitOutputs } from "../shared-CQsoa7gV.mjs";
|
|
4
4
|
import { n as parseOpenAPI } from "../openapi-4yNuDK_n.mjs";
|
|
5
5
|
import { Effect, FileSystem, Result } from "effect";
|
|
6
6
|
import path from "node:path";
|