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