1- import { NodeModulesExternal } from "@finos/perspective-esbuild-plugin/external.js " ;
2- import { build } from "@finos/perspective-esbuild-plugin/build.js " ;
3- import { BuildCss } from "@prospective.co/procss/target/cjs/procss.js " ;
4- 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+
55import fs from "fs" ;
6- import { createRequire } from "node:module " ;
6+ import cpy from "cpy " ;
77import path from "node:path" ;
8-
8+ import { createRequire } from "node:module" ;
99const require = createRequire ( import . meta. url ) ;
1010
1111// Force all react imports to resolve to the same copy to avoid
@@ -17,137 +17,51 @@ const REACT_ALIAS = {
1717 "react/jsx-runtime" : require . resolve ( "react/jsx-runtime" ) ,
1818} ;
1919
20- const BUILD = [
20+ const BUNDLES = [
2121 {
22- define : {
23- global : "window" ,
24- } ,
25- entryPoints : [ "src/index.jsx" ] ,
26- plugins : [ NodeModulesExternal ( ) ] ,
27- format : "esm" ,
28- loader : {
29- ".css" : "text" ,
30- ".html" : "text" ,
31- ".jsx" : "jsx" ,
32- ".png" : "file" ,
33- ".ttf" : "file" ,
34- ".wasm" : "file" ,
35- } ,
36- outfile : "./lib/index.js" ,
22+ entryPoints : [ "./src/js/index.jsx" ] ,
23+ plugins : [ node_modules_external ( ) ] ,
24+ outfile : "dist/index.js" ,
25+ alias : REACT_ALIAS ,
3726 } ,
3827 {
39- define : {
40- global : "window" ,
41- } ,
42- entryPoints : [ "src/main.jsx" ] ,
43- bundle : true ,
44- plugins : [ ] ,
45- format : "esm" ,
46- alias : REACT_ALIAS ,
47- loader : {
48- ".css" : "text" ,
49- ".html" : "text" ,
50- ".jsx" : "jsx" ,
51- ".png" : "file" ,
52- ".ttf" : "file" ,
53- ".wasm" : "file" ,
54- } ,
28+ entryPoints : [ "./src/js/main.jsx" ] ,
5529 outfile : "../csp_gateway/server/build/main.js" ,
56- publicPath : "/static/" ,
30+ alias : REACT_ALIAS ,
31+ publicPath : "/static" ,
5732 } ,
5833] ;
5934
60- function add ( builder , path , path2 ) {
61- builder . add ( path , fs . readFileSync ( require . resolve ( path2 || path ) ) . toString ( ) ) ;
62- }
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+ ] ;
6339
64- async function compile_css ( ) {
65- const builder1 = new BuildCss ( "" ) ;
66- add ( builder1 , "./src/style/index.css" ) ;
67- add ( builder1 , "./src/style/base.css" ) ;
68- add ( builder1 , "./src/style/nord.css" ) ;
69- add ( builder1 , "./src/style/header_footer.css" ) ;
70- add ( builder1 , "./src/style/perspective.css" ) ;
71- add ( builder1 , "./src/style/settings.css" ) ;
72- add (
73- builder1 ,
74- "perspective-viewer-pro.css" ,
75- "@perspective-dev/viewer/dist/css/pro.css" ,
76- ) ;
77- add (
78- builder1 ,
79- "perspective-viewer-pro-dark.css" ,
80- "@perspective-dev/viewer/dist/css/pro-dark.css" ,
81- ) ;
82- add (
83- builder1 ,
84- "perspective-viewer-monokai.css" ,
85- "@perspective-dev/viewer/dist/css/monokai.css" ,
86- ) ;
87- add (
88- builder1 ,
89- "perspective-viewer-vaporwave.css" ,
90- "@perspective-dev/viewer/dist/css/vaporwave.css" ,
91- ) ;
92- add (
93- builder1 ,
94- "perspective-viewer-dracula.css" ,
95- "@perspective-dev/viewer/dist/css/dracula.css" ,
96- ) ;
97- add (
98- builder1 ,
99- "perspective-viewer-gruvbox.css" ,
100- "@perspective-dev/viewer/dist/css/gruvbox.css" ,
101- ) ;
102- add (
103- builder1 ,
104- "perspective-viewer-gruvbox-dark.css" ,
105- "@perspective-dev/viewer/dist/css/gruvbox-dark.css" ,
106- ) ;
107- add (
108- builder1 ,
109- "perspective-viewer-solarized.css" ,
110- "@perspective-dev/viewer/dist/css/solarized.css" ,
111- ) ;
112- add (
113- builder1 ,
114- "perspective-viewer-solarized-dark.css" ,
115- "@perspective-dev/viewer/dist/css/solarized-dark.css" ,
116- ) ;
117- add (
118- builder1 ,
119- "react-modern-drawer.css" ,
120- "react-modern-drawer/dist/index.css" ,
121- ) ;
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+ }
45+ }
12246
123- const css = builder1 . compile ( ) . get ( "index.css" ) ;
47+ async function build ( ) {
48+ // Bundle css
49+ await bundle_css ( ) ;
12450
125- // write to extension
126- fs . writeFileSync ( "./lib/index.css" , css ) ;
127- fs . writeFileSync ( "../csp_gateway/server/build/index.css" , css ) ;
128- }
51+ // Copy HTML
52+ await cpy ( "src/html/*" , "dist/" ) ;
12953
130- async function cp_to_paths ( path ) {
131- await cpy ( path , "../csp_gateway/server/build/" , { flat : true } ) ;
132- }
54+ // Copy images
55+ await cpy ( "src/img/*" , "dist/" , { flat : true } ) ;
13356
134- async function build_all ( ) {
135- /* make directories */
136- fs . mkdirSync ( "../csp_gateway/server/build/" , { recursive : true } ) ;
57+ // Copy Perspective wasm assets for /static/*.wasm requests.
58+ copy_wasm_assets ( "dist" ) ;
13759
138- /* Compile and copy JS */
139- await Promise . all ( BUILD . map ( build ) ) . catch ( ( ) => process . exit ( 1 ) ) ;
140- // await cp_to_paths("./src/style/*.css");
141- await cp_to_paths ( "./src/html/*.html" ) ;
142- await cp_to_paths (
143- "node_modules/@perspective-dev/server/dist/wasm/perspective-server.wasm" ,
144- ) ;
145- await cp_to_paths (
146- "node_modules/@perspective-dev/viewer/dist/wasm/perspective-viewer.wasm" ,
147- ) ;
60+ await Promise . all ( BUNDLES . map ( bundle ) ) . catch ( ( ) => process . exit ( 1 ) ) ;
14861
149- /* Compile and copy css */
150- await compile_css ( ) ;
62+ // Copy servable assets to python extension (exclude esm/)
63+ fs . mkdirSync ( "../csp_gateway/server/build" , { recursive : true } ) ;
64+ await cpy ( "dist/**/*" , "../csp_gateway/server/build" , { flat : true } ) ;
15165}
15266
153- build_all ( ) ;
67+ build ( ) ;
0 commit comments