xpine 0.0.33 → 0.0.35
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/README.md +16 -1
- package/TODO +0 -1
- package/dist/index.js +108 -53
- package/dist/src/build/css.d.ts +2 -0
- package/dist/src/build/css.d.ts.map +1 -0
- package/dist/src/build/postcss/add-breakpoint-data.d.ts +8 -0
- package/dist/src/build/postcss/add-breakpoint-data.d.ts.map +1 -0
- package/dist/src/build/postcss/remove-layers.d.ts +8 -0
- package/dist/src/build/postcss/remove-layers.d.ts.map +1 -0
- package/dist/src/scripts/build.d.ts +0 -1
- package/dist/src/scripts/build.d.ts.map +1 -1
- package/dist/src/scripts/xpine-build.js +108 -52
- package/dist/src/scripts/xpine-dev.js +108 -52
- package/dist/src/static/spa.js +40 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,22 @@ setupEnv also supports AWS secrets manager. Simply add SECRETS_NAME=your_aws_sec
|
|
|
57
57
|
- spa-update-page-content
|
|
58
58
|
- sent when the page content has update
|
|
59
59
|
- spa-update-page-url
|
|
60
|
-
-
|
|
60
|
+
- sent when the page URL has update
|
|
61
|
+
- spa-link-click
|
|
62
|
+
- sent when link initially gets clicked and when link is done updating content
|
|
63
|
+
- the "state" value in the event detail will be "start" or "end"
|
|
64
|
+
- breakpoint-change
|
|
65
|
+
- sent when a breakpoint is changed via your Tailwind css file's breakpoints in the @theme directive, e.g.
|
|
66
|
+
```
|
|
67
|
+
@theme {
|
|
68
|
+
--breakpoint-xl: 1184px;
|
|
69
|
+
--breakpoint-sm: 640px;
|
|
70
|
+
--breakpoint-md: 768px;
|
|
71
|
+
--breakpoint-lg: 1024px;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
- this will send a custom event with the detail being the breakpoint, such as `{ breakpoint: 'xl' }`
|
|
75
|
+
- note this will only send an event based on the values of the breakpoints in your @theme configuration
|
|
61
76
|
|
|
62
77
|
#### Custom scripts for certain pages
|
|
63
78
|
|
package/TODO
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
- spa:updatePageURL should return all available information about the URL instead of just the href it's going to
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import chokidar from "chokidar";
|
|
|
7
7
|
|
|
8
8
|
// src/scripts/build.ts
|
|
9
9
|
import path6 from "path";
|
|
10
|
-
import
|
|
10
|
+
import fs7 from "fs-extra";
|
|
11
11
|
import { build } from "esbuild";
|
|
12
12
|
|
|
13
13
|
// src/build/typescript-builder.ts
|
|
@@ -285,9 +285,7 @@ async function triggerXPineOnLoad(noCache = false) {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
// src/scripts/build.ts
|
|
288
|
-
import { globSync as
|
|
289
|
-
import postcss from "postcss";
|
|
290
|
-
import tailwindPostcss from "@tailwindcss/postcss";
|
|
288
|
+
import { globSync as globSync3 } from "glob";
|
|
291
289
|
|
|
292
290
|
// src/util/paths.ts
|
|
293
291
|
function getXPineDistDir() {
|
|
@@ -300,20 +298,6 @@ function getXPineDistDir() {
|
|
|
300
298
|
return splitDir[0] + "/xpine/dist";
|
|
301
299
|
}
|
|
302
300
|
|
|
303
|
-
// src/util/postcss/remove-layers.ts
|
|
304
|
-
var plugin = (opts = {}) => {
|
|
305
|
-
return {
|
|
306
|
-
postcssPlugin: "postcssRemoveLayers",
|
|
307
|
-
AtRule: {
|
|
308
|
-
layer: (atRule) => {
|
|
309
|
-
atRule.replaceWith(atRule.nodes);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
};
|
|
313
|
-
};
|
|
314
|
-
plugin.postcss = true;
|
|
315
|
-
var remove_layers_default = plugin;
|
|
316
|
-
|
|
317
301
|
// src/build/esbuild/transformTSXFiles.ts
|
|
318
302
|
import fs2 from "fs-extra";
|
|
319
303
|
import ts2 from "typescript";
|
|
@@ -669,9 +653,92 @@ function filePathToURLPath(pathName, isDist = true) {
|
|
|
669
653
|
return result;
|
|
670
654
|
}
|
|
671
655
|
|
|
656
|
+
// src/build/css.ts
|
|
657
|
+
import { globSync as globSync2 } from "glob";
|
|
658
|
+
import fs6 from "fs-extra";
|
|
659
|
+
import postcss from "postcss";
|
|
660
|
+
|
|
661
|
+
// src/build/postcss/remove-layers.ts
|
|
662
|
+
var plugin = (opts = {}) => {
|
|
663
|
+
return {
|
|
664
|
+
postcssPlugin: "postcssRemoveLayers",
|
|
665
|
+
AtRule: {
|
|
666
|
+
layer: (atRule) => {
|
|
667
|
+
atRule.replaceWith(atRule.nodes);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
};
|
|
672
|
+
plugin.postcss = true;
|
|
673
|
+
var remove_layers_default = plugin;
|
|
674
|
+
|
|
675
|
+
// src/build/postcss/add-breakpoint-data.ts
|
|
676
|
+
var plugin2 = (opts = {}) => {
|
|
677
|
+
const nodeValues = [];
|
|
678
|
+
return {
|
|
679
|
+
postcssPlugin: "addBreakpointData",
|
|
680
|
+
AtRule: {
|
|
681
|
+
theme(atRule) {
|
|
682
|
+
const nodes = atRule.nodes.filter((node) => {
|
|
683
|
+
return node.prop.startsWith("--breakpoint-");
|
|
684
|
+
});
|
|
685
|
+
nodeValues.push(...nodes.map((node) => {
|
|
686
|
+
return {
|
|
687
|
+
// @ts-ignore
|
|
688
|
+
breakpoint: node.prop.replace("--breakpoint-", ""),
|
|
689
|
+
// @ts-ignore
|
|
690
|
+
value: node.value
|
|
691
|
+
};
|
|
692
|
+
}));
|
|
693
|
+
}
|
|
694
|
+
},
|
|
695
|
+
OnceExit(root) {
|
|
696
|
+
root.append([
|
|
697
|
+
`body:before {`,
|
|
698
|
+
`content: "default"; display: none; visibility: hidden;`,
|
|
699
|
+
`}`
|
|
700
|
+
].join(""));
|
|
701
|
+
const nodeValuesMapped = nodeValues.sort((a, b) => {
|
|
702
|
+
return Number(a.value.replace(/[^0-9]/g, "")) - Number(b.value.replace(/[^0-9]/g, ""));
|
|
703
|
+
}).map(({ breakpoint, value }) => {
|
|
704
|
+
return [
|
|
705
|
+
`@media (min-width: ${value}) {`,
|
|
706
|
+
`body:before {`,
|
|
707
|
+
`content: "${breakpoint}";`,
|
|
708
|
+
`}`,
|
|
709
|
+
`}`
|
|
710
|
+
].join("");
|
|
711
|
+
});
|
|
712
|
+
for (const value of nodeValuesMapped) {
|
|
713
|
+
root.append(value);
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
};
|
|
717
|
+
};
|
|
718
|
+
plugin2.postcss = true;
|
|
719
|
+
var add_breakpoint_data_default = plugin2;
|
|
720
|
+
|
|
721
|
+
// src/build/css.ts
|
|
722
|
+
import tailwindPostcss from "@tailwindcss/postcss";
|
|
723
|
+
async function buildCSS(disableTailwind) {
|
|
724
|
+
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
725
|
+
for (const file of cssFiles) {
|
|
726
|
+
const fileContents = fs6.readFileSync(file, "utf-8");
|
|
727
|
+
let result = fileContents;
|
|
728
|
+
if (!disableTailwind) {
|
|
729
|
+
result = await postcss([add_breakpoint_data_default()]).process(fileContents, { from: file });
|
|
730
|
+
result = await postcss([tailwindPostcss(), remove_layers_default()]).process(result.css, { from: file });
|
|
731
|
+
}
|
|
732
|
+
const newPath = file.replace(config.srcDir, config.distDir);
|
|
733
|
+
fs6.ensureFileSync(newPath);
|
|
734
|
+
fs6.writeFileSync(newPath, result.css);
|
|
735
|
+
}
|
|
736
|
+
logSize(config.distPublicDir, "css");
|
|
737
|
+
}
|
|
738
|
+
|
|
672
739
|
// src/scripts/build.ts
|
|
673
740
|
var extensions = [".ts", ".tsx"];
|
|
674
|
-
var packageJson = JSON.parse(
|
|
741
|
+
var packageJson = JSON.parse(fs7.readFileSync(config.packageJsonPath, "utf-8"));
|
|
675
742
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
676
743
|
var xpineDistDir = getXPineDistDir();
|
|
677
744
|
async function buildApp(args) {
|
|
@@ -679,12 +746,12 @@ async function buildApp(args) {
|
|
|
679
746
|
const removePreviousBuild = args?.removePreviousBuild || false;
|
|
680
747
|
const disableTailwind = args?.disableTailwind || false;
|
|
681
748
|
try {
|
|
682
|
-
if (removePreviousBuild)
|
|
683
|
-
const srcDirFiles =
|
|
749
|
+
if (removePreviousBuild) fs7.removeSync(config.distDir);
|
|
750
|
+
const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
684
751
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev);
|
|
685
752
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
686
753
|
await buildClientSideFiles([alpineDataFile], isDev);
|
|
687
|
-
|
|
754
|
+
fs7.removeSync(config.distTempFolder);
|
|
688
755
|
await buildCSS(disableTailwind);
|
|
689
756
|
await buildPublicFolderSymlinks();
|
|
690
757
|
await buildOnLoadFile(componentData, isDev);
|
|
@@ -704,7 +771,7 @@ async function buildAppFiles(files, isDev) {
|
|
|
704
771
|
return fileName === "+config";
|
|
705
772
|
});
|
|
706
773
|
const backendFiles = files.filter((file) => extensions.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
|
|
707
|
-
|
|
774
|
+
fs7.ensureDirSync(config.distDir);
|
|
708
775
|
await build({
|
|
709
776
|
entryPoints: backendFiles,
|
|
710
777
|
format: "esm",
|
|
@@ -729,9 +796,9 @@ async function buildAppFiles(files, isDev) {
|
|
|
729
796
|
}
|
|
730
797
|
async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
731
798
|
const tempFilePath = path6.join(config.distTempFolder, "./app.ts");
|
|
732
|
-
|
|
799
|
+
fs7.ensureFileSync(tempFilePath);
|
|
733
800
|
const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
|
|
734
|
-
const clientFiles =
|
|
801
|
+
const clientFiles = globSync3(
|
|
735
802
|
config.publicDir + "/**/*.{js,ts}",
|
|
736
803
|
{
|
|
737
804
|
ignore: pagesScriptsGlob
|
|
@@ -747,7 +814,7 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
|
747
814
|
minify: !isDev,
|
|
748
815
|
sourcemap: isDev ? "inline" : false
|
|
749
816
|
});
|
|
750
|
-
const pagesFiles =
|
|
817
|
+
const pagesFiles = globSync3(pagesScriptsGlob);
|
|
751
818
|
await build({
|
|
752
819
|
entryPoints: pagesFiles || [],
|
|
753
820
|
bundle: true,
|
|
@@ -759,13 +826,13 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
|
759
826
|
}
|
|
760
827
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
761
828
|
const devServerPath = path6.join(xpineDistDir, "./src/static/dev-server.js");
|
|
762
|
-
const content =
|
|
763
|
-
|
|
829
|
+
const content = fs7.readFileSync(devServerPath, "utf-8");
|
|
830
|
+
fs7.appendFileSync(tempFilePath, "\n" + content);
|
|
764
831
|
}
|
|
765
832
|
function writeSpaClientSideCode(tempFilePath) {
|
|
766
833
|
const spaPath = path6.join(xpineDistDir, "./src/static/spa.js");
|
|
767
|
-
const content =
|
|
768
|
-
|
|
834
|
+
const content = fs7.readFileSync(spaPath, "utf-8");
|
|
835
|
+
fs7.appendFileSync(tempFilePath, "\n" + content);
|
|
769
836
|
}
|
|
770
837
|
async function buildAlpineDataFile(componentData, dataFiles) {
|
|
771
838
|
const output = {
|
|
@@ -811,23 +878,12 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
811
878
|
output.code.push(`Alpine.data('${dataFunction.name}', ${dataFunction.name});`);
|
|
812
879
|
}
|
|
813
880
|
const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
|
|
814
|
-
|
|
815
|
-
|
|
881
|
+
fs7.ensureFileSync(config.alpineDataPath);
|
|
882
|
+
fs7.writeFileSync(config.alpineDataPath, result);
|
|
816
883
|
return config.alpineDataPath;
|
|
817
884
|
}
|
|
818
|
-
async function buildCSS(disableTailwind) {
|
|
819
|
-
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
820
|
-
for (const file of cssFiles) {
|
|
821
|
-
const fileContents = fs6.readFileSync(file, "utf-8");
|
|
822
|
-
const result = disableTailwind ? fileContents : await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
|
|
823
|
-
const newPath = file.replace(config.srcDir, config.distDir);
|
|
824
|
-
fs6.ensureFileSync(newPath);
|
|
825
|
-
fs6.writeFileSync(newPath, result.css);
|
|
826
|
-
}
|
|
827
|
-
logSize(config.distPublicDir, "css");
|
|
828
|
-
}
|
|
829
885
|
async function buildPublicFolderSymlinks() {
|
|
830
|
-
const files =
|
|
886
|
+
const files = globSync3(config.publicDir + "/**/*.*", {
|
|
831
887
|
ignore: "/**/*.{css,js,ts,tsx,jsx}"
|
|
832
888
|
});
|
|
833
889
|
for (const file of files) {
|
|
@@ -836,19 +892,19 @@ async function buildPublicFolderSymlinks() {
|
|
|
836
892
|
const splitNewPath = newPath.split("/");
|
|
837
893
|
splitNewPath.pop();
|
|
838
894
|
const newDir = splitNewPath.join("/");
|
|
839
|
-
|
|
840
|
-
|
|
895
|
+
fs7.ensureDirSync(newDir);
|
|
896
|
+
fs7.symlinkSync(file, newPath);
|
|
841
897
|
} catch {
|
|
842
898
|
}
|
|
843
899
|
}
|
|
844
900
|
}
|
|
845
901
|
async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
846
|
-
const files =
|
|
902
|
+
const files = globSync3(pathName + "/**/*" + (type === "css" ? ".css" : ""));
|
|
847
903
|
const fileSizes = files.map((file) => {
|
|
848
904
|
if (!validExtensions.find((ext) => file.endsWith(ext))) return false;
|
|
849
905
|
return {
|
|
850
906
|
file,
|
|
851
|
-
size:
|
|
907
|
+
size: fs7.statSync(file).size / (1024 * 1e3)
|
|
852
908
|
};
|
|
853
909
|
}).filter(Boolean);
|
|
854
910
|
const totalSize = fileSizes.reduce((total, current) => {
|
|
@@ -891,7 +947,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
891
947
|
const req = { params: {} };
|
|
892
948
|
const data = config2?.data ? await config2.data(req) : null;
|
|
893
949
|
const staticComponentOutput = await componentFn({ data, routePath: urlPath });
|
|
894
|
-
|
|
950
|
+
fs7.writeFileSync(
|
|
895
951
|
path6.join(outputPath, "./index.html"),
|
|
896
952
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
897
953
|
);
|
|
@@ -912,8 +968,8 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
912
968
|
const urlPath = filePathToURLPath(updatedOutDir);
|
|
913
969
|
const data = config2?.data ? await config2.data(req) : null;
|
|
914
970
|
const staticComponentOutput = await componentFn({ req, data, routePath: urlPath });
|
|
915
|
-
|
|
916
|
-
|
|
971
|
+
fs7.ensureDirSync(updatedOutDir);
|
|
972
|
+
fs7.writeFileSync(
|
|
917
973
|
path6.join(updatedOutDir, "./index.html"),
|
|
918
974
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
919
975
|
);
|
|
@@ -964,7 +1020,7 @@ async function buildOnLoadFile(componentData, isDev) {
|
|
|
964
1020
|
}
|
|
965
1021
|
`;
|
|
966
1022
|
const onLoadFilePath = path6.join(config.distDir, "./__xpineOnLoad.ts");
|
|
967
|
-
|
|
1023
|
+
fs7.writeFileSync(onLoadFilePath, output);
|
|
968
1024
|
await build({
|
|
969
1025
|
entryPoints: [onLoadFilePath],
|
|
970
1026
|
format: "esm",
|
|
@@ -1126,7 +1182,6 @@ export {
|
|
|
1126
1182
|
JSXRuntime,
|
|
1127
1183
|
addToContextArray,
|
|
1128
1184
|
buildApp,
|
|
1129
|
-
buildCSS,
|
|
1130
1185
|
buildFilesWithConfigs,
|
|
1131
1186
|
buildOnLoadFile,
|
|
1132
1187
|
buildPublicFolderSymlinks,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../src/build/css.ts"],"names":[],"mappings":"AAUA,wBAAsB,QAAQ,CAAC,eAAe,CAAC,EAAE,OAAO,iBAgBvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-breakpoint-data.d.ts","sourceRoot":"","sources":["../../../../src/build/postcss/add-breakpoint-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD,kBAAU,MAAM,CAAC;IACf,UAAiB,OAAO;KAAI;CAC7B;AAID,QAAA,MAAM,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,OAAO,CA4CzC,CAAC;AAGF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-layers.d.ts","sourceRoot":"","sources":["../../../../src/build/postcss/remove-layers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,kBAAU,MAAM,CAAC;IACf,UAAiB,OAAO;KAAG;CAC5B;AAID,QAAA,MAAM,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,OAAO,CASxC,CAAC;AAGH,eAAe,MAAM,CAAC"}
|
|
@@ -5,7 +5,6 @@ type BuildAppArgs = {
|
|
|
5
5
|
disableTailwind?: boolean;
|
|
6
6
|
};
|
|
7
7
|
export declare function buildApp(args: BuildAppArgs): Promise<void>;
|
|
8
|
-
export declare function buildCSS(disableTailwind?: boolean): Promise<void>;
|
|
9
8
|
export declare function buildPublicFolderSymlinks(): Promise<void>;
|
|
10
9
|
export declare function logSize(pathName: string, type: 'app' | 'client' | 'css', validExtensions?: string[]): Promise<void>;
|
|
11
10
|
export declare function buildFilesWithConfigs(componentData: ComponentData[]): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/scripts/build.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAA2B,aAAa,EAAE,MAAM,aAAa,CAAC;AAajF,KAAK,YAAY,GAAG;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAA;AAED,wBAAsB,QAAQ,CAAC,IAAI,EAAE,YAAY,iBAsBhD;AAiJD,wBAAsB,yBAAyB,kBAgB9C;AAED,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,GAAG,QAAQ,GAAG,KAAK,EAAE,eAAe,WAAkB,iBAahH;AAED,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,aAAa,EAAE,iBAezE;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,GAAG,EAAE,kBAAkB,EAAE,MAAM,iBAmEpI;AAED,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,EAAE,CAQxE;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAA;AAGD,wBAAsB,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,EAAE,KAAK,CAAC,EAAE,OAAO,iBAoDpF"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/scripts/build.ts
|
|
4
4
|
import path5 from "path";
|
|
5
|
-
import
|
|
5
|
+
import fs7 from "fs-extra";
|
|
6
6
|
import { build } from "esbuild";
|
|
7
7
|
|
|
8
8
|
// src/build/typescript-builder.ts
|
|
@@ -280,9 +280,7 @@ async function triggerXPineOnLoad(noCache = false) {
|
|
|
280
280
|
}
|
|
281
281
|
|
|
282
282
|
// src/scripts/build.ts
|
|
283
|
-
import { globSync as
|
|
284
|
-
import postcss from "postcss";
|
|
285
|
-
import tailwindPostcss from "@tailwindcss/postcss";
|
|
283
|
+
import { globSync as globSync3 } from "glob";
|
|
286
284
|
|
|
287
285
|
// src/util/paths.ts
|
|
288
286
|
function getXPineDistDir() {
|
|
@@ -295,20 +293,6 @@ function getXPineDistDir() {
|
|
|
295
293
|
return splitDir[0] + "/xpine/dist";
|
|
296
294
|
}
|
|
297
295
|
|
|
298
|
-
// src/util/postcss/remove-layers.ts
|
|
299
|
-
var plugin = (opts = {}) => {
|
|
300
|
-
return {
|
|
301
|
-
postcssPlugin: "postcssRemoveLayers",
|
|
302
|
-
AtRule: {
|
|
303
|
-
layer: (atRule) => {
|
|
304
|
-
atRule.replaceWith(atRule.nodes);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
};
|
|
309
|
-
plugin.postcss = true;
|
|
310
|
-
var remove_layers_default = plugin;
|
|
311
|
-
|
|
312
296
|
// src/build/esbuild/transformTSXFiles.ts
|
|
313
297
|
import fs2 from "fs-extra";
|
|
314
298
|
import ts2 from "typescript";
|
|
@@ -478,9 +462,92 @@ function filePathToURLPath(pathName, isDist = true) {
|
|
|
478
462
|
return result;
|
|
479
463
|
}
|
|
480
464
|
|
|
465
|
+
// src/build/css.ts
|
|
466
|
+
import { globSync as globSync2 } from "glob";
|
|
467
|
+
import fs6 from "fs-extra";
|
|
468
|
+
import postcss from "postcss";
|
|
469
|
+
|
|
470
|
+
// src/build/postcss/remove-layers.ts
|
|
471
|
+
var plugin = (opts = {}) => {
|
|
472
|
+
return {
|
|
473
|
+
postcssPlugin: "postcssRemoveLayers",
|
|
474
|
+
AtRule: {
|
|
475
|
+
layer: (atRule) => {
|
|
476
|
+
atRule.replaceWith(atRule.nodes);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
};
|
|
481
|
+
plugin.postcss = true;
|
|
482
|
+
var remove_layers_default = plugin;
|
|
483
|
+
|
|
484
|
+
// src/build/postcss/add-breakpoint-data.ts
|
|
485
|
+
var plugin2 = (opts = {}) => {
|
|
486
|
+
const nodeValues = [];
|
|
487
|
+
return {
|
|
488
|
+
postcssPlugin: "addBreakpointData",
|
|
489
|
+
AtRule: {
|
|
490
|
+
theme(atRule) {
|
|
491
|
+
const nodes = atRule.nodes.filter((node) => {
|
|
492
|
+
return node.prop.startsWith("--breakpoint-");
|
|
493
|
+
});
|
|
494
|
+
nodeValues.push(...nodes.map((node) => {
|
|
495
|
+
return {
|
|
496
|
+
// @ts-ignore
|
|
497
|
+
breakpoint: node.prop.replace("--breakpoint-", ""),
|
|
498
|
+
// @ts-ignore
|
|
499
|
+
value: node.value
|
|
500
|
+
};
|
|
501
|
+
}));
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
OnceExit(root) {
|
|
505
|
+
root.append([
|
|
506
|
+
`body:before {`,
|
|
507
|
+
`content: "default"; display: none; visibility: hidden;`,
|
|
508
|
+
`}`
|
|
509
|
+
].join(""));
|
|
510
|
+
const nodeValuesMapped = nodeValues.sort((a, b) => {
|
|
511
|
+
return Number(a.value.replace(/[^0-9]/g, "")) - Number(b.value.replace(/[^0-9]/g, ""));
|
|
512
|
+
}).map(({ breakpoint, value }) => {
|
|
513
|
+
return [
|
|
514
|
+
`@media (min-width: ${value}) {`,
|
|
515
|
+
`body:before {`,
|
|
516
|
+
`content: "${breakpoint}";`,
|
|
517
|
+
`}`,
|
|
518
|
+
`}`
|
|
519
|
+
].join("");
|
|
520
|
+
});
|
|
521
|
+
for (const value of nodeValuesMapped) {
|
|
522
|
+
root.append(value);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
};
|
|
527
|
+
plugin2.postcss = true;
|
|
528
|
+
var add_breakpoint_data_default = plugin2;
|
|
529
|
+
|
|
530
|
+
// src/build/css.ts
|
|
531
|
+
import tailwindPostcss from "@tailwindcss/postcss";
|
|
532
|
+
async function buildCSS(disableTailwind2) {
|
|
533
|
+
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
534
|
+
for (const file of cssFiles) {
|
|
535
|
+
const fileContents = fs6.readFileSync(file, "utf-8");
|
|
536
|
+
let result = fileContents;
|
|
537
|
+
if (!disableTailwind2) {
|
|
538
|
+
result = await postcss([add_breakpoint_data_default()]).process(fileContents, { from: file });
|
|
539
|
+
result = await postcss([tailwindPostcss(), remove_layers_default()]).process(result.css, { from: file });
|
|
540
|
+
}
|
|
541
|
+
const newPath = file.replace(config.srcDir, config.distDir);
|
|
542
|
+
fs6.ensureFileSync(newPath);
|
|
543
|
+
fs6.writeFileSync(newPath, result.css);
|
|
544
|
+
}
|
|
545
|
+
logSize(config.distPublicDir, "css");
|
|
546
|
+
}
|
|
547
|
+
|
|
481
548
|
// src/scripts/build.ts
|
|
482
549
|
var extensions = [".ts", ".tsx"];
|
|
483
|
-
var packageJson = JSON.parse(
|
|
550
|
+
var packageJson = JSON.parse(fs7.readFileSync(config.packageJsonPath, "utf-8"));
|
|
484
551
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
485
552
|
var xpineDistDir = getXPineDistDir();
|
|
486
553
|
async function buildApp(args) {
|
|
@@ -488,12 +555,12 @@ async function buildApp(args) {
|
|
|
488
555
|
const removePreviousBuild2 = args?.removePreviousBuild || false;
|
|
489
556
|
const disableTailwind2 = args?.disableTailwind || false;
|
|
490
557
|
try {
|
|
491
|
-
if (removePreviousBuild2)
|
|
492
|
-
const srcDirFiles =
|
|
558
|
+
if (removePreviousBuild2) fs7.removeSync(config.distDir);
|
|
559
|
+
const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
493
560
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev2);
|
|
494
561
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
495
562
|
await buildClientSideFiles([alpineDataFile], isDev2);
|
|
496
|
-
|
|
563
|
+
fs7.removeSync(config.distTempFolder);
|
|
497
564
|
await buildCSS(disableTailwind2);
|
|
498
565
|
await buildPublicFolderSymlinks();
|
|
499
566
|
await buildOnLoadFile(componentData, isDev2);
|
|
@@ -513,7 +580,7 @@ async function buildAppFiles(files, isDev2) {
|
|
|
513
580
|
return fileName === "+config";
|
|
514
581
|
});
|
|
515
582
|
const backendFiles = files.filter((file) => extensions.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
|
|
516
|
-
|
|
583
|
+
fs7.ensureDirSync(config.distDir);
|
|
517
584
|
await build({
|
|
518
585
|
entryPoints: backendFiles,
|
|
519
586
|
format: "esm",
|
|
@@ -538,9 +605,9 @@ async function buildAppFiles(files, isDev2) {
|
|
|
538
605
|
}
|
|
539
606
|
async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
|
|
540
607
|
const tempFilePath = path5.join(config.distTempFolder, "./app.ts");
|
|
541
|
-
|
|
608
|
+
fs7.ensureFileSync(tempFilePath);
|
|
542
609
|
const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
|
|
543
|
-
const clientFiles =
|
|
610
|
+
const clientFiles = globSync3(
|
|
544
611
|
config.publicDir + "/**/*.{js,ts}",
|
|
545
612
|
{
|
|
546
613
|
ignore: pagesScriptsGlob
|
|
@@ -556,7 +623,7 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
|
|
|
556
623
|
minify: !isDev2,
|
|
557
624
|
sourcemap: isDev2 ? "inline" : false
|
|
558
625
|
});
|
|
559
|
-
const pagesFiles =
|
|
626
|
+
const pagesFiles = globSync3(pagesScriptsGlob);
|
|
560
627
|
await build({
|
|
561
628
|
entryPoints: pagesFiles || [],
|
|
562
629
|
bundle: true,
|
|
@@ -568,13 +635,13 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev2) {
|
|
|
568
635
|
}
|
|
569
636
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
570
637
|
const devServerPath = path5.join(xpineDistDir, "./src/static/dev-server.js");
|
|
571
|
-
const content =
|
|
572
|
-
|
|
638
|
+
const content = fs7.readFileSync(devServerPath, "utf-8");
|
|
639
|
+
fs7.appendFileSync(tempFilePath, "\n" + content);
|
|
573
640
|
}
|
|
574
641
|
function writeSpaClientSideCode(tempFilePath) {
|
|
575
642
|
const spaPath = path5.join(xpineDistDir, "./src/static/spa.js");
|
|
576
|
-
const content =
|
|
577
|
-
|
|
643
|
+
const content = fs7.readFileSync(spaPath, "utf-8");
|
|
644
|
+
fs7.appendFileSync(tempFilePath, "\n" + content);
|
|
578
645
|
}
|
|
579
646
|
async function buildAlpineDataFile(componentData, dataFiles) {
|
|
580
647
|
const output = {
|
|
@@ -620,23 +687,12 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
620
687
|
output.code.push(`Alpine.data('${dataFunction.name}', ${dataFunction.name});`);
|
|
621
688
|
}
|
|
622
689
|
const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
|
|
623
|
-
|
|
624
|
-
|
|
690
|
+
fs7.ensureFileSync(config.alpineDataPath);
|
|
691
|
+
fs7.writeFileSync(config.alpineDataPath, result);
|
|
625
692
|
return config.alpineDataPath;
|
|
626
693
|
}
|
|
627
|
-
async function buildCSS(disableTailwind2) {
|
|
628
|
-
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
629
|
-
for (const file of cssFiles) {
|
|
630
|
-
const fileContents = fs6.readFileSync(file, "utf-8");
|
|
631
|
-
const result = disableTailwind2 ? fileContents : await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
|
|
632
|
-
const newPath = file.replace(config.srcDir, config.distDir);
|
|
633
|
-
fs6.ensureFileSync(newPath);
|
|
634
|
-
fs6.writeFileSync(newPath, result.css);
|
|
635
|
-
}
|
|
636
|
-
logSize(config.distPublicDir, "css");
|
|
637
|
-
}
|
|
638
694
|
async function buildPublicFolderSymlinks() {
|
|
639
|
-
const files =
|
|
695
|
+
const files = globSync3(config.publicDir + "/**/*.*", {
|
|
640
696
|
ignore: "/**/*.{css,js,ts,tsx,jsx}"
|
|
641
697
|
});
|
|
642
698
|
for (const file of files) {
|
|
@@ -645,19 +701,19 @@ async function buildPublicFolderSymlinks() {
|
|
|
645
701
|
const splitNewPath = newPath.split("/");
|
|
646
702
|
splitNewPath.pop();
|
|
647
703
|
const newDir = splitNewPath.join("/");
|
|
648
|
-
|
|
649
|
-
|
|
704
|
+
fs7.ensureDirSync(newDir);
|
|
705
|
+
fs7.symlinkSync(file, newPath);
|
|
650
706
|
} catch {
|
|
651
707
|
}
|
|
652
708
|
}
|
|
653
709
|
}
|
|
654
710
|
async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
655
|
-
const files =
|
|
711
|
+
const files = globSync3(pathName + "/**/*" + (type === "css" ? ".css" : ""));
|
|
656
712
|
const fileSizes = files.map((file) => {
|
|
657
713
|
if (!validExtensions.find((ext) => file.endsWith(ext))) return false;
|
|
658
714
|
return {
|
|
659
715
|
file,
|
|
660
|
-
size:
|
|
716
|
+
size: fs7.statSync(file).size / (1024 * 1e3)
|
|
661
717
|
};
|
|
662
718
|
}).filter(Boolean);
|
|
663
719
|
const totalSize = fileSizes.reduce((total, current) => {
|
|
@@ -700,7 +756,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
700
756
|
const req = { params: {} };
|
|
701
757
|
const data = config2?.data ? await config2.data(req) : null;
|
|
702
758
|
const staticComponentOutput = await componentFn({ data, routePath: urlPath });
|
|
703
|
-
|
|
759
|
+
fs7.writeFileSync(
|
|
704
760
|
path5.join(outputPath, "./index.html"),
|
|
705
761
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
706
762
|
);
|
|
@@ -721,8 +777,8 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
721
777
|
const urlPath = filePathToURLPath(updatedOutDir);
|
|
722
778
|
const data = config2?.data ? await config2.data(req) : null;
|
|
723
779
|
const staticComponentOutput = await componentFn({ req, data, routePath: urlPath });
|
|
724
|
-
|
|
725
|
-
|
|
780
|
+
fs7.ensureDirSync(updatedOutDir);
|
|
781
|
+
fs7.writeFileSync(
|
|
726
782
|
path5.join(updatedOutDir, "./index.html"),
|
|
727
783
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
728
784
|
);
|
|
@@ -773,7 +829,7 @@ async function buildOnLoadFile(componentData, isDev2) {
|
|
|
773
829
|
}
|
|
774
830
|
`;
|
|
775
831
|
const onLoadFilePath = path5.join(config.distDir, "./__xpineOnLoad.ts");
|
|
776
|
-
|
|
832
|
+
fs7.writeFileSync(onLoadFilePath, output);
|
|
777
833
|
await build({
|
|
778
834
|
entryPoints: [onLoadFilePath],
|
|
779
835
|
format: "esm",
|
|
@@ -9,7 +9,7 @@ import chokidar from "chokidar";
|
|
|
9
9
|
|
|
10
10
|
// src/scripts/build.ts
|
|
11
11
|
import path5 from "path";
|
|
12
|
-
import
|
|
12
|
+
import fs7 from "fs-extra";
|
|
13
13
|
import { build } from "esbuild";
|
|
14
14
|
|
|
15
15
|
// src/build/typescript-builder.ts
|
|
@@ -287,9 +287,7 @@ async function triggerXPineOnLoad(noCache = false) {
|
|
|
287
287
|
}
|
|
288
288
|
|
|
289
289
|
// src/scripts/build.ts
|
|
290
|
-
import { globSync as
|
|
291
|
-
import postcss from "postcss";
|
|
292
|
-
import tailwindPostcss from "@tailwindcss/postcss";
|
|
290
|
+
import { globSync as globSync3 } from "glob";
|
|
293
291
|
|
|
294
292
|
// src/util/paths.ts
|
|
295
293
|
function getXPineDistDir() {
|
|
@@ -302,20 +300,6 @@ function getXPineDistDir() {
|
|
|
302
300
|
return splitDir[0] + "/xpine/dist";
|
|
303
301
|
}
|
|
304
302
|
|
|
305
|
-
// src/util/postcss/remove-layers.ts
|
|
306
|
-
var plugin = (opts = {}) => {
|
|
307
|
-
return {
|
|
308
|
-
postcssPlugin: "postcssRemoveLayers",
|
|
309
|
-
AtRule: {
|
|
310
|
-
layer: (atRule) => {
|
|
311
|
-
atRule.replaceWith(atRule.nodes);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
};
|
|
316
|
-
plugin.postcss = true;
|
|
317
|
-
var remove_layers_default = plugin;
|
|
318
|
-
|
|
319
303
|
// src/build/esbuild/transformTSXFiles.ts
|
|
320
304
|
import fs2 from "fs-extra";
|
|
321
305
|
import ts2 from "typescript";
|
|
@@ -485,9 +469,92 @@ function filePathToURLPath(pathName, isDist = true) {
|
|
|
485
469
|
return result;
|
|
486
470
|
}
|
|
487
471
|
|
|
472
|
+
// src/build/css.ts
|
|
473
|
+
import { globSync as globSync2 } from "glob";
|
|
474
|
+
import fs6 from "fs-extra";
|
|
475
|
+
import postcss from "postcss";
|
|
476
|
+
|
|
477
|
+
// src/build/postcss/remove-layers.ts
|
|
478
|
+
var plugin = (opts = {}) => {
|
|
479
|
+
return {
|
|
480
|
+
postcssPlugin: "postcssRemoveLayers",
|
|
481
|
+
AtRule: {
|
|
482
|
+
layer: (atRule) => {
|
|
483
|
+
atRule.replaceWith(atRule.nodes);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
};
|
|
488
|
+
plugin.postcss = true;
|
|
489
|
+
var remove_layers_default = plugin;
|
|
490
|
+
|
|
491
|
+
// src/build/postcss/add-breakpoint-data.ts
|
|
492
|
+
var plugin2 = (opts = {}) => {
|
|
493
|
+
const nodeValues = [];
|
|
494
|
+
return {
|
|
495
|
+
postcssPlugin: "addBreakpointData",
|
|
496
|
+
AtRule: {
|
|
497
|
+
theme(atRule) {
|
|
498
|
+
const nodes = atRule.nodes.filter((node) => {
|
|
499
|
+
return node.prop.startsWith("--breakpoint-");
|
|
500
|
+
});
|
|
501
|
+
nodeValues.push(...nodes.map((node) => {
|
|
502
|
+
return {
|
|
503
|
+
// @ts-ignore
|
|
504
|
+
breakpoint: node.prop.replace("--breakpoint-", ""),
|
|
505
|
+
// @ts-ignore
|
|
506
|
+
value: node.value
|
|
507
|
+
};
|
|
508
|
+
}));
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
OnceExit(root) {
|
|
512
|
+
root.append([
|
|
513
|
+
`body:before {`,
|
|
514
|
+
`content: "default"; display: none; visibility: hidden;`,
|
|
515
|
+
`}`
|
|
516
|
+
].join(""));
|
|
517
|
+
const nodeValuesMapped = nodeValues.sort((a, b) => {
|
|
518
|
+
return Number(a.value.replace(/[^0-9]/g, "")) - Number(b.value.replace(/[^0-9]/g, ""));
|
|
519
|
+
}).map(({ breakpoint, value }) => {
|
|
520
|
+
return [
|
|
521
|
+
`@media (min-width: ${value}) {`,
|
|
522
|
+
`body:before {`,
|
|
523
|
+
`content: "${breakpoint}";`,
|
|
524
|
+
`}`,
|
|
525
|
+
`}`
|
|
526
|
+
].join("");
|
|
527
|
+
});
|
|
528
|
+
for (const value of nodeValuesMapped) {
|
|
529
|
+
root.append(value);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
};
|
|
534
|
+
plugin2.postcss = true;
|
|
535
|
+
var add_breakpoint_data_default = plugin2;
|
|
536
|
+
|
|
537
|
+
// src/build/css.ts
|
|
538
|
+
import tailwindPostcss from "@tailwindcss/postcss";
|
|
539
|
+
async function buildCSS(disableTailwind) {
|
|
540
|
+
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
541
|
+
for (const file of cssFiles) {
|
|
542
|
+
const fileContents = fs6.readFileSync(file, "utf-8");
|
|
543
|
+
let result = fileContents;
|
|
544
|
+
if (!disableTailwind) {
|
|
545
|
+
result = await postcss([add_breakpoint_data_default()]).process(fileContents, { from: file });
|
|
546
|
+
result = await postcss([tailwindPostcss(), remove_layers_default()]).process(result.css, { from: file });
|
|
547
|
+
}
|
|
548
|
+
const newPath = file.replace(config.srcDir, config.distDir);
|
|
549
|
+
fs6.ensureFileSync(newPath);
|
|
550
|
+
fs6.writeFileSync(newPath, result.css);
|
|
551
|
+
}
|
|
552
|
+
logSize(config.distPublicDir, "css");
|
|
553
|
+
}
|
|
554
|
+
|
|
488
555
|
// src/scripts/build.ts
|
|
489
556
|
var extensions = [".ts", ".tsx"];
|
|
490
|
-
var packageJson = JSON.parse(
|
|
557
|
+
var packageJson = JSON.parse(fs7.readFileSync(config.packageJsonPath, "utf-8"));
|
|
491
558
|
var allPackages = Object.keys(packageJson.devDependencies).concat(Object.keys(packageJson.dependencies));
|
|
492
559
|
var xpineDistDir = getXPineDistDir();
|
|
493
560
|
async function buildApp(args) {
|
|
@@ -495,12 +562,12 @@ async function buildApp(args) {
|
|
|
495
562
|
const removePreviousBuild = args?.removePreviousBuild || false;
|
|
496
563
|
const disableTailwind = args?.disableTailwind || false;
|
|
497
564
|
try {
|
|
498
|
-
if (removePreviousBuild)
|
|
499
|
-
const srcDirFiles =
|
|
565
|
+
if (removePreviousBuild) fs7.removeSync(config.distDir);
|
|
566
|
+
const srcDirFiles = globSync3(config.srcDir + "/**/*.{js,ts,tsx,jsx}");
|
|
500
567
|
const { componentData, dataFiles } = await buildAppFiles(srcDirFiles, isDev);
|
|
501
568
|
const alpineDataFile = await buildAlpineDataFile(componentData, dataFiles);
|
|
502
569
|
await buildClientSideFiles([alpineDataFile], isDev);
|
|
503
|
-
|
|
570
|
+
fs7.removeSync(config.distTempFolder);
|
|
504
571
|
await buildCSS(disableTailwind);
|
|
505
572
|
await buildPublicFolderSymlinks();
|
|
506
573
|
await buildOnLoadFile(componentData, isDev);
|
|
@@ -520,7 +587,7 @@ async function buildAppFiles(files, isDev) {
|
|
|
520
587
|
return fileName === "+config";
|
|
521
588
|
});
|
|
522
589
|
const backendFiles = files.filter((file) => extensions.find((ext) => file.endsWith(ext))).filter((file) => !file.startsWith(config.publicDir));
|
|
523
|
-
|
|
590
|
+
fs7.ensureDirSync(config.distDir);
|
|
524
591
|
await build({
|
|
525
592
|
entryPoints: backendFiles,
|
|
526
593
|
format: "esm",
|
|
@@ -545,9 +612,9 @@ async function buildAppFiles(files, isDev) {
|
|
|
545
612
|
}
|
|
546
613
|
async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
547
614
|
const tempFilePath = path5.join(config.distTempFolder, "./app.ts");
|
|
548
|
-
|
|
615
|
+
fs7.ensureFileSync(tempFilePath);
|
|
549
616
|
const pagesScriptsGlob = config.publicDir + "/scripts/pages/**/*.{js,ts}";
|
|
550
|
-
const clientFiles =
|
|
617
|
+
const clientFiles = globSync3(
|
|
551
618
|
config.publicDir + "/**/*.{js,ts}",
|
|
552
619
|
{
|
|
553
620
|
ignore: pagesScriptsGlob
|
|
@@ -563,7 +630,7 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
|
563
630
|
minify: !isDev,
|
|
564
631
|
sourcemap: isDev ? "inline" : false
|
|
565
632
|
});
|
|
566
|
-
const pagesFiles =
|
|
633
|
+
const pagesFiles = globSync3(pagesScriptsGlob);
|
|
567
634
|
await build({
|
|
568
635
|
entryPoints: pagesFiles || [],
|
|
569
636
|
bundle: true,
|
|
@@ -575,13 +642,13 @@ async function buildClientSideFiles(alpineDataFiles = [], isDev) {
|
|
|
575
642
|
}
|
|
576
643
|
function writeDevServerClientSideCode(tempFilePath) {
|
|
577
644
|
const devServerPath = path5.join(xpineDistDir, "./src/static/dev-server.js");
|
|
578
|
-
const content =
|
|
579
|
-
|
|
645
|
+
const content = fs7.readFileSync(devServerPath, "utf-8");
|
|
646
|
+
fs7.appendFileSync(tempFilePath, "\n" + content);
|
|
580
647
|
}
|
|
581
648
|
function writeSpaClientSideCode(tempFilePath) {
|
|
582
649
|
const spaPath = path5.join(xpineDistDir, "./src/static/spa.js");
|
|
583
|
-
const content =
|
|
584
|
-
|
|
650
|
+
const content = fs7.readFileSync(spaPath, "utf-8");
|
|
651
|
+
fs7.appendFileSync(tempFilePath, "\n" + content);
|
|
585
652
|
}
|
|
586
653
|
async function buildAlpineDataFile(componentData, dataFiles) {
|
|
587
654
|
const output = {
|
|
@@ -627,23 +694,12 @@ async function buildAlpineDataFile(componentData, dataFiles) {
|
|
|
627
694
|
output.code.push(`Alpine.data('${dataFunction.name}', ${dataFunction.name});`);
|
|
628
695
|
}
|
|
629
696
|
const result = output.imports.join("\n") + "\n" + output.code.join("\n") + "\n" + output.end.join("\n");
|
|
630
|
-
|
|
631
|
-
|
|
697
|
+
fs7.ensureFileSync(config.alpineDataPath);
|
|
698
|
+
fs7.writeFileSync(config.alpineDataPath, result);
|
|
632
699
|
return config.alpineDataPath;
|
|
633
700
|
}
|
|
634
|
-
async function buildCSS(disableTailwind) {
|
|
635
|
-
const cssFiles = globSync2(config.srcDir + "/**/*.css");
|
|
636
|
-
for (const file of cssFiles) {
|
|
637
|
-
const fileContents = fs6.readFileSync(file, "utf-8");
|
|
638
|
-
const result = disableTailwind ? fileContents : await postcss([tailwindPostcss(), remove_layers_default()]).process(fileContents, { from: file });
|
|
639
|
-
const newPath = file.replace(config.srcDir, config.distDir);
|
|
640
|
-
fs6.ensureFileSync(newPath);
|
|
641
|
-
fs6.writeFileSync(newPath, result.css);
|
|
642
|
-
}
|
|
643
|
-
logSize(config.distPublicDir, "css");
|
|
644
|
-
}
|
|
645
701
|
async function buildPublicFolderSymlinks() {
|
|
646
|
-
const files =
|
|
702
|
+
const files = globSync3(config.publicDir + "/**/*.*", {
|
|
647
703
|
ignore: "/**/*.{css,js,ts,tsx,jsx}"
|
|
648
704
|
});
|
|
649
705
|
for (const file of files) {
|
|
@@ -652,19 +708,19 @@ async function buildPublicFolderSymlinks() {
|
|
|
652
708
|
const splitNewPath = newPath.split("/");
|
|
653
709
|
splitNewPath.pop();
|
|
654
710
|
const newDir = splitNewPath.join("/");
|
|
655
|
-
|
|
656
|
-
|
|
711
|
+
fs7.ensureDirSync(newDir);
|
|
712
|
+
fs7.symlinkSync(file, newPath);
|
|
657
713
|
} catch {
|
|
658
714
|
}
|
|
659
715
|
}
|
|
660
716
|
}
|
|
661
717
|
async function logSize(pathName, type, validExtensions = [".js", ".css"]) {
|
|
662
|
-
const files =
|
|
718
|
+
const files = globSync3(pathName + "/**/*" + (type === "css" ? ".css" : ""));
|
|
663
719
|
const fileSizes = files.map((file) => {
|
|
664
720
|
if (!validExtensions.find((ext) => file.endsWith(ext))) return false;
|
|
665
721
|
return {
|
|
666
722
|
file,
|
|
667
|
-
size:
|
|
723
|
+
size: fs7.statSync(file).size / (1024 * 1e3)
|
|
668
724
|
};
|
|
669
725
|
}).filter(Boolean);
|
|
670
726
|
const totalSize = fileSizes.reduce((total, current) => {
|
|
@@ -707,7 +763,7 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
707
763
|
const req = { params: {} };
|
|
708
764
|
const data = config2?.data ? await config2.data(req) : null;
|
|
709
765
|
const staticComponentOutput = await componentFn({ data, routePath: urlPath });
|
|
710
|
-
|
|
766
|
+
fs7.writeFileSync(
|
|
711
767
|
path5.join(outputPath, "./index.html"),
|
|
712
768
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
713
769
|
);
|
|
@@ -728,8 +784,8 @@ async function buildStaticFiles(config2, component, componentImport, builtCompon
|
|
|
728
784
|
const urlPath = filePathToURLPath(updatedOutDir);
|
|
729
785
|
const data = config2?.data ? await config2.data(req) : null;
|
|
730
786
|
const staticComponentOutput = await componentFn({ req, data, routePath: urlPath });
|
|
731
|
-
|
|
732
|
-
|
|
787
|
+
fs7.ensureDirSync(updatedOutDir);
|
|
788
|
+
fs7.writeFileSync(
|
|
733
789
|
path5.join(updatedOutDir, "./index.html"),
|
|
734
790
|
doctypeHTML + (config2?.wrapper ? await config2.wrapper({ req, children: staticComponentOutput, config: config2, data, routePath: urlPath }) : staticComponentOutput) + staticComment
|
|
735
791
|
);
|
|
@@ -780,7 +836,7 @@ async function buildOnLoadFile(componentData, isDev) {
|
|
|
780
836
|
}
|
|
781
837
|
`;
|
|
782
838
|
const onLoadFilePath = path5.join(config.distDir, "./__xpineOnLoad.ts");
|
|
783
|
-
|
|
839
|
+
fs7.writeFileSync(onLoadFilePath, output);
|
|
784
840
|
await build({
|
|
785
841
|
entryPoints: [onLoadFilePath],
|
|
786
842
|
format: "esm",
|
package/dist/src/static/spa.js
CHANGED
|
@@ -13,8 +13,17 @@ async function updatePageOnLinkClick(e) {
|
|
|
13
13
|
if (isExternal && !e?.target?.getAttribute("data-spa-crossorigin")) return;
|
|
14
14
|
e.preventDefault();
|
|
15
15
|
try {
|
|
16
|
+
if (targetHref === window.location.href) return;
|
|
17
|
+
const newURL = isExternal ? safeParseURL(targetHref) : safeParseURL(window.location.href);
|
|
18
|
+
const startEvent = new CustomEvent("spa-link-click", {
|
|
19
|
+
detail: {
|
|
20
|
+
state: "start",
|
|
21
|
+
href: targetHref,
|
|
22
|
+
url: newURL
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
window.dispatchEvent(startEvent);
|
|
16
26
|
await getNewPageContent(targetHref);
|
|
17
|
-
if (targetHref === window.location.pathname) return;
|
|
18
27
|
window.history.pushState(
|
|
19
28
|
{
|
|
20
29
|
type: "link-click",
|
|
@@ -26,10 +35,18 @@ async function updatePageOnLinkClick(e) {
|
|
|
26
35
|
const event = new CustomEvent("spa-update-page-url", {
|
|
27
36
|
detail: {
|
|
28
37
|
href: targetHref,
|
|
29
|
-
url:
|
|
38
|
+
url: newURL
|
|
30
39
|
}
|
|
31
40
|
});
|
|
32
41
|
window.dispatchEvent(event);
|
|
42
|
+
const endEvent = new CustomEvent("spa-link-click", {
|
|
43
|
+
detail: {
|
|
44
|
+
state: "end",
|
|
45
|
+
href: targetHref,
|
|
46
|
+
url: newURL
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
window.dispatchEvent(endEvent);
|
|
33
50
|
} catch (err) {
|
|
34
51
|
console.error(err);
|
|
35
52
|
}
|
|
@@ -180,5 +197,26 @@ function safeParseURL(url) {
|
|
|
180
197
|
return {};
|
|
181
198
|
}
|
|
182
199
|
}
|
|
200
|
+
function handleBreakpointEvents() {
|
|
201
|
+
let lastSentBreakpoint = "";
|
|
202
|
+
let initial = true;
|
|
203
|
+
return function() {
|
|
204
|
+
const breakpoint = window.getComputedStyle(document.body, ":before")?.content?.replace(/[\'\"]/g, "") || "";
|
|
205
|
+
if (breakpoint !== lastSentBreakpoint) {
|
|
206
|
+
const event = new CustomEvent("breakpoint-change", {
|
|
207
|
+
detail: {
|
|
208
|
+
breakpoint,
|
|
209
|
+
initial
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
window.dispatchEvent(event);
|
|
213
|
+
lastSentBreakpoint = breakpoint;
|
|
214
|
+
initial = false;
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
var breakpointEventsFunction = handleBreakpointEvents();
|
|
183
219
|
window.addEventListener("DOMContentLoaded", replaceDocumentContentsWithLinkResponse);
|
|
184
220
|
window.addEventListener("popstate", handleBackButton);
|
|
221
|
+
window.addEventListener("resize", breakpointEventsFunction);
|
|
222
|
+
breakpointEventsFunction();
|