forest-cli 2.5.2 → 2.6.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ # [2.6.0](https://github.com/ForestAdmin/toolbelt/compare/v2.5.5...v2.6.0) (2022-02-21)
2
+
3
+
4
+ ### Features
5
+
6
+ * send better events during project generation ([#348](https://github.com/ForestAdmin/toolbelt/issues/348)) ([60a2800](https://github.com/ForestAdmin/toolbelt/commit/60a2800a5e4e9029d50fe9f7cbe28f53f915b5c1))
7
+
8
+ ## [2.5.5](https://github.com/ForestAdmin/toolbelt/compare/v2.5.4...v2.5.5) (2022-01-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **mongodb:** fix typos on the "analysis" word ([#324](https://github.com/ForestAdmin/toolbelt/issues/324)) ([47670a9](https://github.com/ForestAdmin/toolbelt/commit/47670a9d5f12e3574e62d6368d17a420014af6c1))
14
+
15
+ ## [2.5.4](https://github.com/ForestAdmin/toolbelt/compare/v2.5.3...v2.5.4) (2021-12-31)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * **logger:** allow logger to display object ([#321](https://github.com/ForestAdmin/toolbelt/issues/321)) ([d81d5f1](https://github.com/ForestAdmin/toolbelt/commit/d81d5f17cab5980ee4009c6b8fe56a1ad06a743f))
21
+
22
+ ## [2.5.3](https://github.com/ForestAdmin/toolbelt/compare/v2.5.2...v2.5.3) (2021-12-31)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **mongodb:** force to display progress bar by default ([#322](https://github.com/ForestAdmin/toolbelt/issues/322)) ([c318970](https://github.com/ForestAdmin/toolbelt/commit/c3189707f294615aeecb2a3617519af289486806))
28
+
1
29
  ## [2.5.2](https://github.com/ForestAdmin/toolbelt/compare/v2.5.1...v2.5.2) (2021-12-30)
2
30
 
3
31
 
@@ -1 +1 @@
1
- {"version":"2.5.2","commands":{"branch":{"id":"branch","description":"Create a new branch or list your existing branches.","pluginName":"forest-cli","pluginType":"core","aliases":["branches"],"flags":{"projectId":{"name":"projectId","type":"option","description":"The id of the project to create a branch in."},"delete":{"name":"delete","type":"boolean","char":"d","description":"Delete the branch.","allowNo":false},"force":{"name":"force","type":"boolean","description":"When deleting a branch, skip confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the branch to create.","required":false}]},"deploy":{"id":"deploy","description":"Deploy layout changes of an environment to the reference one.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:deploy"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Skip deploy confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to deploy.","default":null}},"args":[{"name":"ENVIRONMENT_NAME","description":"The name of the environment containing the layout changes to deploy to the reference one.","required":false}]},"environments":{"id":"environments","description":"Manage environments.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:list"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"init":{"id":"init","description":"Set up your development environment in your current folder.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:init"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to init."}},"args":[]},"login":{"id":"login","description":"Sign in with an existing account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"email":{"name":"email","type":"option","char":"e","description":"Your Forest Admin account email."},"password":{"name":"password","type":"option","char":"P","description":"Your Forest Admin account password (ignored if token is set)."},"token":{"name":"token","type":"option","char":"t","description":"Your Forest Admin account token (replaces password)."}},"args":[]},"logout":{"id":"logout","description":"Sign out of your account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"projects":{"id":"projects","description":"Manage projects.","pluginName":"forest-cli","pluginType":"core","aliases":["projects:list"],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"push":{"id":"push","description":"Push layout changes of your current branch to a remote environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branches:push"],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to push onto."},"force":{"name":"force","type":"boolean","description":"Skip push changes confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"switch":{"id":"switch","description":"Switch to another branch in your local development environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branch:switch"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the local branch to set as current.","required":false}]},"user":{"id":"user","description":"Display the current logged in user.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"environments:copy-layout":{"id":"environments:copy-layout","description":"Copy the layout from one environment to another.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"force":{"name":"force","type":"boolean","char":"force","description":"Force copy.","allowNo":false}},"args":[{"name":"fromEnvironment","description":"Source environment ID.","required":true},{"name":"toEnvironment","description":"Target environment ID.","required":true}]},"environments:create":{"id":"environments:create","description":"Create a new environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"name":{"name":"name","type":"option","char":"n","description":"Environment name.","required":true},"url":{"name":"url","type":"option","char":"u","description":"Application URL.","required":true},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"environments:delete":{"id":"environments:delete","description":"Delete an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"force","description":"Force delete.","allowNo":false}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:get":{"id":"environments:get","description":"Get the configuration of an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Output format.","options":["table","json"],"default":"table"}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:reset":{"id":"environments:reset","description":"Reset a remote environment by removing all layout changes","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to reset."},"force":{"name":"force","type":"boolean","description":"Skip reset changes confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"environments:update":{"id":"environments:update","description":"Update an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environmentId":{"name":"environmentId","type":"option","char":"e","description":"The forest environment ID to update.","required":true},"name":{"name":"name","type":"option","char":"n","description":"To update the environment name.","required":false},"url":{"name":"url","type":"option","char":"u","description":"To update the application URL.","required":false}},"args":[]},"projects:create":{"id":"projects:create","description":"Create a Forest API.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"applicationHost":{"name":"applicationHost","type":"option","char":"H","description":"Hostname of your admin backend application.","required":false},"applicationPort":{"name":"applicationPort","type":"option","char":"P","description":"Port of your admin backend application.","required":false},"databaseConnectionURL":{"name":"databaseConnectionURL","type":"option","char":"c","description":"Enter the database credentials with a connection URL.","required":false},"databaseDialect":{"name":"databaseDialect","type":"option","char":"d","description":"Enter your database dialect.","required":false,"options":["mongodb","mssql","mysql","postgres"]},"databaseName":{"name":"databaseName","type":"option","char":"n","description":"Enter your database name.","required":false},"databaseHost":{"name":"databaseHost","type":"option","char":"h","description":"Enter your database host.","required":false},"databasePort":{"name":"databasePort","type":"option","char":"p","description":"Enter your database port.","required":false},"databaseUser":{"name":"databaseUser","type":"option","char":"u","description":"Enter your database user.","required":false},"databasePassword":{"name":"databasePassword","type":"option","description":"Enter your database password.","required":false},"databaseSchema":{"name":"databaseSchema","type":"option","char":"s","description":"Enter your database schema.","required":false},"databaseSSL":{"name":"databaseSSL","type":"boolean","description":"Use SSL for database connection.","required":false,"allowNo":false},"mongoDBSRV":{"name":"mongoDBSRV","type":"boolean","description":"Use SRV DNS record for mongoDB connection.","required":false,"allowNo":false}},"args":[{"name":"applicationName","description":"Name of the project to create.","required":true}]},"projects:get":{"id":"projects:get","description":"Get the configuration of a project.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[{"name":"projectId","description":"ID of a project.","required":true}]},"schema:apply":{"id":"schema:apply","description":"Apply the current schema of your repository to the specified environment (using your \".forestadmin-schema.json\" file).","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"secret":{"name":"secret","type":"option","char":"s","description":"Environment secret of the project (FOREST_ENV_SECRET).","required":false}},"args":[]},"schema:update":{"id":"schema:update","description":"Refresh your schema by generating files that do not currently exist.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Database configuration file to use.","required":false,"default":"config/databases.js"},"outputDirectory":{"name":"outputDirectory","type":"option","char":"o","description":"Output directory where to generate new files.","required":false}},"args":[]}}}
1
+ {"version":"2.6.0","commands":{"branch":{"id":"branch","description":"Create a new branch or list your existing branches.","pluginName":"forest-cli","pluginType":"core","aliases":["branches"],"flags":{"projectId":{"name":"projectId","type":"option","description":"The id of the project to create a branch in."},"delete":{"name":"delete","type":"boolean","char":"d","description":"Delete the branch.","allowNo":false},"force":{"name":"force","type":"boolean","description":"When deleting a branch, skip confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the branch to create.","required":false}]},"deploy":{"id":"deploy","description":"Deploy layout changes of an environment to the reference one.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:deploy"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"force":{"name":"force","type":"boolean","char":"f","description":"Skip deploy confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to deploy.","default":null}},"args":[{"name":"ENVIRONMENT_NAME","description":"The name of the environment containing the layout changes to deploy to the reference one.","required":false}]},"environments":{"id":"environments","description":"Manage environments.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:list"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"init":{"id":"init","description":"Set up your development environment in your current folder.","pluginName":"forest-cli","pluginType":"core","aliases":["environments:init"],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project you want to init."}},"args":[]},"login":{"id":"login","description":"Sign in with an existing account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"email":{"name":"email","type":"option","char":"e","description":"Your Forest Admin account email."},"password":{"name":"password","type":"option","char":"P","description":"Your Forest Admin account password (ignored if token is set)."},"token":{"name":"token","type":"option","char":"t","description":"Your Forest Admin account token (replaces password)."}},"args":[]},"logout":{"id":"logout","description":"Sign out of your account.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"projects":{"id":"projects","description":"Manage projects.","pluginName":"forest-cli","pluginType":"core","aliases":["projects:list"],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"push":{"id":"push","description":"Push layout changes of your current branch to a remote environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branches:push"],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to push onto."},"force":{"name":"force","type":"boolean","description":"Skip push changes confirmation.","allowNo":false},"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"switch":{"id":"switch","description":"Switch to another branch in your local development environment.","pluginName":"forest-cli","pluginType":"core","aliases":["branch:switch"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"BRANCH_NAME","description":"The name of the local branch to set as current.","required":false}]},"user":{"id":"user","description":"Display the current logged in user.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"build":{"name":"build"},"option":{"name":"option"},"enum":{"name":"enum"},"string":{"name":"string"},"boolean":{"name":"boolean"},"integer":{"name":"integer"},"version":{"name":"version"},"help":{"name":"help"}},"args":[]},"environments:copy-layout":{"id":"environments:copy-layout","description":"Copy the layout from one environment to another.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"force":{"name":"force","type":"boolean","char":"force","description":"Force copy.","allowNo":false}},"args":[{"name":"fromEnvironment","description":"Source environment ID.","required":true},{"name":"toEnvironment","description":"Target environment ID.","required":true}]},"environments:create":{"id":"environments:create","description":"Create a new environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"projectId":{"name":"projectId","type":"option","char":"p","description":"Forest project ID.","default":null},"name":{"name":"name","type":"option","char":"n","description":"Environment name.","required":true},"url":{"name":"url","type":"option","char":"u","description":"Application URL.","required":true},"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[]},"environments:delete":{"id":"environments:delete","description":"Delete an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"force":{"name":"force","type":"boolean","char":"force","description":"Force delete.","allowNo":false}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:get":{"id":"environments:get","description":"Get the configuration of an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Output format.","options":["table","json"],"default":"table"}},"args":[{"name":"environmentId","description":"ID of an environment.","required":true}]},"environments:reset":{"id":"environments:reset","description":"Reset a remote environment by removing all layout changes","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environment":{"name":"environment","type":"option","char":"e","description":"The remote environment name to reset."},"force":{"name":"force","type":"boolean","description":"Skip reset changes confirmation.","allowNo":false},"projectId":{"name":"projectId","type":"option","char":"p","description":"The id of the project to work on.","default":null}},"args":[]},"environments:update":{"id":"environments:update","description":"Update an environment.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"environmentId":{"name":"environmentId","type":"option","char":"e","description":"The forest environment ID to update.","required":true},"name":{"name":"name","type":"option","char":"n","description":"To update the environment name.","required":false},"url":{"name":"url","type":"option","char":"u","description":"To update the application URL.","required":false}},"args":[]},"projects:create":{"id":"projects:create","description":"Create a Forest API.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"applicationHost":{"name":"applicationHost","type":"option","char":"H","description":"Hostname of your admin backend application.","required":false},"applicationPort":{"name":"applicationPort","type":"option","char":"P","description":"Port of your admin backend application.","required":false},"databaseConnectionURL":{"name":"databaseConnectionURL","type":"option","char":"c","description":"Enter the database credentials with a connection URL.","required":false},"databaseDialect":{"name":"databaseDialect","type":"option","char":"d","description":"Enter your database dialect.","required":false,"options":["mongodb","mssql","mysql","postgres"]},"databaseName":{"name":"databaseName","type":"option","char":"n","description":"Enter your database name.","required":false},"databaseHost":{"name":"databaseHost","type":"option","char":"h","description":"Enter your database host.","required":false},"databasePort":{"name":"databasePort","type":"option","char":"p","description":"Enter your database port.","required":false},"databaseUser":{"name":"databaseUser","type":"option","char":"u","description":"Enter your database user.","required":false},"databasePassword":{"name":"databasePassword","type":"option","description":"Enter your database password.","required":false},"databaseSchema":{"name":"databaseSchema","type":"option","char":"s","description":"Enter your database schema.","required":false},"databaseSSL":{"name":"databaseSSL","type":"boolean","description":"Use SSL for database connection.","required":false,"allowNo":false},"mongoDBSRV":{"name":"mongoDBSRV","type":"boolean","description":"Use SRV DNS record for mongoDB connection.","required":false,"allowNo":false}},"args":[{"name":"applicationName","description":"Name of the project to create.","required":true}]},"projects:get":{"id":"projects:get","description":"Get the configuration of a project.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"format":{"name":"format","type":"option","char":"format","description":"Ouput format.","options":["table","json"],"default":"table"}},"args":[{"name":"projectId","description":"ID of a project.","required":true}]},"schema:apply":{"id":"schema:apply","description":"Apply the current schema of your repository to the specified environment (using your \".forestadmin-schema.json\" file).","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"secret":{"name":"secret","type":"option","char":"s","description":"Environment secret of the project (FOREST_ENV_SECRET).","required":false}},"args":[]},"schema:update":{"id":"schema:update","description":"Refresh your schema by generating files that do not currently exist.","pluginName":"forest-cli","pluginType":"core","aliases":[],"flags":{"config":{"name":"config","type":"option","char":"c","description":"Database configuration file to use.","required":false,"default":"config/databases.js"},"outputDirectory":{"name":"outputDirectory","type":"option","char":"o","description":"Output directory where to generate new files.","required":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "forest-cli",
3
3
  "description": "The Lumberjacks' toolbelt is the Forest CLI which makes easy to manage your back office application directly from the terminal.",
4
- "version": "2.5.2",
4
+ "version": "2.6.0",
5
5
  "author": "Sandro Munda",
6
6
  "contributors": [
7
7
  "Arnaud Valensi <arnaud.valensi@gmail.com>",
@@ -82,6 +82,12 @@ class CreateCommand extends AbstractAuthenticatedCommand {
82
82
  this.exit(1);
83
83
  }
84
84
 
85
+ const meta = {
86
+ dbDialect: dbConfig.dbDialect,
87
+ agent: dbConfig.dbDialect === 'mongodb' ? 'express-mongoose' : 'express-sequelize',
88
+ isLocal: ['localhost', '127.0.0.1', '::1'].includes(dbConfig.dbHostname),
89
+ };
90
+
85
91
  let schema = {};
86
92
 
87
93
  this.spinner.start({ text: 'Connecting to your database' });
@@ -96,10 +102,14 @@ class CreateCommand extends AbstractAuthenticatedCommand {
96
102
 
97
103
  this.spinner.start({ text: 'Creating your project on Forest Admin' });
98
104
  const projectCreationPromise = this.projectCreator.create(
99
- authenticationToken, appConfig,
105
+ authenticationToken, appConfig, meta.agent,
100
106
  );
101
107
 
102
- const { envSecret, authSecret } = await this.spinner.attachToPromise(projectCreationPromise);
108
+ const {
109
+ id, envSecret, authSecret,
110
+ } = await this.spinner.attachToPromise(projectCreationPromise);
111
+
112
+ meta.projectId = id;
103
113
  config.forestAuthSecret = authSecret;
104
114
  config.forestEnvSecret = envSecret;
105
115
 
@@ -114,12 +124,12 @@ class CreateCommand extends AbstractAuthenticatedCommand {
114
124
  await this.spinner.attachToPromise(dumpPromise);
115
125
 
116
126
  this.logger.success(`Hooray, ${this.chalk.green('installation success')}!`);
117
- await this.eventSender.notifySuccess();
127
+ await this.eventSender.notifySuccess(authenticationToken, meta);
118
128
  }
119
129
 
120
130
  async analyzeDatabase(dbConfig, connection) {
121
131
  if (dbConfig.dbDialect === 'mongodb') {
122
- // the mongodb analyzer display a progress bar during the analyze
132
+ // the mongodb analyzer display a progress bar during the analysis
123
133
  this.logger.info('Analyzing the database...');
124
134
  const analysis = await this.databaseAnalyzer.analyzeMongoDb(connection, dbConfig, true);
125
135
  this.logger.success('Database is analyzed', { lineColor: 'green' });
@@ -5,6 +5,7 @@ module.exports = new JSONAPISerializer('projects', {
5
5
  'name',
6
6
  'defaultEnvironment',
7
7
  'origin',
8
+ 'agent',
8
9
  ],
9
10
  defaultEnvironment: {
10
11
  ref: 'id',
@@ -1,5 +1,16 @@
1
1
  const chalk = require('chalk');
2
2
 
3
+ const ALLOWED_OPTION_KEYS = [
4
+ 'color',
5
+ 'prefix',
6
+ 'std',
7
+ 'lineColor',
8
+ ];
9
+ const DEFAULT_OPTION_VALUES = ALLOWED_OPTION_KEYS.reduce((options, key) => {
10
+ options[key] = undefined;
11
+ return options;
12
+ }, {});
13
+
3
14
  class Logger {
4
15
  constructor({
5
16
  assertPresent,
@@ -20,10 +31,7 @@ class Logger {
20
31
  if (this.silent) return;
21
32
 
22
33
  options = {
23
- color: null,
24
- prefix: null,
25
- std: null,
26
- lineColor: null,
34
+ ...DEFAULT_OPTION_VALUES,
27
35
  ...options,
28
36
  };
29
37
 
@@ -33,11 +41,10 @@ class Logger {
33
41
  actualPrefix = Logger._setBoldColor(options.color, actualPrefix);
34
42
  }
35
43
 
36
- let actualMessage = message;
44
+ let actualMessage = Logger._stringifyIfObject(message);
37
45
  if (options.lineColor) {
38
46
  actualMessage = `${Logger._setColor(options.lineColor, actualMessage)}`;
39
47
  }
40
-
41
48
  actualMessage = `${actualPrefix}${actualMessage}\n`;
42
49
 
43
50
  if (options.std === 'err') {
@@ -54,6 +61,14 @@ class Logger {
54
61
  messages.forEach((message) => this._logLine(message, { ...baseOptions, ...options }));
55
62
  }
56
63
 
64
+ static _stringifyIfObject(message) {
65
+ if (typeof message === 'object') {
66
+ return JSON.stringify(message);
67
+ }
68
+
69
+ return message;
70
+ }
71
+
57
72
  static _setColor(color, message) {
58
73
  return chalk[color](message);
59
74
  }
@@ -62,27 +77,49 @@ class Logger {
62
77
  return chalk.bold[color](message);
63
78
  }
64
79
 
65
- // this method is a hack to keep the signature of all existing public methods.
80
+ static _isObjectKeysMatchAlwaysTheGivenKeys(object) {
81
+ if (typeof object !== 'object') {
82
+ return false;
83
+ }
84
+
85
+ return Object.keys(object).every((key) => ALLOWED_OPTION_KEYS.includes(key));
86
+ }
87
+
88
+ // This is a hack to keep the current signature of Logger methods.
89
+ // Last `message` is considered an option object if its keys are in `ALLOWED_OPTION_KEYS`.
66
90
  static _extractGivenOptionsFromMessages(messages) {
67
91
  let options = {};
68
- const potentialGivenOption = messages[messages.length - 1];
69
92
 
70
- if (typeof potentialGivenOption === 'object') {
71
- options = { ...options, ...potentialGivenOption };
72
- return { messages: messages.slice(0, -1), options };
93
+ const potentialGivenOptions = messages[messages.length - 1];
94
+ const hasOptions = Logger._isObjectKeysMatchAlwaysTheGivenKeys(potentialGivenOptions);
95
+
96
+ if (hasOptions) {
97
+ messages = messages.slice(0, -1);
98
+ options = { ...options, ...potentialGivenOptions };
73
99
  }
100
+
74
101
  return { messages, options };
75
102
  }
76
103
 
77
- error(...messages) { this._logLines(messages, { color: 'red', prefix: '×', std: 'err' }); }
104
+ /**
105
+ * Allows to log one ore more messages, with option object as last optional parameter.
106
+ * @example logger.log('message')
107
+ * @example logger.log('message', { color: 'blue', colorLine: 'green' })
108
+ * @example logger.log('message 1', 'message 2')
109
+ * @example logger.log('message 1', 'message 2', { color: 'blue', colorLine: 'green' })
110
+ */
111
+ log(...messagesAndOptions) { this._logLines(messagesAndOptions); }
78
112
 
79
- info(...messages) { this._logLines(messages, { color: 'blue', prefix: '>' }); }
113
+ error(...messagesAndOptions) { this._logLines(messagesAndOptions, { color: 'red', prefix: '×', std: 'err' }); }
80
114
 
81
- log(...messages) { this._logLines(messages); }
115
+ info(...messagesAndOptions) { this._logLines(messagesAndOptions, { color: 'blue', prefix: '>' }); }
82
116
 
83
- success(...messages) { this._logLines(messages, { color: 'green', prefix: '√' }); }
117
+ success(...messagesAndOptions) { this._logLines(messagesAndOptions, { color: 'green', prefix: '√' }); }
84
118
 
85
- warn(...messages) { this._logLines(messages, { color: 'yellow', prefix: 'Δ' }); }
119
+ warn(...messagesAndOptions) { this._logLines(messagesAndOptions, { color: 'yellow', prefix: 'Δ' }); }
86
120
  }
87
121
 
122
+ if (process.env.NODE_ENV === 'test') {
123
+ Logger.DEFAULT_OPTION_VALUES = DEFAULT_OPTION_VALUES;
124
+ }
88
125
  module.exports = Logger;
@@ -21,12 +21,13 @@ class ProjectCreator {
21
21
  this.terminator = terminator;
22
22
  }
23
23
 
24
- async create(sessionToken, config) {
24
+ async create(sessionToken, config, agent) {
25
25
  try {
26
- const newProjectPayload = { name: config.applicationName };
26
+ const newProjectPayload = { name: config.applicationName, agent };
27
27
  const newProject = await this.api.createProject(config, sessionToken, newProjectPayload);
28
28
 
29
29
  return {
30
+ id: newProject.id,
30
31
  envSecret: newProject.defaultEnvironment.secretKey,
31
32
  authSecret: this.keyGenerator.generate(),
32
33
  };
@@ -133,7 +133,8 @@ class MongoCollectionsAnalyzer {
133
133
  this.reduceCollection = reduceCollection;
134
134
  this.makeProgressBar = makeProgressBar;
135
135
 
136
- this.isDisplayProgressBar = true;
136
+ this.restoreDefaultState();
137
+
137
138
  this.mapReduceOptions = {
138
139
  out: { inline: 1 },
139
140
  limit: 100,
@@ -149,6 +150,10 @@ class MongoCollectionsAnalyzer {
149
150
  };
150
151
  }
151
152
 
153
+ restoreDefaultState() {
154
+ this.isProgressBarDisplay = true;
155
+ }
156
+
152
157
  mergeField(field) {
153
158
  if (field.value && field.value.type === 'embedded') {
154
159
  const schemas = field.value.schemas ? field.value.schemas : [field.value.schema];
@@ -266,7 +271,7 @@ class MongoCollectionsAnalyzer {
266
271
  const countIterations = Math.ceil(countDocuments / numberOfDocumentAllowed);
267
272
 
268
273
  let fetchFunction = this.fetchByChunkFunction(collection, numberOfDocumentAllowed);
269
- if (this.isDisplayProgressBar) {
274
+ if (this.isProgressBarDisplay) {
270
275
  const bar = this.makeProgressBar(
271
276
  `Analysing the **${collectionName}** collection`,
272
277
  countIterations,
@@ -286,13 +291,14 @@ class MongoCollectionsAnalyzer {
286
291
  }
287
292
 
288
293
  async analyzeMongoCollectionsWithoutProgressBar(databaseConnection) {
289
- this.isDisplayProgressBar = false;
294
+ this.isProgressBarDisplay = false;
290
295
  return this.analyzeMongoCollections(databaseConnection);
291
296
  }
292
297
 
293
298
  async analyzeMongoCollections(databaseConnection) {
294
299
  const collections = await databaseConnection.collections();
295
300
  if (collections.length === 0) {
301
+ this.restoreDefaultState();
296
302
  throw new EmptyDatabaseError('no collections found', {
297
303
  orm: 'mongoose',
298
304
  dialect: 'mongodb',
@@ -304,7 +310,7 @@ class MongoCollectionsAnalyzer {
304
310
  );
305
311
 
306
312
  let isMongodbInstanceSupportJs = true;
307
- return P.reduce(collections, async (schema, collection) => {
313
+ const schema = await P.reduce(collections, async (schema, collection) => {
308
314
  const collectionName = this.getCollectionName(collection);
309
315
 
310
316
  // Ignore system collections and collection without a valid name.
@@ -316,7 +322,7 @@ class MongoCollectionsAnalyzer {
316
322
  analysis = await this.analyzeMongoCollectionRemotely(databaseConnection, collectionName);
317
323
  if (analysis === MAP_REDUCE_ERROR_STRING) {
318
324
  isMongodbInstanceSupportJs = false;
319
- this.logger.warn('The analyze is running locally instead of in the db instance because your instance does not support javascript.'
325
+ this.logger.warn('The analysis is running locally instead of in the db instance because your instance does not support javascript.'
320
326
  + ' This action can takes a bit of time because it fetches all the collections.');
321
327
  }
322
328
  }
@@ -329,6 +335,9 @@ class MongoCollectionsAnalyzer {
329
335
  schema[collectionName] = this.buildSchema(analysis);
330
336
  return schema;
331
337
  }, {});
338
+
339
+ this.restoreDefaultState();
340
+ return schema;
332
341
  }
333
342
  }
334
343
 
@@ -31,8 +31,17 @@ class EventSender {
31
31
  }
32
32
  }
33
33
 
34
- async notifySuccess() {
35
- if (!this.applicationName || !this.command) { return; }
34
+ async notifySuccess(sessionToken, {
35
+ projectId, dbDialect, agent, isLocal,
36
+ }) {
37
+ if (
38
+ !this.applicationName
39
+ || !this.command
40
+ || !projectId
41
+ || !dbDialect
42
+ || !agent
43
+ || !!isLocal
44
+ ) { return; }
36
45
 
37
46
  try {
38
47
  await superagent.post(`${this.env.FOREST_URL}/api/lumber/success`, {
@@ -40,10 +49,15 @@ class EventSender {
40
49
  type: 'events',
41
50
  attributes: {
42
51
  command: this.command,
52
+ project_id: projectId,
43
53
  project_name: this.applicationName,
54
+ db_dialect: dbDialect,
55
+ agent,
56
+ is_local: isLocal,
44
57
  },
45
58
  },
46
- });
59
+ })
60
+ .set('Authorization', `Bearer ${sessionToken}`);
47
61
  } catch (e) {
48
62
  // NOTICE: We want silent error because this is just for reporting error
49
63
  // and not not blocking if that does not work.