@pitcher/cli-scripts 1.0.4 → 1.0.6
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 +7 -10
- package/dist/index.js +4 -3
- package/dist/package.json +36 -0
- 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,22 +1,19 @@
|
|
|
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
|
|
|
18
15
|
```bash
|
|
19
|
-
p copy-instance-files <fromInstance> <toInstance> --org
|
|
16
|
+
p copy-instance-files <fromInstance> <toInstance> --org pitcher --api-key myapikey
|
|
20
17
|
```
|
|
21
18
|
|
|
22
19
|
## To run the `publish-app` command:
|
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.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": ["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
|
+
}
|
|
@@ -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 pitcher --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
|
+
}
|