-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-publish-config.js
41 lines (34 loc) · 1.35 KB
/
add-publish-config.js
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
const fs = require('fs');
const path = require('path');
// Function to update package.json files with publishConfig
const updatePackageJson = (dir) => {
const packageJsonPath = path.join(dir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
// Check if "publishConfig" exists and if not, add it
if (!packageJson.publishConfig) {
packageJson.publishConfig = { access: 'public' };
// Write the updated package.json file
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
console.log(`Updated publishConfig in ${packageJsonPath}`);
} else {
console.log(`publishConfig already exists in ${packageJsonPath}`);
}
}
};
// Recursively find all package.json files in the directory
const findPackageJsonFiles = (dir) => {
fs.readdirSync(dir).forEach((file) => {
const fullPath = path.join(dir, file);
// Ignore node_modules directories
if (fs.statSync(fullPath).isDirectory() && file !== 'node_modules') {
// Recurse into subdirectories
findPackageJsonFiles(fullPath);
} else if (file === 'package.json') {
// Update package.json file
updatePackageJson(dir);
}
});
};
// Start at the root of your monorepo (current directory)
findPackageJsonFiles(process.cwd());