-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.js
56 lines (48 loc) · 1.63 KB
/
install.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { exec } from 'child_process';
import fs from 'fs/promises';
import path from 'path';
async function fetchPackageFile() {
try {
const packageFilePath = path.join(process.cwd(), 'package.json');
const data = await fs.readFile(packageFilePath, 'utf8');
return JSON.parse(data);
} catch (err) {
console.error('Error fetching package file:', err);
throw err;
}
}
function padString(str, direction = "right") {
const length = Math.max(str.length, 2);
const pad = " ".repeat(length - str.length);
return direction === "right" ? `${str}${pad}` : `${pad}${str}`;
}
async function install() {
try {
const dirs = ['./Scripts'];
const wd = process.cwd();
for (const dir of dirs) {
const dirPath = path.join(wd, dir);
process.chdir(dirPath);
const packageData = await fetchPackageFile();
await new Promise((resolve, reject) => {
exec('npm install', { stdio: 'ignore' }, (err, stdout, stderr) => {
if (err) {
console.error(`Error installing dependencies for ${packageData.name}: ${err.message}`);
reject(err);
return;
}
const dependencies = Object.keys(packageData.dependencies);
console.log(`Successfully installed dependencies for ${packageData.name} (${dependencies.length})`);
dependencies.forEach(dependency => {
console.log(` - ${padString(dependency)}: ${packageData.dependencies[dependency]}`);
});
resolve();
});
});
}
process.chdir(wd);
} catch (error) {
console.error('An error occurred during installation:', error);
}
}
install();