aboutsummaryrefslogtreecommitdiff
path: root/src/build_ffi.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'src/build_ffi.mjs')
-rw-r--r--src/build_ffi.mjs78
1 files changed, 77 insertions, 1 deletions
diff --git a/src/build_ffi.mjs b/src/build_ffi.mjs
index eff03bf..df15223 100644
--- a/src/build_ffi.mjs
+++ b/src/build_ffi.mjs
@@ -1,4 +1,4 @@
-import { build } from 'esbuild'
+import { build, context } from 'esbuild'
import { Ok, Error } from "./gleam.mjs"
import { lessLoader } from 'esbuild-plugin-less';
@@ -65,3 +65,79 @@ export function less_build(css, out) {
})
})
}
+
+export function bundle_watch(entry, out) {
+ return new Promise(resolve => {
+ context({
+ entryPoints: [entry],
+ bundle: true,
+ minify: true,
+ format: 'esm',
+ outfile: out,
+ }).then(function(ctx){
+ ctx.watch()
+ console.log("watching bundle...")
+ }).then(function(){
+ resolve(new Ok(undefined))
+ }).catch(function(e){
+ resolve(new Error(JSON.stringify(e)))
+ })
+ })
+}
+
+export function js_watch(js, out) {
+ return new Promise(resolve => {
+ context({
+ stdin: {
+ contents: js,
+ loader: 'js',
+ },
+ bundle: false,
+ minify: false,
+ format: 'esm',
+ outfile: out,
+ }).then(function(ctx){
+ ctx.watch()
+ console.log("watching js...")
+ }).then(function(){
+ resolve(new Ok(undefined))
+ }).catch(function(e){
+ resolve(new Error(JSON.stringify(e)))
+ })
+ })
+}
+
+export function copy_watch(src, out) {
+ return new Promise(resolve => {
+ context({
+ entryPoints: [src],
+ loader: {'.wxml': 'copy', '.json': 'copy'},
+ outfile: out,
+ }).then(function(ctx){
+ ctx.watch()
+ console.log(`watching json/wxml ${src}...`)
+ }).then(function(){
+ resolve(new Ok(undefined))
+ }).catch(function(e){
+ resolve(new Error(JSON.stringify(e)))
+ })
+ })
+}
+
+export function less_watch(css, out) {
+ return new Promise(resolve => {
+ context({
+ entryPoints: [css],
+ plugins: [lessLoader()],
+ loader: {'.less': 'css'},
+ outfile: out,
+ }).then(function(ctx){
+ ctx.watch()
+ console.log(`watching css ${css}...`)
+ }).then(function(){
+ resolve(new Ok(undefined))
+ }).catch(function(e){
+ resolve(new Error(JSON.stringify(e)))
+ })
+ })
+}