@pitcher/cli-scripts 1.0.2 → 1.0.4

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.
Files changed (2) hide show
  1. package/dist/publishApp.js +14 -13
  2. package/package.json +1 -1
@@ -3,21 +3,21 @@ import archiver from "archiver";
3
3
  import axios from "axios";
4
4
  import fs from "fs";
5
5
  import path from "path";
6
- import FormData from "form-data"; // Ensure you have form-data installed
6
+ import FormData from "form-data";
7
+ import { fileURLToPath } from 'url';
7
8
  export function createPublishAppCommand() {
8
9
  const program = new Command("publish-app");
9
10
  program
10
- .arguments("[folder]") // Make folder argument optional
11
- .requiredOption("--api-key <apiKey>", "API Key for authentication") // Make API key a required option
11
+ .arguments("[folder]")
12
+ .requiredOption("--api-key <apiKey>", "API Key for authentication")
12
13
  .option("--org <organization>", "Organization subdomain", "dev")
13
- .option("--increment-version", "Increment version in app.json") // Add increment-version option
14
- .option("--dry-run", "Perform a dry run without publishing") // Add dry-run option
14
+ .option("--increment-version", "Increment version in app.json")
15
+ .option("--dry-run", "Perform a dry run without publishing")
16
+ .option("--publish-url <url>", "Explicit publish URL")
15
17
  .description('zip the contents of a folder and publish as an app to a pitcher org URL. for current folder: "p publish-app --api-key myapikey"')
16
- // Set default folder to current directory
17
18
  .action(async (folder = ".", options) => {
18
19
  try {
19
- const folderPath = path.resolve(folder); // Resolve the folder path
20
- // Increment version if --increment-version is provided
20
+ const folderPath = path.resolve(folder);
21
21
  if (options.incrementVersion) {
22
22
  const appJsonPath = path.join(folderPath, "app.json");
23
23
  if (fs.existsSync(appJsonPath)) {
@@ -37,7 +37,8 @@ export function createPublishAppCommand() {
37
37
  return;
38
38
  }
39
39
  }
40
- const zipFilePath = path.join(__dirname, "app.zip");
40
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
41
+ const zipFilePath = path.join(currentDir, "app.zip");
41
42
  const output = fs.createWriteStream(zipFilePath);
42
43
  const archive = archiver("zip", {
43
44
  zlib: { level: 9 },
@@ -46,7 +47,7 @@ export function createPublishAppCommand() {
46
47
  console.log(`Zipped ${archive.pointer()} total bytes`);
47
48
  const formData = new FormData();
48
49
  formData.append("file", fs.createReadStream(zipFilePath));
49
- const publishUrl = `https://${options.org}.my.pitcher.com/api/v1/apps/publish/`; // Construct the publish URL
50
+ const publishUrl = options.publishUrl || `https://${options.org}.my.pitcher.com/api/v1/apps/publish/`;
50
51
  if (options.dryRun) {
51
52
  console.log("Dry run mode enabled. The following data would be published:");
52
53
  console.log("Publish URL:", publishUrl);
@@ -55,14 +56,14 @@ export function createPublishAppCommand() {
55
56
  "x-api-key": options.apiKey,
56
57
  });
57
58
  console.log("app.json content:", fs.readFileSync(path.join(folderPath, "app.json"), "utf-8"));
58
- fs.unlinkSync(zipFilePath); // Clean up the zip file
59
+ fs.unlinkSync(zipFilePath);
59
60
  }
60
61
  else {
61
62
  try {
62
63
  const response = await axios.post(publishUrl, formData, {
63
64
  headers: {
64
65
  ...formData.getHeaders(),
65
- "x-api-key": options.apiKey, // Add API key to headers
66
+ "x-api-key": options.apiKey,
66
67
  },
67
68
  });
68
69
  console.log("Publish response:", response.data);
@@ -73,7 +74,7 @@ export function createPublishAppCommand() {
73
74
  console.error("Error publishing:", errData?.detail ?? errData);
74
75
  }
75
76
  finally {
76
- fs.unlinkSync(zipFilePath); // Clean up the zip file
77
+ fs.unlinkSync(zipFilePath);
77
78
  }
78
79
  }
79
80
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitcher/cli-scripts",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "The Pitcher CLI for various tasks in its ecosystem.",
5
5
  "author": "Pitcher AG",
6
6
  "license": "MIT",