Skip to content

Commit 7e23d65

Browse files
authored
feat: Web CLI utility for copying assets from node_modules to public (#409)
1 parent cb44fe3 commit 7e23d65

File tree

6 files changed

+2896
-1680
lines changed

6 files changed

+2896
-1680
lines changed

.changeset/curly-poets-explode.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@powersync/web': patch
3+
---
4+
5+
Added a bin/cli utilty that can be invoked with `npx powersync-web copy-assets` or `pnpm powersync-web copy-assets`.

demos/react-native-web-supabase-todolist/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ bucket_definitions:
5050
5151
### Configure the app
5252
53-
#### 1. Set up environment variables:
53+
#### 1. Set up environment variables:
5454
5555
Copy the `.env.local.template` file:
5656

@@ -65,7 +65,7 @@ Then edit `.env.local` to insert your Supabase and PowerSync project credentials
6565
This is required for the React Native Web implementation. Learn more in [our docs](https://docs.powersync.com/client-sdk-references/react-native-and-expo/react-native-web-support).
6666

6767
```bash
68-
mkdir -p public/@powersync && cp -r node_modules/@powersync/web/dist/* public/@powersync/
68+
pnpm powersync-web copy-assets
6969
```
7070

7171
### Run the app
@@ -88,4 +88,4 @@ Run on Android:
8888

8989
```sh
9090
pnpm android
91-
```
91+
```

packages/web/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# PowerSync SDK for Web
66

7-
*[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres, MongoDB or MySQL on the server-side.*
7+
_[PowerSync](https://www.powersync.com) is a sync engine for building local-first apps with instantly-responsive UI/UX and simplified state transfer. Syncs between SQLite on the client-side and Postgres, MongoDB or MySQL on the server-side._
88

99
This package (`packages/web`) is the PowerSync SDK for JavaScript Web clients. It is an extension of `packages/common`.
1010

@@ -40,6 +40,15 @@ See the [example Vite config](https://github.com/powersync-ja/powersync-js/blob/
4040

4141
Our [full SDK reference](https://docs.powersync.com/client-sdk-references/js-web) contains everything you need to know to get started implementing PowerSync in your project.
4242

43+
# Public Workers
44+
45+
For some frameworks, it may be required to configure the web workers ([see the docs](https://docs.powersync.com/client-sdk-references/react-native-and-expo/react-native-web-support)).
46+
The `@powersync/web` package includes a CLI utility which can copy the required assets to the `public` directory (configurable with the `--output` option).
47+
48+
```bash
49+
pnpm powersync-web copy-assets
50+
```
51+
4352
# Changelog
4453

4554
A changelog for this SDK is available [here](https://releases.powersync.com/announcements/powersync-js-web-client-sdk).

packages/web/bin/powersync.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
3+
const { Command } = require('commander');
4+
const program = new Command();
5+
const path = require('path');
6+
const fsPromise = require('fs/promises');
7+
const { version } = require('../package.json');
8+
9+
program
10+
.name('powersync-web')
11+
.description('CLI for PowerSync Web SDK utilities')
12+
.version(version);
13+
14+
program
15+
.command('copy-assets')
16+
.description('Copy assets to the specified output directory')
17+
.option('-o, --output <directory>', 'output directory for assets', 'public')
18+
.action(async(options) => {
19+
const outputDir = options.output;
20+
21+
console.log(`Target directory: ${outputDir}`);
22+
23+
const cwd = process.cwd();
24+
const source = path.join(cwd, 'node_modules', '@powersync', 'web', 'dist');
25+
const destination = path.join(cwd, outputDir, '@powersync');
26+
27+
await fsPromise.rm(destination, { recursive: true, force: true }); // Clear old assets
28+
29+
await copyDirectory(source, destination)
30+
});
31+
32+
33+
program.parse(process.argv);
34+
35+
async function copyDirectory(source, destination) {
36+
try {
37+
await fsPromise.cp(source, destination, { recursive: true });
38+
console.log(`Assets copied from ${source} to ${destination}`);
39+
} catch (err) {
40+
console.error(`Error copying assets: ${err.message}`);
41+
process.exit(1);
42+
}
43+
}

packages/web/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
"description": "A Web SDK for JourneyApps PowerSync",
55
"main": "lib/src/index.js",
66
"types": "lib/src/index.d.ts",
7+
"bin": {
8+
"powersync-web": "bin/powersync.js"
9+
},
710
"files": [
11+
"bin",
812
"lib",
913
"!lib/tests",
1014
"dist"
@@ -64,6 +68,7 @@
6468
"async-mutex": "^0.4.0",
6569
"bson": "^6.6.0",
6670
"comlink": "^4.4.1",
71+
"commander": "^12.1.0",
6772
"js-logger": "^1.6.1"
6873
},
6974
"devDependencies": {

0 commit comments

Comments
 (0)