aboutsummaryrefslogtreecommitdiff
path: root/contrib/build-fast-web.sh
blob: 2f213e5f642230b60e2becf94cee25ca0d5980a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash

set -eu
set -x

export DIST=build/web
export NODE_PATH=$DIST:vendor

export BUNDLE_OPTIONS='--bundle --format=esm --target=esnext'

function build_idb() {
  rm -rf packages/idb-bridge/{node_modules,lib,dist,tsconfig.tsbuildinfo}
  idb_dir=$DIST/@gnu-taler/idb-bridge
  mkdir -p $idb_dir
  esbuild $BUNDLE_OPTIONS packages/idb-bridge/src/index.ts > $idb_dir/index.js
}

function build_taler_util() {
  taler_util_dir=$DIST/@gnu-taler/taler-util
  mkdir -p $taler_util_dir
  rm -rf packages/taler-util/{node_modules,lib,dist,tsconfig.tsbuildinfo}

  esbuild $BUNDLE_OPTIONS packages/taler-util/src/index.ts > $taler_util_dir/index.js
}

function build_fflate() {
  fflate_dir=$DIST/fflate
  mkdir -p $fflate_dir
  esbuild $BUNDLE_OPTIONS vendor/fflate/src/index.ts > $fflate_dir/index.js
}

function build_ct() {
  ct_dir=$DIST/cancellationtoken
  mkdir -p $ct_dir
  esbuild $BUNDLE_OPTIONS vendor/cancellationtoken/src/index.ts > $ct_dir/index.js
}

function build_wallet_core() {
  taler_wallet_core_dir=$DIST/@gnu-taler/taler-wallet-core

  rm -rf packages/taler-wallet-core/{node_modules,lib,dist,tsconfig.tsbuildinfo}

  mkdir -p $taler_wallet_core_dir
  esbuild $BUNDLE_OPTIONS --external:@gnu-taler/taler-util packages/taler-wallet-core/src/index.browser.ts > $taler_wallet_core_dir/index.js
}

function build_wallet_embedded() {
  taler_wallet_embedded_dir=$DIST/@gnu-taler/taler-wallet-embedded
  rm -rf packages/taler-wallet-embedded/{node_modules,lib,dist,tsconfig.tsbuildinfo}

  mkdir -p $taler_wallet_embedded_dir
  esbuild $BUNDLE_OPTIONS packages/taler-wallet-embedded/src/index.ts > $taler_wallet_embedded_dir/taler-wallet-embedded.js
}

function build_vendor() {
  mkdir -p $DIST/$1

  esbuild $BUNDLE_OPTIONS vendor/$1/src/index.js > $DIST/$1/index.js
}

function build_preact() {
  mkdir -p $DIST/preact/{debug,hooks}

  esbuild $BUNDLE_OPTIONS vendor/preact/src/index.js > $DIST/preact/index.js
  esbuild $BUNDLE_OPTIONS --external:preact vendor/preact/hooks/src/index.js > $DIST/preact/hooks/index.js
  esbuild $BUNDLE_OPTIONS --external:preact vendor/preact/debug/src/index.js > $DIST/preact/debug/index.js
}

function build_preact-router() {
  mkdir -p $DIST/preact-router/match

  esbuild $BUNDLE_OPTIONS --external:preact vendor/preact-router/src/index.js > $DIST/preact-router/index.js
  esbuild $BUNDLE_OPTIONS --loader:.js=jsx --external:preact --external:preact-router vendor/preact-router/src/match.js > $DIST/preact-router/match/index.js
}

function build_preact_compat() {
  mkdir -p $DIST/{react/jsx-runtime,react-dom/test-utils}

  esbuild $BUNDLE_OPTIONS --loader:.js=jsx vendor/preact/compat/src/index.js > $DIST/react/index.js

  esbuild $BUNDLE_OPTIONS --loader:.js=jsx --external:preact vendor/preact/compat/src/index.js > $DIST/react/index.js
  esbuild $BUNDLE_OPTIONS --loader:.js=jsx --external:preact vendor/preact/compat/src/index.js > $DIST/react-dom/index.js
  esbuild $BUNDLE_OPTIONS --loader:.js=jsx vendor/preact/jsx-runtime/src/index.js > $DIST/react/jsx-runtime/index.js
  esbuild $BUNDLE_OPTIONS --loader:.js=jsx vendor/preact/test-utils/src/index.js > $DIST/react-dom/test-utils/index.js
}

function build_qrcode() {
  mkdir -p $DIST/qrcode-generator

  esbuild $BUNDLE_OPTIONS vendor/qrcode-generator/js/qrcode.js > $DIST/qrcode-generator/index.js
}

function build_history() {
  mkdir -p $DIST/{history,resolve-pathname,value-equal,tiny-warning,tiny-invariant}

  esbuild $BUNDLE_OPTIONS --loader:.js=ts vendor/tiny-warning/src/index.js > $DIST/tiny-warning/index.js
  esbuild $BUNDLE_OPTIONS --loader:.js=ts vendor/tiny-invariant/src/index.js > $DIST/tiny-invariant/index.js

  esbuild $BUNDLE_OPTIONS vendor/resolve-pathname/modules/index.js > $DIST/resolve-pathname/index.js
  esbuild $BUNDLE_OPTIONS vendor/value-equal/modules/index.js > $DIST/value-equal/index.js

  esbuild $BUNDLE_OPTIONS vendor/history/modules/index.js > $DIST/history/index.js
}

function build_linaria() {
  mkdir -p $DIST/@linaria/{react,core}
  mkdir -p $DIST/@emotion/is-prop-valid

  esbuild $BUNDLE_OPTIONS vendor/@emotion/is-prop-valid/index.js > $DIST/@emotion/is-prop-valid/index.js

  esbuild $BUNDLE_OPTIONS vendor/@linaria/packages/core/src/index.ts > $DIST/@linaria/core/index.js
  esbuild $BUNDLE_OPTIONS --external:preact vendor/@linaria/packages/react/src/index.ts > $DIST/@linaria/react/index.js
}

function build_wallet_webextension() {
  rm -rf packages/taler-wallet-webextension/{node_modules,lib,dist,tsconfig.tsbuildinfo,extension}

  taler_wallet_webextension_dir=packages/taler-wallet-webextension/dist
  mkdir -p $taler_wallet_webextension_dir

  esbuild $BUNDLE_OPTIONS packages/taler-wallet-webextension/src/background.ts > $taler_wallet_webextension_dir/background.js
  esbuild $BUNDLE_OPTIONS packages/taler-wallet-webextension/src/browserWorkerEntry.ts > $taler_wallet_webextension_dir/browserWorkerEntry.js

  # implemented as a script because right now esbuild binary does not support plugins
  # FIXME: remove javascript when possible
  node ./contrib/build-fast-with-linaria.mjs packages/taler-wallet-webextension/src/popupEntryPoint.tsx $taler_wallet_webextension_dir
  node ./contrib/build-fast-with-linaria.mjs packages/taler-wallet-webextension/src/walletEntryPoint.tsx $taler_wallet_webextension_dir
}


build_idb
build_taler_util
build_fflate
build_wallet_core

build_vendor date-fns

build_preact
build_preact-router
build_preact_compat

build_qrcode
build_history
build_linaria

build_wallet_webextension