@pitcher/cli-scripts 1.0.3 → 1.0.5
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.internal.md +12 -0
- package/README.md +6 -9
- package/dist/index.js +4 -3
- package/dist/package.json +36 -0
- package/dist/publishApp.js +13 -14
- package/dist/src/copyInstanceFiles.d.ts +2 -0
- package/dist/src/copyInstanceFiles.js +17 -0
- package/dist/src/publishApp.d.ts +2 -0
- package/dist/src/publishApp.js +93 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# @pitcher/cli-scripts
|
|
2
|
+
Pitcher CLI Tools
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
5
|
+
## Help
|
|
7
6
|
```bash
|
|
8
|
-
|
|
7
|
+
p --help
|
|
8
|
+
# or for specific command help:
|
|
9
|
+
p command --help
|
|
9
10
|
```
|
|
10
11
|
|
|
11
|
-
## To install as a term package (until we publish)
|
|
12
|
-
```bash
|
|
13
|
-
bun link
|
|
14
|
-
```
|
|
15
12
|
|
|
16
13
|
## To run the `copy-instance-files` command:
|
|
17
14
|
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { createCopyInstanceFilesCommand } from "./copyInstanceFiles.js";
|
|
4
|
-
import { createPublishAppCommand } from "./publishApp.js";
|
|
3
|
+
import { createCopyInstanceFilesCommand } from "./src/copyInstanceFiles.js";
|
|
4
|
+
import { createPublishAppCommand } from "./src/publishApp.js";
|
|
5
|
+
import pkg from "./package.json";
|
|
5
6
|
const program = new Command();
|
|
6
7
|
program
|
|
7
8
|
.name("p")
|
|
8
9
|
.description("The Pitcher CLI for various tasks in its ecosystem.")
|
|
9
|
-
.version(
|
|
10
|
+
.version(pkg.version);
|
|
10
11
|
// Add subcommands
|
|
11
12
|
program.addCommand(createCopyInstanceFilesCommand());
|
|
12
13
|
program.addCommand(createPublishAppCommand());
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pitcher/cli-scripts",
|
|
3
|
+
"version": "1.0.5",
|
|
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": ["pitcher", "cli", "ng-scripts"],
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"prepublishOnly": "npm run build"
|
|
18
|
+
},
|
|
19
|
+
"bin": {
|
|
20
|
+
"p": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/archiver": "^6.0.2",
|
|
27
|
+
"@types/node": "^20.0.0",
|
|
28
|
+
"typescript": "^5.4.5"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"archiver": "^7.0.1",
|
|
32
|
+
"axios": "^1.7.2",
|
|
33
|
+
"commander": "^12.1.0",
|
|
34
|
+
"form-data": "^4.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/publishApp.js
CHANGED
|
@@ -3,22 +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";
|
|
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]")
|
|
11
|
-
.requiredOption("--api-key <apiKey>", "API Key for authentication")
|
|
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")
|
|
14
|
-
.option("--dry-run", "Perform a dry run without publishing")
|
|
15
|
-
.option("--publish-url <url>", "Explicit publish URL")
|
|
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")
|
|
16
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"')
|
|
17
|
-
// Set default folder to current directory
|
|
18
18
|
.action(async (folder = ".", options) => {
|
|
19
19
|
try {
|
|
20
|
-
const folderPath = path.resolve(folder);
|
|
21
|
-
// Increment version if --increment-version is provided
|
|
20
|
+
const folderPath = path.resolve(folder);
|
|
22
21
|
if (options.incrementVersion) {
|
|
23
22
|
const appJsonPath = path.join(folderPath, "app.json");
|
|
24
23
|
if (fs.existsSync(appJsonPath)) {
|
|
@@ -38,7 +37,8 @@ export function createPublishAppCommand() {
|
|
|
38
37
|
return;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
const
|
|
40
|
+
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
|
41
|
+
const zipFilePath = path.join(currentDir, "app.zip");
|
|
42
42
|
const output = fs.createWriteStream(zipFilePath);
|
|
43
43
|
const archive = archiver("zip", {
|
|
44
44
|
zlib: { level: 9 },
|
|
@@ -47,7 +47,6 @@ export function createPublishAppCommand() {
|
|
|
47
47
|
console.log(`Zipped ${archive.pointer()} total bytes`);
|
|
48
48
|
const formData = new FormData();
|
|
49
49
|
formData.append("file", fs.createReadStream(zipFilePath));
|
|
50
|
-
// Use explicit publish URL if provided, otherwise construct from org
|
|
51
50
|
const publishUrl = options.publishUrl || `https://${options.org}.my.pitcher.com/api/v1/apps/publish/`;
|
|
52
51
|
if (options.dryRun) {
|
|
53
52
|
console.log("Dry run mode enabled. The following data would be published:");
|
|
@@ -57,14 +56,14 @@ export function createPublishAppCommand() {
|
|
|
57
56
|
"x-api-key": options.apiKey,
|
|
58
57
|
});
|
|
59
58
|
console.log("app.json content:", fs.readFileSync(path.join(folderPath, "app.json"), "utf-8"));
|
|
60
|
-
fs.unlinkSync(zipFilePath);
|
|
59
|
+
fs.unlinkSync(zipFilePath);
|
|
61
60
|
}
|
|
62
61
|
else {
|
|
63
62
|
try {
|
|
64
63
|
const response = await axios.post(publishUrl, formData, {
|
|
65
64
|
headers: {
|
|
66
65
|
...formData.getHeaders(),
|
|
67
|
-
"x-api-key": options.apiKey,
|
|
66
|
+
"x-api-key": options.apiKey,
|
|
68
67
|
},
|
|
69
68
|
});
|
|
70
69
|
console.log("Publish response:", response.data);
|
|
@@ -75,7 +74,7 @@ export function createPublishAppCommand() {
|
|
|
75
74
|
console.error("Error publishing:", errData?.detail ?? errData);
|
|
76
75
|
}
|
|
77
76
|
finally {
|
|
78
|
-
fs.unlinkSync(zipFilePath);
|
|
77
|
+
fs.unlinkSync(zipFilePath);
|
|
79
78
|
}
|
|
80
79
|
}
|
|
81
80
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
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
|
+
}
|