xplorajs 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +1 -1
- package/dist/commands/build.js +47 -295
- package/dist/commands/dev.js +107 -383
- package/dist/commands/start.js +8 -137
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import { Command } from "commander";
|
|
|
3
3
|
import { build } from "./commands/build";
|
|
4
4
|
import { dev } from "./commands/dev";
|
|
5
5
|
import { start } from "./commands/start";
|
|
6
|
-
|
|
6
|
+
const program = new Command();
|
|
7
7
|
program.name("xplorajs").description("Xplora.js CLI tool").version("0.0.0");
|
|
8
8
|
program.command("dev").description("Start development server").action(dev);
|
|
9
9
|
program.command("build").description("Build for production").action(build);
|
package/dist/commands/build.js
CHANGED
|
@@ -1,309 +1,61 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] & 5) throw op[1];
|
|
115
|
-
return {
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
1
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
122
2
|
import { join } from "node:path";
|
|
123
3
|
import { glob } from "fast-glob";
|
|
124
4
|
import React from "react";
|
|
125
5
|
import { generateStaticPage } from "xplorajs-react";
|
|
126
6
|
function convertToRoute(filePath) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
return param.slice(1, -1);
|
|
131
|
-
});
|
|
7
|
+
const relativePath = filePath.replace("src/app/", "");
|
|
8
|
+
const path = relativePath.replace(/\.tsx$/, "").replace(/\/page$/, "").replace(/\[([^\]]+)\]/g, ":$1");
|
|
9
|
+
const params = (relativePath.match(/\[([^\]]+)\]/g) || []).map((param)=>param.slice(1, -1));
|
|
132
10
|
return {
|
|
133
|
-
path: path === "page" ? "/" :
|
|
11
|
+
path: path === "page" ? "/" : `/${path}`,
|
|
134
12
|
file: filePath,
|
|
135
13
|
isDynamic: params.length > 0,
|
|
136
|
-
params
|
|
14
|
+
params
|
|
137
15
|
};
|
|
138
16
|
}
|
|
139
|
-
function processPage(page, route) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
];
|
|
155
|
-
case 1:
|
|
156
|
-
module = _state.sent();
|
|
157
|
-
PageComponent = module.default;
|
|
158
|
-
getStaticProps = module.getStaticProps;
|
|
159
|
-
props = {};
|
|
160
|
-
if (!getStaticProps) return [
|
|
161
|
-
3,
|
|
162
|
-
3
|
|
163
|
-
];
|
|
164
|
-
return [
|
|
165
|
-
4,
|
|
166
|
-
getStaticProps()
|
|
167
|
-
];
|
|
168
|
-
case 2:
|
|
169
|
-
result = _state.sent();
|
|
170
|
-
props = result.props;
|
|
171
|
-
_state.label = 3;
|
|
172
|
-
case 3:
|
|
173
|
-
outputPath = join(process.cwd(), "dist", route.path, "index.html");
|
|
174
|
-
return [
|
|
175
|
-
4,
|
|
176
|
-
generateStaticPage({
|
|
177
|
-
component: React.createElement(PageComponent, props),
|
|
178
|
-
outputPath: outputPath,
|
|
179
|
-
props: props
|
|
180
|
-
})
|
|
181
|
-
];
|
|
182
|
-
case 4:
|
|
183
|
-
_state.sent();
|
|
184
|
-
console.log("Generated ".concat(outputPath));
|
|
185
|
-
return [
|
|
186
|
-
3,
|
|
187
|
-
6
|
|
188
|
-
];
|
|
189
|
-
case 5:
|
|
190
|
-
error = _state.sent();
|
|
191
|
-
console.error("Error processing ".concat(page, ":"), error);
|
|
192
|
-
return [
|
|
193
|
-
3,
|
|
194
|
-
6
|
|
195
|
-
];
|
|
196
|
-
case 6:
|
|
197
|
-
return [
|
|
198
|
-
2
|
|
199
|
-
];
|
|
200
|
-
}
|
|
17
|
+
async function processPage(page, route) {
|
|
18
|
+
try {
|
|
19
|
+
const module = await import(join(process.cwd(), page));
|
|
20
|
+
const PageComponent = module.default;
|
|
21
|
+
const getStaticProps = module.getStaticProps;
|
|
22
|
+
let props = {};
|
|
23
|
+
if (getStaticProps) {
|
|
24
|
+
const result = await getStaticProps();
|
|
25
|
+
props = result.props;
|
|
26
|
+
}
|
|
27
|
+
const outputPath = join(process.cwd(), "dist", route.path, "index.html");
|
|
28
|
+
await generateStaticPage({
|
|
29
|
+
component: React.createElement(PageComponent, props),
|
|
30
|
+
outputPath,
|
|
31
|
+
props
|
|
201
32
|
});
|
|
202
|
-
|
|
33
|
+
console.log(`Generated ${outputPath}`);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(`Error processing ${page}:`, error);
|
|
36
|
+
}
|
|
203
37
|
}
|
|
204
|
-
export function build() {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
case 2:
|
|
228
|
-
pages = _state.sent();
|
|
229
|
-
routes = [];
|
|
230
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
231
|
-
_state.label = 3;
|
|
232
|
-
case 3:
|
|
233
|
-
_state.trys.push([
|
|
234
|
-
3,
|
|
235
|
-
8,
|
|
236
|
-
9,
|
|
237
|
-
10
|
|
238
|
-
]);
|
|
239
|
-
_iterator = pages[Symbol.iterator]();
|
|
240
|
-
_state.label = 4;
|
|
241
|
-
case 4:
|
|
242
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
243
|
-
3,
|
|
244
|
-
7
|
|
245
|
-
];
|
|
246
|
-
page = _step.value;
|
|
247
|
-
route = convertToRoute(page);
|
|
248
|
-
routes.push(route);
|
|
249
|
-
return [
|
|
250
|
-
4,
|
|
251
|
-
processPage(page, route)
|
|
252
|
-
];
|
|
253
|
-
case 5:
|
|
254
|
-
_state.sent();
|
|
255
|
-
_state.label = 6;
|
|
256
|
-
case 6:
|
|
257
|
-
_iteratorNormalCompletion = true;
|
|
258
|
-
return [
|
|
259
|
-
3,
|
|
260
|
-
4
|
|
261
|
-
];
|
|
262
|
-
case 7:
|
|
263
|
-
return [
|
|
264
|
-
3,
|
|
265
|
-
10
|
|
266
|
-
];
|
|
267
|
-
case 8:
|
|
268
|
-
err = _state.sent();
|
|
269
|
-
_didIteratorError = true;
|
|
270
|
-
_iteratorError = err;
|
|
271
|
-
return [
|
|
272
|
-
3,
|
|
273
|
-
10
|
|
274
|
-
];
|
|
275
|
-
case 9:
|
|
276
|
-
try {
|
|
277
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
278
|
-
_iterator.return();
|
|
279
|
-
}
|
|
280
|
-
} finally{
|
|
281
|
-
if (_didIteratorError) {
|
|
282
|
-
throw _iteratorError;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return [
|
|
286
|
-
7
|
|
287
|
-
];
|
|
288
|
-
case 10:
|
|
289
|
-
routesConfig = {
|
|
290
|
-
routes: routes,
|
|
291
|
-
generatedAt: new Date().toISOString()
|
|
292
|
-
};
|
|
293
|
-
return [
|
|
294
|
-
4,
|
|
295
|
-
writeFile(join(process.cwd(), ".xplora", "routes.json"), JSON.stringify(routesConfig, null, 2))
|
|
296
|
-
];
|
|
297
|
-
case 11:
|
|
298
|
-
_state.sent();
|
|
299
|
-
console.log("Build completed!");
|
|
300
|
-
console.log("Routes:", routes.map(function(r) {
|
|
301
|
-
return r.path;
|
|
302
|
-
}).join("\n"));
|
|
303
|
-
return [
|
|
304
|
-
2
|
|
305
|
-
];
|
|
306
|
-
}
|
|
307
|
-
});
|
|
308
|
-
})();
|
|
38
|
+
export async function build() {
|
|
39
|
+
console.log("Building application...");
|
|
40
|
+
await mkdir(join(process.cwd(), "dist"), {
|
|
41
|
+
recursive: true
|
|
42
|
+
});
|
|
43
|
+
const pages = await glob("src/app/**/*.tsx", {
|
|
44
|
+
ignore: [
|
|
45
|
+
"**/node_modules/**"
|
|
46
|
+
]
|
|
47
|
+
});
|
|
48
|
+
const routes = [];
|
|
49
|
+
for (const page of pages){
|
|
50
|
+
const route = convertToRoute(page);
|
|
51
|
+
routes.push(route);
|
|
52
|
+
await processPage(page, route);
|
|
53
|
+
}
|
|
54
|
+
const routesConfig = {
|
|
55
|
+
routes,
|
|
56
|
+
generatedAt: new Date().toISOString()
|
|
57
|
+
};
|
|
58
|
+
await writeFile(join(process.cwd(), ".xplora", "routes.json"), JSON.stringify(routesConfig, null, 2));
|
|
59
|
+
console.log("Build completed!");
|
|
60
|
+
console.log("Routes:", routes.map((r)=>r.path).join("\n"));
|
|
309
61
|
}
|
package/dist/commands/dev.js
CHANGED
|
@@ -1,123 +1,3 @@
|
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
2
|
-
try {
|
|
3
|
-
var info = gen[key](arg);
|
|
4
|
-
var value = info.value;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
reject(error);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
113
|
-
}
|
|
114
|
-
if (op[0] & 5) throw op[1];
|
|
115
|
-
return {
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
1
|
import { readFileSync } from "node:fs";
|
|
122
2
|
import { join } from "node:path";
|
|
123
3
|
import { serve } from "bun";
|
|
@@ -126,270 +6,114 @@ import React from "react";
|
|
|
126
6
|
import { WebSocketServer } from "ws";
|
|
127
7
|
import { renderToStream } from "xplora-react";
|
|
128
8
|
import { build } from "./build";
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return [
|
|
139
|
-
4,
|
|
140
|
-
loadRoutes()
|
|
141
|
-
];
|
|
142
|
-
case 1:
|
|
143
|
-
routes = _state.sent();
|
|
144
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
145
|
-
_state.label = 2;
|
|
146
|
-
case 2:
|
|
147
|
-
_state.trys.push([
|
|
148
|
-
2,
|
|
149
|
-
7,
|
|
150
|
-
8,
|
|
151
|
-
9
|
|
152
|
-
]);
|
|
153
|
-
_iterator = routes[Symbol.iterator]();
|
|
154
|
-
_state.label = 3;
|
|
155
|
-
case 3:
|
|
156
|
-
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done)) return [
|
|
157
|
-
3,
|
|
158
|
-
6
|
|
159
|
-
];
|
|
160
|
-
route = _step.value;
|
|
161
|
-
abs = join(process.cwd(), route.file);
|
|
162
|
-
(_require = import.meta.require) === null || _require === void 0 ? true : (_require_cache = _require.cache) === null || _require_cache === void 0 ? true : delete _require_cache[abs];
|
|
163
|
-
// biome-ignore lint/suspicious/noExplicitAny: <intended>
|
|
164
|
-
_ = pages.set;
|
|
165
|
-
_tmp = [
|
|
166
|
-
route.path
|
|
167
|
-
];
|
|
168
|
-
return [
|
|
169
|
-
4,
|
|
170
|
-
import(abs)
|
|
171
|
-
];
|
|
172
|
-
case 4:
|
|
173
|
-
_.apply(pages, _tmp.concat([
|
|
174
|
-
_state.sent().default
|
|
175
|
-
]));
|
|
176
|
-
_state.label = 5;
|
|
177
|
-
case 5:
|
|
178
|
-
_iteratorNormalCompletion = true;
|
|
179
|
-
return [
|
|
180
|
-
3,
|
|
181
|
-
3
|
|
182
|
-
];
|
|
183
|
-
case 6:
|
|
184
|
-
return [
|
|
185
|
-
3,
|
|
186
|
-
9
|
|
187
|
-
];
|
|
188
|
-
case 7:
|
|
189
|
-
err = _state.sent();
|
|
190
|
-
_didIteratorError = true;
|
|
191
|
-
_iteratorError = err;
|
|
192
|
-
return [
|
|
193
|
-
3,
|
|
194
|
-
9
|
|
195
|
-
];
|
|
196
|
-
case 8:
|
|
197
|
-
try {
|
|
198
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
199
|
-
_iterator.return();
|
|
200
|
-
}
|
|
201
|
-
} finally{
|
|
202
|
-
if (_didIteratorError) {
|
|
203
|
-
throw _iteratorError;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return [
|
|
207
|
-
7
|
|
208
|
-
];
|
|
209
|
-
case 9:
|
|
210
|
-
return [
|
|
211
|
-
2
|
|
212
|
-
];
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
})();
|
|
9
|
+
const pages = new Map();
|
|
10
|
+
async function loadPages() {
|
|
11
|
+
pages.clear();
|
|
12
|
+
const routes = await loadRoutes();
|
|
13
|
+
for (const route of routes){
|
|
14
|
+
const abs = join(process.cwd(), route.file);
|
|
15
|
+
delete import.meta.require?.cache?.[abs];
|
|
16
|
+
pages.set(route.path, (await import(abs)).default);
|
|
17
|
+
}
|
|
216
18
|
}
|
|
217
|
-
function loadRoutes() {
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
2,
|
|
226
|
-
JSON.parse(routesContent).routes
|
|
227
|
-
];
|
|
228
|
-
} catch (e) {
|
|
229
|
-
return [
|
|
230
|
-
2,
|
|
231
|
-
[]
|
|
232
|
-
];
|
|
233
|
-
}
|
|
234
|
-
return [
|
|
235
|
-
2
|
|
236
|
-
];
|
|
237
|
-
});
|
|
238
|
-
})();
|
|
19
|
+
async function loadRoutes() {
|
|
20
|
+
try {
|
|
21
|
+
const routesPath = join(process.cwd(), ".xplora", "routes.json");
|
|
22
|
+
const routesContent = readFileSync(routesPath, "utf-8");
|
|
23
|
+
return JSON.parse(routesContent).routes;
|
|
24
|
+
} catch {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
239
27
|
}
|
|
240
|
-
export function dev() {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
];
|
|
273
|
-
case 2:
|
|
274
|
-
_state.sent();
|
|
275
|
-
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
276
|
-
try {
|
|
277
|
-
for(_iterator = wss.clients[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
278
|
-
client = _step.value;
|
|
279
|
-
if (client.readyState === WebSocket.OPEN) {
|
|
280
|
-
client.send(JSON.stringify({
|
|
281
|
-
type: "reload"
|
|
282
|
-
}));
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
} catch (err) {
|
|
286
|
-
_didIteratorError = true;
|
|
287
|
-
_iteratorError = err;
|
|
288
|
-
} finally{
|
|
289
|
-
try {
|
|
290
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
291
|
-
_iterator.return();
|
|
292
|
-
}
|
|
293
|
-
} finally{
|
|
294
|
-
if (_didIteratorError) {
|
|
295
|
-
throw _iteratorError;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return [
|
|
300
|
-
2
|
|
301
|
-
];
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
})();
|
|
305
|
-
});
|
|
306
|
-
return [
|
|
307
|
-
4,
|
|
308
|
-
build()
|
|
309
|
-
];
|
|
310
|
-
case 1:
|
|
311
|
-
_state.sent();
|
|
312
|
-
return [
|
|
313
|
-
4,
|
|
314
|
-
loadPages()
|
|
315
|
-
];
|
|
316
|
-
case 2:
|
|
317
|
-
_state.sent();
|
|
318
|
-
serve({
|
|
319
|
-
port: 3000,
|
|
320
|
-
fetch: function fetch(req) {
|
|
321
|
-
return _async_to_generator(function() {
|
|
322
|
-
var url, f, Page, stream, head, foot;
|
|
323
|
-
return _ts_generator(this, function(_state) {
|
|
324
|
-
switch(_state.label){
|
|
325
|
-
case 0:
|
|
326
|
-
url = new URL(req.url).pathname;
|
|
327
|
-
if (!url.startsWith("/assets/")) return [
|
|
328
|
-
3,
|
|
329
|
-
2
|
|
330
|
-
];
|
|
331
|
-
f = Bun.file(join(process.cwd(), "dist", url));
|
|
332
|
-
return [
|
|
333
|
-
4,
|
|
334
|
-
f.exists()
|
|
335
|
-
];
|
|
336
|
-
case 1:
|
|
337
|
-
if (_state.sent()) return [
|
|
338
|
-
2,
|
|
339
|
-
new Response(f)
|
|
340
|
-
];
|
|
341
|
-
_state.label = 2;
|
|
342
|
-
case 2:
|
|
343
|
-
Page = pages.get(url);
|
|
344
|
-
if (!Page) return [
|
|
345
|
-
2,
|
|
346
|
-
new Response("Not Found", {
|
|
347
|
-
status: 404
|
|
348
|
-
})
|
|
349
|
-
];
|
|
350
|
-
return [
|
|
351
|
-
4,
|
|
352
|
-
renderToStream(React.createElement(Page))
|
|
353
|
-
];
|
|
354
|
-
case 3:
|
|
355
|
-
stream = _state.sent();
|
|
356
|
-
head = '<!DOCTYPE html><html><head>\n <meta charset="utf-8"/>\n <link rel="stylesheet" href="/assets/style.css"/>\n <script>window.process={env:{NODE_ENV:"development"}};</script>\n </head><body><div id="root">';
|
|
357
|
-
foot = '</div>\n <script type="module">\n import * as RefreshRuntime from "https://esm.sh/react-refresh@0.17.0/runtime";\n if (window.process?.env?.NODE_ENV === "development") {\n console.log("Fast refresh runtime loaded in development mode");\n }\n RefreshRuntime.injectIntoGlobalHook(window);\n window.$RefreshReg$=()=>{};\n window.$RefreshSig$=()=>t=>t;\n </script>\n <script>\n const ws=new WebSocket("ws://localhost:3001");\n ws.onmessage=async e=>{\n if(e.data==="css"){\n document.querySelectorAll(\'link[rel="stylesheet"]\').forEach(l=>l.href="/assets/style.css?v="+Date.now());\n }\n if(e.data==="reload"){\n console.log("Reloading...");\n location.reload();\n }\n };\n </script>\n </body></html>';
|
|
358
|
-
return [
|
|
359
|
-
2,
|
|
360
|
-
new Response(new ReadableStream({
|
|
361
|
-
start: function start(ctrl) {
|
|
362
|
-
ctrl.enqueue(new TextEncoder().encode(head));
|
|
363
|
-
if (typeof stream === "string") {
|
|
364
|
-
ctrl.enqueue(new TextEncoder().encode(stream));
|
|
365
|
-
} else {
|
|
366
|
-
stream.pipeTo(new WritableStream({
|
|
367
|
-
write: function write(c) {
|
|
368
|
-
ctrl.enqueue(c);
|
|
369
|
-
},
|
|
370
|
-
close: function close() {
|
|
371
|
-
ctrl.enqueue(new TextEncoder().encode(foot));
|
|
372
|
-
ctrl.close();
|
|
373
|
-
}
|
|
374
|
-
}));
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}), {
|
|
378
|
-
headers: {
|
|
379
|
-
"Content-Type": "text/html; charset=utf-8"
|
|
380
|
-
}
|
|
381
|
-
})
|
|
382
|
-
];
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
})();
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
console.log("Development server running at http://localhost:3000");
|
|
389
|
-
return [
|
|
390
|
-
2
|
|
391
|
-
];
|
|
28
|
+
export async function dev() {
|
|
29
|
+
console.log("Starting development server...");
|
|
30
|
+
const wss = new WebSocketServer({
|
|
31
|
+
port: 3001
|
|
32
|
+
});
|
|
33
|
+
const watcher = watch([
|
|
34
|
+
"src/**/*"
|
|
35
|
+
], {
|
|
36
|
+
ignored: /(^|[\/\\])\../,
|
|
37
|
+
persistent: true
|
|
38
|
+
});
|
|
39
|
+
watcher.on("change", async (path)=>{
|
|
40
|
+
console.log(`File ${path} has been changed`);
|
|
41
|
+
await build();
|
|
42
|
+
await loadPages();
|
|
43
|
+
for (const client of wss.clients){
|
|
44
|
+
if (client.readyState === WebSocket.OPEN) {
|
|
45
|
+
client.send(JSON.stringify({
|
|
46
|
+
type: "reload"
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
await build();
|
|
52
|
+
await loadPages();
|
|
53
|
+
serve({
|
|
54
|
+
port: 3000,
|
|
55
|
+
async fetch (req) {
|
|
56
|
+
const url = new URL(req.url).pathname;
|
|
57
|
+
if (url.startsWith("/assets/")) {
|
|
58
|
+
const f = Bun.file(join(process.cwd(), "dist", url));
|
|
59
|
+
if (await f.exists()) return new Response(f);
|
|
392
60
|
}
|
|
393
|
-
|
|
394
|
-
|
|
61
|
+
const Page = pages.get(url);
|
|
62
|
+
if (!Page) return new Response("Not Found", {
|
|
63
|
+
status: 404
|
|
64
|
+
});
|
|
65
|
+
const stream = await renderToStream(React.createElement(Page));
|
|
66
|
+
const head = `<!DOCTYPE html><html><head>
|
|
67
|
+
<meta charset="utf-8"/>
|
|
68
|
+
<link rel="stylesheet" href="/assets/style.css"/>
|
|
69
|
+
<script>window.process={env:{NODE_ENV:"development"}};</script>
|
|
70
|
+
</head><body><div id="root">`;
|
|
71
|
+
const foot = `</div>
|
|
72
|
+
<script type="module">
|
|
73
|
+
import * as RefreshRuntime from "https://esm.sh/react-refresh@0.17.0/runtime";
|
|
74
|
+
if (window.process?.env?.NODE_ENV === "development") {
|
|
75
|
+
console.log("Fast refresh runtime loaded in development mode");
|
|
76
|
+
}
|
|
77
|
+
RefreshRuntime.injectIntoGlobalHook(window);
|
|
78
|
+
window.$RefreshReg$=()=>{};
|
|
79
|
+
window.$RefreshSig$=()=>t=>t;
|
|
80
|
+
</script>
|
|
81
|
+
<script>
|
|
82
|
+
const ws=new WebSocket("ws://localhost:3001");
|
|
83
|
+
ws.onmessage=async e=>{
|
|
84
|
+
if(e.data==="css"){
|
|
85
|
+
document.querySelectorAll('link[rel="stylesheet"]').forEach(l=>l.href="/assets/style.css?v="+Date.now());
|
|
86
|
+
}
|
|
87
|
+
if(e.data==="reload"){
|
|
88
|
+
console.log("Reloading...");
|
|
89
|
+
location.reload();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
</script>
|
|
93
|
+
</body></html>`;
|
|
94
|
+
return new Response(new ReadableStream({
|
|
95
|
+
start (ctrl) {
|
|
96
|
+
ctrl.enqueue(new TextEncoder().encode(head));
|
|
97
|
+
if (typeof stream === "string") {
|
|
98
|
+
ctrl.enqueue(new TextEncoder().encode(stream));
|
|
99
|
+
} else {
|
|
100
|
+
stream.pipeTo(new WritableStream({
|
|
101
|
+
write (c) {
|
|
102
|
+
ctrl.enqueue(c);
|
|
103
|
+
},
|
|
104
|
+
close () {
|
|
105
|
+
ctrl.enqueue(new TextEncoder().encode(foot));
|
|
106
|
+
ctrl.close();
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}), {
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "text/html; charset=utf-8"
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
console.log("Development server running at http://localhost:3000");
|
|
395
119
|
}
|
package/dist/commands/start.js
CHANGED
|
@@ -1,139 +1,10 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
if (info.done) {
|
|
10
|
-
resolve(value);
|
|
11
|
-
} else {
|
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
function _async_to_generator(fn) {
|
|
16
|
-
return function() {
|
|
17
|
-
var self = this, args = arguments;
|
|
18
|
-
return new Promise(function(resolve, reject) {
|
|
19
|
-
var gen = fn.apply(self, args);
|
|
20
|
-
function _next(value) {
|
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
22
|
-
}
|
|
23
|
-
function _throw(err) {
|
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
25
|
-
}
|
|
26
|
-
_next(undefined);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
function _ts_generator(thisArg, body) {
|
|
31
|
-
var f, y, t, _ = {
|
|
32
|
-
label: 0,
|
|
33
|
-
sent: function() {
|
|
34
|
-
if (t[0] & 1) throw t[1];
|
|
35
|
-
return t[1];
|
|
36
|
-
},
|
|
37
|
-
trys: [],
|
|
38
|
-
ops: []
|
|
39
|
-
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
40
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
41
|
-
return this;
|
|
42
|
-
}), g;
|
|
43
|
-
function verb(n) {
|
|
44
|
-
return function(v) {
|
|
45
|
-
return step([
|
|
46
|
-
n,
|
|
47
|
-
v
|
|
48
|
-
]);
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function step(op) {
|
|
52
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
53
|
-
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
54
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
55
|
-
if (y = 0, t) op = [
|
|
56
|
-
op[0] & 2,
|
|
57
|
-
t.value
|
|
58
|
-
];
|
|
59
|
-
switch(op[0]){
|
|
60
|
-
case 0:
|
|
61
|
-
case 1:
|
|
62
|
-
t = op;
|
|
63
|
-
break;
|
|
64
|
-
case 4:
|
|
65
|
-
_.label++;
|
|
66
|
-
return {
|
|
67
|
-
value: op[1],
|
|
68
|
-
done: false
|
|
69
|
-
};
|
|
70
|
-
case 5:
|
|
71
|
-
_.label++;
|
|
72
|
-
y = op[1];
|
|
73
|
-
op = [
|
|
74
|
-
0
|
|
75
|
-
];
|
|
76
|
-
continue;
|
|
77
|
-
case 7:
|
|
78
|
-
op = _.ops.pop();
|
|
79
|
-
_.trys.pop();
|
|
80
|
-
continue;
|
|
81
|
-
default:
|
|
82
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
83
|
-
_ = 0;
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
87
|
-
_.label = op[1];
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
if (op[0] === 6 && _.label < t[1]) {
|
|
91
|
-
_.label = t[1];
|
|
92
|
-
t = op;
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
if (t && _.label < t[2]) {
|
|
96
|
-
_.label = t[2];
|
|
97
|
-
_.ops.push(op);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
if (t[2]) _.ops.pop();
|
|
101
|
-
_.trys.pop();
|
|
102
|
-
continue;
|
|
103
|
-
}
|
|
104
|
-
op = body.call(thisArg, _);
|
|
105
|
-
} catch (e) {
|
|
106
|
-
op = [
|
|
107
|
-
6,
|
|
108
|
-
e
|
|
109
|
-
];
|
|
110
|
-
y = 0;
|
|
111
|
-
} finally{
|
|
112
|
-
f = t = 0;
|
|
1
|
+
export async function start() {
|
|
2
|
+
console.log("Starting production server...");
|
|
3
|
+
const server = Bun.serve({
|
|
4
|
+
port: 3000,
|
|
5
|
+
fetch (req) {
|
|
6
|
+
return new Response("Production server running...");
|
|
113
7
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
value: op[0] ? op[1] : void 0,
|
|
117
|
-
done: true
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export function start() {
|
|
122
|
-
return _async_to_generator(function() {
|
|
123
|
-
var server;
|
|
124
|
-
return _ts_generator(this, function(_state) {
|
|
125
|
-
console.log("Starting production server...");
|
|
126
|
-
server = Bun.serve({
|
|
127
|
-
port: 3000,
|
|
128
|
-
fetch: function fetch(req) {
|
|
129
|
-
// TODO: Implement production server logic
|
|
130
|
-
return new Response("Production server running...");
|
|
131
|
-
}
|
|
132
|
-
});
|
|
133
|
-
console.log("Production server running at http://localhost:".concat(server.port));
|
|
134
|
-
return [
|
|
135
|
-
2
|
|
136
|
-
];
|
|
137
|
-
});
|
|
138
|
-
})();
|
|
8
|
+
});
|
|
9
|
+
console.log(`Production server running at http://localhost:${server.port}`);
|
|
139
10
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xplorajs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
16
|
"dev": "bun run build --watch",
|
|
17
|
-
"build": "swc src -d dist",
|
|
17
|
+
"build": "swc src -d dist --config-file .swcrc",
|
|
18
18
|
"prepublishOnly": "bun run build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|