forest-cli 3.0.11 → 3.0.12-beta.1

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 (138) hide show
  1. package/bin/run +1 -1
  2. package/oclif.manifest.json +1 -1
  3. package/package.json +17 -8
  4. package/src/abstract-authenticated-command.js +0 -46
  5. package/src/abstract-command.js +0 -27
  6. package/src/commands/branch.js +0 -136
  7. package/src/commands/deploy.js +0 -90
  8. package/src/commands/environments/copy-layout.js +0 -116
  9. package/src/commands/environments/create.js +0 -62
  10. package/src/commands/environments/delete.js +0 -81
  11. package/src/commands/environments/get.js +0 -48
  12. package/src/commands/environments/reset.js +0 -76
  13. package/src/commands/environments/update.js +0 -46
  14. package/src/commands/environments.js +0 -41
  15. package/src/commands/init.js +0 -169
  16. package/src/commands/login.js +0 -34
  17. package/src/commands/logout.js +0 -18
  18. package/src/commands/projects/create.js +0 -262
  19. package/src/commands/projects/get.js +0 -53
  20. package/src/commands/projects.js +0 -36
  21. package/src/commands/push.js +0 -75
  22. package/src/commands/schema/apply.js +0 -140
  23. package/src/commands/schema/update.js +0 -70
  24. package/src/commands/set-origin.js +0 -59
  25. package/src/commands/switch.js +0 -117
  26. package/src/commands/user.js +0 -44
  27. package/src/context/command-project-create-plan.js +0 -11
  28. package/src/context/command-projects-common-plan.js +0 -65
  29. package/src/context/command-schema-update-command-plan.js +0 -4
  30. package/src/context/dependencies-plan.js +0 -21
  31. package/src/context/env-plan.js +0 -27
  32. package/src/context/plan.js +0 -12
  33. package/src/context/process-plan.js +0 -3
  34. package/src/context/renderers-plan.js +0 -7
  35. package/src/context/serializers-plan.js +0 -8
  36. package/src/context/services-plan.js +0 -8
  37. package/src/context/static.js +0 -19
  38. package/src/context/utils-plan.js +0 -7
  39. package/src/deserializers/api-error.js +0 -21
  40. package/src/deserializers/application-token.js +0 -15
  41. package/src/deserializers/branch.js +0 -8
  42. package/src/deserializers/environment.js +0 -5
  43. package/src/deserializers/job.js +0 -5
  44. package/src/deserializers/project.js +0 -11
  45. package/src/errors/application-error.js +0 -9
  46. package/src/errors/application-token/unable-to-create-application-token-error.js +0 -16
  47. package/src/errors/database/empty-database-error.js +0 -5
  48. package/src/errors/dumper/incompatible-liana-for-update-error.js +0 -16
  49. package/src/errors/dumper/invalid-forest-cli-project-structure-error.js +0 -16
  50. package/src/errors/forest-cli-error.js +0 -32
  51. package/src/index.js +0 -1
  52. package/src/renderers/branches.js +0 -45
  53. package/src/renderers/defaults.js +0 -19
  54. package/src/renderers/environment.js +0 -51
  55. package/src/renderers/environments.js +0 -51
  56. package/src/renderers/project.js +0 -45
  57. package/src/renderers/projects.js +0 -45
  58. package/src/serializers/application-token.js +0 -11
  59. package/src/serializers/deployment-request.js +0 -5
  60. package/src/serializers/environment.js +0 -20
  61. package/src/serializers/job.js +0 -5
  62. package/src/serializers/project.js +0 -17
  63. package/src/serializers/schema.js +0 -116
  64. package/src/services/api.js +0 -110
  65. package/src/services/apimap-sorter.js +0 -104
  66. package/src/services/application-token.js +0 -56
  67. package/src/services/ask-for-environment.js +0 -24
  68. package/src/services/authenticator.js +0 -187
  69. package/src/services/branch-manager.js +0 -169
  70. package/src/services/dumper/dumper.js +0 -503
  71. package/src/services/dumper/handlebars/helpers/equal.js +0 -3
  72. package/src/services/dumper/handlebars/helpers/indent.js +0 -3
  73. package/src/services/dumper/handlebars/helpers/is-array.js +0 -3
  74. package/src/services/dumper/handlebars/helpers/is-object.js +0 -3
  75. package/src/services/dumper/handlebars/helpers/sum.js +0 -3
  76. package/src/services/dumper/handlebars/helpers/wrap-quotes.js +0 -7
  77. package/src/services/dumper/handlebars/loader.js +0 -10
  78. package/src/services/dumper/handlebars/partials/render-nested.js +0 -27
  79. package/src/services/dumper/templates/app/Dockerfile.hbs +0 -6
  80. package/src/services/dumper/templates/app/app.hbs +0 -79
  81. package/src/services/dumper/templates/app/config/databases.hbs +0 -49
  82. package/src/services/dumper/templates/app/docker-compose.hbs +0 -33
  83. package/src/services/dumper/templates/app/dockerignore.hbs +0 -3
  84. package/src/services/dumper/templates/app/env.hbs +0 -20
  85. package/src/services/dumper/templates/app/forest/collection.hbs +0 -13
  86. package/src/services/dumper/templates/app/gitignore.hbs +0 -3
  87. package/src/services/dumper/templates/app/middlewares/forestadmin.hbs +0 -21
  88. package/src/services/dumper/templates/app/middlewares/welcome.hbs +0 -7
  89. package/src/services/dumper/templates/app/models/index.hbs +0 -56
  90. package/src/services/dumper/templates/app/models/mongo-model.hbs +0 -16
  91. package/src/services/dumper/templates/app/models/sequelize-model.hbs +0 -48
  92. package/src/services/dumper/templates/app/public/favicon.png +0 -0
  93. package/src/services/dumper/templates/app/routes/route.hbs +0 -61
  94. package/src/services/dumper/templates/app/server.hbs +0 -56
  95. package/src/services/dumper/templates/app/views/index.hbs +0 -73
  96. package/src/services/environment-manager.js +0 -139
  97. package/src/services/init-manager.js +0 -183
  98. package/src/services/job-state-checker.js +0 -57
  99. package/src/services/logger.js +0 -125
  100. package/src/services/oidc/authenticator.js +0 -109
  101. package/src/services/oidc/error.js +0 -32
  102. package/src/services/project-manager.js +0 -89
  103. package/src/services/projects/create/command-generate-config-getter.js +0 -61
  104. package/src/services/projects/create/project-creator.js +0 -89
  105. package/src/services/prompter/abstract-prompter.js +0 -13
  106. package/src/services/prompter/application-prompts.js +0 -63
  107. package/src/services/prompter/database-prompts.js +0 -208
  108. package/src/services/prompter/general-prompter.js +0 -61
  109. package/src/services/prompter/project-prompts.js +0 -47
  110. package/src/services/prompter/prompter-error.js +0 -10
  111. package/src/services/schema/schema-service.js +0 -154
  112. package/src/services/schema/update/analyzer/database-analyzer.js +0 -64
  113. package/src/services/schema/update/analyzer/mongo-collections-analyzer.js +0 -344
  114. package/src/services/schema/update/analyzer/mongo-embedded-analyzer.js +0 -226
  115. package/src/services/schema/update/analyzer/mongo-hasmany-analyzer.js +0 -55
  116. package/src/services/schema/update/analyzer/mongo-references-analyzer.js +0 -51
  117. package/src/services/schema/update/analyzer/mysql-table-constraints-getter.js +0 -59
  118. package/src/services/schema/update/analyzer/sequelize-column-type-getter.js +0 -147
  119. package/src/services/schema/update/analyzer/sequelize-default-value.js +0 -122
  120. package/src/services/schema/update/analyzer/sequelize-table-constraints-getter.js +0 -298
  121. package/src/services/schema/update/analyzer/sequelize-tables-analyzer.js +0 -529
  122. package/src/services/schema/update/database.js +0 -160
  123. package/src/services/schema-sender.js +0 -55
  124. package/src/services/spinner.js +0 -130
  125. package/src/services/with-current-project.js +0 -41
  126. package/src/utils/database-url.js +0 -33
  127. package/src/utils/directory-existence-checker.js +0 -17
  128. package/src/utils/error-handler.js +0 -63
  129. package/src/utils/error.js +0 -21
  130. package/src/utils/event-sender.js +0 -80
  131. package/src/utils/fields.js +0 -14
  132. package/src/utils/key-generator.js +0 -18
  133. package/src/utils/messages.js +0 -7
  134. package/src/utils/mongo-collections.js +0 -35
  135. package/src/utils/mongo-primitive-type.js +0 -44
  136. package/src/utils/strings.js +0 -49
  137. package/src/utils/terminator.js +0 -38
  138. package/src/utils/to-valid-package-name.js +0 -24
package/bin/run CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('../src/index').run()
3
+ require('../dist/index').run()
4
4
  .then(require('@oclif/command/flush'))
5
5
  .catch(require('@oclif/errors/handle'));
@@ -1 +1 @@
1
- {"version":"3.0.11","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},"format":{"name":"format","type":"option","char":"format","description":"Output format.","options":["table","json"],"default":"table"},"origin":{"name":"origin","type":"option","char":"o","description":"Set the origin of the created branch."}},"args":[{"name":"BRANCH_NAME","description":"The name of the branch to create.","required":false}]},"deploy":{"id":"deploy","description":"Deploy layout changes of the current branch 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":[]},"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 the branch origin.","pluginName":"forest-cli","pluginType":"core","aliases":["branches:push"],"flags":{"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":[]},"set-origin":{"id":"set-origin","description":"Set an environment as your branch's origin. Your branch will build on top of that environment's layout.","pluginName":"forest-cli","pluginType":"core","aliases":["branches:origin"],"flags":{"help":{"name":"help","type":"boolean","description":"Display usage information.","allowNo":false}},"args":[{"name":"ENVIRONMENT_NAME","description":"The environment to set as origin.","required":false}]},"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":[{"name":"mongodb","value":"mongodb"},{"name":"mssql","value":"mssql"},{"name":"mysql / mariadb","value":"mysql"},{"name":"postgres","value":"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":"3.0.12-beta.1","commands":{}}
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": "3.0.11",
4
+ "version": "3.0.12-beta.1",
5
5
  "author": "Sandro Munda",
6
6
  "contributors": [
7
7
  "Arnaud Valensi <arnaud.valensi@gmail.com>",
@@ -61,8 +61,12 @@
61
61
  "@oclif/dev-cli": "1.22.2",
62
62
  "@semantic-release/changelog": "6.0.1",
63
63
  "@semantic-release/git": "10.0.1",
64
+ "@swc/core": "1.3.34",
65
+ "@swc/jest": "0.2.24",
64
66
  "@types/jest": "27.0.2",
65
- "eslint": "6.8.0",
67
+ "@typescript-eslint/eslint-plugin": "^5.9.1",
68
+ "@typescript-eslint/parser": "^5.9.1",
69
+ "eslint": "^8.6.0",
66
70
  "eslint-config-airbnb-base": "14.0.0",
67
71
  "eslint-config-oclif": "3.1.0",
68
72
  "eslint-plugin-import": "2.25.2",
@@ -77,7 +81,9 @@
77
81
  "nock": "13.0.4",
78
82
  "rimraf": "3.0.2",
79
83
  "semantic-release": "19.0.3",
80
- "semantic-release-slack-bot": "3.5.2"
84
+ "semantic-release-slack-bot": "3.5.2",
85
+ "tsc-watch": "6.0.0",
86
+ "typescript": "^4.5.4"
81
87
  },
82
88
  "engines": {
83
89
  "node": ">=8.0.0"
@@ -86,16 +92,16 @@
86
92
  "/bin",
87
93
  "/npm-shrinkwrap.json",
88
94
  "/oclif.manifest.json",
89
- "/src"
95
+ "/dist"
90
96
  ],
91
97
  "homepage": "https://github.com/ForestAdmin/toolbelt",
92
98
  "keywords": [
93
99
  "forestadmin"
94
100
  ],
95
101
  "license": "GPL-3.0",
96
- "main": "src/index.js",
102
+ "main": "dist/index.js",
97
103
  "oclif": {
98
- "commands": "./src/commands",
104
+ "commands": "./dist/commands",
99
105
  "bin": "forest",
100
106
  "plugins": [
101
107
  "@oclif/plugin-help",
@@ -110,11 +116,14 @@
110
116
  },
111
117
  "repository": "ForestAdmin/toolbelt",
112
118
  "scripts": {
113
- "lint": "./node_modules/eslint/bin/eslint.js ./*.js src test",
119
+ "lint": "eslint src test",
114
120
  "prepare": "husky install",
115
121
  "prepack": "oclif-dev manifest",
116
122
  "postpack": "rm -f oclif.manifest.json",
123
+ "build": "tsc",
124
+ "build:watch": "tsc-watch --onSuccess 'yarn postbuild'",
117
125
  "test": "jest --runInBand",
118
- "test:coverage": "jest --runInBand --coverage"
126
+ "test:coverage": "jest --runInBand --coverage",
127
+ "postbuild": "cp -R src/services/dumper/templates dist/services/dumper/templates"
119
128
  }
120
129
  }
@@ -1,46 +0,0 @@
1
- const AbstractCommand = require('./abstract-command');
2
-
3
- class AbstractAuthenticatedCommand extends AbstractCommand {
4
- init(plan) {
5
- super.init(plan);
6
- const { assertPresent, authenticator } = this.context;
7
- assertPresent({ authenticator });
8
-
9
- /** @protected @readonly */
10
- this.authenticator = authenticator;
11
- }
12
-
13
- async run() {
14
- if (!this.authenticator.getAuthToken()) {
15
- this.logger.info('Login required.');
16
- await this.authenticator.tryLogin({});
17
- if (!this.authenticator.getAuthToken()) {
18
- this.exit(10);
19
- }
20
- }
21
-
22
- try {
23
- return await this.runIfAuthenticated();
24
- } catch (error) {
25
- // NOTICE: Due to ip-whitelist, 404 will never be thrown for a project
26
- if (error.status === 403) {
27
- this.logger.error('You do not have the right to execute this action on this project');
28
- this.exit(2);
29
- }
30
-
31
- if (error.status === 401) {
32
- await this.authenticator.logout();
33
- this.logger.error(`Please use '${this.chalk.bold('forest login')}' to sign in to your Forest account.`);
34
- this.exit(10);
35
- }
36
-
37
- throw error;
38
- }
39
- }
40
-
41
- async runIfAuthenticated() {
42
- throw new Error(`'runIfAuthenticated' is not implemented on ${this.constructor.name}`);
43
- }
44
- }
45
-
46
- module.exports = AbstractAuthenticatedCommand;
@@ -1,27 +0,0 @@
1
- const { Command, flags } = require('@oclif/command');
2
- const Context = require('@forestadmin/context');
3
-
4
- const defaultPlan = require('./context/plan');
5
-
6
- class AbstractCommand extends Command {
7
- init(plan) {
8
- Context.init(plan || defaultPlan);
9
- this.context = Context.inject();
10
- // FIXME: Restore when no more Context.inject present in services.
11
- // this.context = Context.execute(plan || defaultPlan);
12
- const { assertPresent, logger, chalk } = this.context;
13
- assertPresent({ logger, chalk });
14
-
15
- /** @protected @readonly */
16
- this.logger = logger;
17
-
18
- /** @protected @readonly */
19
- this.chalk = chalk;
20
- }
21
- }
22
-
23
- // NOTICE: Exports flag types within base command to remove need for
24
- // requiring @oclif/command in all command files.
25
- AbstractCommand.flags = flags;
26
-
27
- module.exports = AbstractCommand;
@@ -1,136 +0,0 @@
1
- const AbstractAuthenticatedCommand = require('../abstract-authenticated-command');
2
- const BranchManager = require('../services/branch-manager');
3
- const ProjectManager = require('../services/project-manager');
4
- const withCurrentProject = require('../services/with-current-project');
5
- const askForEnvironment = require('../services/ask-for-environment');
6
-
7
- class BranchCommand extends AbstractAuthenticatedCommand {
8
- init(plan) {
9
- super.init(plan);
10
- const {
11
- assertPresent, env, inquirer, branchesRenderer,
12
- } = this.context;
13
- assertPresent({ env, inquirer });
14
- this.env = env;
15
- this.inquirer = inquirer;
16
- this.branchesRenderer = branchesRenderer;
17
- }
18
-
19
- async listBranches(envSecret, format) {
20
- try {
21
- const branches = await BranchManager.getBranches(envSecret);
22
- if (!branches || branches.length === 0) {
23
- this.logger.warn('You don\'t have any branch yet. Use `forest branch <branch_name>` to create one.');
24
- } else {
25
- this.branchesRenderer.render(branches, format);
26
- }
27
- } catch (error) {
28
- const customError = BranchManager.handleBranchError(error);
29
-
30
- this.logger.error(customError);
31
- this.exit(2);
32
- }
33
- }
34
-
35
- async createBranch(branchName, environmentSecret, originName) {
36
- try {
37
- await BranchManager.createBranch(branchName, environmentSecret, originName);
38
-
39
- this.logger.success(`Switched to new branch: ${branchName}.`);
40
- } catch (error) {
41
- const customError = BranchManager.handleBranchError(error);
42
- this.logger.error(customError);
43
- this.exit(2);
44
- }
45
- }
46
-
47
- async deleteBranch(branchName, forceDelete, envSecret) {
48
- if (!forceDelete) {
49
- const response = await this.inquirer
50
- .prompt([{
51
- type: 'confirm',
52
- name: 'confirm',
53
- message: `Delete branch ${branchName}`,
54
- }]);
55
- if (!response.confirm) return;
56
- }
57
- try {
58
- await BranchManager.deleteBranch(branchName, envSecret);
59
- this.logger.success(`Branch ${branchName} successfully deleted.`);
60
- } catch (error) {
61
- const customError = BranchManager.handleBranchError(error);
62
-
63
- this.logger.error(customError);
64
- this.exit(2);
65
- }
66
- }
67
-
68
- async runIfAuthenticated() {
69
- const parsed = this.parse(BranchCommand);
70
- const envSecret = this.env.FOREST_ENV_SECRET;
71
- const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
72
- let config;
73
-
74
- try {
75
- config = await withCurrentProject({ ...this.env, ...commandOptions });
76
-
77
- if (!config.envSecret) {
78
- const environment = await new ProjectManager(config)
79
- .getDevelopmentEnvironmentForUser(config.projectId);
80
- config.envSecret = environment.secretKey;
81
- }
82
-
83
- if (!config.origin && config.BRANCH_NAME && !config.delete) {
84
- config.origin = await askForEnvironment(config, 'Select the remote environment you want as origin', ['production', 'remote']);
85
- }
86
- } catch (error) {
87
- const customError = BranchManager.handleBranchError(error);
88
- this.logger.error(customError);
89
- this.exit(2);
90
- }
91
-
92
- if (config.BRANCH_NAME) {
93
- if (config.delete) {
94
- return this.deleteBranch(config.BRANCH_NAME, config.force, config.envSecret);
95
- }
96
- return this.createBranch(config.BRANCH_NAME, config.envSecret, config.origin);
97
- }
98
- return this.listBranches(config.envSecret, config.format);
99
- }
100
- }
101
-
102
- BranchCommand.aliases = ['branches'];
103
-
104
- BranchCommand.description = 'Create a new branch or list your existing branches.';
105
-
106
- BranchCommand.flags = {
107
- projectId: AbstractAuthenticatedCommand.flags.integer({
108
- description: 'The id of the project to create a branch in.',
109
- }),
110
- delete: AbstractAuthenticatedCommand.flags.boolean({
111
- char: 'd',
112
- description: 'Delete the branch.',
113
- }),
114
- force: AbstractAuthenticatedCommand.flags.boolean({
115
- description: 'When deleting a branch, skip confirmation.',
116
- }),
117
- help: AbstractAuthenticatedCommand.flags.boolean({
118
- description: 'Display usage information.',
119
- }),
120
- format: AbstractAuthenticatedCommand.flags.string({
121
- char: 'format',
122
- description: 'Output format.',
123
- options: ['table', 'json'],
124
- default: 'table',
125
- }),
126
- origin: AbstractAuthenticatedCommand.flags.string({
127
- char: 'o',
128
- description: 'Set the origin of the created branch.',
129
- }),
130
- };
131
-
132
- BranchCommand.args = [{
133
- name: 'BRANCH_NAME', required: false, description: 'The name of the branch to create.',
134
- }];
135
-
136
- module.exports = BranchCommand;
@@ -1,90 +0,0 @@
1
- const AbstractAuthenticatedCommand = require('../abstract-authenticated-command');
2
- const EnvironmentManager = require('../services/environment-manager');
3
- const ProjectManager = require('../services/project-manager');
4
- const { handleBranchError } = require('../services/branch-manager');
5
- const withCurrentProject = require('../services/with-current-project');
6
-
7
- /** Deploy layout changes of an environment to the reference one. */
8
- class DeployCommand extends AbstractAuthenticatedCommand {
9
- init(plan) {
10
- super.init(plan);
11
- const { assertPresent, env, inquirer } = this.context;
12
- assertPresent({ env, inquirer });
13
- this.env = env;
14
- this.inquirer = inquirer;
15
- }
16
-
17
- /**
18
- * Get command configuration (merge env configuration with command context).
19
- * @returns {Object} The command configuration, including its envSecret correctly set.
20
- */
21
- async getConfig() {
22
- const envSecret = this.env.FOREST_ENV_SECRET;
23
- const parsed = this.parse(DeployCommand);
24
- const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
25
- const config = await withCurrentProject({ ...this.env, ...commandOptions });
26
-
27
- if (!config.envSecret) {
28
- const environment = await new ProjectManager(config)
29
- .getDevelopmentEnvironmentForUser(config.projectId);
30
- config.envSecret = environment.secretKey;
31
- }
32
-
33
- return config;
34
- }
35
-
36
- /**
37
- * Ask for confirmation before deploying layout changes.
38
- * @param {Object} environment - The environment containing the layout changes to deploy.
39
- * @returns {Boolean} Return true if user has confirmed.
40
- */
41
- async confirm() {
42
- const response = await this.inquirer
43
- .prompt([{
44
- type: 'confirm',
45
- name: 'confirm',
46
- message: 'Deploy layout changes to reference?',
47
- }]);
48
- return response.confirm;
49
- }
50
-
51
- /**
52
- * The "deploy" command procedure itself.
53
- * @returns {void}
54
- */
55
- async runIfAuthenticated() {
56
- try {
57
- const config = await this.getConfig();
58
-
59
- if (!config.force && !(await this.confirm())) return;
60
-
61
- await new EnvironmentManager(config).deploy();
62
-
63
- this.logger.success('Deployed layout changes to reference environment.');
64
- } catch (error) {
65
- this.logger.error(handleBranchError(error));
66
- this.exit(2);
67
- }
68
- }
69
- }
70
-
71
- DeployCommand.aliases = ['environments:deploy'];
72
-
73
- DeployCommand.description = 'Deploy layout changes of the current branch to the reference one.';
74
-
75
- DeployCommand.flags = {
76
- help: AbstractAuthenticatedCommand.flags.boolean({
77
- description: 'Display usage information.',
78
- }),
79
- force: AbstractAuthenticatedCommand.flags.boolean({
80
- char: 'f',
81
- description: 'Skip deploy confirmation.',
82
- }),
83
- projectId: AbstractAuthenticatedCommand.flags.integer({
84
- char: 'p',
85
- description: 'The id of the project you want to deploy.',
86
- default: null,
87
- }),
88
- };
89
-
90
- module.exports = DeployCommand;
@@ -1,116 +0,0 @@
1
- const AbstractAuthenticatedCommand = require('../../abstract-authenticated-command');
2
- const EnvironmentManager = require('../../services/environment-manager');
3
- const withCurrentProject = require('../../services/with-current-project');
4
-
5
- class CopyLayoutCommand extends AbstractAuthenticatedCommand {
6
- init(plan) {
7
- super.init(plan);
8
- const {
9
- assertPresent,
10
- chalk,
11
- env,
12
- inquirer,
13
- } = this.context;
14
- assertPresent({
15
- chalk,
16
- env,
17
- inquirer,
18
- });
19
- this.chalk = chalk;
20
- this.env = env;
21
- this.inquirer = inquirer;
22
- }
23
-
24
- async _getEnvironments(manager, config) {
25
- let fromEnvironment;
26
- let toEnvironment;
27
- try {
28
- fromEnvironment = await manager.getEnvironment(config.fromEnvironment);
29
- } catch (error) {
30
- if (error.status !== 404) {
31
- throw error;
32
- }
33
- this.logger.error(`Cannot find the source environment ${this.chalk.bold(config.fromEnvironment)} on the project ${this.chalk.bold(config.projectId)}.`);
34
- this.exit(3);
35
- }
36
-
37
- try {
38
- toEnvironment = await manager.getEnvironment(config.toEnvironment);
39
- } catch (error) {
40
- if (error.status !== 404) {
41
- throw error;
42
- }
43
- this.logger.error(`Cannot find the target environment ${this.chalk.bold(config.toEnvironment)} on the project ${this.chalk.bold(config.projectId)}.`);
44
- this.exit(3);
45
- }
46
-
47
- return { fromEnvironment, toEnvironment };
48
- }
49
-
50
- async runIfAuthenticated() {
51
- const oclifExit = this.exit.bind(this);
52
- const parsed = this.parse(CopyLayoutCommand);
53
- const config = await withCurrentProject({ ...this.env, ...parsed.flags, ...parsed.args });
54
- const manager = new EnvironmentManager(config);
55
-
56
- const { fromEnvironment, toEnvironment } = await this._getEnvironments(manager, config);
57
- let answers;
58
-
59
- if (!config.force) {
60
- answers = await this.inquirer
61
- .prompt([{
62
- type: 'input',
63
- prefix: 'Δ WARNING \t',
64
- name: 'confirm',
65
- message: `This will copy the environment's layout from ${this.chalk.red(fromEnvironment.name)} to ${this.chalk.red(toEnvironment.name)} and override the whole previous configuration.\nTo proceed, type ${this.chalk.red(toEnvironment.name)} or re-run this command with --force : `,
66
- }]);
67
- }
68
-
69
- try {
70
- if (!answers || answers.confirm === toEnvironment.name) {
71
- const copyLayout = await manager.copyLayout(
72
- fromEnvironment.id,
73
- toEnvironment.id,
74
- oclifExit,
75
- );
76
- if (copyLayout) {
77
- this.logger.log(`Environment's layout ${this.chalk.red(fromEnvironment.name)} successfully copied to ${this.chalk.red(toEnvironment.name)}.`);
78
- } else {
79
- this.logger.error('Oops, something went wrong.');
80
- this.exit(1);
81
- }
82
- } else {
83
- this.logger.error(`Confirmation did not match ${this.chalk.red(toEnvironment.name)}. Aborted.`);
84
- this.exit(2);
85
- }
86
- } catch (error) {
87
- if (error.status === 403) {
88
- this.logger.error(`You do not have the rights to copy the layout of the environment ${this.chalk.bold(fromEnvironment.name)} to ${this.chalk.bold(toEnvironment.name)}.`);
89
- } else {
90
- this.logger.error(error);
91
- }
92
- this.exit(1);
93
- }
94
- }
95
- }
96
-
97
- CopyLayoutCommand.description = 'Copy the layout from one environment to another.';
98
-
99
- CopyLayoutCommand.flags = {
100
- projectId: AbstractAuthenticatedCommand.flags.integer({
101
- char: 'p',
102
- description: 'Forest project ID.',
103
- default: null,
104
- }),
105
- force: AbstractAuthenticatedCommand.flags.boolean({
106
- char: 'force',
107
- description: 'Force copy.',
108
- }),
109
- };
110
-
111
- CopyLayoutCommand.args = [
112
- { name: 'fromEnvironment', required: true, description: 'Source environment ID.' },
113
- { name: 'toEnvironment', required: true, description: 'Target environment ID.' },
114
- ];
115
-
116
- module.exports = CopyLayoutCommand;
@@ -1,62 +0,0 @@
1
- const EnvironmentManager = require('../../services/environment-manager');
2
- const AbstractAuthenticatedCommand = require('../../abstract-authenticated-command');
3
- const withCurrentProject = require('../../services/with-current-project');
4
-
5
- class CreateCommand extends AbstractAuthenticatedCommand {
6
- init(plan) {
7
- super.init(plan);
8
- const { assertPresent, env, environmentRenderer } = this.context;
9
- assertPresent({ env, environmentRenderer });
10
- this.env = env;
11
- this.environmentRenderer = environmentRenderer;
12
- }
13
-
14
- async runIfAuthenticated() {
15
- const parsed = this.parse(CreateCommand);
16
- const config = await withCurrentProject({ ...this.env, ...parsed.flags });
17
- const manager = new EnvironmentManager(config);
18
-
19
- try {
20
- const environment = await manager.createEnvironment();
21
- this.environmentRenderer.render(environment, config);
22
- } catch (error) {
23
- if (error.response && error.status !== 403) {
24
- const errorData = JSON.parse(error.response.text);
25
- if (errorData && errorData.errors && errorData.errors.length
26
- && errorData.errors[0] && errorData.errors[0].detail) {
27
- this.logger.error(errorData.errors[0].detail);
28
- this.exit(1);
29
- }
30
- }
31
- throw error;
32
- }
33
- }
34
- }
35
-
36
- CreateCommand.description = 'Create a new environment.';
37
-
38
- CreateCommand.flags = {
39
- projectId: AbstractAuthenticatedCommand.flags.integer({
40
- char: 'p',
41
- description: 'Forest project ID.',
42
- default: null,
43
- }),
44
- name: AbstractAuthenticatedCommand.flags.string({
45
- char: 'n',
46
- description: 'Environment name.',
47
- required: true,
48
- }),
49
- url: AbstractAuthenticatedCommand.flags.string({
50
- char: 'u',
51
- description: 'Application URL.',
52
- required: true,
53
- }),
54
- format: AbstractAuthenticatedCommand.flags.string({
55
- char: 'format',
56
- description: 'Ouput format.',
57
- options: ['table', 'json'],
58
- default: 'table',
59
- }),
60
- };
61
-
62
- module.exports = CreateCommand;