forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcopy-assets.mjs
More file actions
64 lines (55 loc) · 2.17 KB
/
Copy pathcopy-assets.mjs
File metadata and controls
64 lines (55 loc) · 2.17 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
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const srcDir = path.join(__dirname, '..', 'src', 'assets');
const destDir = path.join(__dirname, '..', 'dist', 'assets');
const inspectorSrcDir = path.join(__dirname, '..', 'node_modules', '@aws', 'agent-inspector', 'dist-assets');
const inspectorDestDir = path.join(__dirname, '..', 'dist', 'agent-inspector');
/**
* Recursively copy directory contents, excluding specified files at root level only
* @param {string} src - Source directory
* @param {string} dest - Destination directory
* @param {string[]} excludeAtRoot - Files to exclude only at the root level (e.g., 'AGENTS.md')
* @param {boolean} isRoot - Whether this is the root level call
*/
function copyDir(src, dest, excludeAtRoot = [], isRoot = true) {
// Create destination directory if it doesn't exist
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest, { recursive: true });
}
const entries = fs.readdirSync(src, { withFileTypes: true });
for (const entry of entries) {
const srcPath = path.join(src, entry.name);
const destPath = path.join(dest, entry.name);
// Skip excluded files only at root level
if (isRoot && excludeAtRoot.includes(entry.name)) {
continue;
}
if (entry.isDirectory()) {
copyDir(srcPath, destPath, excludeAtRoot, false);
} else {
fs.copyFileSync(srcPath, destPath);
}
}
}
try {
console.log('Copying assets...');
copyDir(srcDir, destDir, ['AGENTS.md']);
console.log('Assets copied successfully!');
// Copy @aws/agent-inspector built assets into dist/agent-inspector/ for bundled CLI
if (fs.existsSync(inspectorSrcDir)) {
console.log('Copying @aws/agent-inspector assets...');
copyDir(inspectorSrcDir, inspectorDestDir);
console.log('@aws/agent-inspector assets copied successfully!');
} else {
console.error(
'Error: @aws/agent-inspector dist-assets/ not found. Run "npm install" to ensure the package is available.'
);
process.exit(1);
}
} catch (error) {
console.error('Error copying assets:', error);
process.exit(1);
}