-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathinstall-dependencies.js
More file actions
50 lines (46 loc) · 1.6 KB
/
install-dependencies.js
File metadata and controls
50 lines (46 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
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
// Function to install dependencies if the directory exists
const installDependencies = (projectPath, projectName) => {
return new Promise((resolve, reject) => {
if (fs.existsSync(projectPath)) {
console.log(`Installing dependencies for ${projectName}...`);
const process = spawn('npm', ['install'], {
cwd: projectPath,
stdio: 'inherit',
shell: true
});
process.on('close', (code) => {
if (code === 0) {
console.log(`${projectName} dependencies installed successfully.`);
resolve();
} else {
console.error(`Error installing ${projectName} dependencies. Exit code: ${code}`);
reject(new Error(`Failed to install dependencies for ${projectName}`));
}
});
} else {
console.error(`Directory ${projectPath} does not exist.`);
reject(new Error(`Directory ${projectPath} does not exist.`));
}
});
};
(async () => {
//#if(includeExpoProject)
const expoPath = path.resolve(__dirname, 'src/Next-Solution.ExpoApp');
try {
await installDependencies(expoPath, 'Expo app');
} catch (error) {
console.error(`Failed to install dependencies for Expo app: ${error.message}`);
}
//#endif
//#if(includeNextProject)
const nextPath = path.resolve(__dirname, 'src/Next-Solution.NextApp');
try {
await installDependencies(nextPath, 'Next.js app');
} catch (error) {
console.error(`Failed to install dependencies for Next.js app: ${error.message}`);
}
//#endif
})();