🆕 Sync server as npm package (#4798)

* sync server as npm package

* yarn lock

* workflow

* fix yml

* fix script

* named job better

* imagine trusting an ai

* pack and publish separately

* v4 instead of v3 upload

* dependencies

* identifying the right package for uplaod

* updating references

* what

* i see

* here comes the glory

* aaaand here it comes

* perms

* hmm

* try changing scope

* owner is invalid for git so have to go to npm instead

* better names on workflow

* package the api too

* updates

* rename to play better with gitignore

* yarn

* better

* dont ignore me

* yarn

* readme

* readme

* release note

* typo

* updating to read package.json from fs rather than import to support more node versions

* more ai autocomplete more problems
This commit is contained in:
Michael Clark
2025-04-15 20:51:17 +01:00
committed by GitHub
parent b9e7d7e9c2
commit 31fe766a2b
8 changed files with 234 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
name: Publish npm packages
# # Npm packages are published for every new tag
on:
push:
tags:
- 'v*.*.*'
jobs:
build-and-pack:
runs-on: ubuntu-latest
name: Build and pack npm packages
steps:
- uses: actions/checkout@v4
- name: Set up environment
uses: ./.github/actions/setup
- name: Build Web
run: yarn build:browser
- name: Pack the web and server packages
run: |
yarn workspace @actual-app/web pack --filename @actual-app/web.tgz
yarn workspace @actual-app/sync-server pack --filename @actual-app/sync-server.tgz
- name: Build API
run: yarn build:api
- name: Pack the api package
run: |
yarn workspace @actual-app/api pack --filename @actual-app/api.tgz
- name: Upload package artifacts
uses: actions/upload-artifact@v4
with:
name: npm-packages
path: |
packages/desktop-client/@actual-app/web.tgz
packages/sync-server/@actual-app/sync-server.tgz
packages/api/@actual-app/api.tgz
publish:
runs-on: ubuntu-latest
name: Publish npm packages
needs: build-and-pack
permissions:
contents: read
packages: write
steps:
- name: Download the artifacts
uses: actions/download-artifact@v4
with:
name: npm-packages
- name: Setup node and npm registry
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'
- name: Publish Web
run: |
npm publish desktop-client/@actual-app/web.tgz --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish Sync-Server
run: |
npm publish sync-server/@actual-app/sync-server.tgz --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Publish API
run: |
npm publish api/@actual-app/api.tgz --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

1
.gitignore vendored
View File

@@ -3,6 +3,7 @@
!data/.gitkeep
/data2
Actual-*
!actual-server.js
**/xcuserdata/*
export-2020-01-10.csv

View File

@@ -0,0 +1,7 @@
Copyright James Long
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -8,6 +8,46 @@ If you are interested in contributing, or want to know how development works, se
Want to say thanks? Click the ⭐ at the top of the page.
### Using the CLI tool
Node.js v18 or higher is required for the @actual-app/sync-server npm package
**Install globally with npm:**
```bash
npm install --location=global @actual-app/sync-server
```
After installing, you can execute actual-server commands directly in your terminal.
**Usage**
```bash
actual-server [options]
```
**Available options**
| Command | Description |
| ------------------- | ---------------------------- |
| `-h` or `--help` | Print this list and exit. |
| `-v` or `--version` | Print this version and exit. |
| `--config` | Path to the config file. |
**Examples**
Run with default configuration
```bash
actual-server
```
Run with custom configuration
```bash
actual-server --config ./config.json
```
### Documentation
We have a wide range of documentation on how to use Actual. This is all available in our [Community Documentation](https://actualbudget.org/docs/), including topics on [installing](https://actualbudget.org/docs/install/), [Budgeting](https://actualbudget.org/docs/budgeting/), [Account Management](https://actualbudget.org/docs/accounts/), [Tips & Tricks](https://actualbudget.org/docs/getting-started/tips-tricks) and some documentation for developers.

View File

@@ -0,0 +1,88 @@
#!/usr/bin/env node
import { existsSync, readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { parseArgs } from 'node:util';
const args = process.argv;
const options = {
help: {
type: 'boolean',
short: 'h',
},
version: {
type: 'boolean',
short: 'v',
},
config: {
type: 'string',
},
};
const { values } = parseArgs({
args,
options,
allowPositionals: true,
});
if (values.help) {
console.log(
[
'usage: actual-server [options]',
'',
'options:',
' --config Path to config file',
'',
' -h --help Print this list and exit.',
' -v --version Print the version and exit.',
'',
'Examples:',
'',
'Runs actual-server with default configuration',
' actual-server',
'',
'Runs actual-server with custom configuration',
' actual-server --config ./config.json',
].join('\n'),
);
process.exit();
}
if (values.version) {
const __dirname = dirname(fileURLToPath(import.meta.url));
const packageJsonPath = resolve(__dirname, '../package.json');
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
console.log('v' + packageJson.version);
process.exit();
}
// Read the config argument if specified
if (values.config) {
const configExists = existsSync(values.config);
if (!configExists) {
console.log(
`Please specify a valid config path. The path ${values.config} does not exist.`,
);
process.exit();
} else if (values.config) {
console.log(`Loading config from ${values.config}`);
process.env.ACTUAL_CONFIG_PATH = values.config;
}
} else {
// No config specified, use reasonable defaults
console.info(
'Using default config. You can specify a custom config with --config',
);
process.env.ACTUAL_DATA_DIR = './';
console.info(
'user-files and server-files will be created in the current directory',
);
}
// start the sync server
import('../app.js');

View File

@@ -3,7 +3,19 @@
"version": "25.4.0",
"license": "MIT",
"description": "actual syncing server",
"bin": {
"actual-server": "./bin/actual-server.js"
},
"type": "module",
"files": [
"bin",
"src",
"app.js",
"migrations",
"default-db.sqlite",
"README.md",
"LICENSE"
],
"scripts": {
"start": "node app",
"start-monitor": "nodemon app",

View File

@@ -0,0 +1,6 @@
---
category: Features
authors: [MikesGlitch]
---
Add new sync-server CLI tool to allow users to run the server with one command

View File

@@ -126,6 +126,8 @@ __metadata:
typescript: "npm:^5.8.2"
uuid: "npm:^9.0.1"
winston: "npm:^3.17.0"
bin:
actual-server: ./bin/actual-server.js
languageName: unknown
linkType: soft