Repository navigation
Expand file tree
/
Copy pathbuild.js
More file actions
185 lines (145 loc) · 4.3 KB
/
Copy pathbuild.js
File metadata and controls
185 lines (145 loc) · 4.3 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
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
182
183
184
185
const { execSync, exec } = require('child_process')
const jsZip = require('jszip')
const fs = require('fs')
const package = require('./package.json')
console.time('build')
// make sure we have pkg installed
try {
execSync('pkg --version')
} catch (e) {
console.log('pkg not installed. installing...')
execSync('npm install -g pkg')
}
// make sure we have pyinstaller installed
try {
execSync('pyinstaller --version')
} catch (e) {
console.log('pyinstaller not installed. installing...')
execSync('pip install pyinstaller')
}
// make sure we have customtkinter installed
let requiredPyPackages = ['customtkinter', 'CTkColorPicker']
let cTkinterLocation = ''
let locations = []
let res = ""
for (let package of requiredPyPackages) {
res = ""
let tries = 0
do {
try {
tries++
res = execSync(`pip show ${package}`).toString()
} catch (e) {
console.log(`${package} not installed. installing...`)
execSync(`pip install ${package}`)
}
}
while (res == "" || tries > 2)
if (res == "" || tries > 2) {
console.log(`Couldn't install ${package} / get the path. Aborting...`)
process.exit(1)
}
res.split("\n").forEach(line => {
// console.log("line:", line)
if (line.startsWith('Location:')) {
// cTkinterLocation = line.split('Location:')[1].trim()
// return
locations.push(line.split('Location:')[1].trim() + `/${package};${package}/`)
return
}
})
}
// cTkinterLocation += "/customtkinter;customtkinter/"
console.log(locations)
// return
//*
// clean up
console.log('Cleaning up...')
let cleanupFiles = [
'dist',
'build.zip',
// "temp",
// "build"
]
.concat(
fs.readdirSync("./").filter(f => f.endsWith('.spec'))
)
console.log(cleanupFiles)
for (let file of cleanupFiles) {
if (fs.existsSync(file)) {
console.log(`Deleting ${file}`)
fs.rmSync(file, { recursive: true })
}
}
// auto change log generation
/*
try {
execSync("github_changelog_generator --help")
console.log("Generating changelog...")
console.log(execSync("github_changelog_generator -u 1Euro7Cent -p Mrballou-drawbot -o ./dist/CHANGELOG.md").toString())
}
catch (e) {
console.warn("github_changelog_generator not installed. skipping changelog generation")
}
//*/
// return
const commands = [
"pkg index.temp.js -o ./dist/drawbot.exe",
`pyinstaller --workpath "./temp" --onefile initializePositions.py`,
// `pyinstaller --workpath "./temp" --onefile gui.py --add-data \"${cTkinterLocation}\"`
]
let mainFileInstall = "pyinstaller --workpath \"./temp\" --onefile gui.py"
for (let location of locations) {
mainFileInstall += ` --add-data \"${location}\"`
}
commands.push(mainFileInstall)
console.log(commands)
// return
if (!fs.existsSync('build')) fs.mkdirSync('build')
// insert version number into script
let script = fs.readFileSync('index.js', 'utf8')
let replaceWith = `let package = {`
for (let key in package) {
if (typeof package[key] != "number" && typeof package[key] != "string") continue
let isStr = typeof package[key] == 'string'
replaceWith += `
${key}: ${isStr ? `"` : ""}${package[key]}${isStr ? `"` : ""},`
}
replaceWith += "}"
script = script.replace('let package = {}', replaceWith)
fs.writeFileSync('index.temp.js', script)
// return
for (let command of commands) {
console.log(`Executing: ${command}`)
execSync(command)
}
fs.rmSync('index.temp.js')
//*/
console.log('Build complete. files are found in dist/ \nPacking to zip file...')
let startBatch = `@echo off
start cmd /k "drawbot.exe"
echo Waiting for drawbot to start...
timeout /t 3
start cmd /k "gui.exe"
`
fs.writeFileSync('dist/start.bat', startBatch)
let zip = new jsZip()
let files = zip.folder('')
for (let file of fs.readdirSync('./dist')) {
if (fs.statSync(`./dist/${file}`).isFile()) {
if (files != null)
files.file(file, fs.readFileSync(`./dist/${file}`))
}
}
// console.log(zip)
zip.generateAsync({
type: 'nodebuffer',
compression: "DEFLATE",
compressionOptions: {
level: 9
}
}).then((content) => {
fs.writeFileSync('./build.zip', content)
console.log('Packing complete. file is found in build.zip')
console.timeEnd('build')
})