Skip to content

Commit 9a5ce7c

Browse files
committed
feat: setup, managed copying, etc.
- renamed createManifest.js back to build.js - added `yarn prepare` - added `yarn setup` - used `yargs` to manage CLI params
1 parent 71ac838 commit 9a5ce7c

File tree

6 files changed

+232
-110
lines changed

6 files changed

+232
-110
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Next-Gen Chat Deployment Prototype
2+
3+
Takes NGC builds from the agentforce-messaging repo and adds them to this repo to prepare for deployment to S3.
4+
5+
## Commands
6+
7+
- `yarn build` - copies all versions from builds/ngc and generates the manifest file
8+
- `yarn prepare` - takes the current build from agentforce-messaging, copies it into this repo, and commits it
9+
- `yarn setup repo <path>` - configures the `.local-config` file with the path to the agentforce-messaging repository
File renamed without changes.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"main": "index.js",
55
"type": "module",
66
"scripts": {
7-
"create-manifest": "node createManifest.js",
8-
"copy-build": "node copyBuild.js",
7+
"build": "node build.js",
8+
"prepare": "node prepare.js",
99
"setup": "node setup.js"
1010
},
1111
"repository": {
@@ -20,6 +20,7 @@
2020
"homepage": "https://github.com/airkitjeremy/ngcproto#readme",
2121
"description": "",
2222
"devDependencies": {
23-
"terminal-kit": "^3.1.2"
23+
"yaml": "^2.7.1",
24+
"yargs": "^17.7.2"
2425
}
2526
}

prepare.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { exec } from "node:child_process";
2+
import {
3+
existsSync,
4+
readFileSync,
5+
mkdirSync,
6+
rmSync,
7+
cpSync,
8+
} from "node:fs";
9+
import { dirname, resolve } from "node:path";
10+
import { exit } from "node:process";
11+
import { fileURLToPath } from "node:url";
12+
import { promisify } from "node:util";
13+
import { parse } from "yaml";
14+
15+
const __dirname = dirname(fileURLToPath(import.meta.url));
16+
17+
const configFilename = ".local-config";
18+
const configFilePath = resolve(__dirname, configFilename);
19+
20+
if (!existsSync(configFilePath)) {
21+
console.error(".local-config does not exist; create it with `yarn setup repo <path>`");
22+
exit(1);
23+
}
24+
25+
const config = parse(readFileSync(configFilePath, "utf8"));
26+
27+
const agentforceMessagingRepoPath = config.agentforceMessaging?.repository;
28+
const resolvedRepoPath = agentforceMessagingRepoPath && resolve(__dirname, agentforceMessagingRepoPath);
29+
const resolvedPackageJsonPath = resolvedRepoPath && resolve(resolvedRepoPath, "package.json");
30+
31+
if (!resolvedRepoPath || !existsSync(resolvedPackageJsonPath)) {
32+
console.error(
33+
"A valid path to the agentforce-messaging repository was not specified in .local-config"
34+
);
35+
exit(1);
36+
}
37+
38+
const packageJson = JSON.parse(readFileSync(resolvedPackageJsonPath, "utf8"));
39+
const currentVersion = packageJson.version;
40+
const currentMajorMinorVersion = currentVersion.replace(/^(\d+\.\d+)\.\d+.*$/, "$1");
41+
const versionIsValid = /^\d+\.\d+$/.test(currentMajorMinorVersion);
42+
43+
if (!versionIsValid) {
44+
console.error(`agentforce-messaging version string "${currentVersion}" is not compatible with this tool; must be "x.x.x" or "x.x.x-tag"`);
45+
exit(1);
46+
}
47+
48+
console.log(`Current agentforce-messaging version is ${currentMajorMinorVersion}`);
49+
50+
const distDir = resolve(resolvedRepoPath, "dist/");
51+
if (!existsSync(distDir)) {
52+
console.error("agentforce-messaging has not been built");
53+
exit(1);
54+
}
55+
56+
const releasesDir = resolve(__dirname, "builds/ngc");
57+
const releaseDir = resolve(releasesDir, currentMajorMinorVersion);
58+
if (!existsSync(releaseDir)) {
59+
console.log(`Version ${currentMajorMinorVersion} not found in this repo; adding it now`);
60+
} else {
61+
console.log(`Overwriting existing ${currentMajorMinorVersion} release`);
62+
rmSync(releaseDir, { recursive: true });
63+
}
64+
mkdirSync(releaseDir);
65+
66+
console.log(`Copying version ${currentMajorMinorVersion} from agentforce-messaging`);
67+
cpSync(distDir, releaseDir, { recursive: true });
68+
console.log(`Copying finished! Staging files for Git commit`);
69+
await promisify(exec)(`git add builds/ngc/${currentMajorMinorVersion}/*`);
70+
console.log(`Committing changes`);
71+
await promisify(exec)(`git commit -m "feat: auto-commit of agentforce-messaging v${currentVersion}`);
72+
console.log(`Commit completed. Be sure to push your changes and open a PR!`);

setup.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
existsSync,
3+
readFileSync,
4+
writeFileSync,
5+
} from "node:fs";
6+
import { dirname, resolve } from "node:path";
7+
import { exit } from "node:process";
8+
import { fileURLToPath } from "node:url";
9+
import yargs from "yargs";
10+
import { hideBin } from "yargs/helpers";
11+
import { parse, stringify } from "yaml";
12+
13+
const DEFAULT_CONFIG = `agentforce-messaging:
14+
repository: ""
15+
`;
16+
17+
const __dirname = dirname(fileURLToPath(import.meta.url));
18+
19+
const configFilename = ".local-config";
20+
const configFilePath = resolve(__dirname, configFilename);
21+
22+
const args = yargs(hideBin(process.argv))
23+
.command("repo <path>", "set the path to the agentforce-messaging repository", (yargs) => {
24+
return yargs.positional("path", {
25+
describe: "path of repository"
26+
});
27+
})
28+
.parse();
29+
30+
const path = args["path"];
31+
const configExists = existsSync(configFilePath);
32+
33+
if (!path && !existsSync) {
34+
console.error(".local-config does not exist and a valid path was not specified");
35+
exit(1);
36+
}
37+
38+
if (!configExists) {
39+
console.log("Creating .local-config");
40+
writeFileSync(configFilename, DEFAULT_CONFIG, { encoding: "utf8" });
41+
}
42+
43+
const config = parse(readFileSync(configFilePath, "utf8"));
44+
45+
const agentforceMessagingRepoPath = path || config.agentforceMessaging?.repository;
46+
47+
console.log(`Setting repo path to ${agentforceMessagingRepoPath}`);
48+
const newConfig = Object.assign({}, config, { agentforceMessaging: { repository: agentforceMessagingRepoPath } });
49+
writeFileSync(configFilePath, stringify(newConfig), { encoding: "utf8" });
50+
console.log("Wrote new config", newConfig);
51+
exit(0);

0 commit comments

Comments
 (0)