@pitcher/cli-scripts 1.0.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 +29 -0
- package/dist/copyInstanceFiles.d.ts +2 -0
- package/dist/copyInstanceFiles.js +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -0
- package/dist/publishApp.d.ts +2 -0
- package/dist/publishApp.js +92 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# ng-scripts
|
|
2
|
+
<img width="1576" alt="Screenshot 2024-06-27 at 1 55 41 PM" src="https://github.com/PitcherAG/ng-scripts/assets/11925511/9c5bfc2b-1b24-4482-8afe-35eb5e0a3f8e">
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## To install dependencies:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun install
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## To install as a term package (until we publish)
|
|
12
|
+
```bash
|
|
13
|
+
bun link
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## To run the `copy-instance-files` command:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
p copy-instance-files <fromInstance> <toInstance> --org mondelez --api-key myapikey
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## To run the `publish-app` command:
|
|
23
|
+
```bash
|
|
24
|
+
p publish-app <folder> --url https://dev.my.pitcher.com --api-key myapikey
|
|
25
|
+
# or for current folder and dev org
|
|
26
|
+
p publish-app --api-key myapikey
|
|
27
|
+
# or for dry run and incrementing app.json's version
|
|
28
|
+
p publish-app --api-key myapikey --dry-run --increment-version
|
|
29
|
+
```
|
|
@@ -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
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { createCopyInstanceFilesCommand } from "./copyInstanceFiles";
|
|
4
|
+
import { createPublishAppCommand } from "./publishApp";
|
|
5
|
+
const program = new Command();
|
|
6
|
+
program
|
|
7
|
+
.name("p")
|
|
8
|
+
.description("The Pitcher CLI for various tasks in its ecosystem.")
|
|
9
|
+
.version("1.0.0");
|
|
10
|
+
// Add subcommands
|
|
11
|
+
program.addCommand(createCopyInstanceFilesCommand());
|
|
12
|
+
program.addCommand(createPublishAppCommand());
|
|
13
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,92 @@
|
|
|
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"; // Ensure you have form-data installed
|
|
7
|
+
export function createPublishAppCommand() {
|
|
8
|
+
const program = new Command("publish-app");
|
|
9
|
+
program
|
|
10
|
+
.arguments("[folder]") // Make folder argument optional
|
|
11
|
+
.requiredOption("--api-key <apiKey>", "API Key for authentication") // Make API key a required option
|
|
12
|
+
.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
|
|
15
|
+
.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
|
+
.action(async (folder = ".", options) => {
|
|
18
|
+
try {
|
|
19
|
+
const folderPath = path.resolve(folder); // Resolve the folder path
|
|
20
|
+
// Increment version if --increment-version is provided
|
|
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 zipFilePath = path.join(__dirname, "app.zip");
|
|
41
|
+
const output = fs.createWriteStream(zipFilePath);
|
|
42
|
+
const archive = archiver("zip", {
|
|
43
|
+
zlib: { level: 9 },
|
|
44
|
+
});
|
|
45
|
+
output.on("close", async () => {
|
|
46
|
+
console.log(`Zipped ${archive.pointer()} total bytes`);
|
|
47
|
+
const formData = new FormData();
|
|
48
|
+
formData.append("file", fs.createReadStream(zipFilePath));
|
|
49
|
+
const publishUrl = `https://${options.org}.my.pitcher.com/api/v1/apps/publish/`; // Construct the publish URL
|
|
50
|
+
if (options.dryRun) {
|
|
51
|
+
console.log("Dry run mode enabled. The following data would be published:");
|
|
52
|
+
console.log("Publish URL:", publishUrl);
|
|
53
|
+
console.log("Headers:", {
|
|
54
|
+
...formData.getHeaders(),
|
|
55
|
+
"x-api-key": options.apiKey,
|
|
56
|
+
});
|
|
57
|
+
console.log("app.json content:", fs.readFileSync(path.join(folderPath, "app.json"), "utf-8"));
|
|
58
|
+
fs.unlinkSync(zipFilePath); // Clean up the zip file
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
try {
|
|
62
|
+
const response = await axios.post(publishUrl, formData, {
|
|
63
|
+
headers: {
|
|
64
|
+
...formData.getHeaders(),
|
|
65
|
+
"x-api-key": options.apiKey, // Add API key to headers
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
console.log("Publish response:", response.data);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
const error = e;
|
|
72
|
+
const errData = error?.response?.data;
|
|
73
|
+
console.error("Error publishing:", errData?.detail ?? errData);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
fs.unlinkSync(zipFilePath); // Clean up the zip file
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
archive.on("error", (err) => {
|
|
81
|
+
throw err;
|
|
82
|
+
});
|
|
83
|
+
archive.pipe(output);
|
|
84
|
+
archive.directory(folderPath, false);
|
|
85
|
+
await archive.finalize();
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
console.error("Error zipping or publishing:", error);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return program;
|
|
92
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pitcher/cli-scripts",
|
|
3
|
+
"version": "1.0.0",
|
|
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
|
+
}
|