1- < << << << before updating
2- import { NodeModulesExternal } from "@finos/perspective-esbuild-plugin/external.js" ;
3- import { build } from "@finos/perspective-esbuild-plugin/build.js" ;
4- import { BuildCss } from "@prospective.co/procss/target/cjs/procss.js" ;
5- import cpy from "cpy" ;
1+ import { bundle } from "./tools/bundle.mjs" ;
2+ import { bundle_css } from "./tools/css.mjs" ;
3+ import { node_modules_external } from "./tools/externals.mjs" ;
4+
65import fs from "fs" ;
7- import { createRequire } from "node:module " ;
6+ import cpy from "cpy " ;
87import path from "node:path" ;
9-
8+ import { createRequire } from "node:module" ;
109const require = createRequire ( import . meta. url ) ;
1110
1211// Force all react imports to resolve to the same copy to avoid
@@ -17,177 +16,52 @@ const REACT_ALIAS = {
1716 "react-dom" : path . dirname ( require . resolve ( "react-dom/package.json" ) ) ,
1817 "react/jsx-runtime" : require . resolve ( "react/jsx-runtime" ) ,
1918} ;
20- = === ===
21- import { bundle } from "./tools/bundle.mjs" ;
22- import { bundle_css } from "./tools/css.mjs" ;
23- import { node_modules_external } from "./tools/externals.mjs" ;
24-
25- import fs from "fs" ;
26- import cpy from "cpy" ;
27- > >>> >>> after updating
2819
2920const BUNDLES = [
3021 {
31- << < << << before updating
32- define : {
33- global : "window" ,
34- } ,
35- entryPoints : [ "src/index.jsx" ] ,
36- plugins : [ NodeModulesExternal ( ) ] ,
37- format : "esm" ,
38- loader : {
39- ".css" : "text" ,
40- ".html" : "text" ,
41- ".jsx" : "jsx" ,
42- ".png" : "file" ,
43- ".ttf" : "file" ,
44- ".wasm" : "file" ,
45- } ,
46- outfile : "./lib/index.js" ,
22+ entryPoints : [ "./src/js/index.jsx" ] ,
23+ plugins : [ node_modules_external ( ) ] ,
24+ outfile : "dist/index.js" ,
25+ alias : REACT_ALIAS ,
4726 } ,
4827 {
49- define : {
50- global : "window" ,
51- } ,
52- entryPoints : [ "src/main.jsx" ] ,
53- bundle : true ,
54- plugins : [ ] ,
55- format : "esm" ,
56- alias : REACT_ALIAS ,
57- loader : {
58- ".css" : "text" ,
59- ".html" : "text" ,
60- ".jsx" : "jsx" ,
61- ".png" : "file" ,
62- ".ttf" : "file" ,
63- ".wasm" : "file" ,
64- } ,
28+ entryPoints : [ "./src/js/main.jsx" ] ,
6529 outfile : "../csp_gateway/server/build/main.js" ,
66- publicPath : "/static/" ,
30+ alias : REACT_ALIAS ,
31+ publicPath : "/static" ,
6732 } ,
6833] ;
6934
70- function add ( builder , path , path2 ) {
71- builder . add ( path , fs . readFileSync ( require . resolve ( path2 || path ) ) . toString ( ) ) ;
72- }
73-
74- async function compile_css ( ) {
75- const builder1 = new BuildCss ( "" ) ;
76- add ( builder1 , "./src/style/index.css" ) ;
77- add ( builder1 , "./src/style/base.css" ) ;
78- add ( builder1 , "./src/style/nord.css" ) ;
79- add ( builder1 , "./src/style/header_footer.css" ) ;
80- add ( builder1 , "./src/style/perspective.css" ) ;
81- add ( builder1 , "./src/style/settings.css" ) ;
82- add (
83- builder1 ,
84- "perspective-viewer-pro.css" ,
85- "@perspective-dev/viewer/dist/css/pro.css" ,
86- ) ;
87- add (
88- builder1 ,
89- "perspective-viewer-pro-dark.css" ,
90- "@perspective-dev/viewer/dist/css/pro-dark.css" ,
91- ) ;
92- add (
93- builder1 ,
94- "perspective-viewer-monokai.css" ,
95- "@perspective-dev/viewer/dist/css/monokai.css" ,
96- ) ;
97- add (
98- builder1 ,
99- "perspective-viewer-vaporwave.css" ,
100- "@perspective-dev/viewer/dist/css/vaporwave.css" ,
101- ) ;
102- add (
103- builder1 ,
104- "perspective-viewer-dracula.css" ,
105- "@perspective-dev/viewer/dist/css/dracula.css" ,
106- ) ;
107- add (
108- builder1 ,
109- "perspective-viewer-gruvbox.css" ,
110- "@perspective-dev/viewer/dist/css/gruvbox.css" ,
111- ) ;
112- add (
113- builder1 ,
114- "perspective-viewer-gruvbox-dark.css" ,
115- "@perspective-dev/viewer/dist/css/gruvbox-dark.css" ,
116- ) ;
117- add (
118- builder1 ,
119- "perspective-viewer-solarized.css" ,
120- "@perspective-dev/viewer/dist/css/solarized.css" ,
121- ) ;
122- add (
123- builder1 ,
124- "perspective-viewer-solarized-dark.css" ,
125- "@perspective-dev/viewer/dist/css/solarized-dark.css" ,
126- ) ;
127- add (
128- builder1 ,
129- "react-modern-drawer.css" ,
130- "react-modern-drawer/dist/index.css" ,
131- ) ;
132-
133- const css = builder1 . compile ( ) . get ( "index.css" ) ;
134-
135- // write to extension
136- fs . writeFileSync ( "./lib/index.css" , css ) ;
137- fs . writeFileSync ( "../csp_gateway/server/build/index.css" , css ) ;
138- }
35+ const WASM_ASSETS = [
36+ "node_modules/@perspective-dev/server/dist/wasm/perspective-server.wasm" ,
37+ "node_modules/@perspective-dev/viewer/dist/wasm/perspective-viewer.wasm" ,
38+ ] ;
13939
140- async function cp_to_paths ( path ) {
141- await cpy ( path , "../csp_gateway/server/build/" , { flat : true } ) ;
40+ function copy_wasm_assets ( outdir ) {
41+ fs . mkdirSync ( outdir , { recursive : true } ) ;
42+ for ( const wasm of WASM_ASSETS ) {
43+ fs . copyFileSync ( wasm , path . join ( outdir , path . basename ( wasm ) ) ) ;
44+ }
14245}
14346
144- async function build_all ( ) {
145- /* make directories */
146- fs . mkdirSync ( "../csp_gateway/server/build/" , { recursive : true } ) ;
147-
148- /* Compile and copy JS */
149- await Promise . all ( BUILD . map ( build ) ) . catch ( ( ) => process . exit ( 1 ) ) ;
150- // await cp_to_paths("./src/style/*.css");
151- await cp_to_paths ( "./src/html/*.html" ) ;
152- await cp_to_paths (
153- "node_modules/@perspective-dev/server/dist/wasm/perspective-server.wasm" ,
154- ) ;
155- await cp_to_paths (
156- "node_modules/@perspective-dev/viewer/dist/wasm/perspective-viewer.wasm" ,
157- ) ;
158-
159- /* Compile and copy css */
160- await compile_css ( ) ;
161- = === ===
162- entryPoints: [ "src/ts/index.ts" ] ,
163- plugins : [ node_modules_external ( ) ] ,
164- outfile : "dist/esm/index.js" ,
165- } ,
166- {
167- entryPoints : [ "src/ts/index.ts" ] ,
168- outfile : "dist/cdn/index.js" ,
169- } ,
170- ] ;
171-
17247async function build ( ) {
17348 // Bundle css
17449 await bundle_css ( ) ;
17550
17651 // Copy HTML
177- cpy ( "src/html/*" , "dist/" ) ;
52+ await cpy ( "src/html/*" , "dist/" ) ;
17853
17954 // Copy images
180- fs . mkdirSync ( "dist/img" , { recursive : true } ) ;
181- cpy ( "src/img/*" , "dist/img" ) ;
55+ await cpy ( "src/img/*" , "dist/" , { flat : true } ) ;
56+
57+ // Copy Perspective wasm assets for /static/*.wasm requests.
58+ copy_wasm_assets ( "dist" ) ;
18259
18360 await Promise . all ( BUNDLES . map ( bundle ) ) . catch ( ( ) => process . exit ( 1 ) ) ;
18461
18562 // Copy servable assets to python extension (exclude esm/)
186- fs . mkdirSync ( "../csp_gateway/extension" , { recursive : true } ) ;
187- cpy ( "dist/**/*" , "../csp_gateway/extension" , {
188- filter : ( file ) => ! file . relativePath . startsWith ( "esm" ) ,
189- } ) ;
190- > >>> >>> after updating
63+ fs . mkdirSync ( "../csp_gateway/server/build" , { recursive : true } ) ;
64+ await cpy ( "dist/**/*" , "../csp_gateway/server/build" , { flat : true } ) ;
19165}
19266
19367build ( ) ;
0 commit comments