xpine 0.0.26 → 0.0.28
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/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +299 -111
- package/dist/src/build/esbuild/transformTSXFiles.d.ts.map +1 -1
- package/dist/src/build/typescript-builder.d.ts +7 -0
- package/dist/src/build/typescript-builder.d.ts.map +1 -1
- package/dist/src/context.d.ts +18 -0
- package/dist/src/context.d.ts.map +1 -0
- package/dist/src/express.d.ts.map +1 -1
- package/dist/src/scripts/build.d.ts +13 -2
- package/dist/src/scripts/build.d.ts.map +1 -1
- package/dist/src/scripts/xpine-build.js +273 -111
- package/dist/src/scripts/xpine-dev.js +258 -97
- package/dist/src/util/hooks/onInit.d.ts +3 -0
- package/dist/src/util/hooks/onInit.d.ts.map +1 -0
- package/dist/src/util/paths.d.ts +2 -0
- package/dist/src/util/paths.d.ts.map +1 -0
- package/dist/src/util/require.d.ts +0 -1
- package/dist/src/util/require.d.ts.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -1
- package/types.ts +3 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,12 +9,146 @@ import chokidar from "chokidar";
|
|
|
9
9
|
import path5 from "path";
|
|
10
10
|
import fs5 from "fs-extra";
|
|
11
11
|
import { build } from "esbuild";
|
|
12
|
-
import ts3 from "typescript";
|
|
13
12
|
|
|
14
13
|
// src/build/typescript-builder.ts
|
|
15
14
|
import ts from "typescript";
|
|
16
15
|
import fs from "fs-extra";
|
|
16
|
+
import path2 from "path";
|
|
17
|
+
|
|
18
|
+
// src/util/get-config.ts
|
|
17
19
|
import path from "path";
|
|
20
|
+
|
|
21
|
+
// src/util/require.ts
|
|
22
|
+
import { createRequire } from "module";
|
|
23
|
+
var require_default = createRequire(import.meta.url);
|
|
24
|
+
|
|
25
|
+
// src/util/get-config.ts
|
|
26
|
+
var rootDir = process.cwd();
|
|
27
|
+
function fromRoot(pathName) {
|
|
28
|
+
if (!pathName) return rootDir;
|
|
29
|
+
return path.join(rootDir, pathName);
|
|
30
|
+
}
|
|
31
|
+
var userConfig = require_default(path.join(process.cwd(), "./xpine.config.mjs")).default;
|
|
32
|
+
var configDefaults = {
|
|
33
|
+
rootDir: fromRoot(),
|
|
34
|
+
srcDir: fromRoot("./src"),
|
|
35
|
+
distDir: fromRoot("./dist"),
|
|
36
|
+
packageJsonPath: fromRoot("package.json"),
|
|
37
|
+
// We need to use getters here in the event someone wants to change folders, such as the dist folder
|
|
38
|
+
get distPublicDir() {
|
|
39
|
+
return path.join(this.distDir, "./public");
|
|
40
|
+
},
|
|
41
|
+
get distPublicScriptsDir() {
|
|
42
|
+
return path.join(this.distPublicDir, "./scripts");
|
|
43
|
+
},
|
|
44
|
+
get distTempFolder() {
|
|
45
|
+
return path.join(this.distDir, "./temp");
|
|
46
|
+
},
|
|
47
|
+
get clientJSBundlePath() {
|
|
48
|
+
return path.join(this.distPublicScriptsDir, "./app.js");
|
|
49
|
+
},
|
|
50
|
+
get alpineDataPath() {
|
|
51
|
+
return path.join(this.distTempFolder, "./alpine-data.ts");
|
|
52
|
+
},
|
|
53
|
+
get serverDistDir() {
|
|
54
|
+
return path.join(this.distDir, "./server");
|
|
55
|
+
},
|
|
56
|
+
get serverDistAppPath() {
|
|
57
|
+
return path.join(this.serverDistDir, "./app.js");
|
|
58
|
+
},
|
|
59
|
+
// Important dirs/paths
|
|
60
|
+
get pagesDir() {
|
|
61
|
+
return path.join(this.srcDir, "./pages");
|
|
62
|
+
},
|
|
63
|
+
get distPagesDir() {
|
|
64
|
+
return path.join(this.distDir, "./pages");
|
|
65
|
+
},
|
|
66
|
+
get publicDir() {
|
|
67
|
+
return path.join(this.srcDir, "./public");
|
|
68
|
+
},
|
|
69
|
+
get serverDir() {
|
|
70
|
+
return path.join(this.srcDir, "./server");
|
|
71
|
+
},
|
|
72
|
+
get runDir() {
|
|
73
|
+
return path.join(this.serverDir, "./run");
|
|
74
|
+
},
|
|
75
|
+
get serverAppPath() {
|
|
76
|
+
return path.join(this.serverDir, "./app.ts");
|
|
77
|
+
},
|
|
78
|
+
get globalCSSFile() {
|
|
79
|
+
return path.join(this.publicDir, "./styles/global.css");
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
var config = {
|
|
83
|
+
...configDefaults,
|
|
84
|
+
...userConfig
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/context.ts
|
|
88
|
+
function createContext(value) {
|
|
89
|
+
let stateValue = value;
|
|
90
|
+
let arrayQueue = {};
|
|
91
|
+
return {
|
|
92
|
+
get(id) {
|
|
93
|
+
const val = stateValue[id];
|
|
94
|
+
if (Array.isArray(val)) return val.filter((item) => item !== void 0);
|
|
95
|
+
return val;
|
|
96
|
+
},
|
|
97
|
+
set(id, callback, defaultValue) {
|
|
98
|
+
if (!stateValue[id]) stateValue[id] = defaultValue ?? null;
|
|
99
|
+
stateValue[id] = callback(stateValue[id]);
|
|
100
|
+
},
|
|
101
|
+
clear() {
|
|
102
|
+
stateValue = {};
|
|
103
|
+
},
|
|
104
|
+
getAll() {
|
|
105
|
+
return stateValue;
|
|
106
|
+
},
|
|
107
|
+
getArrayQueue() {
|
|
108
|
+
return arrayQueue;
|
|
109
|
+
},
|
|
110
|
+
addToArray(id, value2, position) {
|
|
111
|
+
const output = {
|
|
112
|
+
id,
|
|
113
|
+
value: addToContextArray(value2, position),
|
|
114
|
+
position
|
|
115
|
+
};
|
|
116
|
+
if (!arrayQueue[id]) {
|
|
117
|
+
arrayQueue[id] = [output];
|
|
118
|
+
} else {
|
|
119
|
+
arrayQueue[id].push(output);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
runArrayQueue() {
|
|
123
|
+
Object.keys(arrayQueue).forEach((key) => {
|
|
124
|
+
arrayQueue[key].sort((a, b) => {
|
|
125
|
+
return (a?.position ?? Infinity) - (b.position ?? Infinity);
|
|
126
|
+
});
|
|
127
|
+
for (const item of arrayQueue[key]) {
|
|
128
|
+
this.set(key, item.value, []);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
arrayQueue = {};
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
var context = createContext({});
|
|
136
|
+
function addToContextArray(newValue, position) {
|
|
137
|
+
return function(currentValue) {
|
|
138
|
+
if (!currentValue) return [newValue];
|
|
139
|
+
if (typeof position === "number") {
|
|
140
|
+
if (position > currentValue?.length) {
|
|
141
|
+
const output = [...currentValue, ...new Array(position + 1 - currentValue.length)];
|
|
142
|
+
return output.toSpliced(position, 0, newValue);
|
|
143
|
+
}
|
|
144
|
+
if (currentValue?.[position] === void 0) return currentValue.toSpliced(position, 1, newValue);
|
|
145
|
+
return currentValue.toSpliced(position, 0, newValue);
|
|
146
|
+
}
|
|
147
|
+
return [...currentValue, newValue];
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/build/typescript-builder.ts
|
|
18
152
|
function findDataAttributesAndFunctions(node, sourceFile, foundDataAttributes = [], foundFunctions = []) {
|
|
19
153
|
if (node.kind === ts.SyntaxKind.JsxAttribute) {
|
|
20
154
|
const attribute = getAttributeValuePair(node, sourceFile);
|
|
@@ -86,18 +220,7 @@ function removeClientScriptInTSXFile(pathName, source) {
|
|
|
86
220
|
}
|
|
87
221
|
if (child.kind === ts.SyntaxKind.ImportDeclaration && child.pos >= clientDataStart) {
|
|
88
222
|
const text = child.getText(source);
|
|
89
|
-
|
|
90
|
-
if (child2.kind === ts.SyntaxKind.StringLiteral) {
|
|
91
|
-
const text2 = child2.getText(source);
|
|
92
|
-
const importPath = text2.replace(/[\"\']/g, "");
|
|
93
|
-
const isRelativeImport = importPath.startsWith(".") || importPath.startsWith("/");
|
|
94
|
-
if (!isRelativeImport) return;
|
|
95
|
-
clientImportsToReplace.push({
|
|
96
|
-
old: importPath,
|
|
97
|
-
new: path.join(path.dirname(pathName), importPath)
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
});
|
|
223
|
+
clientImportsToReplace.push(...getImportsToAbsolutePaths(child, source, pathName));
|
|
101
224
|
clientImportsToHoist.push(text);
|
|
102
225
|
}
|
|
103
226
|
});
|
|
@@ -113,18 +236,58 @@ function removeClientScriptInTSXFile(pathName, source) {
|
|
|
113
236
|
clientDataStart
|
|
114
237
|
};
|
|
115
238
|
}
|
|
239
|
+
function getImportsToAbsolutePaths(child, source, pathName) {
|
|
240
|
+
const output = [];
|
|
241
|
+
child.forEachChild((child2) => {
|
|
242
|
+
if (child2.kind === ts.SyntaxKind.StringLiteral) {
|
|
243
|
+
const text = child2.getText(source);
|
|
244
|
+
const importPath = text.replace(/[\"\']/g, "");
|
|
245
|
+
const isRelativeImport = importPath.startsWith(".") || importPath.startsWith("/");
|
|
246
|
+
if (!isRelativeImport) return;
|
|
247
|
+
output.push({
|
|
248
|
+
old: importPath,
|
|
249
|
+
new: path2.join(path2.dirname(pathName), importPath)
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return output;
|
|
254
|
+
}
|
|
255
|
+
function getXpineOnLoadFunction(pathName, source, onLoadFileResult) {
|
|
256
|
+
const value = {
|
|
257
|
+
imports: "",
|
|
258
|
+
fn: ""
|
|
259
|
+
};
|
|
260
|
+
source.forEachChild((child) => {
|
|
261
|
+
if (child.kind == ts.SyntaxKind.ImportDeclaration) {
|
|
262
|
+
let importText = child.getText(source);
|
|
263
|
+
const importOutput = getImportsToAbsolutePaths(child, source, pathName);
|
|
264
|
+
for (const importItem of importOutput) {
|
|
265
|
+
importText = importText.replace(importItem.old, importItem.new);
|
|
266
|
+
}
|
|
267
|
+
value.imports = importText + "\n" + value.imports;
|
|
268
|
+
}
|
|
269
|
+
if ([ts.SyntaxKind.FirstStatement, ts.SyntaxKind.FunctionDeclaration].includes(child.kind)) {
|
|
270
|
+
let text = child.getText(source);
|
|
271
|
+
if (text.includes("xpineOnLoad")) {
|
|
272
|
+
const body = child?.body?.getText(source) || "";
|
|
273
|
+
value.fn = value.fn + "\n" + body ? `(function() ${body})();` : "";
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
return value;
|
|
278
|
+
}
|
|
279
|
+
async function triggerXPineOnLoad(noCache = false) {
|
|
280
|
+
context.clear();
|
|
281
|
+
const xpineOnLoad = (await import(path2.join(config.distDir, `./__xpineOnLoad.js${noCache ? `?cache=${Date.now()}` : ""}`)))?.default;
|
|
282
|
+
if (xpineOnLoad) await xpineOnLoad();
|
|
283
|
+
}
|
|
116
284
|
|
|
117
285
|
// src/scripts/build.ts
|
|
118
286
|
import { globSync } from "glob";
|
|
119
287
|
import postcss from "postcss";
|
|
120
288
|
import tailwindPostcss from "@tailwindcss/postcss";
|
|
121
289
|
|
|
122
|
-
// src/util/
|
|
123
|
-
import path2 from "path";
|
|
124
|
-
|
|
125
|
-
// src/util/require.ts
|
|
126
|
-
import { createRequire } from "module";
|
|
127
|
-
var require_default = createRequire(import.meta.url);
|
|
290
|
+
// src/util/paths.ts
|
|
128
291
|
function getXPineDistDir() {
|
|
129
292
|
const dir = import.meta.dirname;
|
|
130
293
|
const splitDir = dir.split("/xpine/dist");
|
|
@@ -135,68 +298,6 @@ function getXPineDistDir() {
|
|
|
135
298
|
return splitDir[0] + "/xpine/dist";
|
|
136
299
|
}
|
|
137
300
|
|
|
138
|
-
// src/util/get-config.ts
|
|
139
|
-
var rootDir = process.cwd();
|
|
140
|
-
function fromRoot(pathName) {
|
|
141
|
-
if (!pathName) return rootDir;
|
|
142
|
-
return path2.join(rootDir, pathName);
|
|
143
|
-
}
|
|
144
|
-
var userConfig = require_default(path2.join(process.cwd(), "./xpine.config.mjs")).default;
|
|
145
|
-
var configDefaults = {
|
|
146
|
-
rootDir: fromRoot(),
|
|
147
|
-
srcDir: fromRoot("./src"),
|
|
148
|
-
distDir: fromRoot("./dist"),
|
|
149
|
-
packageJsonPath: fromRoot("package.json"),
|
|
150
|
-
// We need to use getters here in the event someone wants to change folders, such as the dist folder
|
|
151
|
-
get distPublicDir() {
|
|
152
|
-
return path2.join(this.distDir, "./public");
|
|
153
|
-
},
|
|
154
|
-
get distPublicScriptsDir() {
|
|
155
|
-
return path2.join(this.distPublicDir, "./scripts");
|
|
156
|
-
},
|
|
157
|
-
get distTempFolder() {
|
|
158
|
-
return path2.join(this.distDir, "./temp");
|
|
159
|
-
},
|
|
160
|
-
get clientJSBundlePath() {
|
|
161
|
-
return path2.join(this.distPublicScriptsDir, "./app.js");
|
|
162
|
-
},
|
|
163
|
-
get alpineDataPath() {
|
|
164
|
-
return path2.join(this.distTempFolder, "./alpine-data.ts");
|
|
165
|
-
},
|
|
166
|
-
get serverDistDir() {
|
|
167
|
-
return path2.join(this.distDir, "./server");
|
|
168
|
-
},
|
|
169
|
-
get serverDistAppPath() {
|
|
170
|
-
return path2.join(this.serverDistDir, "./app.js");
|
|
171
|
-
},
|
|
172
|
-
// Important dirs/paths
|
|
173
|
-
get pagesDir() {
|
|
174
|
-
return path2.join(this.srcDir, "./pages");
|
|
175
|
-
},
|
|
176
|
-
get distPagesDir() {
|
|
177
|
-
return path2.join(this.distDir, "./pages");
|
|
178
|
-
},
|
|
179
|
-
get publicDir() {
|
|
180
|
-
return path2.join(this.srcDir, "./public");
|
|
181
|
-
},
|
|
182
|
-
get serverDir() {
|
|
183
|
-
return path2.join(this.srcDir, "./server");
|
|
184
|
-
},
|
|
185
|
-
get runDir() {
|
|
186
|
-
return path2.join(this.serverDir, "./run");
|
|
187
|
-
},
|
|
188
|
-
get serverAppPath() {
|
|
189
|
-
return path2.join(this.serverDir, "./app.ts");
|
|
190
|
-
},
|
|
191
|
-
get globalCSSFile() {
|
|
192
|
-
return path2.join(this.publicDir, "./styles/global.css");
|
|
193
|
-
}
|
|
194
|
-
};
|
|
195
|
-
var config = {
|
|
196
|
-
...configDefaults,
|
|
197
|
-
...userConfig
|
|
198
|
-
};
|
|
199
|
-
|
|
200
301
|
// src/util/postcss/remove-layers.ts
|
|
201
302
|
var plugin = (opts = {}) => {
|
|
202
303
|
return {
|
|
@@ -270,13 +371,16 @@ function transformTSXFiles(componentData, pageConfigFiles) {
|
|
|
270
371
|
ts2.ScriptTarget.Latest
|
|
271
372
|
);
|
|
272
373
|
const cleanedContent = removeClientScriptInTSXFile(args.path, source);
|
|
273
|
-
const htmlImportStart =
|
|
274
|
-
|
|
374
|
+
const htmlImportStart = [
|
|
375
|
+
"import { html } from 'xpine';"
|
|
376
|
+
];
|
|
377
|
+
const newContent = `${htmlImportStart.join("\n")}${cleanedContent.content}`;
|
|
275
378
|
componentData.push({
|
|
276
379
|
...args,
|
|
277
380
|
contents: `${htmlImportStart}${cleanedContent.fullContent}`,
|
|
278
381
|
clientContent: cleanedContent.clientContent,
|
|
279
|
-
configFiles: isAConfigFile(args?.path) ? null : getConfigFiles(args.path, pageConfigFiles)
|
|
382
|
+
configFiles: isAConfigFile(args?.path) ? null : getConfigFiles(args.path, pageConfigFiles),
|
|
383
|
+
source
|
|
280
384
|
});
|
|
281
385
|
return {
|
|
282
386
|
contents: newContent,
|
|
@@ -342,11 +446,15 @@ var doctypeHTML = "<!DOCTYPE html>";
|
|
|
342
446
|
var staticComment = "<!-- static -->";
|
|
343
447
|
|
|
344
448
|
// src/scripts/build.ts
|
|
449
|
+
import ts3 from "typescript";
|
|
345
450
|
var extensions = [".ts", ".tsx"];
|
|
346
451
|
var packageJson = JSON.parse(fs5.readFileSync(config.packageJsonPath, "utf-8"));
|
|
347
452
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
348
453
|
var xpineDistDir = getXPineDistDir();
|
|
349
|
-
async function buildApp(
|
|
454
|
+
async function buildApp(args) {
|
|
455
|
+
const isDev = args?.isDev || false;
|
|
456
|
+
const removePreviousBuild = args?.removePreviousBuild || false;
|
|
457
|
+
const disableTailwind = args?.disableTailwind || false;
|
|
350
458
|
try {
|
|
351
459
|
if (removePreviousBuild) fs5.removeSync(config.distDir);
|
|
352
460
|
const srcDirFiles = globSync(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
@@ -354,9 +462,12 @@ async function buildApp(isDev = false, removePreviousBuild = false) {
|
|
|
354
462
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
355
463
|
await buildClientSideFiles([alpineDataFile], isDev);
|
|
356
464
|
fs5.removeSync(config.distTempFolder);
|
|
357
|
-
await buildCSS();
|
|
465
|
+
await buildCSS(disableTailwind);
|
|
358
466
|
await buildPublicFolderSymlinks();
|
|
467
|
+
await buildOnLoadFile(componentData, isDev);
|
|
468
|
+
if (!isDev) await triggerXPineOnLoad();
|
|
359
469
|
if (!isDev) await buildFilesWithConfigs(componentData);
|
|
470
|
+
if (!isDev) context.clear();
|
|
360
471
|
} catch (err) {
|
|
361
472
|
console.error("Build failed");
|
|
362
473
|
console.error(err);
|
|
@@ -450,12 +561,14 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
450
561
|
};
|
|
451
562
|
const componentsAndDataFiles = componentData.concat(dataFiles);
|
|
452
563
|
for (const component of componentsAndDataFiles) {
|
|
453
|
-
|
|
454
|
-
component.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
564
|
+
if (!component.source) {
|
|
565
|
+
component.source = ts3.createSourceFile(
|
|
566
|
+
component.path,
|
|
567
|
+
component.contents,
|
|
568
|
+
ts3.ScriptTarget.Latest
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
const dataFunctionResult = findDataAttributesAndFunctions(component.source, component.source);
|
|
459
572
|
dataFunctionResults.foundDataAttributes.push(...dataFunctionResult.foundDataAttributes);
|
|
460
573
|
const foundFunctionsWithPath = dataFunctionResult.foundFunctions.map((item) => {
|
|
461
574
|
return {
|
|
@@ -479,11 +592,11 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
479
592
|
fs5.writeFileSync(config.alpineDataPath, result);
|
|
480
593
|
return config.alpineDataPath;
|
|
481
594
|
}
|
|
482
|
-
async function buildCSS() {
|
|
595
|
+
async function buildCSS(disableTailwind) {
|
|
483
596
|
const cssFiles = globSync(config.srcDir + "/**/*.css");
|
|
484
597
|
for (const file of cssFiles) {
|
|
485
598
|
const fileContents = fs5.readFileSync(file, "utf-8");
|
|
486
|
-
const result = await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
|
|
599
|
+
const result = disableTailwind ? fileContents : await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
|
|
487
600
|
const newPath = file.replace(config.srcDir, config.distDir);
|
|
488
601
|
fs5.ensureFileSync(newPath);
|
|
489
602
|
fs5.writeFileSync(newPath, result.css);
|
|
@@ -545,6 +658,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
545
658
|
}
|
|
546
659
|
const componentDynamicPaths = getComponentDynamicPaths(componentFileName);
|
|
547
660
|
const componentFn = componentImport.default;
|
|
661
|
+
if (componentImport?.onInit) await componentImport.onInit();
|
|
548
662
|
const outputPath = componentDynamicPaths?.length ? componentDynamicPaths.reduce((total, current) => {
|
|
549
663
|
return total.replace(`/[${current}]`, "");
|
|
550
664
|
}, path5.dirname(builtComponentPath)) : path5.dirname(builtComponentPath);
|
|
@@ -594,6 +708,53 @@ function getComponentDynamicPaths(componentPath) {
|
|
|
594
708
|
}
|
|
595
709
|
return output;
|
|
596
710
|
}
|
|
711
|
+
async function buildOnLoadFile(componentData, isDev) {
|
|
712
|
+
const onLoadFiles = [];
|
|
713
|
+
const onLoadFileResult = {
|
|
714
|
+
imports: "",
|
|
715
|
+
fn: ""
|
|
716
|
+
};
|
|
717
|
+
for (const component of componentData) {
|
|
718
|
+
if (component.contents.includes("xpineOnLoad")) {
|
|
719
|
+
onLoadFiles.push({
|
|
720
|
+
path: sourcePathToDistPath(component.path),
|
|
721
|
+
source: component.source
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
onLoadFiles.sort((a, b) => {
|
|
726
|
+
return a.path.localeCompare(b.path);
|
|
727
|
+
});
|
|
728
|
+
for (const file of onLoadFiles) {
|
|
729
|
+
const result = getXpineOnLoadFunction(file.path, file.source, onLoadFileResult);
|
|
730
|
+
onLoadFileResult.fn += result.fn;
|
|
731
|
+
onLoadFileResult.imports += result.imports;
|
|
732
|
+
}
|
|
733
|
+
const output = `
|
|
734
|
+
${onLoadFileResult.imports}
|
|
735
|
+
import { context } from "xpine";
|
|
736
|
+
export default async function triggerOnLoad() {
|
|
737
|
+
${onLoadFileResult.fn}
|
|
738
|
+
context.runArrayQueue();
|
|
739
|
+
}
|
|
740
|
+
`;
|
|
741
|
+
const onLoadFilePath = path5.join(config.distDir, "./__xpineOnLoad.ts");
|
|
742
|
+
fs5.writeFileSync(onLoadFilePath, output);
|
|
743
|
+
await build({
|
|
744
|
+
entryPoints: [onLoadFilePath],
|
|
745
|
+
format: "esm",
|
|
746
|
+
platform: "node",
|
|
747
|
+
outdir: config.distDir,
|
|
748
|
+
bundle: true,
|
|
749
|
+
sourcemap: isDev ? "inline" : false,
|
|
750
|
+
external: allPackages,
|
|
751
|
+
jsx: "transform",
|
|
752
|
+
minify: !isDev,
|
|
753
|
+
plugins: [
|
|
754
|
+
addDotJS(allPackages, extensions, isDev)
|
|
755
|
+
]
|
|
756
|
+
});
|
|
757
|
+
}
|
|
597
758
|
|
|
598
759
|
// src/runDevServer.ts
|
|
599
760
|
import path7 from "path";
|
|
@@ -634,7 +795,7 @@ await setupEnv();
|
|
|
634
795
|
async function runDevServer() {
|
|
635
796
|
process.env.NODE_ENV = "development";
|
|
636
797
|
const rebuildEmitter = createRebuildEmitter();
|
|
637
|
-
await buildApp(true);
|
|
798
|
+
await buildApp({ isDev: true });
|
|
638
799
|
const startServer = (await import(config.serverDistAppPath + `?cache=${Date.now()}`)).default;
|
|
639
800
|
let appServer = await startServer();
|
|
640
801
|
const watcher = chokidar.watch(config.srcDir, {
|
|
@@ -649,14 +810,14 @@ async function runDevServer() {
|
|
|
649
810
|
rebuildEmitter.emit("rebuild-server");
|
|
650
811
|
return;
|
|
651
812
|
}
|
|
652
|
-
await buildApp(true);
|
|
813
|
+
await buildApp({ isDev: true });
|
|
653
814
|
refreshEmitter.emit("refresh");
|
|
654
815
|
});
|
|
655
816
|
rebuildEmitter.on("done", async () => {
|
|
656
817
|
await rebuildServer();
|
|
657
818
|
});
|
|
658
819
|
async function rebuildServer() {
|
|
659
|
-
await buildApp(true);
|
|
820
|
+
await buildApp({ isDev: true });
|
|
660
821
|
const startServer2 = (await import(config.serverDistAppPath + `?cache=${Date.now()}`)).default;
|
|
661
822
|
appServer = await startServer2();
|
|
662
823
|
}
|
|
@@ -756,12 +917,19 @@ function getTokenFromRequest(req) {
|
|
|
756
917
|
import requestIP from "request-ip";
|
|
757
918
|
import fs6 from "fs-extra";
|
|
758
919
|
import path8 from "path";
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
920
|
+
import EventEmitter2 from "events";
|
|
921
|
+
var OnInitEmitter = class extends EventEmitter2 {
|
|
922
|
+
};
|
|
923
|
+
var onInitEmitter = new OnInitEmitter();
|
|
924
|
+
onInitEmitter.on("triggerOnInit", async (paths) => {
|
|
925
|
+
for (const routePath of paths) {
|
|
926
|
+
const pathImport = await import(routePath.path + `?cache=${Date.now()}`);
|
|
927
|
+
if (pathImport?.config?.onInit) await pathImport.config.onInit();
|
|
928
|
+
}
|
|
929
|
+
});
|
|
930
|
+
function getAllBuiltRoutes() {
|
|
763
931
|
const routes = globSync2(config.pagesDir + "/**/*.{tsx,ts}");
|
|
764
|
-
|
|
932
|
+
return routes.map((route) => {
|
|
765
933
|
const routeFormatted = route.split(config.pagesDir).pop().replace(".tsx", "").replace(".js", "").replace(".ts", "");
|
|
766
934
|
if (routeFormatted.endsWith("+config")) return;
|
|
767
935
|
const routeFormattedWithIndex = routeFormatted.replace(/\/index$/g, "");
|
|
@@ -771,8 +939,15 @@ async function createRouter() {
|
|
|
771
939
|
originalRoute: route
|
|
772
940
|
};
|
|
773
941
|
}).filter(Boolean);
|
|
942
|
+
}
|
|
943
|
+
async function createRouter() {
|
|
944
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
945
|
+
const methods = ["get", "post", "put", "patch", "delete"];
|
|
946
|
+
const router = express2.Router();
|
|
947
|
+
const routeMap = getAllBuiltRoutes();
|
|
774
948
|
const routeResults = [];
|
|
775
949
|
const configFiles = globSync2(config.pagesDir + "/**/+config.{tsx,ts}");
|
|
950
|
+
await triggerXPineOnLoad();
|
|
776
951
|
for (const route of routeMap) {
|
|
777
952
|
const isJSX = route.originalRoute.endsWith(".tsx") || route.originalRoute.endsWith(".jsx");
|
|
778
953
|
const slugRoute = route.route.replace(/[ ]/g, "");
|
|
@@ -786,15 +961,21 @@ async function createRouter() {
|
|
|
786
961
|
formattedRouteItem = formattedRouteItem.replace(match[0], ":" + match[2]);
|
|
787
962
|
}
|
|
788
963
|
}
|
|
789
|
-
const componentImport =
|
|
790
|
-
const componentFn = componentImport?.default;
|
|
964
|
+
const componentImport = await import(route.path);
|
|
965
|
+
const componentFn = isDev ? null : componentImport?.default;
|
|
966
|
+
if (componentImport?.config?.onInit) {
|
|
967
|
+
await componentImport.config?.onInit();
|
|
968
|
+
}
|
|
969
|
+
let config2 = {};
|
|
791
970
|
const configFilePaths = getConfigFiles(route.originalRoute, configFiles);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
971
|
+
if (!isDev) {
|
|
972
|
+
config2 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
|
|
973
|
+
if (componentImport?.config) {
|
|
974
|
+
config2 = {
|
|
975
|
+
...config2,
|
|
976
|
+
...componentImport.config
|
|
977
|
+
};
|
|
978
|
+
}
|
|
798
979
|
}
|
|
799
980
|
routeResults.push({
|
|
800
981
|
formattedRouteItem,
|
|
@@ -819,8 +1000,10 @@ async function createRouter() {
|
|
|
819
1000
|
}
|
|
820
1001
|
return;
|
|
821
1002
|
}
|
|
1003
|
+
await triggerXPineOnLoad(true);
|
|
822
1004
|
const componentImportDev = await import(route.path + `?cache=${Date.now()}`);
|
|
823
1005
|
const componentFnDev = componentImportDev.default;
|
|
1006
|
+
onInitEmitter.emit("triggerOnInit", getAllBuiltRoutes());
|
|
824
1007
|
if (isJSX) {
|
|
825
1008
|
let config3 = configFilePaths && await getCompleteConfig(configFilePaths, Date.now());
|
|
826
1009
|
if (componentImportDev?.config) {
|
|
@@ -830,8 +1013,9 @@ async function createRouter() {
|
|
|
830
1013
|
};
|
|
831
1014
|
}
|
|
832
1015
|
const data = config3?.data ? await config3.data(req) : null;
|
|
833
|
-
const originalResult = await componentFnDev({ req, res, data });
|
|
1016
|
+
const originalResult = await componentFnDev({ req, res, data, config: config3 });
|
|
834
1017
|
const output = config3?.wrapper ? await config3.wrapper({ req, children: originalResult, config: config3, data }) : originalResult;
|
|
1018
|
+
context.clear();
|
|
835
1019
|
res.send(doctypeHTML + output);
|
|
836
1020
|
} else {
|
|
837
1021
|
await componentFnDev(req, res);
|
|
@@ -922,12 +1106,16 @@ function JSXRuntime() {
|
|
|
922
1106
|
}
|
|
923
1107
|
export {
|
|
924
1108
|
JSXRuntime,
|
|
1109
|
+
addToContextArray,
|
|
925
1110
|
buildApp,
|
|
926
1111
|
buildCSS,
|
|
927
1112
|
buildFilesWithConfigs,
|
|
1113
|
+
buildOnLoadFile,
|
|
928
1114
|
buildPublicFolderSymlinks,
|
|
929
1115
|
buildStaticFiles,
|
|
930
1116
|
config,
|
|
1117
|
+
context,
|
|
1118
|
+
createContext,
|
|
931
1119
|
createRouter,
|
|
932
1120
|
createXPineRouter,
|
|
933
1121
|
fromRoot,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformTSXFiles.d.ts","sourceRoot":"","sources":["../../../../src/build/esbuild/transformTSXFiles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE;;;
|
|
1
|
+
{"version":3,"file":"transformTSXFiles.d.ts","sourceRoot":"","sources":["../../../../src/build/esbuild/transformTSXFiles.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE;;;EA8BlG"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
|
+
import { OnLoadFileResult } from '../scripts/build';
|
|
2
3
|
type ImportDeclaration = {
|
|
3
4
|
node: ts.Node;
|
|
4
5
|
importPath: string;
|
|
@@ -25,6 +26,12 @@ export declare function removeClientScriptInTSXFile(pathName: string, source: ts
|
|
|
25
26
|
clientDataStart: number;
|
|
26
27
|
};
|
|
27
28
|
export declare function createStaticFile(pathName: string, source: ts.SourceFile): void;
|
|
29
|
+
export declare function getImportsToAbsolutePaths(child: ts.Node, source: ts.SourceFile, pathName: string): any[];
|
|
28
30
|
export declare function printRecursiveFrom(node: ts.Node, indentLevel: number, sourceFile: ts.SourceFile): void;
|
|
31
|
+
export declare function getXpineOnLoadFunction(pathName: string, source: ts.SourceFile, onLoadFileResult: OnLoadFileResult): {
|
|
32
|
+
imports: string;
|
|
33
|
+
fn: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function triggerXPineOnLoad(noCache?: boolean): Promise<void>;
|
|
29
36
|
export {};
|
|
30
37
|
//# sourceMappingURL=typescript-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typescript-builder.d.ts","sourceRoot":"","sources":["../../../src/build/typescript-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"typescript-builder.d.ts","sourceRoot":"","sources":["../../../src/build/typescript-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAIpD,KAAK,iBAAiB,GAAG;IACvB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAA;AAGD,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,kBAAkB,GAAE,iBAAiB,EAAO,uBAiB/H;AAED,wBAAgB,yBAAyB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,UAO3H;AAED,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;CACpB,CAAA;AAED,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,EAAE,CAAC,IAAI,EACb,UAAU,EAAE,EAAE,CAAC,UAAU,EACzB,mBAAmB,GAAE,MAAM,EAAO,EAClC,cAAc,GAAE,mBAAmB,EAAO;;;EA0B3C;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,MAAM,EAAE,CAMxF;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,mBAAmB,CAkBzG;AAGD,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,aAAa,EAAE,MAAM,QAO1F;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU;;;;;;EAmClF;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,QAUvE;AAED,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,SAgBhG;AAED,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,QAU9D;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,EAAE,gBAAgB,EAAE,gBAAgB;;;EA0BjH;AAED,wBAAsB,kBAAkB,CAAC,OAAO,GAAE,OAAe,iBAMhE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SetContext<Type> = (currentContext: Type) => Type;
|
|
2
|
+
export type State<StateProps> = {
|
|
3
|
+
get: (id: string) => StateProps;
|
|
4
|
+
set: (id: string, callback: SetContext<StateProps>, defaultValue?: any) => void;
|
|
5
|
+
clear: () => void;
|
|
6
|
+
getAll: () => any;
|
|
7
|
+
addToArray: (id: string, value: any, position?: number) => void;
|
|
8
|
+
getArrayQueue: () => any;
|
|
9
|
+
runArrayQueue: () => void;
|
|
10
|
+
};
|
|
11
|
+
type ContextType<Type> = {
|
|
12
|
+
[key: string]: Type;
|
|
13
|
+
};
|
|
14
|
+
export declare function createContext(value: ContextType<any>): State<any>;
|
|
15
|
+
export declare const context: State<any>;
|
|
16
|
+
export declare function addToContextArray(newValue: any, position?: number): (currentValue: any) => any;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/context.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,IAAI,IAAI,CAAC,cAAc,EAAE,IAAI,KAAK,IAAI,CAAC;AAE9D,MAAM,MAAM,KAAK,CAAC,UAAU,IAAI;IAC9B,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,UAAU,CAAC;IAChC,GAAG,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAChF,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,CAAC;IAClB,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,aAAa,EAAE,MAAM,GAAG,CAAC;IACzB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B,CAAA;AAED,KAAK,WAAW,CAAC,IAAI,IAAI;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CA8CjE;AAED,eAAO,MAAM,OAAO,YAAoB,CAAC;AAEzC,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,CAAC,EAAE,MAAM,kBACjC,GAAG,SAYnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"express.d.ts","sourceRoot":"","sources":["../../src/express.ts"],"names":[],"mappings":"AAAA,OAAgB,EAAgB,OAAO,EAAqB,MAAM,SAAS,CAAC;AAyC5E,wBAAsB,YAAY;;;GA8GjC;AAiBD,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,IAAI,iBA6B1F;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,GAAG,MAAM,GAAG,KAAK,CAWnG"}
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { ConfigFile, ComponentData } from '../../types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type BuildAppArgs = {
|
|
3
|
+
isDev?: boolean;
|
|
4
|
+
removePreviousBuild?: boolean;
|
|
5
|
+
disableTailwind?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function buildApp(args: BuildAppArgs): Promise<void>;
|
|
8
|
+
export declare function buildCSS(disableTailwind?: boolean): Promise<void>;
|
|
4
9
|
export declare function buildPublicFolderSymlinks(): Promise<void>;
|
|
5
10
|
export declare function logSize(pathName: string, type: 'app' | 'client' | 'css', validExtensions?: string[]): Promise<void>;
|
|
6
11
|
export declare function buildFilesWithConfigs(componentData: ComponentData[]): Promise<void>;
|
|
7
12
|
export declare function buildStaticFiles(config: ConfigFile, component: ComponentData, componentImport: any, builtComponentPath: string): Promise<void>;
|
|
8
13
|
export declare function getComponentDynamicPaths(componentPath: string): string[];
|
|
14
|
+
export type OnLoadFileResult = {
|
|
15
|
+
imports: string;
|
|
16
|
+
fn: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function buildOnLoadFile(componentData: ComponentData[], isDev?: boolean): Promise<void>;
|
|
19
|
+
export {};
|
|
9
20
|
//# sourceMappingURL=build.d.ts.map
|