-
Notifications
You must be signed in to change notification settings - Fork 11
/
beforePackage.js
108 lines (103 loc) · 5.07 KB
/
beforePackage.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
const fs = require('fs')
const path = require('path')
const shelljs = require('shelljs')
var compressor = require('node-minify')
if (process.platform == 'win32') {
var fpresolver = '\\'
} else {
var fpresolver = '/'
}
function removeStuff () {
shelljs.rm('-rf',
__dirname + fpresolver + 'src' + fpresolver + 'entry' + fpresolver,
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'entry' + fpresolver,
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'entryDev.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'ace' + fpresolver + 'chaos.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'ace' + fpresolver + 'language_tools.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'ace' + fpresolver + 'light.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'ace' + fpresolver + 'searchbox.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'ace' + fpresolver + 'snippetsTex.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'ace' + fpresolver + 'tex.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'assets' + fpresolver + 'texstarters' + fpresolver,
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'App.jsx',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'Grid.jsx',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'InfiniTex.jsx',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'react' + fpresolver + 'InfinitrConverters.js',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'static' + fpresolver + 'main.css',
__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'static' + fpresolver + 'style.css'
)
}
function removeLines () {
fs.readFile(__dirname + '/prod/src/index.js', 'utf-8', (err, data) => {
if (err) {
alert(err)
} else {
let indexXwrisSkata = data.replace(
'\nif (isDevMode) {', ''
).replace(
'require(\'electron-reload\')(__dirname)}', ''
).replace(
'file://${__dirname}/index.html', 'file://${__dirname}/index.min.html'
).replace(
'// Open the DevTools.', ''
).replace(
'if (isDevMode) {', ''
).replace(
'mainWindow.webContents.openDevTools()}', ''
).replace(
'// devTools', 'devTools'
)
fs.writeFileSync(__dirname + '/prod/src/index.js', indexXwrisSkata)
compressor.minify({
compressor: 'uglify-es',
input: __dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'index.js',
output: __dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'index.min.js',
options: {
warnings: true, // pass true to display compressor warnings.
mangle: true, // pass false to skip mangling names.
compress: true
}
})
fs.unlinkSync(__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'index.js')
}
})
fs.readFile(__dirname + '/prod/src/index.html', 'utf-8', (err, data) => {
if (err) {
alert(err)
} else {
let htmlXwrisSkata = data.replace(
'<!-- <script src=\"./react/inf.min.js\"></script> -->', '<script src=\"./react/inf.min.js\"></script>'
).replace(
'<script src=\"entryDev.js\"></script>', ''
)
fs.writeFileSync(__dirname + '/prod/src/index.html', htmlXwrisSkata)
compressor.minify({
compressor: 'html-minifier',
input: __dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'index.html',
output: __dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'index.min.html'
})
fs.unlinkSync(__dirname + fpresolver + 'prod' + fpresolver + 'src' + fpresolver + 'index.html')
}
})
fs.readFile(__dirname + '/prod/package.json', 'utf-8', (err, data) => {
if (err) {
alert(err)
} else {
let packXwrisSkata = data.replace(
'\"electron-prebuilt-compile\": \"^3.0.6\"', '\"electron\": \"^4.0.0-beta.7\"'
).replace(
'\"src/index.js\"', '\"src/index.min.js\"'
)
fs.writeFileSync(__dirname + '/prod/package.json', packXwrisSkata)
}
})
removeStuff();
}
function copyPasteStuff () {
shelljs.cp('-R', __dirname + fpresolver + 'src' + fpresolver, __dirname + fpresolver + 'prod' + fpresolver)
shelljs.cp(__dirname + fpresolver + 'package.json', __dirname + fpresolver + 'prod' + fpresolver)
shelljs.cp(__dirname + fpresolver + 'yarn.lock', __dirname + fpresolver + 'prod' + fpresolver)
removeLines()
}
shelljs.mkdir('-p', __dirname + fpresolver + 'prod' + fpresolver)
copyPasteStuff()