@lukoweb/apitogo 0.1.19 → 0.1.20

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 CHANGED
@@ -3822,7 +3822,7 @@ import {
3822
3822
  // package.json
3823
3823
  var package_default = {
3824
3824
  name: "@lukoweb/apitogo",
3825
- version: "0.1.19",
3825
+ version: "0.1.20",
3826
3826
  type: "module",
3827
3827
  sideEffects: [
3828
3828
  "**/*.css",
@@ -8247,6 +8247,7 @@ var VERSION_CHECK_FILE = "version.json";
8247
8247
  var SENTRY_DSN = void 0;
8248
8248
  var MAX_WAIT_PENDING_TIME_MS = 1e3;
8249
8249
  var POST_HOG_CAPTURE_KEY = void 0;
8250
+ var DEPLOY_SERVER_API_KEY = "qRVLTP22TFStdN6";
8250
8251
 
8251
8252
  // src/cli/common/output.ts
8252
8253
  function printDiagnosticsToConsole(message) {
@@ -8495,11 +8496,12 @@ on:
8495
8496
  pull_request:
8496
8497
  branches:
8497
8498
  - main
8499
+ types: [opened, synchronize, reopened, closed]
8498
8500
  workflow_dispatch:
8499
8501
 
8500
8502
  jobs:
8501
8503
  preview:
8502
- if: github.event_name == 'pull_request'
8504
+ if: github.event_name == 'pull_request' && github.event.action != 'closed'
8503
8505
  runs-on: ubuntu-latest
8504
8506
 
8505
8507
  environment:
@@ -8546,6 +8548,23 @@ jobs:
8546
8548
 
8547
8549
  echo "url=$URL" >> "$GITHUB_OUTPUT"
8548
8550
 
8551
+ cleanup-preview:
8552
+ if: github.event_name == 'pull_request' && github.event.action == 'closed'
8553
+ runs-on: ubuntu-latest
8554
+
8555
+ steps:
8556
+ - name: Install APIToGo CLI
8557
+ run: npm install -g @lukoweb/apitogo@latest
8558
+
8559
+ - name: Remove preview deployment
8560
+ env:
8561
+ APITOGO_TOKEN: \${{ secrets.APITOGO_TOKEN }}
8562
+ shell: bash
8563
+ run: |
8564
+ ENV_NAME=preview-pr-\${{ github.event.pull_request.number }}
8565
+
8566
+ apitogo remove --deployment-token="$APITOGO_TOKEN" --env=$ENV_NAME --json-only
8567
+
8549
8568
  production:
8550
8569
  if: github.event_name == 'push' && github.ref == 'refs/heads/main'
8551
8570
  runs-on: ubuntu-latest
@@ -8626,11 +8645,18 @@ var configure_github_workflow_default = {
8626
8645
  init_logger();
8627
8646
  function isDeployJsonOnlyArgv() {
8628
8647
  const args = process.argv;
8629
- const deployIdx = args.indexOf("deploy");
8630
- if (deployIdx === -1) {
8648
+ let cmdIdx = -1;
8649
+ for (const cmd of ["deploy", "remove"]) {
8650
+ const i = args.indexOf(cmd);
8651
+ if (i !== -1) {
8652
+ cmdIdx = i;
8653
+ break;
8654
+ }
8655
+ }
8656
+ if (cmdIdx === -1) {
8631
8657
  return false;
8632
8658
  }
8633
- return args.slice(deployIdx).some((a) => a === "--json-only" || a.startsWith("--json-only="));
8659
+ return args.slice(cmdIdx).some((a) => a === "--json-only" || a.startsWith("--json-only="));
8634
8660
  }
8635
8661
  function isJsonOnlyDeployEnv() {
8636
8662
  return process.env.APITOGO_JSON_ONLY === "1";
@@ -8648,8 +8674,7 @@ function applyJsonOnlyDeployQuietMode() {
8648
8674
  import { access as access2, readFile as readFile4 } from "node:fs/promises";
8649
8675
  import path28 from "node:path";
8650
8676
  import { create as createTar } from "tar";
8651
- var DEPLOY_ENDPOINT = "https://deployserver.apitogo.com/deploy";
8652
- var DEPLOY_API_KEY = "qRVLTP22TFStdN6";
8677
+ var DEPLOY_ENDPOINT = "https://deploy-server-dotnet2-b3fkcaaraydbckfe.canadacentral-01.azurewebsites.net/deploy";
8653
8678
  var ARCHIVE_NAME = "dist.tgz";
8654
8679
  var createDeploymentArchive = async (dir) => {
8655
8680
  const distDir = path28.join(dir, "dist");
@@ -8700,7 +8725,7 @@ async function deploy(argv) {
8700
8725
  const response = await fetch(deployUrl, {
8701
8726
  method: "POST",
8702
8727
  headers: {
8703
- "x-api-key": DEPLOY_API_KEY
8728
+ "x-api-key": DEPLOY_SERVER_API_KEY
8704
8729
  },
8705
8730
  body: formData
8706
8731
  });
@@ -9170,14 +9195,15 @@ var dev_default = {
9170
9195
  };
9171
9196
 
9172
9197
  // src/cli/make-config/handler.ts
9173
- import { readFile as readFile6, writeFile as writeFile8 } from "node:fs/promises";
9198
+ import { constants as constants3 } from "node:fs";
9199
+ import { access as access4, mkdir as mkdir7, readFile as readFile6, writeFile as writeFile8 } from "node:fs/promises";
9174
9200
  import path33 from "node:path";
9175
9201
  import { glob as glob5 } from "glob";
9176
9202
 
9177
9203
  // src/cli/make-config/scaffold-project.ts
9178
9204
  init_package_json();
9179
- import { access as access3, readFile as readFile5, writeFile as writeFile7 } from "node:fs/promises";
9180
9205
  import { constants as constants2 } from "node:fs";
9206
+ import { access as access3, readFile as readFile5, writeFile as writeFile7 } from "node:fs/promises";
9181
9207
  import path32 from "node:path";
9182
9208
  import { glob as glob4 } from "glob";
9183
9209
  var OPENAPI_GLOBS = [
@@ -9305,7 +9331,9 @@ async function ensurePackageJson(dir) {
9305
9331
  try {
9306
9332
  pkg = JSON.parse(raw);
9307
9333
  } catch {
9308
- throw new Error("package.json exists but is not valid JSON; fix or remove it and run again.");
9334
+ throw new Error(
9335
+ "package.json exists but is not valid JSON; fix or remove it and run again."
9336
+ );
9309
9337
  }
9310
9338
  pkg.scripts = {
9311
9339
  ...typeof pkg.scripts === "object" && pkg.scripts !== null ? pkg.scripts : {}
@@ -9651,6 +9679,17 @@ const config: ApitogoConfig = {
9651
9679
  export default config;
9652
9680
  `;
9653
9681
  };
9682
+ var ensureApitogoDeployWorkflow = async (dir) => {
9683
+ const workflowPath = path33.join(dir, ".github", "workflows", "apitogo-deploy.yml");
9684
+ try {
9685
+ await access4(workflowPath, constants3.F_OK);
9686
+ return false;
9687
+ } catch {
9688
+ }
9689
+ await mkdir7(path33.join(dir, ".github", "workflows"), { recursive: true });
9690
+ await writeFile8(workflowPath, APITOGO_DEPLOY_WORKFLOW_YAML, "utf8");
9691
+ return true;
9692
+ };
9654
9693
  var findExistingConfigPath = async (dir) => {
9655
9694
  for (const filename of CONFIG_FILENAMES) {
9656
9695
  const fullPath = path33.join(dir, filename);
@@ -9672,7 +9711,9 @@ async function makeConfig(argv) {
9672
9711
  const createdPackageJson = await ensurePackageJson(dir);
9673
9712
  const createdTsconfig = await ensureTsconfigJson(dir);
9674
9713
  if (createdPackageJson) {
9675
- printDiagnosticsToConsole("Created package.json with dev, build, and preview scripts.");
9714
+ printDiagnosticsToConsole(
9715
+ "Created package.json with dev, build, and preview scripts."
9716
+ );
9676
9717
  }
9677
9718
  if (createdTsconfig) {
9678
9719
  printDiagnosticsToConsole("Created tsconfig.json.");
@@ -9723,6 +9764,12 @@ async function makeConfig(argv) {
9723
9764
  printResultToConsole(
9724
9765
  `${action} ${path33.basename(configPath)} from ${pagesDir}/ (navigation and redirects; other top-level settings preserved unless newly scaffolded).`
9725
9766
  );
9767
+ const createdWorkflow = await ensureApitogoDeployWorkflow(dir);
9768
+ if (createdWorkflow) {
9769
+ printDiagnosticsToConsole(
9770
+ "Created .github/workflows/apitogo-deploy.yml (preview + production; removes preview when a PR is closed)."
9771
+ );
9772
+ }
9726
9773
  if (createdPackageJson) {
9727
9774
  printDiagnosticsToConsole(
9728
9775
  "Next: run npm install (or pnpm install / yarn) in this directory, then npm run dev."
@@ -9778,6 +9825,84 @@ var previewCommand = {
9778
9825
  };
9779
9826
  var preview_default = previewCommand;
9780
9827
 
9828
+ // src/cli/remove/handler.ts
9829
+ var REMOVE_ENDPOINT = "https://deploy-server-dotnet2-b3fkcaaraydbckfe.canadacentral-01.azurewebsites.net/remove";
9830
+ async function remove(argv) {
9831
+ const deploymentToken = argv.deploymentToken?.trim() || process.env.npm_config_deployment_token?.trim();
9832
+ const env = argv.env?.trim() || process.env.npm_config_env?.trim() || "production";
9833
+ try {
9834
+ if (!deploymentToken) {
9835
+ throw new Error("A deployment token is required.");
9836
+ }
9837
+ if (!isJsonOnlyDeployEnv()) {
9838
+ printDiagnosticsToConsole(`Removing deployment from ${env}...`);
9839
+ }
9840
+ const formData = new FormData();
9841
+ formData.append("deploymentToken", deploymentToken);
9842
+ formData.append("env", env);
9843
+ const removeUrl = new URL(REMOVE_ENDPOINT);
9844
+ if (argv.jsonOnly) {
9845
+ removeUrl.searchParams.set("jsonOnly", "true");
9846
+ }
9847
+ const response = await fetch(removeUrl, {
9848
+ method: "POST",
9849
+ headers: {
9850
+ "x-api-key": DEPLOY_SERVER_API_KEY
9851
+ },
9852
+ body: formData
9853
+ });
9854
+ const responseText = await response.text();
9855
+ if (!response.ok) {
9856
+ throw new Error(
9857
+ `Remove failed with ${response.status}: ${JSON.stringify(textOrJson(responseText))}`
9858
+ );
9859
+ }
9860
+ if (isJsonOnlyDeployEnv()) {
9861
+ const parsed = responseText.trim() ? textOrJson(responseText) : {};
9862
+ console.log(JSON.stringify(parsed));
9863
+ return;
9864
+ }
9865
+ printResultToConsole(`Removal request sent to ${removeUrl.href}`);
9866
+ if (responseText.trim()) {
9867
+ printDiagnosticsToConsole(
9868
+ JSON.stringify(textOrJson(responseText), null, 2)
9869
+ );
9870
+ }
9871
+ } catch (error) {
9872
+ const message = error instanceof Error ? error.message : String(error);
9873
+ if (isJsonOnlyDeployEnv()) {
9874
+ printJsonOnlyErrorAndExit(message);
9875
+ } else {
9876
+ await printCriticalFailureToConsoleAndExit(message);
9877
+ }
9878
+ }
9879
+ }
9880
+
9881
+ // src/cli/cmds/remove.ts
9882
+ var remove_default = {
9883
+ desc: "Remove a deployment from the target environment",
9884
+ command: "remove",
9885
+ builder: (yargs2) => yargs2.option("deployment-token", {
9886
+ type: "string",
9887
+ describe: "Deployment token sent to the remove endpoint"
9888
+ }).option("env", {
9889
+ type: "string",
9890
+ describe: "Target environment name sent to the remove API (e.g. production, preview, preview-a, preview-b)",
9891
+ default: "production"
9892
+ }).option("json-only", {
9893
+ type: "boolean",
9894
+ describe: "JSON-only output on stdout; adds ?jsonOnly=true to the remove request",
9895
+ default: false
9896
+ }),
9897
+ handler: async (argv) => {
9898
+ if (argv.jsonOnly) {
9899
+ applyJsonOnlyDeployQuietMode();
9900
+ }
9901
+ await captureEvent({ argv, event: "apitogo remove" });
9902
+ await remove(argv);
9903
+ }
9904
+ };
9905
+
9781
9906
  // src/cli/common/outdated.ts
9782
9907
  import { existsSync as existsSync2, mkdirSync } from "node:fs";
9783
9908
  import { readFile as readFile7, writeFile as writeFile9 } from "node:fs/promises";
@@ -10022,7 +10147,7 @@ var cli = yargs(hideBin(process.argv)).option("zuplo", {
10022
10147
  process.env.ZUPLO = "1";
10023
10148
  printDiagnosticsToConsole("Running in Zuplo mode");
10024
10149
  }
10025
- }).middleware(warnPackageVersionMismatch).command(build_default).command(configure_github_workflow_default).command(dev_default).command(deploy_default).command(preview_default).command(make_config_default).demandCommand().strictCommands().version(packageJson?.version).fail(false).help();
10150
+ }).middleware(warnPackageVersionMismatch).command(build_default).command(configure_github_workflow_default).command(dev_default).command(deploy_default).command(remove_default).command(preview_default).command(make_config_default).demandCommand().strictCommands().version(packageJson?.version).fail(false).help();
10026
10151
  try {
10027
10152
  void warnIfOutdatedVersion(packageJson?.version);
10028
10153
  await cli.argv;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lukoweb/apitogo",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "type": "module",
5
5
  "sideEffects": [
6
6
  "**/*.css",