@sysnee/pgs 0.1.4-rc2 → 0.1.4-rc4

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.
Files changed (2) hide show
  1. package/manager.js +28 -12
  2. package/package.json +1 -1
package/manager.js CHANGED
@@ -9,6 +9,9 @@ import { execSync } from 'child_process';
9
9
  import { fileURLToPath } from 'url';
10
10
  import { dirname } from 'path';
11
11
 
12
+ import packageJson from './package.json' with { type: 'json' };
13
+
14
+
12
15
  const __filename = fileURLToPath(import.meta.url);
13
16
  const __dirname = dirname(__filename);
14
17
 
@@ -21,10 +24,6 @@ const TENANT_ACCESS_FILE_PATH = path.join(CONFIG_DIR, 'tenant-access.json');
21
24
  const SETUP_STATUS_PATH = path.join(CONFIG_DIR, 'status.txt');
22
25
 
23
26
  function loadCompose() {
24
- if (!fs.existsSync(COMPOSE_FILE_PATH)) {
25
- const dockerComposeInitialContent = readFileSync(path.join(path.dirname(''), 'docker-compose.yml'), 'utf8')
26
- writeFileSync(COMPOSE_FILE_PATH, dockerComposeInitialContent)
27
- }
28
27
  const content = fs.readFileSync(COMPOSE_FILE_PATH, 'utf8');
29
28
  console.debug(`docker-compose file readed from ${COMPOSE_FILE_PATH}`)
30
29
  return yaml.load(content);
@@ -38,9 +37,6 @@ function saveCompose(doc) {
38
37
  // ==================== Tenant Access Management ====================
39
38
 
40
39
  function loadTenantAccess() {
41
- if (!fs.existsSync(TENANT_ACCESS_FILE_PATH)) {
42
- fs.writeFileSync(TENANT_ACCESS_FILE_PATH, '{}');
43
- }
44
40
  const content = fs.readFileSync(TENANT_ACCESS_FILE_PATH, 'utf8');
45
41
  return JSON.parse(content) || {};
46
42
  }
@@ -203,13 +199,33 @@ function ensureNetwork(doc) {
203
199
  }
204
200
  }
205
201
 
202
+ function initialSetup() {
203
+ createInitialFiles()
204
+ ensureDockerPrivilegies()
205
+ console.log('All ready!')
206
+ }
207
+
206
208
  function ensureDockerPrivilegies() {
209
+ execSync('sudo usermod -aG docker $USER && newgrp docker')
210
+ writeFileSync(SETUP_STATUS_PATH, 'container:ok')
211
+ }
212
+
213
+ function createInitialFiles() {
214
+ // config dir
207
215
  if (!existsSync(CONFIG_DIR)) {
208
216
  mkdirSync(CONFIG_DIR, { recursive: true });
209
217
  }
210
- execSync('sudo usermod -aG docker $USER && newgrp docker')
211
- writeFileSync(SETUP_STATUS_PATH, 'container:ok')
212
- console.log('All ready!')
218
+
219
+ // docker-compose.yml
220
+ if (!fs.existsSync(COMPOSE_FILE_PATH)) {
221
+ const dockerComposeInitialContent = readFileSync(path.join(path.dirname(''), 'docker-compose.yml'), 'utf8')
222
+ writeFileSync(COMPOSE_FILE_PATH, dockerComposeInitialContent)
223
+ }
224
+
225
+ // tenant-access.json
226
+ if (!fs.existsSync(TENANT_ACCESS_FILE_PATH)) {
227
+ fs.writeFileSync(TENANT_ACCESS_FILE_PATH, '{}');
228
+ }
213
229
  }
214
230
 
215
231
  function checkSetupStatus() {
@@ -397,13 +413,13 @@ const program = new Command();
397
413
  program
398
414
  .name('postgres-manager')
399
415
  .description('Manage PostgreSQL tenant instances')
400
- .version(JSON.parse(readFileSync('package.json', 'utf8')).version);
416
+ .version(packageJson.version);
401
417
 
402
418
  program
403
419
  .command('setup')
404
420
  .description('Initial required setup')
405
421
  .action(() => {
406
- ensureDockerPrivilegies()
422
+ initialSetup()
407
423
  })
408
424
 
409
425
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sysnee/pgs",
3
- "version": "0.1.4-rc2",
3
+ "version": "0.1.4-rc4",
4
4
  "description": "Dynamic PostgreSQL service instance manager",
5
5
  "type": "module",
6
6
  "bin": {