-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
138 lines (75 loc) · 3.62 KB
/
index.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
const spawn = require('child_process').spawn;
const exec = require('child_process').exec;
const fs = require('fs');
module.exports.create_app = (name) => {
let create_react_app = spawn('npx', ['create-react-app', name]);
console.log();
console.log('\x1b[35m%s\x1b[0m', 'Create [React/Electron] App');
console.log();
create_react_app.stdout.on('data', data => console.log(data.toString()));
create_react_app.stderr.on('data', data => console.log(data.toString()));
create_react_app.on('exit', code => {
console.log('adding electron packages')
console.log();
let add_electron = spawn('yarn', ['add', 'electron', 'electron-builder', 'wait-on', 'concurrently', '--dev'], { cwd: `${process.cwd()}/${name}` })
add_electron.stdout.on('data', data => console.log(data.toString()))
add_electron.stderr.on('data', data => console.log(data.toString()));
add_electron.on('exit', code => {
console.log('adding electron-is-dev')
let electron_is_dev = spawn('yarn', ['add', 'electron-is-dev', 'typescript', 'fsevents'], { cwd: `${process.cwd()}/${name}` });
electron_is_dev.stdout.on('data', data => console.log(data.toString()));
electron_is_dev.stderr.on('data', data => console.log(data.toString()));
electron_is_dev.on('exit', code => {
console.log()
console.log('creating electron file');
fs.readFile(`${__dirname}/electron_file.txt`, 'utf-8', (err, data) => {
if (err) console.log(err);
fs.writeFile(`${process.cwd()}/${name}/public/electron.js`, data, err => {
if (err) throw err;
console.log();
console.log('Editing package.json');
console.log();
console.log('\x1b[32m', 'package.json edited successfully');
fs.readFile(`${process.cwd()}/${name}/package.json`, 'utf-8', (err, file) => {
if (err) throw err;
let json = JSON.parse(file);
json["main"] = "public/electron.js"
json["scripts"]["electron-dev"] = "concurrently \"BROWSER=none yarn start\" \"wait-on http://localhost:3000 && electron .\""
json["scripts"]["electron-pack"] = "build -c.extraMetadata.main=build/electron.js -mlw"
json["scripts"]["preelectron-pack"] = "yarn build"
json["author"] = "Captain Electron"
json["homepage"] = "./"
json["build"] = {
"appId": "com.example.react-electron-app",
"files": [
"build/**/*",
"node_modules/**/*"
],
"directories": {
"buildResources": 'assets'
}
}
fs.writeFile(`${process.cwd()}/${name}/package.json`, JSON.stringify(json, null, 2), err => {
if (err) throw err;
console.log();
console.log('\x1b[35m', `run the following commands`);
console.log();
console.log('\x1b[36m', `1- cd ${name}`);
console.log();
console.log('\x1b[36m', `2- yarn`);
console.log();
console.log('\x1b[35m', 'To Run The App In Development Run');
console.log();
console.log('\x1b[36m', 'npm run electron-dev for development');
console.log();
console.log('\x1b[35m', 'To Pack The Electron App Run');
console.log();
console.log('\x1b[36m', 'npm run electron-pack for production');
})
})
})
})
})
})
});
}