poad 2.5.6 → 2.5.8

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/global/cli.js CHANGED
@@ -9,5 +9,6 @@
9
9
  module.exports = {
10
10
  install: `Install poad environment`,
11
11
  init: `Init poad project`,
12
- start: 'Start containers for poad local development',
12
+ start: 'Start container for poad local development',
13
+ stop: 'Stop container for poad local development',
13
14
  };
package/global/init.js CHANGED
@@ -6,6 +6,7 @@ module.exports = async (args) => {
6
6
  const json2toml = require('json2toml');
7
7
  const fs = require('fs').promises;
8
8
  const generateUniqueId = require('generate-unique-id');
9
+ const chalk = require('chalk-v2');
9
10
  const anon = {
10
11
  role: 'anon',
11
12
  iss: 'poad',
@@ -22,13 +23,19 @@ module.exports = async (args) => {
22
23
  config.project_id = path.basename(process.cwd());
23
24
  config.project_uuid = generateUniqueId();
24
25
  await fs.mkdir(path.join(process.cwd(), 'poad', 'data'), { recursive: true });
25
- const ports = await findFreePorts(3);
26
+ const ports = await findFreePorts(4);
26
27
  config.db = {
27
28
  port: ports[0],
28
29
  };
29
30
  config.web = {
30
31
  port: ports[1],
31
32
  };
33
+ config.s3 = {
34
+ port: ports[2],
35
+ };
36
+ config.inbucket = {
37
+ port: ports[3],
38
+ };
32
39
  const key = generateSecret();
33
40
  config.auth = {
34
41
  jwt_expiry: 3600,
@@ -37,6 +44,20 @@ module.exports = async (args) => {
37
44
  service: jwt.sign(service, key),
38
45
  admin: jwt.sign(admin, key),
39
46
  };
47
+ config.s3 = {
48
+ port: config.s3.port,
49
+ access_key: generateSecret(),
50
+ secret_key: generateSecret(),
51
+ region: 'local',
52
+ };
40
53
  const toml = json2toml(config);
54
+ const isInstalled = await fs
55
+ .stat(path.join(process.cwd(), 'poad', 'config.toml'))
56
+ .catch(() => false);
57
+ if (isInstalled)
58
+ return console.log(
59
+ chalk.bold('\n ✅ Your project has already been initialized')
60
+ );
41
61
  await fs.writeFile(path.join(process.cwd(), 'poad', 'config.toml'), toml);
62
+ console.log(chalk.bold('\n ✅ Your project has been initialized'));
42
63
  };
package/global/install.js CHANGED
@@ -4,7 +4,7 @@ module.exports = async (args) => {
4
4
  const cliProgress = require('cli-progress');
5
5
 
6
6
  const docker = new Docker();
7
- const imageName = 'poadio/engine:latest';
7
+ const imageName = 'poadio/engine:0.5.2';
8
8
  const platform = 'linux/amd64';
9
9
 
10
10
  // Create a new progress bar
package/global/start.js CHANGED
@@ -1,19 +1,26 @@
1
1
  module.exports = async (args) => {
2
+ const chalk = require('chalk-v2');
2
3
  const Docker = require('dockerode');
3
4
  const docker = new Docker();
4
5
  const toml = require('toml');
5
6
  const path = require('path');
7
+ const ora = require('ora');
6
8
  const fs = require('fs').promises;
9
+ const prettyoutput = require('prettyoutput');
7
10
  const { findPoadDir } = require('../utils/findpoad');
11
+ const { isDockerExist } = require('../utils/docker');
8
12
  const root = findPoadDir(process.cwd());
9
13
  const config = toml.parse(await fs.readFile(root, 'utf-8'));
10
-
11
- const webPort = config.web.port;
12
- const dbPort = config.db.port;
13
-
14
+ const containerName = config.project_uuid;
15
+ console.log(' ');
16
+ if (await isDockerExist(containerName)) {
17
+ return console.log(chalk.bold('Container already started'));
18
+ }
19
+ const progress = ora('Starting container').start();
14
20
  docker
15
21
  .createContainer({
16
- Image: 'poadio/engine',
22
+ name: containerName,
23
+ Image: 'poadio/engine:0.5.2',
17
24
  Tty: false,
18
25
  Env: [
19
26
  'OMNEEDIA_GATEWAY_URL=http://localhost:' + config.web.port,
@@ -23,11 +30,16 @@ module.exports = async (args) => {
23
30
  'JWT_SECRET=' + config.auth.secret,
24
31
  'ANON_KEY=' + config.auth.anon,
25
32
  'SERVICE_ROLE_KEY=' + config.auth.service,
33
+ 'S3_ACCESS_KEY=' + config.s3.access_key,
34
+ 'S3_SECRET_KEY=' + config.s3.secret_key,
35
+ 'S3_REGION=local',
26
36
  ],
27
37
  HostConfig: {
28
38
  PortBindings: {
29
39
  '5432/tcp': [{ HostPort: config.db.port.toString() }],
30
40
  '8000/tcp': [{ HostPort: config.web.port.toString() }],
41
+ '9500/tcp': [{ HostPort: config.s3.port.toString() }],
42
+ '9000/tcp': [{ HostPort: config.inbucket.port.toString() }],
31
43
  },
32
44
  Binds: [path.dirname(root) + '/data:/data'],
33
45
  AutoRemove: true,
@@ -38,9 +50,26 @@ module.exports = async (args) => {
38
50
  return container.start();
39
51
  })
40
52
  .then((container) => {
41
- console.log('Container started successfully');
53
+ progress.succeed(chalk.bold('container started.'));
54
+ console.log(' ');
55
+ console.log(chalk.bold(' 🚀 Container started successfully'));
56
+ console.log(' ');
57
+ const info = {
58
+ 'API URL': `http://localhost:${config.web.port}`,
59
+ 'DB URL': `postgres://postgres:postgres@localhost:${config.db.port}/postgres`,
60
+ 'S3 URL': `http://localhost:${config.s3.port}/`,
61
+ 'S3 ACCESS KEY': config.s3.access_key,
62
+ 'S3 SECRET KEY': config.s3.secret_key,
63
+ 'S3 REGION': 'local',
64
+ 'Inbucket URL': `http://localhost:${config.inbucket.port}`,
65
+ 'JWT secret': `${config.auth.secret}`,
66
+ 'anon key': config.auth.anon,
67
+ 'service_role key': config.auth.service,
68
+ };
69
+ console.log(prettyoutput(info));
42
70
  })
43
71
  .catch((err) => {
44
- console.error('Error:', err);
72
+ console.log(err);
73
+ progress.fail(chalk.redBright('Error: Container failed to start'));
45
74
  });
46
75
  };
package/global/stop.js ADDED
@@ -0,0 +1,28 @@
1
+ module.exports = async (args) => {
2
+ const Docker = require('dockerode');
3
+ const docker = new Docker();
4
+ const toml = require('toml');
5
+ const path = require('path');
6
+ const fs = require('fs').promises;
7
+ const { findPoadDir } = require('../utils/findpoad');
8
+ const { isDockerExist } = require('../utils/docker');
9
+ const root = findPoadDir(process.cwd());
10
+ const config = toml.parse(await fs.readFile(root, 'utf-8'));
11
+ const containerName = config.project_uuid;
12
+ const ora = require('ora');
13
+ const chalk = require('chalk-v2');
14
+ console.log(' ');
15
+ if (!(await isDockerExist(containerName))) {
16
+ return console.log(chalk.redBright('Container not found'));
17
+ }
18
+ const progress = ora('Stopping container').start();
19
+ docker
20
+ .getContainer(containerName)
21
+ .stop()
22
+ .then(() => {
23
+ progress.succeed(chalk.bold('Container stopped successfully'));
24
+ })
25
+ .catch((err) => {
26
+ progress.fail('Error: Failed to stop container');
27
+ });
28
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poad",
3
- "version": "2.5.6",
3
+ "version": "2.5.8",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -19,7 +19,10 @@
19
19
  "generate-unique-id": "^2.0.3",
20
20
  "json2toml": "^6.1.1",
21
21
  "jsonwebtoken": "^9.0.2",
22
+ "listr": "^0.14.3",
22
23
  "log-beautify": "^1.2.0",
24
+ "ora": "^5.4.1",
25
+ "prettyoutput": "^1.2.0",
23
26
  "toml": "^3.0.0"
24
27
  }
25
28
  }
package/poad.js CHANGED
@@ -469,7 +469,9 @@ const main = async () => {
469
469
  if (version === null) {
470
470
  version = current_version;
471
471
  }
472
- if (current_version != version) {
472
+ const cv = current_version.replace(/\./g, '') * 1;
473
+ const v = version.replace(/\./g, '') * 1;
474
+ if (v > cv) {
473
475
  const message =
474
476
  `A new version (${version}) is available. You can upgrade by running:\n` +
475
477
  chalk.white.bold(`npm i -g poad@${version}`);
@@ -0,0 +1,30 @@
1
+ module.exports = async (args) => {
2
+ const chalk = require('chalk-v2');
3
+ const toml = require('toml');
4
+ const path = require('path');
5
+ const fs = require('fs').promises;
6
+ const prettyoutput = require('prettyoutput');
7
+ const { findPoadDir } = require('../utils/findpoad');
8
+ const { isDockerExist } = require('../utils/docker');
9
+ const root = findPoadDir(process.cwd());
10
+ const config = toml.parse(await fs.readFile(root, 'utf-8'));
11
+ console.log(' ');
12
+ if (!(await isDockerExist(config.project_uuid))) {
13
+ return console.log(chalk.redBright('Container not found'));
14
+ }
15
+ console.log(chalk.bold('POAD project info'));
16
+ console.log(' ');
17
+ const info = {
18
+ 'API URL': `http://localhost:${config.web.port}`,
19
+ 'DB URL': `postgres://postgres:postgres@localhost:${config.db.port}/postgres`,
20
+ 'S3 URL': `http://localhost:${config.s3.port}/`,
21
+ 'S3 ACCESS KEY': config.s3.access_key,
22
+ 'S3 SECRET KEY': config.s3.secret_key,
23
+ 'S3 REGION': 'local',
24
+ 'Inbucket URL': `http://localhost:${config.inbucket.port}`,
25
+ 'JWT secret': `${config.auth.secret}`,
26
+ 'anon key': config.auth.anon,
27
+ 'service_role key': config.auth.service,
28
+ };
29
+ console.log(prettyoutput(info));
30
+ };
@@ -0,0 +1,23 @@
1
+ const Docker = require('dockerode');
2
+ const docker = new Docker();
3
+
4
+ async function isDockerExist(containerName) {
5
+ try {
6
+ const containers = await docker.listContainers({ all: true });
7
+
8
+ for (const container of containers) {
9
+ if (container.Names.includes(`/${containerName}`)) {
10
+ return true;
11
+ }
12
+ }
13
+
14
+ return false;
15
+ } catch (error) {
16
+ console.error(
17
+ `Erreur lors de la vérification du conteneur: ${error.message}`
18
+ );
19
+ return false;
20
+ }
21
+ }
22
+
23
+ module.exports = { isDockerExist };
package/0.txt DELETED
@@ -1,16 +0,0 @@
1
- docker run
2
- --platform=linux/amd64
3
- --rm
4
- -v ~/prj/omneedia/infra/aio/data:/data
5
- -e OMNEEDIA_GATEWAY_URL=http://localhost:8000
6
- -e DATA_VOLUME_MOUNTPOINT=/data
7
- -e POSTGRES_PASSWORD=dreams
8
- -p 5432:5432
9
- -p 8000:8000
10
- -e ADMIN_API_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoic3VwYWJhc2VfYWRtaW4iLCJpc3MiOiJzdXBhYmFzZS1kZW1vIiwiaWF0IjoxNjQxNzY5MjAwLCJleHAiOjE3OTk1MzU2MDB9.Y9mSNVuTw2TdfryoaqM5wySvwQemGGWfSe9ixcklVfM
11
- -e JWT_SECRET=277e90e7515dbf46bf76ddabfbfa6fa04a11966f4e7550ef3330a31258c49be95944a87c97b725defb264dbb772567592b8a91849115dce1ece7b949a668900ac0738a8d0a89db4a48d77706474e4ea34d20134ac889b73f7ecd732b046bdce7b7367fb9f56638eed1db1bba916a5e674a472ed443d316127b6176a2a6066ca08bffd97ed47ef9f1cfe22c668afca3f7d0011352d113e4315803c35787a3c2bc16424ab02a88452ab7c04ad48143c11f2616c148f85461842afcf28295a0281281c69f2df6344476286425290f7721470c9f92576ece15f275feac53a3dd6763eb0d88bbcdc9391c64f62c4bf556c131f49a5de9de9e914f544c42a5ef33ca10
12
- -e ANON_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MTcyNjg2MTQ4OH0.fsIJu0uDoMBBxXnHuoXtMlwF4sGHxkFGkLpFDfKuV9g
13
- -e SERVICE_ROLE_KEY=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyAgCiAgICAicm9sZSI6ICJzZXJ2aWNlX3JvbGUiLAogICAgImlzcyI6ICJzdXBhYmFzZS1kZW1vIiwKICAgICJpYXQiOiAxNjQxNzY5MjAwLAogICAgImV4cCI6IDE3OTk1MzU2MDAKfQ.DaYlNEoUrrEn2Ig7tqibS-PHK5vgusbcbo7X36XVt4Q
14
- poadio/engine
15
- &>data/service.log
16
- &
package/project/init.js DELETED
@@ -1,9 +0,0 @@
1
- module.exports = (args) => {
2
- return {
3
- info: {
4
- title: 'init',
5
- description: `Démarrage d'un projet poad.`,
6
- },
7
- start: async () => {},
8
- };
9
- };