-
Notifications
You must be signed in to change notification settings - Fork 6
/
main_process.js
181 lines (169 loc) · 5.57 KB
/
main_process.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// @ts-nocheck
const { app, BrowserWindow, ipcMain, Menu, Dialog } = require('electron');
const createMenuBar = require('./backend/menuBar.js');
const { fork, exec } = require('child_process');
const path = require('path');
const fs = require('fs');
let mainWindow;
app.on('ready', () => {
mainWindow = new BrowserWindow({ width: 1300, height: 900 });
mainWindow.loadURL(`file://${__dirname}/app/index.html`);
//Adding Menu Bar
const menu = Menu.buildFromTemplate(createMenuBar(mainWindow, ResetDir, OpenDir));
Menu.setApplicationMenu(menu);
if (process.env.NODE_ENV === 'packaging') {
const initialStartFlagFilePath = path.join(__dirname, 'electronUserData', 'initialStartup.txt');
if (!fs.existsSync(initialStartFlagFilePath)) {
let pathToExecutable;
if (process.platform === 'darwin') {
pathToExecutable = path.join(__dirname, '..', '..', 'MacOS', 'bundle-bee');
} else if (process.platform === 'win32') {
pathToExecutable = path.join(__dirname, '..', '..', 'MacOS', 'bundle-bee');
}
fs.writeFile(
initialStartFlagFilePath,
`command to run executable:
open ${pathToExecutable}
dirname: ${__dirname}
filename: ${__filename}
initalstartflagfilepath: ${initialStartFlagFilePath}
`
);
exec(`open ${pathToExecutable}`, err => {
app.exit(0);
});
} else {
fs.unlink(initialStartFlagFilePath, err => {
if (err) console.log(err);
});
}
mainWindow.on('close', () => {
app.exit(0);
});
}
});
ipcMain.on('ondragstart', (event, filePath) => {
event.sender.startDrag({
file: filePath,
icon: '/path/to/icon.png',
});
});
ipcMain.on('restart', () => {
ResetDir();
});
ipcMain.on('index-project-files-from-dropped-item-path', (event, rootDirPath) => {
const pathToIndexFileModule = path.join(
__dirname,
'backend',
'create-config',
'utils',
'indexFilesFromRoot.js'
);
const indexFilesChild = fork(pathToIndexFileModule, [rootDirPath]);
indexFilesChild.on('message', ({ foundWebpackConfig, foundEntryFile, e }) => {
if (e) {
console.log(e);
return event.sender.send('error');
}
event.sender.send('handle-file-indexing-results', {
foundWebpackConfig,
foundEntryFile,
});
});
});
ipcMain.on('run-webpack', (event, { createNewConfig, pathFromDrag }) => {
const pathToCreateWebpackFileModule = path.join(
__dirname,
'backend',
'create-config',
'utils',
'createWebpackConfig.js'
);
const pathToRunWebpackFileModule = path.join(
__dirname,
'backend',
'create-config',
'utils',
'runWebpack.js'
);
const pathToWriteStatsFile = path.join(__dirname, 'electronUserData', 'stats.json');
if (createNewConfig) {
const createWebpackChild = fork(pathToCreateWebpackFileModule, [pathFromDrag]);
createWebpackChild.on('message', ({ webpackDirectory, err }) => {
if (err) return event.sender.send('error');
const runWebpackChild = fork(pathToRunWebpackFileModule, [pathToWriteStatsFile], {
cwd: webpackDirectory,
});
runWebpackChild.on('message', message => {
if (message.error) {
console.log(message.error);
return event.sender.send('error');
}
console.log('webpack successfully run and stats.json successfully written...');
event.sender.send('webpack-stats-results-json', __dirname);
});
});
} else {
const { rootDir } = JSON.parse(
fs.readFileSync(path.join(__dirname, 'electronUserData', 'configurationData.js'), 'utf-8')
);
const runWebpackChild = fork(pathToRunWebpackFileModule, [pathToWriteStatsFile], {
cwd: rootDir,
});
runWebpackChild.on('message', message => {
if (message.error) {
console.log(message.error);
return event.sender.send('error');
}
console.log('webpack successfully run and stats.json successfully written...');
event.sender.send('webpack-stats-results-json', __dirname);
});
}
});
ipcMain.on('run-parcel', event => {
const pathToRunParcelFileModule = path.join(
__dirname,
'backend',
'create-config',
'utils',
'runParcel.js'
);
const { rootDir } = JSON.parse(
fs.readFileSync(path.join(__dirname, 'electronUserData', 'configurationData.js'), 'utf-8')
);
const pathToWriteStatsFile = path.join(__dirname, 'electronUserData', 'parcel-stats.json');
const createParcelChild = fork(pathToRunParcelFileModule, [rootDir, pathToWriteStatsFile]);
createParcelChild.on('message', message => {
if (message.error) {
console.log(message.error);
return event.sender.send('error');
}
console.log('parcel successfully run and stats.json successfully written...');
event.sender.send('parcel-stats-results-json', __dirname);
});
});
ipcMain.on('run-rollup', event => {
const pathToRunRollupModule = path.join(
__dirname,
'backend',
'create-config',
'utils',
'runRollup.js'
);
const pathToWriteStatsFile = path.join(__dirname, 'electronUserData', 'rollup-stats.json');
const createRollupChild = fork(pathToRunRollupModule, [pathToWriteStatsFile]);
createRollupChild.on('message', message => {
if (message.error) {
console.log(message.error);
return event.sender.send('error');
}
console.log('rollup successfully run and stats.json successfully written...');
event.sender.send('rollup-stats-results-json', __dirname);
});
});
function ResetDir() {
app.relaunch({ args: process.argv.slice(1).concat(['--relaunch']) });
console.log('running reset dir2');
app.exit(0);
}
function OpenDir(build) { }