Skip to content

Commit ff259cb

Browse files
committed
fix link script
1 parent 278f0c6 commit ff259cb

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

typescript-sdk/apps/dojo/scripts/link-cpk.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,49 @@ const fs = require('fs');
33
const { execSync } = require('child_process');
44
const path = require('path');
55

6-
const gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8' }).trim();
6+
const cpkPath = process.argv[2];
7+
if (!cpkPath) {
8+
console.error('Usage: node link-cpk.js <cpk-path>');
9+
process.exit(1);
10+
}
11+
12+
if (!fs.existsSync(cpkPath)) {
13+
console.error(`copilot kit repo path ${cpkPath} does not exist`);
14+
process.exit(1);
15+
}
16+
17+
18+
const gitRoot = execSync('git rev-parse --show-toplevel', { encoding: 'utf-8', cwd: __dirname }).trim();
719
const dojoDir = path.join(gitRoot, 'typescript-sdk/apps/dojo');
20+
const cpkPackageDir = path.join(cpkPath, 'CopilotKit', 'packages');
21+
const relative = `./${path.relative(dojoDir, cpkPackageDir)}`;
822

923
function linkCopilotKit() {
1024
const pkgPath = path.join(dojoDir, 'package.json');
1125
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
1226
const packages = Object.keys(pkg.dependencies).filter(pkg => pkg.startsWith('@copilotkit/'));
1327

1428
success = true;
15-
packages.forEach(pkg => {
16-
console.log(`Linking ${pkg}`);
17-
try {
18-
execSync(`pnpm link ${pkg}`, {cwd: dojoDir});
19-
console.log(`Linked ${pkg}`);
20-
} catch (e) {
21-
console.error(`Error linking ${pkg}: ${e}`);
29+
packages.forEach(packageName => {
30+
const packageFolderName = packageName.replace('@copilotkit/', '');
31+
32+
if (!fs.existsSync(path.join(cpkPackageDir, packageFolderName))) {
33+
console.error(`Package ${packageName} does not exist in ${cpkPackageDir}!!`);
2234
success = false;
2335
}
2436

37+
pkg.dependencies[packageName] = path.join(relative, packageFolderName);
2538
});
2639

40+
41+
2742
if (!success) {
43+
console.error('One or more packages do not exist in the copilot kit repo!');
2844
process.exit(1);
2945
}
3046

47+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
48+
3149
}
3250

3351
linkCopilotKit();

0 commit comments

Comments
 (0)