@lukoweb/apitogo 0.1.14 → 0.1.15
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/cli.js +220 -80
- package/package.json +1 -1
package/dist/cli/cli.js
CHANGED
|
@@ -131,7 +131,7 @@ import { stat } from "node:fs/promises";
|
|
|
131
131
|
var fileExists;
|
|
132
132
|
var init_file_exists = __esm({
|
|
133
133
|
"src/config/file-exists.ts"() {
|
|
134
|
-
fileExists = (
|
|
134
|
+
fileExists = (path32) => stat(path32).then(() => true).catch(() => false);
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
@@ -3822,7 +3822,7 @@ import {
|
|
|
3822
3822
|
// package.json
|
|
3823
3823
|
var package_default = {
|
|
3824
3824
|
name: "@lukoweb/apitogo",
|
|
3825
|
-
version: "0.1.
|
|
3825
|
+
version: "0.1.15",
|
|
3826
3826
|
type: "module",
|
|
3827
3827
|
sideEffects: [
|
|
3828
3828
|
"**/*.css",
|
|
@@ -3895,7 +3895,7 @@ var package_default = {
|
|
|
3895
3895
|
typecheck: "tsc --project tsconfig.app.json --noEmit",
|
|
3896
3896
|
"generate:types": "tsx scripts/generate-types.js && tsx scripts/generate-flat-config.js",
|
|
3897
3897
|
"build:standalone": "vite build --mode standalone --config vite.standalone.config.ts --log-level=error",
|
|
3898
|
-
|
|
3898
|
+
prepack: "npm run build && tsx scripts/generate-publish-exports.ts",
|
|
3899
3899
|
clean: "rm -rf dist",
|
|
3900
3900
|
codegen: "graphql-codegen --config ./src/codegen.ts"
|
|
3901
3901
|
},
|
|
@@ -4533,14 +4533,14 @@ var flattenAllOf = (schema2) => {
|
|
|
4533
4533
|
};
|
|
4534
4534
|
|
|
4535
4535
|
// src/lib/util/traverse.ts
|
|
4536
|
-
var traverse = (specification, transform,
|
|
4537
|
-
const transformed = transform(specification,
|
|
4536
|
+
var traverse = (specification, transform, path32 = []) => {
|
|
4537
|
+
const transformed = transform(specification, path32);
|
|
4538
4538
|
if (typeof transformed !== "object" || transformed === null) {
|
|
4539
4539
|
return transformed;
|
|
4540
4540
|
}
|
|
4541
4541
|
const result = Array.isArray(transformed) ? [] : {};
|
|
4542
4542
|
for (const [key, value] of Object.entries(transformed)) {
|
|
4543
|
-
const currentPath = [...
|
|
4543
|
+
const currentPath = [...path32, key];
|
|
4544
4544
|
if (Array.isArray(value)) {
|
|
4545
4545
|
result[key] = value.map(
|
|
4546
4546
|
(item, index) => typeof item === "object" && item != null ? traverse(item, transform, [...currentPath, index.toString()]) : item
|
|
@@ -4568,9 +4568,9 @@ var resolveLocalRef = (schema2, ref) => {
|
|
|
4568
4568
|
if (schemaCache?.has(ref)) {
|
|
4569
4569
|
return schemaCache.get(ref);
|
|
4570
4570
|
}
|
|
4571
|
-
const
|
|
4571
|
+
const path32 = ref.split("/").slice(1);
|
|
4572
4572
|
let current = schema2;
|
|
4573
|
-
for (const segment of
|
|
4573
|
+
for (const segment of path32) {
|
|
4574
4574
|
if (!current || typeof current !== "object") {
|
|
4575
4575
|
current = null;
|
|
4576
4576
|
}
|
|
@@ -4589,7 +4589,7 @@ var dereference = async (schema2, resolvers = []) => {
|
|
|
4589
4589
|
}
|
|
4590
4590
|
const cloned = structuredClone(schema2);
|
|
4591
4591
|
const visited = /* @__PURE__ */ new Set();
|
|
4592
|
-
const resolve = async (current,
|
|
4592
|
+
const resolve = async (current, path32) => {
|
|
4593
4593
|
if (isIndexableObject(current)) {
|
|
4594
4594
|
if (visited.has(current)) {
|
|
4595
4595
|
return CIRCULAR_REF;
|
|
@@ -4597,7 +4597,7 @@ var dereference = async (schema2, resolvers = []) => {
|
|
|
4597
4597
|
visited.add(current);
|
|
4598
4598
|
if (Array.isArray(current)) {
|
|
4599
4599
|
for (let index = 0; index < current.length; index++) {
|
|
4600
|
-
current[index] = await resolve(current[index], `${
|
|
4600
|
+
current[index] = await resolve(current[index], `${path32}/${index}`);
|
|
4601
4601
|
}
|
|
4602
4602
|
} else {
|
|
4603
4603
|
if ("$ref" in current && typeof current.$ref === "string") {
|
|
@@ -4608,13 +4608,13 @@ var dereference = async (schema2, resolvers = []) => {
|
|
|
4608
4608
|
for (const resolver of resolvers) {
|
|
4609
4609
|
const resolved = await resolver($ref);
|
|
4610
4610
|
if (resolved) {
|
|
4611
|
-
result2 = await resolve(resolved,
|
|
4611
|
+
result2 = await resolve(resolved, path32);
|
|
4612
4612
|
break;
|
|
4613
4613
|
}
|
|
4614
4614
|
}
|
|
4615
4615
|
if (result2 === void 0) {
|
|
4616
4616
|
const resolved = await resolveLocalRef(cloned, $ref);
|
|
4617
|
-
result2 = await resolve(resolved,
|
|
4617
|
+
result2 = await resolve(resolved, path32);
|
|
4618
4618
|
}
|
|
4619
4619
|
if (hasSiblings) {
|
|
4620
4620
|
if (result2 === CIRCULAR_REF) {
|
|
@@ -4627,7 +4627,7 @@ var dereference = async (schema2, resolvers = []) => {
|
|
|
4627
4627
|
return result2;
|
|
4628
4628
|
}
|
|
4629
4629
|
for (const key in current) {
|
|
4630
|
-
current[key] = await resolve(current[key], `${
|
|
4630
|
+
current[key] = await resolve(current[key], `${path32}/${key}`);
|
|
4631
4631
|
}
|
|
4632
4632
|
}
|
|
4633
4633
|
visited.delete(current);
|
|
@@ -4666,9 +4666,9 @@ var upgradeSchema = (schema2) => {
|
|
|
4666
4666
|
}
|
|
4667
4667
|
return sub;
|
|
4668
4668
|
});
|
|
4669
|
-
schema2 = traverse(schema2, (sub,
|
|
4669
|
+
schema2 = traverse(schema2, (sub, path32) => {
|
|
4670
4670
|
if (sub.example !== void 0) {
|
|
4671
|
-
if (isSchemaPath(
|
|
4671
|
+
if (isSchemaPath(path32 ?? [])) {
|
|
4672
4672
|
sub.examples = [sub.example];
|
|
4673
4673
|
} else {
|
|
4674
4674
|
sub.examples = {
|
|
@@ -4681,11 +4681,11 @@ var upgradeSchema = (schema2) => {
|
|
|
4681
4681
|
}
|
|
4682
4682
|
return sub;
|
|
4683
4683
|
});
|
|
4684
|
-
schema2 = traverse(schema2, (schema3,
|
|
4684
|
+
schema2 = traverse(schema2, (schema3, path32) => {
|
|
4685
4685
|
if (schema3.type === "object" && schema3.properties !== void 0) {
|
|
4686
|
-
const parentPath =
|
|
4686
|
+
const parentPath = path32?.slice(0, -1);
|
|
4687
4687
|
const isMultipart = parentPath?.some((segment, index) => {
|
|
4688
|
-
return segment === "content" &&
|
|
4688
|
+
return segment === "content" && path32?.[index + 1] === "multipart/form-data";
|
|
4689
4689
|
});
|
|
4690
4690
|
if (isMultipart) {
|
|
4691
4691
|
const entries = Object.entries(schema3.properties);
|
|
@@ -4699,8 +4699,8 @@ var upgradeSchema = (schema2) => {
|
|
|
4699
4699
|
}
|
|
4700
4700
|
return schema3;
|
|
4701
4701
|
});
|
|
4702
|
-
schema2 = traverse(schema2, (schema3,
|
|
4703
|
-
if (
|
|
4702
|
+
schema2 = traverse(schema2, (schema3, path32) => {
|
|
4703
|
+
if (path32?.includes("content") && path32.includes("application/octet-stream")) {
|
|
4704
4704
|
return {};
|
|
4705
4705
|
}
|
|
4706
4706
|
if (schema3.type === "string" && schema3.format === "binary") {
|
|
@@ -4726,11 +4726,11 @@ var upgradeSchema = (schema2) => {
|
|
|
4726
4726
|
}
|
|
4727
4727
|
return sub;
|
|
4728
4728
|
});
|
|
4729
|
-
schema2 = traverse(schema2, (schema3,
|
|
4729
|
+
schema2 = traverse(schema2, (schema3, path32) => {
|
|
4730
4730
|
if (schema3.type === "string" && schema3.format === "byte") {
|
|
4731
|
-
const parentPath =
|
|
4731
|
+
const parentPath = path32?.slice(0, -1);
|
|
4732
4732
|
const contentMediaType = parentPath?.find(
|
|
4733
|
-
(_, index) =>
|
|
4733
|
+
(_, index) => path32?.[index - 1] === "content"
|
|
4734
4734
|
);
|
|
4735
4735
|
return {
|
|
4736
4736
|
type: "string",
|
|
@@ -4742,7 +4742,7 @@ var upgradeSchema = (schema2) => {
|
|
|
4742
4742
|
});
|
|
4743
4743
|
return schema2;
|
|
4744
4744
|
};
|
|
4745
|
-
function isSchemaPath(
|
|
4745
|
+
function isSchemaPath(path32) {
|
|
4746
4746
|
const schemaLocations = [
|
|
4747
4747
|
["components", "schemas"],
|
|
4748
4748
|
"properties",
|
|
@@ -4755,10 +4755,10 @@ function isSchemaPath(path31) {
|
|
|
4755
4755
|
];
|
|
4756
4756
|
return schemaLocations.some((location) => {
|
|
4757
4757
|
if (Array.isArray(location)) {
|
|
4758
|
-
return location.every((segment, index) =>
|
|
4758
|
+
return location.every((segment, index) => path32[index] === segment);
|
|
4759
4759
|
}
|
|
4760
|
-
return
|
|
4761
|
-
}) ||
|
|
4760
|
+
return path32.includes(location);
|
|
4761
|
+
}) || path32.includes("schema") || path32.some((segment) => segment.endsWith("Schema"));
|
|
4762
4762
|
}
|
|
4763
4763
|
|
|
4764
4764
|
// src/lib/oas/parser/index.ts
|
|
@@ -4840,13 +4840,13 @@ var OPENAPI_PROPS = /* @__PURE__ */ new Set([
|
|
|
4840
4840
|
"anyOf",
|
|
4841
4841
|
"oneOf"
|
|
4842
4842
|
]);
|
|
4843
|
-
var handleCircularRefs = (obj, currentPath = /* @__PURE__ */ new WeakSet(), refs = /* @__PURE__ */ new WeakMap(),
|
|
4843
|
+
var handleCircularRefs = (obj, currentPath = /* @__PURE__ */ new WeakSet(), refs = /* @__PURE__ */ new WeakMap(), path32 = [], currentRefPaths = /* @__PURE__ */ new Set()) => {
|
|
4844
4844
|
if (obj === null || typeof obj !== "object") return obj;
|
|
4845
4845
|
const refPath = obj.__$ref;
|
|
4846
4846
|
const isCircular = currentPath.has(obj) || typeof refPath === "string" && currentRefPaths.has(refPath);
|
|
4847
4847
|
if (isCircular) {
|
|
4848
4848
|
if (typeof refPath === "string") return SCHEMA_REF_PREFIX + refPath;
|
|
4849
|
-
const circularProp =
|
|
4849
|
+
const circularProp = path32.find((p) => !OPENAPI_PROPS.has(p)) || path32[0];
|
|
4850
4850
|
return [CIRCULAR_REF, circularProp].filter(Boolean).join(":");
|
|
4851
4851
|
}
|
|
4852
4852
|
if (refs.has(obj)) return refs.get(obj);
|
|
@@ -4856,7 +4856,7 @@ var handleCircularRefs = (obj, currentPath = /* @__PURE__ */ new WeakSet(), refs
|
|
|
4856
4856
|
value,
|
|
4857
4857
|
currentPath,
|
|
4858
4858
|
refs,
|
|
4859
|
-
[...
|
|
4859
|
+
[...path32, key],
|
|
4860
4860
|
currentRefPaths
|
|
4861
4861
|
);
|
|
4862
4862
|
const result = Array.isArray(obj) ? obj.map((item, i) => recurse(item, i.toString())) : Object.fromEntries(
|
|
@@ -4891,7 +4891,7 @@ var resolveExtensions = (obj) => Object.fromEntries(
|
|
|
4891
4891
|
var getAllTags = (schema2) => {
|
|
4892
4892
|
const rootTags = schema2.tags ?? [];
|
|
4893
4893
|
const operations = Object.values(schema2.paths ?? {}).flatMap(
|
|
4894
|
-
(
|
|
4894
|
+
(path32) => HttpMethods.map((k) => path32?.[k]).filter((op) => op != null)
|
|
4895
4895
|
);
|
|
4896
4896
|
const operationTags = new Set(operations.flatMap((op) => op.tags ?? []));
|
|
4897
4897
|
const hasUntaggedOperations = operations.some(
|
|
@@ -4946,7 +4946,7 @@ var getAllSlugs = (ops, schemaTags = []) => {
|
|
|
4946
4946
|
var getOperationSlugKey = (op) => [op.path, op.method, op.operationId, op.summary].filter(Boolean).join("-");
|
|
4947
4947
|
var getAllOperations = (paths) => {
|
|
4948
4948
|
const operations = Object.entries(paths ?? {}).flatMap(
|
|
4949
|
-
([
|
|
4949
|
+
([path32, value]) => HttpMethods.flatMap((method) => {
|
|
4950
4950
|
if (!value?.[method]) return [];
|
|
4951
4951
|
const operation = value[method];
|
|
4952
4952
|
const pathParameters = value.parameters ?? [];
|
|
@@ -4966,7 +4966,7 @@ var getAllOperations = (paths) => {
|
|
|
4966
4966
|
return {
|
|
4967
4967
|
...operation,
|
|
4968
4968
|
method,
|
|
4969
|
-
path:
|
|
4969
|
+
path: path32,
|
|
4970
4970
|
parameters,
|
|
4971
4971
|
servers,
|
|
4972
4972
|
tags: operation.tags ?? []
|
|
@@ -5324,8 +5324,8 @@ var Schema = builder.objectRef("Schema").implement({
|
|
|
5324
5324
|
}),
|
|
5325
5325
|
paths: t.field({
|
|
5326
5326
|
type: [PathItem],
|
|
5327
|
-
resolve: (root) => Object.entries(root.paths ?? {}).map(([
|
|
5328
|
-
path:
|
|
5327
|
+
resolve: (root) => Object.entries(root.paths ?? {}).map(([path32, value]) => ({
|
|
5328
|
+
path: path32,
|
|
5329
5329
|
// biome-ignore lint/style/noNonNullAssertion: value is guaranteed to be defined
|
|
5330
5330
|
methods: Object.keys(value)
|
|
5331
5331
|
}))
|
|
@@ -5472,7 +5472,7 @@ init_joinUrl();
|
|
|
5472
5472
|
|
|
5473
5473
|
// src/vite/api/schema-codegen.ts
|
|
5474
5474
|
var unescapeJsonPointer = (uri) => decodeURIComponent(uri.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
5475
|
-
var getSegmentsFromPath = (
|
|
5475
|
+
var getSegmentsFromPath = (path32) => path32.split("/").slice(1).map(unescapeJsonPointer);
|
|
5476
5476
|
var createLocalRefMap = (obj) => {
|
|
5477
5477
|
const refMap = /* @__PURE__ */ new Map();
|
|
5478
5478
|
const siblingsMap = /* @__PURE__ */ new Map();
|
|
@@ -5503,16 +5503,16 @@ var replaceMarkers = (code, mergedRefs) => code.replace(/"__refMap:(.*?)"/g, '__
|
|
|
5503
5503
|
/"__refMap\+Siblings:(.*?)"/g,
|
|
5504
5504
|
(_, key) => mergedRefs.get(key) ?? `__refMap["${key}"]`
|
|
5505
5505
|
);
|
|
5506
|
-
var lookup = (schema2,
|
|
5507
|
-
const parts = getSegmentsFromPath(
|
|
5506
|
+
var lookup = (schema2, path32, filePath) => {
|
|
5507
|
+
const parts = getSegmentsFromPath(path32);
|
|
5508
5508
|
let val = schema2;
|
|
5509
5509
|
for (const part of parts) {
|
|
5510
5510
|
while (val.$ref?.startsWith("#/")) {
|
|
5511
|
-
val = val.$ref ===
|
|
5511
|
+
val = val.$ref === path32 ? val : lookup(schema2, val.$ref, filePath);
|
|
5512
5512
|
}
|
|
5513
5513
|
if (val[part] === void 0) {
|
|
5514
5514
|
throw new Error(
|
|
5515
|
-
`Error in ${filePath ?? "code generation"}: Could not find path segment ${part} in path: ${
|
|
5515
|
+
`Error in ${filePath ?? "code generation"}: Could not find path segment ${part} in path: ${path32}`
|
|
5516
5516
|
);
|
|
5517
5517
|
}
|
|
5518
5518
|
val = val[part];
|
|
@@ -5757,8 +5757,8 @@ var SchemaManager = class {
|
|
|
5757
5757
|
}
|
|
5758
5758
|
}
|
|
5759
5759
|
};
|
|
5760
|
-
getLatestSchema = (
|
|
5761
|
-
getSchemasForPath = (
|
|
5760
|
+
getLatestSchema = (path32) => this.processedSchemas[path32]?.at(0);
|
|
5761
|
+
getSchemasForPath = (path32) => this.processedSchemas[path32];
|
|
5762
5762
|
getSchemaImports = () => Object.values(this.processedSchemas).flat().filter((s) => s.importKey);
|
|
5763
5763
|
getUrlToFilePathMap = () => {
|
|
5764
5764
|
const map = /* @__PURE__ */ new Map();
|
|
@@ -7847,14 +7847,14 @@ async function generateSitemap({
|
|
|
7847
7847
|
|
|
7848
7848
|
// src/vite/prerender/utils.ts
|
|
7849
7849
|
init_joinUrl();
|
|
7850
|
-
var resolveRoutePath = (
|
|
7851
|
-
const segments =
|
|
7850
|
+
var resolveRoutePath = (path32) => {
|
|
7851
|
+
const segments = path32.split("/");
|
|
7852
7852
|
if (segments.some((s) => s.startsWith(":") && !s.endsWith("?"))) {
|
|
7853
7853
|
return void 0;
|
|
7854
7854
|
}
|
|
7855
7855
|
return segments.filter((s) => !s.startsWith(":")).join("/") || void 0;
|
|
7856
7856
|
};
|
|
7857
|
-
var isSkipped = (
|
|
7857
|
+
var isSkipped = (path32) => path32.includes("*") || /^\d+$/.test(path32);
|
|
7858
7858
|
var resolveRoutes = (routes, parentPath = "") => routes.flatMap((route) => {
|
|
7859
7859
|
if (route.path && isSkipped(route.path)) return [];
|
|
7860
7860
|
const routePath = route.path ? resolveRoutePath(route.path) : void 0;
|
|
@@ -8454,6 +8454,146 @@ var build_default = {
|
|
|
8454
8454
|
}
|
|
8455
8455
|
};
|
|
8456
8456
|
|
|
8457
|
+
// src/cli/configure-github-workflow/handler.ts
|
|
8458
|
+
import { access, mkdir as mkdir6, writeFile as writeFile6 } from "node:fs/promises";
|
|
8459
|
+
import { constants } from "node:fs";
|
|
8460
|
+
import path25 from "node:path";
|
|
8461
|
+
var APITOGO_DEPLOY_WORKFLOW_YAML = `name: Build and Deploy
|
|
8462
|
+
|
|
8463
|
+
on:
|
|
8464
|
+
push:
|
|
8465
|
+
branches:
|
|
8466
|
+
- main
|
|
8467
|
+
pull_request:
|
|
8468
|
+
branches:
|
|
8469
|
+
- main
|
|
8470
|
+
workflow_dispatch:
|
|
8471
|
+
|
|
8472
|
+
jobs:
|
|
8473
|
+
preview:
|
|
8474
|
+
if: github.event_name == 'pull_request'
|
|
8475
|
+
runs-on: ubuntu-latest
|
|
8476
|
+
|
|
8477
|
+
environment:
|
|
8478
|
+
name: preview
|
|
8479
|
+
url: \${{ steps.deploy.outputs.url }}
|
|
8480
|
+
|
|
8481
|
+
steps:
|
|
8482
|
+
- name: Checkout repository
|
|
8483
|
+
uses: actions/checkout@v4
|
|
8484
|
+
|
|
8485
|
+
- name: Setup Node.js
|
|
8486
|
+
uses: actions/setup-node@v4
|
|
8487
|
+
with:
|
|
8488
|
+
node-version: 20
|
|
8489
|
+
cache: npm
|
|
8490
|
+
|
|
8491
|
+
- name: Install dependencies
|
|
8492
|
+
run: npm ci
|
|
8493
|
+
|
|
8494
|
+
- name: Install APIToGo CLI
|
|
8495
|
+
run: npm install -g @lukoweb/apitogo@latest
|
|
8496
|
+
|
|
8497
|
+
- name: Check APIToGo version
|
|
8498
|
+
run: apitogo --version
|
|
8499
|
+
|
|
8500
|
+
- name: Deploy preview
|
|
8501
|
+
id: deploy
|
|
8502
|
+
env:
|
|
8503
|
+
APITOGO_TOKEN: \${{ secrets.APITOGO_TOKEN }}
|
|
8504
|
+
shell: bash
|
|
8505
|
+
run: |
|
|
8506
|
+
ENV_NAME=preview-pr-\${{ github.event.pull_request.number }}
|
|
8507
|
+
|
|
8508
|
+
OUTPUT=$(apitogo deploy --deployment-token="$APITOGO_TOKEN" --env=$ENV_NAME --json-only)
|
|
8509
|
+
|
|
8510
|
+
echo "$OUTPUT"
|
|
8511
|
+
|
|
8512
|
+
URL=$(echo "$OUTPUT" | jq -r '.url')
|
|
8513
|
+
|
|
8514
|
+
if [ -z "$URL" ] || [ "$URL" = "null" ]; then
|
|
8515
|
+
echo "Failed to extract preview URL"
|
|
8516
|
+
exit 1
|
|
8517
|
+
fi
|
|
8518
|
+
|
|
8519
|
+
echo "url=$URL" >> "$GITHUB_OUTPUT"
|
|
8520
|
+
|
|
8521
|
+
production:
|
|
8522
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
8523
|
+
runs-on: ubuntu-latest
|
|
8524
|
+
|
|
8525
|
+
environment:
|
|
8526
|
+
name: production
|
|
8527
|
+
|
|
8528
|
+
steps:
|
|
8529
|
+
- name: Checkout repository
|
|
8530
|
+
uses: actions/checkout@v4
|
|
8531
|
+
|
|
8532
|
+
- name: Setup Node.js
|
|
8533
|
+
uses: actions/setup-node@v4
|
|
8534
|
+
with:
|
|
8535
|
+
node-version: 20
|
|
8536
|
+
cache: npm
|
|
8537
|
+
|
|
8538
|
+
- name: Install dependencies
|
|
8539
|
+
run: npm ci
|
|
8540
|
+
|
|
8541
|
+
- name: Install APIToGo CLI
|
|
8542
|
+
run: npm install -g @lukoweb/apitogo@latest
|
|
8543
|
+
|
|
8544
|
+
- name: Check APIToGo version
|
|
8545
|
+
run: apitogo --version
|
|
8546
|
+
|
|
8547
|
+
- name: Deploy production
|
|
8548
|
+
env:
|
|
8549
|
+
APITOGO_TOKEN: \${{ secrets.APITOGO_TOKEN }}
|
|
8550
|
+
run: apitogo deploy --deployment-token="$APITOGO_TOKEN" --json-only
|
|
8551
|
+
`;
|
|
8552
|
+
async function configureGithubWorkflow(argv) {
|
|
8553
|
+
const dir = path25.resolve(process.cwd(), argv.dir);
|
|
8554
|
+
const workflowDir = path25.join(dir, ".github", "workflows");
|
|
8555
|
+
const workflowPath = path25.join(workflowDir, "apitogo-deploy.yml");
|
|
8556
|
+
try {
|
|
8557
|
+
try {
|
|
8558
|
+
await access(workflowPath, constants.F_OK);
|
|
8559
|
+
if (!argv.force) {
|
|
8560
|
+
await printCriticalFailureToConsoleAndExit(
|
|
8561
|
+
`Workflow file already exists: ${workflowPath}. Pass --force to overwrite.`
|
|
8562
|
+
);
|
|
8563
|
+
}
|
|
8564
|
+
} catch {
|
|
8565
|
+
}
|
|
8566
|
+
await mkdir6(workflowDir, { recursive: true });
|
|
8567
|
+
await writeFile6(workflowPath, APITOGO_DEPLOY_WORKFLOW_YAML, "utf8");
|
|
8568
|
+
printResultToConsole("Wrote .github/workflows/apitogo-deploy.yml");
|
|
8569
|
+
} catch (error) {
|
|
8570
|
+
await printCriticalFailureToConsoleAndExit(
|
|
8571
|
+
error instanceof Error ? error.message : String(error)
|
|
8572
|
+
);
|
|
8573
|
+
}
|
|
8574
|
+
}
|
|
8575
|
+
|
|
8576
|
+
// src/cli/cmds/configure-github-workflow.ts
|
|
8577
|
+
var configure_github_workflow_default = {
|
|
8578
|
+
desc: "Add a GitHub Actions workflow for APIToGo preview and production deploys",
|
|
8579
|
+
command: "configure-github-workflow",
|
|
8580
|
+
builder: (yargs2) => yargs2.option("dir", {
|
|
8581
|
+
type: "string",
|
|
8582
|
+
describe: "The directory containing your project",
|
|
8583
|
+
default: ".",
|
|
8584
|
+
normalize: true,
|
|
8585
|
+
hidden: true
|
|
8586
|
+
}).option("force", {
|
|
8587
|
+
type: "boolean",
|
|
8588
|
+
describe: "Overwrite .github/workflows/apitogo-deploy.yml if it already exists",
|
|
8589
|
+
default: false
|
|
8590
|
+
}),
|
|
8591
|
+
handler: async (argv) => {
|
|
8592
|
+
await captureEvent({ argv, event: "apitogo configure-github-workflow" });
|
|
8593
|
+
await configureGithubWorkflow(argv);
|
|
8594
|
+
}
|
|
8595
|
+
};
|
|
8596
|
+
|
|
8457
8597
|
// src/cli/common/json-only-deploy.ts
|
|
8458
8598
|
init_logger();
|
|
8459
8599
|
function isDeployJsonOnlyArgv() {
|
|
@@ -8479,16 +8619,16 @@ function applyJsonOnlyDeployQuietMode() {
|
|
|
8479
8619
|
}
|
|
8480
8620
|
|
|
8481
8621
|
// src/cli/deploy/handler.ts
|
|
8482
|
-
import { access, readFile as readFile4 } from "node:fs/promises";
|
|
8483
|
-
import
|
|
8622
|
+
import { access as access2, readFile as readFile4 } from "node:fs/promises";
|
|
8623
|
+
import path26 from "node:path";
|
|
8484
8624
|
import { create as createTar } from "tar";
|
|
8485
8625
|
var DEPLOY_ENDPOINT = "https://deployserver.apitogo.com/deploy";
|
|
8486
8626
|
var DEPLOY_API_KEY = "qRVLTP22TFStdN6";
|
|
8487
8627
|
var ARCHIVE_NAME = "dist.tgz";
|
|
8488
8628
|
var createDeploymentArchive = async (dir) => {
|
|
8489
|
-
const distDir =
|
|
8490
|
-
await
|
|
8491
|
-
const archivePath =
|
|
8629
|
+
const distDir = path26.join(dir, "dist");
|
|
8630
|
+
await access2(distDir);
|
|
8631
|
+
const archivePath = path26.join(dir, ARCHIVE_NAME);
|
|
8492
8632
|
await createTar(
|
|
8493
8633
|
{
|
|
8494
8634
|
cwd: dir,
|
|
@@ -8502,7 +8642,7 @@ var createDeploymentArchive = async (dir) => {
|
|
|
8502
8642
|
};
|
|
8503
8643
|
async function deploy(argv) {
|
|
8504
8644
|
await build({ ...argv, preview: void 0 });
|
|
8505
|
-
const dir =
|
|
8645
|
+
const dir = path26.resolve(process.cwd(), argv.dir);
|
|
8506
8646
|
const deploymentToken = argv.deploymentToken?.trim() || process.env.npm_config_deployment_token?.trim();
|
|
8507
8647
|
const env = argv.env?.trim() || process.env.npm_config_env?.trim() || "production";
|
|
8508
8648
|
try {
|
|
@@ -8515,7 +8655,7 @@ async function deploy(argv) {
|
|
|
8515
8655
|
const archivePath = await createDeploymentArchive(dir);
|
|
8516
8656
|
if (!isJsonOnlyDeployEnv()) {
|
|
8517
8657
|
printDiagnosticsToConsole(
|
|
8518
|
-
`Uploading ${
|
|
8658
|
+
`Uploading ${path26.basename(archivePath)} to ${env}...`
|
|
8519
8659
|
);
|
|
8520
8660
|
}
|
|
8521
8661
|
const archiveBuffer = await readFile4(archivePath);
|
|
@@ -8523,7 +8663,7 @@ async function deploy(argv) {
|
|
|
8523
8663
|
formData.append(
|
|
8524
8664
|
"file",
|
|
8525
8665
|
new Blob([archiveBuffer], { type: "application/gzip" }),
|
|
8526
|
-
|
|
8666
|
+
path26.basename(archivePath)
|
|
8527
8667
|
);
|
|
8528
8668
|
formData.append("deploymentToken", deploymentToken);
|
|
8529
8669
|
formData.append("env", env);
|
|
@@ -8574,7 +8714,7 @@ var deploy_default = {
|
|
|
8574
8714
|
describe: "Deployment token sent to the deploy endpoint"
|
|
8575
8715
|
}).option("env", {
|
|
8576
8716
|
type: "string",
|
|
8577
|
-
describe: "
|
|
8717
|
+
describe: "Target environment name sent to the deploy API (e.g. production, preview, preview-a, preview-b)",
|
|
8578
8718
|
default: "production"
|
|
8579
8719
|
}).option("dir", {
|
|
8580
8720
|
type: "string",
|
|
@@ -8608,14 +8748,14 @@ var deploy_default = {
|
|
|
8608
8748
|
|
|
8609
8749
|
// src/cli/dev/handler.ts
|
|
8610
8750
|
init_joinUrl();
|
|
8611
|
-
import
|
|
8751
|
+
import path29 from "node:path";
|
|
8612
8752
|
|
|
8613
8753
|
// src/vite/dev-server.ts
|
|
8614
8754
|
init_logger();
|
|
8615
8755
|
import fs3 from "node:fs/promises";
|
|
8616
8756
|
import http from "node:http";
|
|
8617
8757
|
import https from "node:https";
|
|
8618
|
-
import
|
|
8758
|
+
import path28 from "node:path";
|
|
8619
8759
|
import { createHttpTerminator } from "http-terminator";
|
|
8620
8760
|
import {
|
|
8621
8761
|
createServer as createViteServer,
|
|
@@ -8648,7 +8788,7 @@ init_loader();
|
|
|
8648
8788
|
// src/vite/pagefind-dev-index.ts
|
|
8649
8789
|
init_invariant();
|
|
8650
8790
|
init_joinUrl();
|
|
8651
|
-
import
|
|
8791
|
+
import path27 from "node:path";
|
|
8652
8792
|
import { createIndex as createIndex2 } from "pagefind";
|
|
8653
8793
|
import { isRunnableDevEnvironment } from "vite";
|
|
8654
8794
|
async function* buildPagefindDevIndex(vite, config2) {
|
|
@@ -8701,7 +8841,7 @@ async function* buildPagefindDevIndex(vite, config2) {
|
|
|
8701
8841
|
path: urlPath
|
|
8702
8842
|
};
|
|
8703
8843
|
}
|
|
8704
|
-
const outputPath =
|
|
8844
|
+
const outputPath = path27.join(vite.config.publicDir, "pagefind");
|
|
8705
8845
|
await pagefindIndex.writeFiles({ outputPath });
|
|
8706
8846
|
yield { type: "complete", success: true, indexed };
|
|
8707
8847
|
}
|
|
@@ -8720,9 +8860,9 @@ var DevServer = class {
|
|
|
8720
8860
|
this.protocol = "https";
|
|
8721
8861
|
const { dir } = this.options;
|
|
8722
8862
|
const [key, cert, ca] = await Promise.all([
|
|
8723
|
-
fs3.readFile(
|
|
8724
|
-
fs3.readFile(
|
|
8725
|
-
config2.https.ca ? fs3.readFile(
|
|
8863
|
+
fs3.readFile(path28.resolve(dir, config2.https.key)),
|
|
8864
|
+
fs3.readFile(path28.resolve(dir, config2.https.cert)),
|
|
8865
|
+
config2.https.ca ? fs3.readFile(path28.resolve(dir, config2.https.ca)) : void 0
|
|
8726
8866
|
]);
|
|
8727
8867
|
return https.createServer({ key, cert, ca });
|
|
8728
8868
|
}
|
|
@@ -8749,7 +8889,7 @@ var DevServer = class {
|
|
|
8749
8889
|
// built-in transform middleware which would treat the path as a static asset.
|
|
8750
8890
|
name: "apitogo:entry-client",
|
|
8751
8891
|
configureServer(server2) {
|
|
8752
|
-
const entryPath =
|
|
8892
|
+
const entryPath = path28.posix.join(
|
|
8753
8893
|
server2.config.base,
|
|
8754
8894
|
"/__z/entry.client.tsx"
|
|
8755
8895
|
);
|
|
@@ -8822,13 +8962,13 @@ var DevServer = class {
|
|
|
8822
8962
|
`Server-side rendering ${this.options.ssr ? "enabled" : "disabled"}`
|
|
8823
8963
|
);
|
|
8824
8964
|
if (config2.search?.type === "pagefind") {
|
|
8825
|
-
const pagefindPath =
|
|
8965
|
+
const pagefindPath = path28.join(
|
|
8826
8966
|
vite.config.publicDir,
|
|
8827
8967
|
"pagefind/pagefind.js"
|
|
8828
8968
|
);
|
|
8829
8969
|
const exists = await fs3.stat(pagefindPath).catch(() => false);
|
|
8830
8970
|
if (!exists) {
|
|
8831
|
-
await fs3.mkdir(
|
|
8971
|
+
await fs3.mkdir(path28.dirname(pagefindPath), { recursive: true });
|
|
8832
8972
|
await fs3.writeFile(pagefindPath, 'throw new Error("NOT_BUILT_YET");');
|
|
8833
8973
|
}
|
|
8834
8974
|
}
|
|
@@ -8922,7 +9062,7 @@ init_package_json();
|
|
|
8922
9062
|
async function dev(argv) {
|
|
8923
9063
|
const packageJson2 = getZudokuPackageJson();
|
|
8924
9064
|
process.env.NODE_ENV = "development";
|
|
8925
|
-
const dir =
|
|
9065
|
+
const dir = path29.resolve(process.cwd(), argv.dir);
|
|
8926
9066
|
const server = new DevServer({
|
|
8927
9067
|
dir,
|
|
8928
9068
|
argPort: argv.port,
|
|
@@ -9027,8 +9167,8 @@ var previewCommand = {
|
|
|
9027
9167
|
var preview_default = previewCommand;
|
|
9028
9168
|
|
|
9029
9169
|
// src/cli/sync-config/handler.ts
|
|
9030
|
-
import { readFile as readFile5, writeFile as
|
|
9031
|
-
import
|
|
9170
|
+
import { readFile as readFile5, writeFile as writeFile7 } from "node:fs/promises";
|
|
9171
|
+
import path30 from "node:path";
|
|
9032
9172
|
import { glob as glob4 } from "glob";
|
|
9033
9173
|
var CONFIG_FILENAMES = [
|
|
9034
9174
|
"apitogo.config.tsx",
|
|
@@ -9043,7 +9183,7 @@ var CONFIG_FILENAMES = [
|
|
|
9043
9183
|
"zudoku.config.mjs"
|
|
9044
9184
|
];
|
|
9045
9185
|
var createTreeNode = () => ({ docs: [], children: /* @__PURE__ */ new Map() });
|
|
9046
|
-
var toPosixPath2 = (value) => value.split(
|
|
9186
|
+
var toPosixPath2 = (value) => value.split(path30.sep).join(path30.posix.sep);
|
|
9047
9187
|
var toRoutePath = (relativeFile, pagesDir) => {
|
|
9048
9188
|
const relativeNoExt = relativeFile.replace(/\.mdx?$/, "");
|
|
9049
9189
|
const withoutPagesPrefix = relativeNoExt.replace(
|
|
@@ -9223,7 +9363,7 @@ var replaceArrayProperty = (source, propertyName, replacement) => {
|
|
|
9223
9363
|
};
|
|
9224
9364
|
var findConfigPath = async (dir) => {
|
|
9225
9365
|
for (const filename of CONFIG_FILENAMES) {
|
|
9226
|
-
const fullPath =
|
|
9366
|
+
const fullPath = path30.join(dir, filename);
|
|
9227
9367
|
try {
|
|
9228
9368
|
await readFile5(fullPath, "utf8");
|
|
9229
9369
|
return fullPath;
|
|
@@ -9233,7 +9373,7 @@ var findConfigPath = async (dir) => {
|
|
|
9233
9373
|
throw new Error("No APIToGo config file found in the project root.");
|
|
9234
9374
|
};
|
|
9235
9375
|
async function syncConfig(argv) {
|
|
9236
|
-
const dir =
|
|
9376
|
+
const dir = path30.resolve(process.cwd(), argv.dir);
|
|
9237
9377
|
const pagesDir = toPosixPath2(
|
|
9238
9378
|
argv.pagesDir.replace(/^[./]+/, "").replace(/\/+$/, "")
|
|
9239
9379
|
);
|
|
@@ -9263,9 +9403,9 @@ async function syncConfig(argv) {
|
|
|
9263
9403
|
"redirects",
|
|
9264
9404
|
buildRedirectsCode(routePaths[0])
|
|
9265
9405
|
);
|
|
9266
|
-
await
|
|
9406
|
+
await writeFile7(configPath, withRedirects, "utf8");
|
|
9267
9407
|
printResultToConsole(
|
|
9268
|
-
`Updated ${
|
|
9408
|
+
`Updated ${path30.basename(configPath)} from ${pagesDir}/`
|
|
9269
9409
|
);
|
|
9270
9410
|
} catch (error) {
|
|
9271
9411
|
await printCriticalFailureToConsoleAndExit(
|
|
@@ -9297,7 +9437,7 @@ var sync_config_default = {
|
|
|
9297
9437
|
|
|
9298
9438
|
// src/cli/common/outdated.ts
|
|
9299
9439
|
import { existsSync as existsSync2, mkdirSync } from "node:fs";
|
|
9300
|
-
import { readFile as readFile6, writeFile as
|
|
9440
|
+
import { readFile as readFile6, writeFile as writeFile8 } from "node:fs/promises";
|
|
9301
9441
|
import { join } from "node:path";
|
|
9302
9442
|
import colors10 from "picocolors";
|
|
9303
9443
|
import { gt } from "semver";
|
|
@@ -9347,12 +9487,12 @@ function box(message, {
|
|
|
9347
9487
|
|
|
9348
9488
|
// src/cli/common/xdg/lib.ts
|
|
9349
9489
|
import { homedir } from "node:os";
|
|
9350
|
-
import
|
|
9490
|
+
import path31 from "node:path";
|
|
9351
9491
|
function defineDirectoryWithFallback(xdgName, fallback) {
|
|
9352
9492
|
if (process.env[xdgName]) {
|
|
9353
9493
|
return process.env[xdgName];
|
|
9354
9494
|
} else {
|
|
9355
|
-
return
|
|
9495
|
+
return path31.join(homedir(), fallback);
|
|
9356
9496
|
}
|
|
9357
9497
|
}
|
|
9358
9498
|
var XDG_CONFIG_HOME = defineDirectoryWithFallback(
|
|
@@ -9367,15 +9507,15 @@ var XDG_STATE_HOME = defineDirectoryWithFallback(
|
|
|
9367
9507
|
"XDG_DATA_HOME",
|
|
9368
9508
|
".local/state"
|
|
9369
9509
|
);
|
|
9370
|
-
var ZUDOKU_XDG_CONFIG_HOME =
|
|
9510
|
+
var ZUDOKU_XDG_CONFIG_HOME = path31.join(
|
|
9371
9511
|
XDG_CONFIG_HOME,
|
|
9372
9512
|
CLI_XDG_FOLDER_NAME
|
|
9373
9513
|
);
|
|
9374
|
-
var ZUDOKU_XDG_DATA_HOME =
|
|
9514
|
+
var ZUDOKU_XDG_DATA_HOME = path31.join(
|
|
9375
9515
|
XDG_DATA_HOME,
|
|
9376
9516
|
CLI_XDG_FOLDER_NAME
|
|
9377
9517
|
);
|
|
9378
|
-
var ZUDOKU_XDG_STATE_HOME =
|
|
9518
|
+
var ZUDOKU_XDG_STATE_HOME = path31.join(
|
|
9379
9519
|
XDG_STATE_HOME,
|
|
9380
9520
|
CLI_XDG_FOLDER_NAME
|
|
9381
9521
|
);
|
|
@@ -9452,7 +9592,7 @@ async function getVersionCheckInfo() {
|
|
|
9452
9592
|
lastCheck: Date.now(),
|
|
9453
9593
|
latestVersion
|
|
9454
9594
|
};
|
|
9455
|
-
await
|
|
9595
|
+
await writeFile8(
|
|
9456
9596
|
versionCheckPath,
|
|
9457
9597
|
JSON.stringify(versionCheckInfo),
|
|
9458
9598
|
"utf-8"
|
|
@@ -9539,7 +9679,7 @@ var cli = yargs(hideBin(process.argv)).option("zuplo", {
|
|
|
9539
9679
|
process.env.ZUPLO = "1";
|
|
9540
9680
|
printDiagnosticsToConsole("Running in Zuplo mode");
|
|
9541
9681
|
}
|
|
9542
|
-
}).middleware(warnPackageVersionMismatch).command(build_default).command(dev_default).command(deploy_default).command(preview_default).command(sync_config_default).demandCommand().strictCommands().version(packageJson?.version).fail(false).help();
|
|
9682
|
+
}).middleware(warnPackageVersionMismatch).command(build_default).command(configure_github_workflow_default).command(dev_default).command(deploy_default).command(preview_default).command(sync_config_default).demandCommand().strictCommands().version(packageJson?.version).fail(false).help();
|
|
9543
9683
|
try {
|
|
9544
9684
|
void warnIfOutdatedVersion(packageJson?.version);
|
|
9545
9685
|
await cli.argv;
|