-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsync-jay-packages.cjs
More file actions
executable file
·227 lines (195 loc) · 7.65 KB
/
Copy pathsync-jay-packages.cjs
File metadata and controls
executable file
·227 lines (195 loc) · 7.65 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Parse command-line arguments
const args = process.argv.slice(2);
const SCRIPT_DIR = __dirname;
const sourceRepoArg = args[0] || path.join(__dirname, '..', 'jay');
const SOURCE_REPO = path.resolve(sourceRepoArg);
const TARGET_DIR = path.join(SCRIPT_DIR, 'node_modules');
const PACKAGE_PREFIX = '@jay-framework';
// Colors for console output
const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
reset: '\x1b[0m',
};
// Show help if requested
if (args.includes('--help') || args.includes('-h')) {
console.log(`${colors.yellow}Jay Framework Package Sync Script${colors.reset}`);
console.log('');
console.log('Usage:');
console.log(' node sync-jay-packages.cjs [source-repo-path]');
console.log('');
console.log('Arguments:');
console.log(' source-repo-path Path to the jay source repository');
console.log(' Default: ../jay (relative to script location)');
console.log('');
console.log('Examples:');
console.log(' node sync-jay-packages.cjs');
console.log(' node sync-jay-packages.cjs /path/to/jay');
console.log(' node sync-jay-packages.cjs ../jay');
process.exit(0);
}
console.log(`${colors.yellow}Jay Framework Package Sync Script${colors.reset}`);
console.log(`Script directory: ${SCRIPT_DIR}`);
console.log(`Source: ${SOURCE_REPO}`);
console.log(`Target: ${TARGET_DIR}`);
console.log('');
// Helper function to copy directory recursively (excluding package.json files)
function copyDirSync(src, dest) {
if (!fs.existsSync(src)) {
throw new Error(`Source directory does not exist: ${src}`);
}
// Create destination directory
fs.mkdirSync(dest, { recursive: true });
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
// Skip package.json files to avoid messing with dependencies
if (entry.name === 'package.json') {
continue;
}
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
if (entry.isDirectory()) {
copyDirSync(srcPath, destPath);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
// Function to copy a package (content only, preserving existing package.json)
function copyPackage(packageName, sourcePath) {
const targetPath = path.join(TARGET_DIR, PACKAGE_PREFIX, packageName);
const sourceDistPath = path.join(sourcePath, 'dist');
const targetDistPath = path.join(targetPath, 'dist');
if (fs.existsSync(sourcePath)) {
console.log(`Copying ${colors.green}${packageName}${colors.reset}...`);
if (!fs.existsSync(sourceDistPath)) {
console.log(`${colors.red} ✗ dist folder not found: ${sourceDistPath}${colors.reset}`);
return false;
}
try {
// Only copy content from dist folder to dist folder, preserving existing package.json
copyDirSync(sourceDistPath, targetDistPath);
console.log(` ✓ Copied dist to ${targetDistPath}`);
// Copy plugin.yaml if it exists in the source package root
const sourcePluginYaml = path.join(sourcePath, 'plugin.yaml');
if (fs.existsSync(sourcePluginYaml)) {
fs.copyFileSync(sourcePluginYaml, path.join(targetPath, 'plugin.yaml'));
console.log(` ✓ Copied plugin.yaml`);
}
// Also copy agent-kit-template folder if it exists
const sourceAgentKitPath = path.join(sourcePath, 'agent-kit-template');
const targetAgentKitPath = path.join(targetPath, 'agent-kit-template');
if (fs.existsSync(sourceAgentKitPath)) {
copyDirSync(sourceAgentKitPath, targetAgentKitPath);
console.log(` ✓ Copied agent-kit-template`);
}
return true;
} catch (error) {
console.log(`${colors.red} ✗ Error copying ${packageName}: ${error.message}${colors.reset}`);
return false;
}
} else {
console.log(`${colors.red} ✗ Source not found: ${sourcePath}${colors.reset}`);
return false;
}
}
// Main function
function main() {
// Check if source repo exists
if (!fs.existsSync(SOURCE_REPO)) {
console.log(`${colors.red}Error: Source repository not found at ${SOURCE_REPO}${colors.reset}`);
process.exit(1);
}
// Create node_modules/@jay-framework if it doesn't exist
const jayFrameworkDir = path.join(TARGET_DIR, PACKAGE_PREFIX);
if (!fs.existsSync(jayFrameworkDir)) {
fs.mkdirSync(jayFrameworkDir, { recursive: true });
}
// Read existing @jay-framework packages from node_modules
console.log('Reading existing @jay-framework packages from node_modules...');
if (!fs.existsSync(jayFrameworkDir)) {
console.log(`${colors.yellow}No @jay-framework directory found in node_modules${colors.reset}`);
console.log(
'Run npm install first to install the packages, then run this script to sync them.',
);
process.exit(0);
}
const existingPackages = fs
.readdirSync(jayFrameworkDir, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name);
if (existingPackages.length === 0) {
console.log(`${colors.yellow}No @jay-framework packages found in node_modules${colors.reset}`);
process.exit(0);
}
console.log('Found existing packages:');
existingPackages.forEach((packageName) => {
console.log(` - ${packageName}`);
});
console.log('');
// Copy each existing package
let successCount = 0;
let failCount = 0;
for (const packageName of existingPackages) {
// Handle package name mappings for jay-stack packages
let actualPackageName = packageName;
if (packageName === 'jay-stack-cli') {
actualPackageName = 'stack-cli';
} else if (packageName === 'jay-cli') {
actualPackageName = 'cli';
} else if (packageName === 'fullstack-component') {
actualPackageName = 'full-stack-component';
} else if (packageName === 'stack-route-scanner') {
actualPackageName = 'route-scanner';
} else if (packageName === 'gemini-agent-plugin') {
actualPackageName = 'gemini-agent';
} else if (packageName === 'webmcp-plugin') {
actualPackageName = 'webmcp';
}
// Try different possible source paths
const possiblePaths = [
path.join(SOURCE_REPO, 'packages', 'jay-stack', actualPackageName),
path.join(SOURCE_REPO, 'packages', 'jay-stack-plugins', actualPackageName),
path.join(SOURCE_REPO, 'packages', 'compiler', actualPackageName),
path.join(SOURCE_REPO, 'packages', 'runtime', actualPackageName),
path.join(SOURCE_REPO, 'packages', 'plugins', actualPackageName),
path.join(SOURCE_REPO, 'packages', actualPackageName),
];
let found = false;
for (const sourcePath of possiblePaths) {
if (fs.existsSync(sourcePath)) {
if (copyPackage(packageName, sourcePath)) {
successCount++;
} else {
failCount++;
}
found = true;
break;
}
}
if (!found) {
console.log(`${colors.red} ✗ Could not find source for: ${packageName}${colors.reset}`);
console.log(' Tried paths:');
possiblePaths.forEach((p) => console.log(` ${p}`));
failCount++;
}
}
console.log('');
console.log(`${colors.green}Package sync complete!${colors.reset}`);
console.log(`${colors.green}✓ ${successCount} packages copied successfully${colors.reset}`);
if (failCount > 0) {
console.log(`${colors.red}✗ ${failCount} packages failed${colors.reset}`);
}
console.log('');
console.log('Note: If you encounter issues, you may need to:');
console.log(`1. Build the packages in the source repo first: cd ${SOURCE_REPO} && yarn build`);
console.log(
'2. Check that the package names in your package.json match the actual package structure',
);
}
// Run the script
main();