-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcopyFiles.js
More file actions
58 lines (48 loc) · 1.6 KB
/
copyFiles.js
File metadata and controls
58 lines (48 loc) · 1.6 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
/**
* Copies LICENSE.md and CHANGELOG.md to the specified target directory
* @param {string} targetDir - The directory to copy files to
*/
function copyFiles(targetDir) {
if (!targetDir) {
console.error('Error: Target directory not provided');
console.log('Usage: node copyFiles.js <target-directory>');
process.exit(1);
}
const rootDir = __dirname;
const filesToCopy = ['LICENSE.md', 'CHANGELOG.md'];
// Ensure target directory exists
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir, { recursive: true });
console.log(`Created directory: ${targetDir}`);
}
// Copy each file
filesToCopy.forEach(file => {
const sourcePath = path.join(rootDir, file);
const destPath = path.resolve(targetDir, file);
if (!fs.existsSync(sourcePath)) {
console.error(`Error: Source file not found: ${sourcePath}`);
process.exit(1);
}
try {
fs.copyFileSync(sourcePath, destPath);
console.log(`Copied ${file}`);
console.log(` From: ${sourcePath}`);
console.log(` To: ${destPath}`);
} catch (error) {
console.error(`Error copying ${file}:`, error.message);
process.exit(1);
}
});
console.log('All files copied successfully!');
}
// Get target directory from command line arguments
const targetDir = process.argv[2];
copyFiles(targetDir);