Files
actual/packages/sync-server/bin/actual-server.js
Matiss Janis Aboltins 541df52441 Enable restrict-template-expressions linting rule (#7181)
* [AI] Promote typescript/restrict-template-expressions to error and fix violations

Convert the oxlint rule from "warn" to "error" and fix all 42 violations
by wrapping non-string template expressions with String(). This ensures
type safety in template literals across the codebase.

https://claude.ai/code/session_01Uk8SwFbD6HuUuo3SSMwU9z

* Add release notes for PR #7181

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-03-13 18:36:58 +00:00

127 lines
3.3 KiB
JavaScript
Executable File

#!/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',
},
'reset-password': {
type: 'boolean',
},
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();
}
const setupDataDir = (dataDir = undefined) => {
if (process.env.ACTUAL_DATA_DIR) {
return; // Env variables must not be overwritten
}
if (dataDir) {
process.env.ACTUAL_DATA_DIR = dataDir; // Use the dir specified
} else {
// Setup defaults
if (existsSync('./data')) {
// The default data directory exists - use it
console.info('Found existing data directory');
process.env.ACTUAL_DATA_DIR = resolve('./data');
} else {
console.info(
'Using default data directory. You can specify a custom config with --config',
);
process.env.ACTUAL_DATA_DIR = resolve('./');
}
console.info(`Data directory: ${process.env.ACTUAL_DATA_DIR}`);
}
};
if (values.config) {
const configExists = existsSync(values.config);
if (!configExists) {
console.log(
`Please specify a valid config path. The path ${String(values.config)} does not exist.`,
);
process.exit();
} else {
console.log(`Loading config from ${String(values.config)}`);
const configJson = JSON.parse(readFileSync(values.config, 'utf-8'));
process.env.ACTUAL_CONFIG_PATH = values.config;
setupDataDir(configJson.dataDir);
}
} else {
// If no config is specified, check for a default config in the current directory
const defaultConfigJsonFile = './config.json';
const configExists = existsSync(defaultConfigJsonFile);
if (configExists) {
console.info('Found config.json in the current directory');
const configJson = JSON.parse(readFileSync(defaultConfigJsonFile, 'utf-8'));
process.env.ACTUAL_CONFIG_PATH = defaultConfigJsonFile;
setupDataDir(configJson.dataDir);
} else {
setupDataDir(); // No default config exists - setup data dir with defaults
}
}
if (values['reset-password']) {
console.info('Running reset password script...');
await import('../src/scripts/reset-password.js');
process.exit();
}
// start the sync server
void import('../app.js');