diff --git a/.github/workflows/publish-npm-packages.yml b/.github/workflows/publish-npm-packages.yml new file mode 100644 index 0000000000..6eb79b16ee --- /dev/null +++ b/.github/workflows/publish-npm-packages.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index 8a714340c1..7ad4c9796c 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ !data/.gitkeep /data2 Actual-* +!actual-server.js **/xcuserdata/* export-2020-01-10.csv diff --git a/packages/sync-server/LICENSE b/packages/sync-server/LICENSE new file mode 100644 index 0000000000..3898f370d3 --- /dev/null +++ b/packages/sync-server/LICENSE @@ -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. diff --git a/packages/sync-server/README.md b/packages/sync-server/README.md index 4577c3b172..1b33101477 100644 --- a/packages/sync-server/README.md +++ b/packages/sync-server/README.md @@ -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. diff --git a/packages/sync-server/bin/actual-server.js b/packages/sync-server/bin/actual-server.js new file mode 100644 index 0000000000..973d187dda --- /dev/null +++ b/packages/sync-server/bin/actual-server.js @@ -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'); diff --git a/packages/sync-server/package.json b/packages/sync-server/package.json index 0b22cbd0bb..e49d5e21ef 100644 --- a/packages/sync-server/package.json +++ b/packages/sync-server/package.json @@ -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", diff --git a/upcoming-release-notes/4798.md b/upcoming-release-notes/4798.md new file mode 100644 index 0000000000..df102c3f83 --- /dev/null +++ b/upcoming-release-notes/4798.md @@ -0,0 +1,6 @@ +--- +category: Features +authors: [MikesGlitch] +--- + +Add new sync-server CLI tool to allow users to run the server with one command diff --git a/yarn.lock b/yarn.lock index 65e36c0cc0..ceea328838 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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