@sysnee/pgs 0.1.4-rc3 → 0.1.4-rc5

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 +24 -11
  2. package/package.json +1 -1
package/manager.js CHANGED
@@ -24,10 +24,6 @@ const TENANT_ACCESS_FILE_PATH = path.join(CONFIG_DIR, 'tenant-access.json');
24
24
  const SETUP_STATUS_PATH = path.join(CONFIG_DIR, 'status.txt');
25
25
 
26
26
  function loadCompose() {
27
- if (!fs.existsSync(COMPOSE_FILE_PATH)) {
28
- const dockerComposeInitialContent = readFileSync(path.join(path.dirname(''), 'docker-compose.yml'), 'utf8')
29
- writeFileSync(COMPOSE_FILE_PATH, dockerComposeInitialContent)
30
- }
31
27
  const content = fs.readFileSync(COMPOSE_FILE_PATH, 'utf8');
32
28
  console.debug(`docker-compose file readed from ${COMPOSE_FILE_PATH}`)
33
29
  return yaml.load(content);
@@ -41,9 +37,6 @@ function saveCompose(doc) {
41
37
  // ==================== Tenant Access Management ====================
42
38
 
43
39
  function loadTenantAccess() {
44
- if (!fs.existsSync(TENANT_ACCESS_FILE_PATH)) {
45
- fs.writeFileSync(TENANT_ACCESS_FILE_PATH, '{}');
46
- }
47
40
  const content = fs.readFileSync(TENANT_ACCESS_FILE_PATH, 'utf8');
48
41
  return JSON.parse(content) || {};
49
42
  }
@@ -206,13 +199,33 @@ function ensureNetwork(doc) {
206
199
  }
207
200
  }
208
201
 
202
+ function initialSetup() {
203
+ createInitialFiles()
204
+ ensureDockerPrivilegies()
205
+ console.log('All ready!')
206
+ }
207
+
209
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
210
215
  if (!existsSync(CONFIG_DIR)) {
211
216
  mkdirSync(CONFIG_DIR, { recursive: true });
212
217
  }
213
- execSync('sudo usermod -aG docker $USER && newgrp docker')
214
- writeFileSync(SETUP_STATUS_PATH, 'container:ok')
215
- console.log('All ready!')
218
+
219
+ // docker-compose.yml
220
+ if (!fs.existsSync(COMPOSE_FILE_PATH)) {
221
+ const dockerComposeInitialContent = readFileSync(path.join(__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
+ }
216
229
  }
217
230
 
218
231
  function checkSetupStatus() {
@@ -406,7 +419,7 @@ program
406
419
  .command('setup')
407
420
  .description('Initial required setup')
408
421
  .action(() => {
409
- ensureDockerPrivilegies()
422
+ initialSetup()
410
423
  })
411
424
 
412
425
  program
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sysnee/pgs",
3
- "version": "0.1.4-rc3",
3
+ "version": "0.1.4-rc5",
4
4
  "description": "Dynamic PostgreSQL service instance manager",
5
5
  "type": "module",
6
6
  "bin": {