@pitcher/cli-scripts 1.0.8 → 1.1.0

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/README.md CHANGED
@@ -1,12 +1,13 @@
1
1
  # @pitcher/cli-scripts
2
- Pitcher CLI Tools
2
+
3
+ > Pitcher CLI Tools provide a suite of command-line utilities to streamline your workflow. For the best experience, we recommend installing the tools globally using `npm install -g @pitcher/cli-scripts`.
3
4
 
4
5
 
5
6
  ## Help
6
7
  ```bash
7
8
  p --help
8
9
  # or for specific command help:
9
- p command --help
10
+ p command --help
10
11
  ```
11
12
 
12
13
 
@@ -23,4 +24,8 @@ p publish-app <folder> --url https://dev.my.pitcher.com --api-key myapikey
23
24
  p publish-app --api-key myapikey
24
25
  # or for dry run and incrementing app.json's version
25
26
  p publish-app --api-key myapikey --dry-run --increment-version
27
+
28
+ # Alternative: Set API key via environment variable
29
+ export NG_API_KEY=myapikey
30
+ p publish-app --increment-version
26
31
  ```
@@ -9,13 +9,19 @@ export function createPublishAppCommand() {
9
9
  const program = new Command("publish-app");
10
10
  program
11
11
  .arguments("[folder]")
12
- .requiredOption("--api-key <apiKey>", "API Key for authentication")
12
+ .option("--api-key <apiKey>", "API Key for authentication")
13
13
  .option("--org <organization>", "Organization subdomain", "dev")
14
14
  .option("--increment-version", "Increment version in app.json")
15
15
  .option("--dry-run", "Perform a dry run without publishing")
16
16
  .option("--publish-url <url>", "Explicit publish URL")
17
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"')
18
18
  .action(async (folder = ".", options) => {
19
+ const apiKey = options.apiKey || process.env.NG_API_KEY;
20
+ if (!apiKey) {
21
+ console.error("Error: API key is required. Provide it via --api-key or set the NG_API_KEY environment variable.");
22
+ process.exit(1);
23
+ }
24
+ options.apiKey = apiKey;
19
25
  try {
20
26
  const folderPath = path.resolve(folder);
21
27
  if (options.incrementVersion) {
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "@pitcher/cli-scripts",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "description": "The Pitcher CLI for various tasks in its ecosystem.",
5
5
  "author": "Pitcher AG",
6
6
  "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/PitcherAG/ng-scripts.git"
10
- },
11
7
  "keywords": [
12
8
  "pitcher",
13
9
  "cli",
@@ -27,14 +23,14 @@
27
23
  "dist"
28
24
  ],
29
25
  "devDependencies": {
30
- "@types/archiver": "^6.0.2",
31
- "@types/node": "^20.0.0",
32
- "typescript": "^5.4.5"
26
+ "@types/archiver": "^6.0.3",
27
+ "@types/node": "^22.13.4",
28
+ "typescript": "^5.7.3"
33
29
  },
34
30
  "dependencies": {
35
31
  "archiver": "^7.0.1",
36
- "axios": "^1.7.2",
37
- "commander": "^12.1.0",
38
- "form-data": "^4.0.0"
32
+ "axios": "^1.8.3",
33
+ "commander": "^13.1.0",
34
+ "form-data": "^4.0.2"
39
35
  }
40
36
  }
@@ -1,21 +0,0 @@
1
- ## To install dependencies:
2
-
3
- ```bash
4
- yarn install
5
- ```
6
-
7
- ## To work on it
8
-
9
- ```bash
10
- # at the root folder:
11
- npm link
12
- ```
13
-
14
- ## To use version from npm globally installed
15
-
16
- ```bash
17
- # anywhere:
18
- npm unlink @pitcher/cli-scripts
19
- # then
20
- npm install -g @pitcher/cli-scripts
21
- ```
@@ -1,2 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function createCopyInstanceFilesCommand(): Command;
@@ -1,17 +0,0 @@
1
- import { Command } from "commander";
2
- export function createCopyInstanceFilesCommand() {
3
- const program = new Command("copy-instance-files");
4
- program
5
- .arguments("<fromInstance> <toInstance>")
6
- .requiredOption("--api-key <apiKey>", "API Key", process.env.PITCHER_API_KEY)
7
- .requiredOption("--org <orgName>", "Organization Name", process.env.PITCHER_ORG)
8
- .description('clone instance files into another one e.g. "p copy-instance-files <fromInstanceId> <toInstanceId> --org mondelez --api-key myapikey"')
9
- .action((sourceInstanceId, destinationInstanceId, options) => {
10
- console.log("clone instance files command called", {
11
- sourceInstanceId,
12
- destinationInstanceId,
13
- options,
14
- });
15
- });
16
- return program;
17
- }
package/dist/package.json DELETED
@@ -1,40 +0,0 @@
1
- {
2
- "name": "@pitcher/cli-scripts",
3
- "version": "1.0.6",
4
- "description": "The Pitcher CLI for various tasks in its ecosystem.",
5
- "author": "Pitcher AG",
6
- "license": "MIT",
7
- "repository": {
8
- "type": "git",
9
- "url": "https://github.com/PitcherAG/ng-scripts.git"
10
- },
11
- "keywords": [
12
- "pitcher",
13
- "cli",
14
- "ng-scripts"
15
- ],
16
- "type": "module",
17
- "main": "./dist/index.js",
18
- "types": "./dist/index.d.ts",
19
- "scripts": {
20
- "build": "tsc",
21
- "prepublishOnly": "npm run build"
22
- },
23
- "bin": {
24
- "p": "node --no-warnings ./dist/index.js"
25
- },
26
- "files": [
27
- "dist"
28
- ],
29
- "devDependencies": {
30
- "@types/archiver": "^6.0.2",
31
- "@types/node": "^20.0.0",
32
- "typescript": "^5.4.5"
33
- },
34
- "dependencies": {
35
- "archiver": "^7.0.1",
36
- "axios": "^1.7.2",
37
- "commander": "^12.1.0",
38
- "form-data": "^4.0.0"
39
- }
40
- }
@@ -1,2 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function createPublishAppCommand(): Command;
@@ -1,93 +0,0 @@
1
- import { Command } from "commander";
2
- import archiver from "archiver";
3
- import axios from "axios";
4
- import fs from "fs";
5
- import path from "path";
6
- import FormData from "form-data";
7
- import { fileURLToPath } from 'url';
8
- export function createPublishAppCommand() {
9
- const program = new Command("publish-app");
10
- program
11
- .arguments("[folder]")
12
- .requiredOption("--api-key <apiKey>", "API Key for authentication")
13
- .option("--org <organization>", "Organization subdomain", "dev")
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")
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"')
18
- .action(async (folder = ".", options) => {
19
- try {
20
- const folderPath = path.resolve(folder);
21
- if (options.incrementVersion) {
22
- const appJsonPath = path.join(folderPath, "app.json");
23
- if (fs.existsSync(appJsonPath)) {
24
- const appJson = JSON.parse(fs.readFileSync(appJsonPath, "utf-8"));
25
- const now = new Date();
26
- const year = now.getFullYear();
27
- const month = String(now.getMonth() + 1).padStart(2, "0");
28
- const day = String(now.getDate()).padStart(2, "0");
29
- const timestamp = now.getTime();
30
- const version = `${year}.${month}.${day}.${timestamp}`;
31
- appJson.version = version;
32
- fs.writeFileSync(appJsonPath, JSON.stringify(appJson, null, 2));
33
- console.log(`Updated app.json version to ${version}`);
34
- }
35
- else {
36
- console.error("app.json not found in the specified folder.");
37
- return;
38
- }
39
- }
40
- const currentDir = path.dirname(fileURLToPath(import.meta.url));
41
- const zipFilePath = path.join(currentDir, "app.zip");
42
- const output = fs.createWriteStream(zipFilePath);
43
- const archive = archiver("zip", {
44
- zlib: { level: 9 },
45
- });
46
- output.on("close", async () => {
47
- console.log(`Zipped ${archive.pointer()} total bytes`);
48
- const formData = new FormData();
49
- formData.append("file", fs.createReadStream(zipFilePath));
50
- const publishUrl = options.publishUrl || `https://${options.org}.my.pitcher.com/api/v1/apps/publish/`;
51
- if (options.dryRun) {
52
- console.log("Dry run mode enabled. The following data would be published:");
53
- console.log("Publish URL:", publishUrl);
54
- console.log("Headers:", {
55
- ...formData.getHeaders(),
56
- "x-api-key": options.apiKey,
57
- });
58
- console.log("app.json content:", fs.readFileSync(path.join(folderPath, "app.json"), "utf-8"));
59
- fs.unlinkSync(zipFilePath);
60
- }
61
- else {
62
- try {
63
- const response = await axios.post(publishUrl, formData, {
64
- headers: {
65
- ...formData.getHeaders(),
66
- "x-api-key": options.apiKey,
67
- },
68
- });
69
- console.log("Publish response:", response.data);
70
- }
71
- catch (e) {
72
- const error = e;
73
- const errData = error?.response?.data;
74
- console.error("Error publishing:", errData?.detail ?? errData);
75
- }
76
- finally {
77
- fs.unlinkSync(zipFilePath);
78
- }
79
- }
80
- });
81
- archive.on("error", (err) => {
82
- throw err;
83
- });
84
- archive.pipe(output);
85
- archive.directory(folderPath, false);
86
- await archive.finalize();
87
- }
88
- catch (error) {
89
- console.error("Error zipping or publishing:", error);
90
- }
91
- });
92
- return program;
93
- }