-
Notifications
You must be signed in to change notification settings - Fork 0
/
onStartup.js
52 lines (41 loc) · 1.51 KB
/
onStartup.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
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const directory = 'weekDays'
const currentDay = new Date().toLocaleDateString('en-US', { weekday: 'long' });
const appFolderToStartup = path.join(process.cwd(), directory, currentDay)
// ensure weekDays folder exists and if it doesn't create it
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
// ensure week day folder exists in weekDays folder and if not create it
for (let day of ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']) {
const dayPath = path.join(directory, day);
if (!fs.existsSync(dayPath)) {
fs.mkdirSync(dayPath);
}
}
fs.readdir(appFolderToStartup, async (err, files) => {
if (err) {
console.error(`Error reading folder: ${err}`);
process.exit(1);
}
// ensure it is a file and not hidden
const apps = files.filter(file => {
const filePath = path.join(appFolderToStartup, file);
return fs.statSync(filePath).isFile() && !file.startsWith('.');
});
// loop over all apps and execute them
for(let app of apps) {
console.log(`Starting ${app}`);
const appFullPath = path.join(appFolderToStartup, app);
exec(`${appFullPath}`, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing ${app}: ${error}`);
}
if (stderr) {
console.error(`Error: ${stderr}`);
}
})
}
})