el-contador 1.0.2 → 1.0.3

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.
package/.env.example CHANGED
@@ -1,5 +1,6 @@
1
- # Used by docker-compose for Postgres and the backend.
2
1
  # Copy to .env and set values: cp .env.example .env
2
+ # These are used by Docker: the PostgreSQL container creates this user and database
3
+ # automatically on first run. You do not need to install PostgreSQL or create them manually.
3
4
 
4
5
  DB_USER=el_contador
5
6
  DB_PASSWORD=
package/README.md CHANGED
@@ -4,6 +4,8 @@ Bookkeeping and expense management – expenses, sales, bank transactions, and r
4
4
 
5
5
  ## Install (first time)
6
6
 
7
+ You do **not** need to install PostgreSQL on the host or create a database/user manually. The first run creates everything from your `.env`: PostgreSQL runs in a container and creates the user and database automatically; the app then applies the schema and creates the admin user.
8
+
7
9
  1. Create a project directory and add the package:
8
10
 
9
11
  ```bash
@@ -12,16 +14,22 @@ Bookkeeping and expense management – expenses, sales, bank transactions, and r
12
14
  npm install el-contador
13
15
  ```
14
16
 
15
- 2. Copy the env template and set at least `DB_PASSWORD` and `SESSION_SECRET`:
17
+ 2. Create `.env` with the credentials you want (these will be used to create the PostgreSQL user and database on first run):
16
18
 
17
19
  ```bash
18
20
  cp node_modules/el-contador/.env.example .env
19
- # Edit .env: set DB_PASSWORD and SESSION_SECRET
20
21
  ```
21
22
 
22
- `.env` is never published with the package (it is gitignored and not in the published files). Each installation uses its own `.env`; you can also set the Gemini API key later in the admin under **Invoice settings** (see below).
23
+ Edit `.env` and set at least:
24
+
25
+ - **DB_PASSWORD** – password for the database (required).
26
+ - **SESSION_SECRET** – long random string for session cookies.
27
+
28
+ Optional: **DB_USER** (default `el_contador`), **DB_NAME** (default `el_contador_finance`). The first run will create this PostgreSQL user and database inside the container; no separate setup needed.
29
+
30
+ Run `npx el-contador` (or `docker compose ...`) from the **same directory** that contains `.env`. If you see `Set DB_PASSWORD in .env`, create or fix `.env` in that directory.
23
31
 
24
- 3. Start the app:
32
+ 3. Start the app (this starts PostgreSQL and the backend; on first run the DB and admin user are created):
25
33
 
26
34
  ```bash
27
35
  npx el-contador
@@ -33,7 +41,7 @@ Bookkeeping and expense management – expenses, sales, bank transactions, and r
33
41
  docker compose -f node_modules/el-contador/docker-compose.yml --env-file .env up -d
34
42
  ```
35
43
 
36
- 4. Open the admin UI at `http://localhost:3080` (or the port in `ADMIN_PORT`). Log in with the admin user (see `.env`: `INIT_ADMIN_EMAIL` / `INIT_ADMIN_PASSWORD`, or `DB_PASSWORD` if `INIT_ADMIN_PASSWORD` is not set).
44
+ 4. Open the admin UI at `http://localhost:3080` (or the port in `ADMIN_PORT`). Log in with the admin user: **INIT_ADMIN_EMAIL** from `.env` (default `admin@example.com`), and **INIT_ADMIN_PASSWORD** or **DB_PASSWORD** if not set.
37
45
 
38
46
  ## Deploy on another server
39
47
 
package/bin/cli.js CHANGED
@@ -11,12 +11,22 @@ const hasEnv = fs.existsSync(envFile);
11
11
 
12
12
  const cmd = process.argv[2] || 'start';
13
13
 
14
- function composeArgs(sub) {
15
- const a = ['compose', '-f', composePath];
16
- if (hasEnv) a.push('--env-file', envFile);
17
- return a.concat(sub);
14
+ // Prefer "docker compose" (plugin); fall back to "docker-compose" (standalone) on older hosts
15
+ function getComposeRunner() {
16
+ const r = spawnSync('docker', ['compose', 'version'], { encoding: 'utf8' });
17
+ if (r.status === 0) {
18
+ return { bin: 'docker', args: (sub) => ['compose', '-f', composePath].concat(hasEnv ? ['--env-file', envFile] : []).concat(sub) };
19
+ }
20
+ const r2 = spawnSync('docker-compose', ['--version'], { encoding: 'utf8' });
21
+ if (r2.status === 0) {
22
+ return { bin: 'docker-compose', args: (sub) => ['-f', composePath].concat(hasEnv ? ['--env-file', envFile] : []).concat(sub) };
23
+ }
24
+ console.error('el-contador: need "docker compose" or "docker-compose". Install Docker and Docker Compose.');
25
+ process.exit(1);
18
26
  }
19
27
 
28
+ const runner = getComposeRunner();
29
+
20
30
  if (cmd === 'update') {
21
31
  const npm = process.platform === 'win32' ? 'npm.cmd' : 'npm';
22
32
  const r = spawnSync(npm, ['update', 'el-contador'], { cwd, stdio: 'inherit' });
@@ -30,12 +40,12 @@ if (cmd === 'start' || cmd === 'up' || cmd === 'update') {
30
40
  process.exit(1);
31
41
  }
32
42
  if (!hasEnv) console.warn('el-contador: no .env in current directory; copy from node_modules/el-contador/.env.example');
33
- const args = composeArgs(['up', '-d']);
43
+ const args = runner.args(['up', '-d']);
34
44
  if (cmd === 'update') args.push('--build');
35
- const r = spawnSync('docker', args, { stdio: 'inherit', cwd });
45
+ const r = spawnSync(runner.bin, args, { stdio: 'inherit', cwd });
36
46
  process.exit(r.status !== null ? r.status : 1);
37
47
  } else if (cmd === 'down' || cmd === 'stop') {
38
- const r = spawnSync('docker', composeArgs(['down']), { stdio: 'inherit', cwd });
48
+ const r = spawnSync(runner.bin, runner.args(['down']), { stdio: 'inherit', cwd });
39
49
  process.exit(r.status !== null ? r.status : 1);
40
50
  } else {
41
51
  console.log('Usage: el-contador [start|up|down|stop|update]');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "el-contador",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Bookkeeping and expense management – run with Docker",
5
5
  "keywords": ["bookkeeping", "expenses", "docker", "accounting", "finance"],
6
6
  "license": "MIT",