@actual-app/sync-server 25.4.0-alpha.5 → 25.4.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59,7 +59,23 @@ if (values.version) {
59
59
  process.exit();
60
60
  }
61
61
 
62
- // Read the config argument if specified
62
+ const setupDataDir = () => {
63
+ if (!process.env.ACTUAL_DATA_DIR) {
64
+ if (existsSync('./data')) {
65
+ // The default data directory exists - use it
66
+ console.info('Found existing data directory');
67
+ process.env.ACTUAL_DATA_DIR = './data';
68
+ } else {
69
+ console.info(
70
+ 'Using default data directory. You can specify a custom config with --config',
71
+ );
72
+ process.env.ACTUAL_DATA_DIR = './';
73
+ }
74
+
75
+ console.info(`Data directory: ${process.env.ACTUAL_DATA_DIR}`);
76
+ }
77
+ };
78
+
63
79
  if (values.config) {
64
80
  const configExists = existsSync(values.config);
65
81
 
@@ -69,24 +85,30 @@ if (values.config) {
69
85
  );
70
86
 
71
87
  process.exit();
72
- } else if (values.config) {
88
+ } else {
73
89
  console.log(`Loading config from ${values.config}`);
74
90
  process.env.ACTUAL_CONFIG_PATH = values.config;
91
+
92
+ const configJson = JSON.parse(readFileSync(values.config, 'utf-8'));
93
+ if (!configJson.dataDir) {
94
+ setupDataDir();
95
+ }
75
96
  }
76
97
  } else {
77
- // No config specified, use reasonable defaults
78
- if (!process.env.ACTUAL_DATA_DIR) {
79
- if (existsSync('./data')) {
80
- console.info('Found existing data directory');
81
- process.env.ACTUAL_DATA_DIR = './data';
82
- } else {
83
- console.info(
84
- 'Using default data directory. You can specify a custom config with --config',
85
- );
86
- process.env.ACTUAL_DATA_DIR = './';
87
- }
98
+ // If no config is specified, check for a default config in the current directory
99
+ const defaultConfigJsonFile = './config.json';
100
+ const configExists = existsSync(defaultConfigJsonFile);
88
101
 
89
- console.info(`Data directory: ${process.env.ACTUAL_DATA_DIR}`);
102
+ if (configExists) {
103
+ console.info('Found config.json in the current directory');
104
+ const configJson = JSON.parse(readFileSync(defaultConfigJsonFile, 'utf-8'));
105
+ process.env.ACTUAL_CONFIG_PATH = defaultConfigJsonFile;
106
+
107
+ if (!configJson.dataDir) {
108
+ setupDataDir(); // No dataDir specified in config.json. Set it up
109
+ }
110
+ } else {
111
+ setupDataDir(); // No default config exists - setup data dir
90
112
  }
91
113
  }
92
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actual-app/sync-server",
3
- "version": "25.4.0-alpha.5",
3
+ "version": "25.4.0-alpha.6",
4
4
  "license": "MIT",
5
5
  "description": "actual syncing server",
6
6
  "bin": {