-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathadd-license.js
More file actions
executable file
·66 lines (55 loc) · 1.77 KB
/
Copy pathadd-license.js
File metadata and controls
executable file
·66 lines (55 loc) · 1.77 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
#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
// Directories containing packages
const packageDirs = [
'packages/core',
'packages/adapters',
'packages/plugins',
'packages/providers',
];
// Function to process a directory and update package.json
function processDirectory(dir) {
// Check if it's a direct package directory
const packageJsonPath = path.join(dir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
updatePackageJson(packageJsonPath);
return;
}
// Otherwise, list subdirectories and process each
try {
const subdirs = fs
.readdirSync(dir, { withFileTypes: true })
.filter(dirent => dirent.isDirectory())
.map(dirent => path.join(dir, dirent.name));
for (const subdir of subdirs) {
const subPackageJsonPath = path.join(subdir, 'package.json');
if (fs.existsSync(subPackageJsonPath)) {
updatePackageJson(subPackageJsonPath);
}
}
} catch (error) {
console.error(`Error processing directory ${dir}:`, error);
}
}
// Function to update the package.json file
function updatePackageJson(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
const pkg = JSON.parse(content);
if (!pkg.license) {
pkg.license = 'MIT';
// Find the position to insert the license field (after version)
const updatedContent = JSON.stringify(pkg, null, 2);
fs.writeFileSync(filePath, updatedContent);
console.log(`✅ Added MIT license to ${filePath}`);
} else {
console.log(`ℹ️ License already exists in ${filePath}`);
}
} catch (error) {
console.error(`Error updating ${filePath}:`, error);
}
}
// Process each package directory
packageDirs.forEach(processDirectory);
console.log('License update completed!');