-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun-dev.html
221 lines (189 loc) · 6.61 KB
/
run-dev.html
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<html window-frame="extended" window-resizable="true" window-state="maximized" window-icon="src/assets/Icon.svg">
<head>
<title>QwikTape Dev</title>
<style>
@import url(unit-test/unittest.css);
body { flow: horizontal; }
body > div#log { width: 25%; height: *; }
body > div#controls > * { width: *; margin: 4dip; }
body > div#controls { flow: vertical; }
</style>
<link rel="unittest" href="tests/sciter-tape-grammar.tests.js" />
<script|module>
import * as sys from "@sys";
import * as env from '@env';
import * as sciter from '@sciter';
const app = document.$("frame");
const log = document.$("plaintext#tree");
async function saveAndLaunch(path, buffer){
let file;
try {
file = await sys.fs.open(path, "w+", 0o666);
await file.write(buffer, "utf-8");
}
catch (error) {
Window.modal(<warning>Cannot open file {path} for writing.<br/>{error}<br/>File will not be saved.</warning>);
}
finally {
if (file) {
file.close();
env.launch(path);
}
}
}
function checkFile(path) {
if (sys.fs.$stat(path)) return path;
return null;
}
function makePath(dir, subdirs, nameext) {
let path = dir;
for (const sub of subdirs) {
path += "/";
path += sub;
if (checkFile(path)) continue;
if (!sys.fs.$mkdir(path)) throw "makePath: cannot create dir:" + path;
}
return path + "/" + nameext;
}
function copyFileForce(fnSrc, fnDes) {
if (sys.fs.$stat(fnDes))
sys.fs.$unlink(fnDes);
sys.fs.$copyfile(fnSrc, fnDes);
}
//exert from sciter quark project, by @mice2100 on gitlab
function makeAppleBundle(exefile, params) {
makePath(params.out, [`${params.exe}.app`, "Contents", "MacOS"], "");
makePath(params.out, [`${params.exe}.app`, "Contents", "Resources"], "");
let appPath = `${params.out}/${params.exe}.app`;
sys.fs.$chmod(appPath, 0o755);
appPath += "/Contents"
copyFileForce(__DIR__ + "main/res/Info.plist", appPath + "/Info.plist");
copyFileForce(exefile, appPath + "/MacOS/" + params.exe);
sys.fs.$chmod(appPath + "/MacOS/" + params.exe, 0o755);
copyFileForce(__DIR__ + "main/res/QwikTape.icns", `${appPath}/Resources/${params.exe}.icns`);
}
document.on("click", "button#tests", ()=>{
document.post(new Event("present-tests", {bubbles: true}));
})
document.on("click", "button#refresh", ()=>{
app.frame.loadFile(app.frame.url);
})
document.on("click", "button#diagram", ()=>{
const { QwikTape } = sciter.import("./src/parser/tape-embedded.js");
const { parser, diagramBuilder } = QwikTape;
const sgp = parser.getSerializedGastProductions();
const htmlText = diagramBuilder(sgp, {
resourceBase: `https://cdn.jsdelivr.net/npm/chevrotain/diagrams/`,
css: `https://cdn.jsdelivr.net/npm/chevrotain/diagrams/diagrams.css`
});
saveAndLaunch(URL.toPath(__DIR__ + "build/railroad-diagram.htm"), htmlText);
})
document.on("click", "button#generate", (evt, checkbox)=>{
if(checkbox.value){
log.value = "";
Window.post(new Event("debug-show-parse", { bubbles: true, data: (value)=>{log.value = value}} ));
}
else {
log.value = "";
}
})
document.on("click", "button#build", async (evt, el)=>{
let packfolder = 'packfolder';
let scapp = 'scapp';
let output = 'qwiktape';
if(env.PLATFORM === 'Windows'){
packfolder = '../' + packfolder + '.exe';
scapp = scapp + '.exe';
}
if(env.PLATFORM === 'Linux'){
packfolder = '../' + packfolder;
}
console.log(env.home(packfolder));
const pack = sys.spawn([env.home(packfolder), "src/", "build/resource.dat", "-binary"]);
const spawn = await pack.wait();
if (spawn.exitCode != 0) throw `packfolder: failed to produce build/resource.dat file, status=${spawn.exitCode}`;
const platforms = {
windows: __DIR__ + "/sdk/bin/windows/x64/scapp.exe",
linux: __DIR__ + "/sdk/bin/linux/x64/scapp",
macosx: __DIR__ + "/sdk/bin/macosx/scapp",
}
for(var platform of Object.keys(platforms)){
const path = "build/" + platform;
if (!sys.fs.$stat("build/" + platform)){
if (!sys.fs.$mkdir("build/" + platform)) throw "mkdir: cannot create dir:" + path;
}
let info = null;
if(platform === 'windows'){
info = {
icofile: __DIR__ + "main/res/QwikTape.ico",
productName: 'QwikTape',
productVersion: "v0.7",
productDescription: "Write Calculate Annotate",
productCopyright: "Copyright (C) 2022 Viral Ghelani @4silvertooth",
productCompany: "TechViral",
}
}
const build = Window.this.scapp.assembleExe(
platforms[platform],
"build/resource.dat",
path + "/" + output + (platform === 'windows' ? '.exe' : ''),
info
);
if(platform === 'macosx'){
makeAppleBundle(path + "/" + output, {
exe: output,
out: path,
productVersion: "v0.7",
})
}
console.log(platform, path, build);
}
env.launch(URL.toPath(__DIR__+"build/"));
})
document.on("click", "button#screenshot", async (evt, el)=>{
const screenshot = new Graphics.Image(app);
const buffer = screenshot.toBytes('png', 90);
const path = URL.toPath(__DIR__ + "build/main-screen.png");
saveAndLaunch(path, buffer);
})
document.on("click", "button#inspector", async function() {
const SUFFIX = {Windows: ".exe", OSX: ".app"};
const PREFIX = {Windows: "\\", OSX: "/../../../"};
const inspectorPath = env.home((PREFIX[env.PLATFORM] || "") + "inspector" + (SUFFIX[env.PLATFORM] || ""));
try {
await sys.fs.stat(inspectorPath);
env.launch(inspectorPath);
}
catch (error) {
Window.modal(<alert>Cannot find {inspectorPath}</alert>);
}
});
document.on("click", "button#help", function() {
const url = URL.fromPath(env.home("../../../samples.sciter/applications.quark/mdview/main.htm"));
let w = new Window({
url: url,
parameters: { folder: env.home("../../../docs/md") },
state: Window.WINDOW_HIDDEN
});
if(!w)
Window.this.modal(<alert>Error launching {url}</alert>);
});
</script>
</head>
<body>
<frame src="src/main.htm"/>
<div#log>
<button|checkbox#generate>View Parse</button>
<plaintext id='tree'/>
</div>
<div#controls>
<button#diagram>Diagram</button>
<button#refresh>Refresh</button>
<button#tests>Tests</button>
<button#screenshot>Screen Shot</button>
<button#build>Build</button>
<button#inspector>Inspector</button>
<button#help>Help</button>
<div>
</body>
</html>