Skip to content

Commit 8c5d773

Browse files
committed
Added powersync-web cli file to bin.
1 parent d72ac11 commit 8c5d773

File tree

4 files changed

+63
-45
lines changed

4 files changed

+63
-45
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`.

packages/web/bin/powersync.js

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

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": {

pnpm-lock.yaml

Lines changed: 12 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)