Add pnpm scripts and run via CI
This commit is contained in:
parent
42b98e27f0
commit
caa2eb2d98
39
.github/workflows/ci.yml
vendored
39
.github/workflows/ci.yml
vendored
@ -15,38 +15,41 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "20"
|
||||
cache: "pnpm"
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
cache: true
|
||||
|
||||
- name: Setup pnpm
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@10.23.0 --activate
|
||||
pnpm --version
|
||||
|
||||
- name: Install build dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends build-essential
|
||||
|
||||
- name: Go env
|
||||
run: |
|
||||
go version
|
||||
go env
|
||||
- name: pnpm format:check
|
||||
run: pnpm -s format:check
|
||||
|
||||
- name: Test (default)
|
||||
- name: pnpm lint
|
||||
run: pnpm -s lint
|
||||
|
||||
- name: pnpm test
|
||||
env:
|
||||
CGO_ENABLED: "1"
|
||||
run: go test ./...
|
||||
run: pnpm -s test
|
||||
|
||||
- name: Test (sqlite_fts5)
|
||||
- name: pnpm build
|
||||
env:
|
||||
CGO_ENABLED: "1"
|
||||
run: go test -tags sqlite_fts5 ./...
|
||||
|
||||
- name: Build (default)
|
||||
env:
|
||||
CGO_ENABLED: "1"
|
||||
run: go build ./cmd/wacli
|
||||
|
||||
- name: Build (sqlite_fts5)
|
||||
env:
|
||||
CGO_ENABLED: "1"
|
||||
run: go build -tags sqlite_fts5 ./cmd/wacli
|
||||
run: pnpm -s build
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@ -39,3 +39,6 @@ go.work.sum
|
||||
|
||||
# Built CLI binary
|
||||
/wacli
|
||||
|
||||
# pnpm build output
|
||||
/dist/
|
||||
|
||||
@ -39,16 +39,16 @@ func newAuthCmd(flags *rootFlags) *cobra.Command {
|
||||
|
||||
fmt.Fprintln(os.Stderr, "Starting authentication…")
|
||||
res, err := a.Sync(ctx, appPkg.SyncOptions{
|
||||
Mode: mode,
|
||||
AllowQR: true,
|
||||
DownloadMedia: downloadMedia,
|
||||
Mode: mode,
|
||||
AllowQR: true,
|
||||
DownloadMedia: downloadMedia,
|
||||
RefreshContacts: true,
|
||||
RefreshGroups: true,
|
||||
IdleExit: idleExit,
|
||||
IdleExit: idleExit,
|
||||
OnQRCode: func(code string) {
|
||||
fmt.Fprintln(os.Stderr, "\nScan this QR code with WhatsApp (Linked Devices):")
|
||||
qrterminal.GenerateHalfBlock(code, qrterminal.M, os.Stderr)
|
||||
fmt.Fprintln(os.Stderr)
|
||||
fmt.Fprintln(os.Stderr, "\nScan this QR code with WhatsApp (Linked Devices):")
|
||||
qrterminal.GenerateHalfBlock(code, qrterminal.M, os.Stderr)
|
||||
fmt.Fprintln(os.Stderr)
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@ -38,4 +38,3 @@ func truncate(s string, max int) string {
|
||||
}
|
||||
return s[:max-1] + "…"
|
||||
}
|
||||
|
||||
|
||||
@ -9,4 +9,3 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -70,13 +70,13 @@ func newMediaDownloadCmd(flags *rootFlags) *cobra.Command {
|
||||
_ = a.DB().MarkMediaDownloaded(info.ChatJID, info.MsgID, target, now)
|
||||
|
||||
resp := map[string]any{
|
||||
"chat": info.ChatJID,
|
||||
"id": info.MsgID,
|
||||
"path": target,
|
||||
"bytes": bytes,
|
||||
"media_type": info.MediaType,
|
||||
"mime_type": info.MimeType,
|
||||
"downloaded": true,
|
||||
"chat": info.ChatJID,
|
||||
"id": info.MsgID,
|
||||
"path": target,
|
||||
"bytes": bytes,
|
||||
"media_type": info.MediaType,
|
||||
"mime_type": info.MimeType,
|
||||
"downloaded": true,
|
||||
"downloaded_at": now.Format(time.RFC3339Nano),
|
||||
}
|
||||
if flags.asJSON {
|
||||
|
||||
@ -74,9 +74,9 @@ func newApp(ctx context.Context, flags *rootFlags, needLock bool, allowUnauthed
|
||||
}
|
||||
|
||||
a, err := app.New(app.Options{
|
||||
StoreDir: storeDir,
|
||||
Version: version,
|
||||
JSON: flags.asJSON,
|
||||
StoreDir: storeDir,
|
||||
Version: version,
|
||||
JSON: flags.asJSON,
|
||||
AllowUnauthed: allowUnauthed,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@ -48,12 +48,12 @@ func newSyncCmd(flags *rootFlags) *cobra.Command {
|
||||
}
|
||||
|
||||
res, err := a.Sync(ctx, appPkg.SyncOptions{
|
||||
Mode: mode,
|
||||
AllowQR: false,
|
||||
DownloadMedia: downloadMedia,
|
||||
Mode: mode,
|
||||
AllowQR: false,
|
||||
DownloadMedia: downloadMedia,
|
||||
RefreshContacts: refreshContacts,
|
||||
RefreshGroups: refreshGroups,
|
||||
IdleExit: idleExit,
|
||||
IdleExit: idleExit,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -15,4 +15,3 @@ func newVersionCmd() *cobra.Command {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -76,10 +76,10 @@ func (a *App) EnsureAuthed() error {
|
||||
return fmt.Errorf("not authenticated; run `wacli auth`")
|
||||
}
|
||||
|
||||
func (a *App) WA() *wa.Client { return a.wa }
|
||||
func (a *App) DB() *store.DB { return a.db }
|
||||
func (a *App) StoreDir() string { return a.opts.StoreDir }
|
||||
func (a *App) Version() string { return a.opts.Version }
|
||||
func (a *App) WA() *wa.Client { return a.wa }
|
||||
func (a *App) DB() *store.DB { return a.db }
|
||||
func (a *App) StoreDir() string { return a.opts.StoreDir }
|
||||
func (a *App) Version() string { return a.opts.Version }
|
||||
func (a *App) AllowUnauthed() bool { return a.opts.AllowUnauthed }
|
||||
|
||||
func (a *App) Connect(ctx context.Context, allowQR bool, qrWriter func(string)) error {
|
||||
|
||||
@ -44,4 +44,3 @@ func (a *App) refreshGroups(ctx context.Context) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -140,4 +140,3 @@ func (a *App) downloadMediaJob(ctx context.Context, job mediaJob) error {
|
||||
now := time.Now().UTC()
|
||||
return a.db.MarkMediaDownloaded(info.ChatJID, info.MsgID, targetPath, now)
|
||||
}
|
||||
|
||||
|
||||
@ -23,14 +23,14 @@ const (
|
||||
)
|
||||
|
||||
type SyncOptions struct {
|
||||
Mode SyncMode
|
||||
AllowQR bool
|
||||
OnQRCode func(string)
|
||||
DownloadMedia bool
|
||||
Mode SyncMode
|
||||
AllowQR bool
|
||||
OnQRCode func(string)
|
||||
DownloadMedia bool
|
||||
RefreshContacts bool
|
||||
RefreshGroups bool
|
||||
IdleExit time.Duration // only used for bootstrap/once
|
||||
Verbosity int // future
|
||||
IdleExit time.Duration // only used for bootstrap/once
|
||||
Verbosity int // future
|
||||
}
|
||||
|
||||
type SyncResult struct {
|
||||
|
||||
@ -12,4 +12,3 @@ func DefaultStoreDir() string {
|
||||
}
|
||||
return filepath.Join(home, ".wacli")
|
||||
}
|
||||
|
||||
|
||||
@ -34,4 +34,3 @@ func WriteError(w io.Writer, asJSON bool, err error) error {
|
||||
_, _ = fmt.Fprintln(w, err.Error())
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -38,4 +38,3 @@ func SanitizeFilename(name string) string {
|
||||
name = strings.ReplaceAll(name, string(filepath.Separator), "_")
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
@ -231,12 +231,12 @@ type Message struct {
|
||||
}
|
||||
|
||||
type Contact struct {
|
||||
JID string
|
||||
Phone string
|
||||
Name string
|
||||
Alias string
|
||||
Tags []string
|
||||
UpdatedAt time.Time
|
||||
JID string
|
||||
Phone string
|
||||
Name string
|
||||
Alias string
|
||||
Tags []string
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
func unix(t time.Time) int64 {
|
||||
@ -276,23 +276,23 @@ func (d *DB) UpsertChat(jid, kind, name string, lastTS time.Time) error {
|
||||
}
|
||||
|
||||
type UpsertMessageParams struct {
|
||||
ChatJID string
|
||||
ChatName string
|
||||
MsgID string
|
||||
SenderJID string
|
||||
SenderName string
|
||||
Timestamp time.Time
|
||||
FromMe bool
|
||||
Text string
|
||||
MediaType string
|
||||
MediaCaption string
|
||||
Filename string
|
||||
MimeType string
|
||||
DirectPath string
|
||||
MediaKey []byte
|
||||
FileSHA256 []byte
|
||||
ChatJID string
|
||||
ChatName string
|
||||
MsgID string
|
||||
SenderJID string
|
||||
SenderName string
|
||||
Timestamp time.Time
|
||||
FromMe bool
|
||||
Text string
|
||||
MediaType string
|
||||
MediaCaption string
|
||||
Filename string
|
||||
MimeType string
|
||||
DirectPath string
|
||||
MediaKey []byte
|
||||
FileSHA256 []byte
|
||||
FileEncSHA256 []byte
|
||||
FileLength uint64
|
||||
FileLength uint64
|
||||
}
|
||||
|
||||
func (d *DB) UpsertMessage(p UpsertMessageParams) error {
|
||||
|
||||
@ -91,4 +91,3 @@ func (c *Client) LeaveGroup(ctx context.Context, group types.JID) error {
|
||||
}
|
||||
return cli.LeaveGroup(ctx, group)
|
||||
}
|
||||
|
||||
|
||||
@ -85,4 +85,3 @@ func (c *Client) DownloadMediaToFile(ctx context.Context, directPath string, enc
|
||||
}
|
||||
return info.Size(), nil
|
||||
}
|
||||
|
||||
|
||||
@ -163,4 +163,3 @@ func clone(b []byte) []byte {
|
||||
copy(out, b)
|
||||
return out
|
||||
}
|
||||
|
||||
|
||||
16
package.json
Normal file
16
package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "wacli",
|
||||
"private": true,
|
||||
"packageManager": "pnpm@10.23.0",
|
||||
"scripts": {
|
||||
"wacli": "go run -tags sqlite_fts5 ./cmd/wacli --",
|
||||
"build": "mkdir -p dist && go build -tags sqlite_fts5 -o dist/wacli ./cmd/wacli",
|
||||
"start": "pnpm -s build && ./dist/wacli",
|
||||
"test": "pnpm -s test:go && pnpm -s test:fts",
|
||||
"test:go": "go test ./...",
|
||||
"test:fts": "go test -tags sqlite_fts5 ./...",
|
||||
"lint": "go vet ./...",
|
||||
"format": "gofmt -w .",
|
||||
"format:check": "bash -lc 'out=$(gofmt -l .); if [ -n \"$out\" ]; then echo \"$out\"; exit 1; fi'"
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user