Skip to content

Commit c67c12a

Browse files
use Dart script instead of sh script for wasm init
1 parent 44a466f commit c67c12a

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

melos.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ scripts:
3838
scope:
3939
- powersync_web_worker
4040

41-
update:wasm: sh scripts/init_sqlite_wasm.sh
41+
update:wasm: dart run scripts/init_sqlite_wasm.dart
4242

4343
test:
4444
description: Run tests in a specific package.

scripts/init_sqlite_wasm.dart

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/// Downloads sqlite3.wasm and copies it to all demo folders
2+
import 'dart:io';
3+
4+
final sqliteUrl =
5+
'https://github.com/simolus3/sqlite3.dart/releases/download/sqlite3-2.3.0/sqlite3.wasm';
6+
7+
void main() async {
8+
// Create assets directory if it doesn't exist
9+
final assetsDir = Directory('assets');
10+
if (!await assetsDir.exists()) {
11+
await assetsDir.create();
12+
}
13+
14+
final sqliteFilename = 'sqlite3.wasm';
15+
final sqlitePath = 'assets/$sqliteFilename';
16+
17+
// Download sqlite3.wasm
18+
await downloadFile(sqliteUrl, sqlitePath);
19+
20+
await for (var entity in Directory('demos').list()) {
21+
if (entity is Directory) {
22+
var demoDir = entity;
23+
var webDir = Directory('${demoDir.path}/web');
24+
if (await webDir.exists()) {
25+
await File(sqlitePath).copy('${webDir.path}/$sqliteFilename');
26+
print('Copied $sqlitePath to ${webDir.path}');
27+
}
28+
}
29+
}
30+
}
31+
32+
Future<void> downloadFile(String url, String savePath) async {
33+
print('Downloading: $url');
34+
var httpClient = HttpClient();
35+
var request = await httpClient.getUrl(Uri.parse(url));
36+
var response = await request.close();
37+
if (response.statusCode == HttpStatus.ok) {
38+
var file = File(savePath);
39+
await response.pipe(file.openWrite());
40+
} else {
41+
print(
42+
'Failed to download file: ${response.statusCode} ${response.reasonPhrase}');
43+
}
44+
}

scripts/init_sqlite_wasm.sh

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)