forest-cli 2.7.0 → 3.0.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/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/src/commands/branch.js +25 -11
- package/src/commands/deploy.js +6 -48
- package/src/commands/environments/reset.js +2 -17
- package/src/commands/init.js +1 -1
- package/src/commands/push.js +15 -42
- package/src/commands/set-origin.js +59 -0
- package/src/context/renderers-plan.js +2 -1
- package/src/deserializers/branch.js +3 -0
- package/src/renderers/branches.js +45 -0
- package/src/services/ask-for-environment.js +24 -0
- package/src/services/authenticator.js +4 -0
- package/src/services/branch-manager.js +25 -5
- package/src/services/environment-manager.js +2 -4
- package/src/utils/database-url.js +6 -6
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"2.7.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":[{"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.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},"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":[]}}}
|
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": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"author": "Sandro Munda",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Arnaud Valensi <arnaud.valensi@gmail.com>",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"mock-stdin": "1.0.0",
|
|
77
77
|
"nock": "13.0.4",
|
|
78
78
|
"rimraf": "3.0.2",
|
|
79
|
-
"semantic-release": "19.0.
|
|
79
|
+
"semantic-release": "19.0.3",
|
|
80
80
|
"semantic-release-slack-bot": "3.5.2"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
package/src/commands/branch.js
CHANGED
|
@@ -2,25 +2,27 @@ const AbstractAuthenticatedCommand = require('../abstract-authenticated-command'
|
|
|
2
2
|
const BranchManager = require('../services/branch-manager');
|
|
3
3
|
const ProjectManager = require('../services/project-manager');
|
|
4
4
|
const withCurrentProject = require('../services/with-current-project');
|
|
5
|
+
const askForEnvironment = require('../services/ask-for-environment');
|
|
5
6
|
|
|
6
7
|
class BranchCommand extends AbstractAuthenticatedCommand {
|
|
7
8
|
init(plan) {
|
|
8
9
|
super.init(plan);
|
|
9
|
-
const {
|
|
10
|
+
const {
|
|
11
|
+
assertPresent, env, inquirer, branchesRenderer,
|
|
12
|
+
} = this.context;
|
|
10
13
|
assertPresent({ env, inquirer });
|
|
11
14
|
this.env = env;
|
|
12
15
|
this.inquirer = inquirer;
|
|
16
|
+
this.branchesRenderer = branchesRenderer;
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
async listBranches(envSecret) {
|
|
19
|
+
async listBranches(envSecret, format) {
|
|
16
20
|
try {
|
|
17
21
|
const branches = await BranchManager.getBranches(envSecret);
|
|
18
22
|
if (!branches || branches.length === 0) {
|
|
19
23
|
this.logger.warn('You don\'t have any branch yet. Use `forest branch <branch_name>` to create one.');
|
|
20
24
|
} else {
|
|
21
|
-
|
|
22
|
-
this.logger.log(`${branch.name} ${branch.isCurrent ? '< current branch' : ''}`);
|
|
23
|
-
});
|
|
25
|
+
this.branchesRenderer.render(branches, format);
|
|
24
26
|
}
|
|
25
27
|
} catch (error) {
|
|
26
28
|
const customError = BranchManager.handleBranchError(error);
|
|
@@ -30,14 +32,13 @@ class BranchCommand extends AbstractAuthenticatedCommand {
|
|
|
30
32
|
}
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
async createBranch(branchName, environmentSecret) {
|
|
35
|
+
async createBranch(branchName, environmentSecret, originName) {
|
|
34
36
|
try {
|
|
35
|
-
await BranchManager.createBranch(branchName, environmentSecret);
|
|
37
|
+
await BranchManager.createBranch(branchName, environmentSecret, originName);
|
|
36
38
|
|
|
37
39
|
this.logger.success(`Switched to new branch: ${branchName}.`);
|
|
38
40
|
} catch (error) {
|
|
39
41
|
const customError = BranchManager.handleBranchError(error);
|
|
40
|
-
|
|
41
42
|
this.logger.error(customError);
|
|
42
43
|
this.exit(2);
|
|
43
44
|
}
|
|
@@ -78,20 +79,23 @@ class BranchCommand extends AbstractAuthenticatedCommand {
|
|
|
78
79
|
.getDevelopmentEnvironmentForUser(config.projectId);
|
|
79
80
|
config.envSecret = environment.secretKey;
|
|
80
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
|
+
}
|
|
81
86
|
} catch (error) {
|
|
82
87
|
const customError = BranchManager.handleBranchError(error);
|
|
83
88
|
this.logger.error(customError);
|
|
84
89
|
this.exit(2);
|
|
85
|
-
return null;
|
|
86
90
|
}
|
|
87
91
|
|
|
88
92
|
if (config.BRANCH_NAME) {
|
|
89
93
|
if (config.delete) {
|
|
90
94
|
return this.deleteBranch(config.BRANCH_NAME, config.force, config.envSecret);
|
|
91
95
|
}
|
|
92
|
-
return this.createBranch(config.BRANCH_NAME, config.envSecret);
|
|
96
|
+
return this.createBranch(config.BRANCH_NAME, config.envSecret, config.origin);
|
|
93
97
|
}
|
|
94
|
-
return this.listBranches(config.envSecret);
|
|
98
|
+
return this.listBranches(config.envSecret, config.format);
|
|
95
99
|
}
|
|
96
100
|
}
|
|
97
101
|
|
|
@@ -113,6 +117,16 @@ BranchCommand.flags = {
|
|
|
113
117
|
help: AbstractAuthenticatedCommand.flags.boolean({
|
|
114
118
|
description: 'Display usage information.',
|
|
115
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
|
+
}),
|
|
116
130
|
};
|
|
117
131
|
|
|
118
132
|
BranchCommand.args = [{
|
package/src/commands/deploy.js
CHANGED
|
@@ -14,41 +14,6 @@ class DeployCommand extends AbstractAuthenticatedCommand {
|
|
|
14
14
|
this.inquirer = inquirer;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* Get selected environment; prompt for environment when none is provided.
|
|
19
|
-
* @param {Object} config - Actual command config (including command parameters).
|
|
20
|
-
* @throws Will throw an error when there is no environment (unreachable).
|
|
21
|
-
* @throws Will throw an error when there is no reference environment.
|
|
22
|
-
* @return {Object} The environment found.
|
|
23
|
-
*/
|
|
24
|
-
async getEnvironment(config) {
|
|
25
|
-
const environments = await new EnvironmentManager(config).listEnvironments();
|
|
26
|
-
|
|
27
|
-
if (environments.length === 0) throw new Error('No environment found.');
|
|
28
|
-
|
|
29
|
-
const environmentName = config.ENVIRONMENT_NAME || await this.selectEnvironment(environments);
|
|
30
|
-
return environments.find((environment) => environment.name === environmentName);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Display an environment selector.
|
|
35
|
-
* @param {Array} environments List of environments (from backend).
|
|
36
|
-
* @see getEnvironment
|
|
37
|
-
*/
|
|
38
|
-
async selectEnvironment(environments) {
|
|
39
|
-
// NOTICE: Remove production since it should not be deployable on itself.
|
|
40
|
-
const choices = environments
|
|
41
|
-
.filter((environment) => environment.type !== 'production')
|
|
42
|
-
.map(({ name }) => name);
|
|
43
|
-
const response = await this.inquirer.prompt([{
|
|
44
|
-
name: 'environment',
|
|
45
|
-
message: 'Select the environment containing the layout changes you want to deploy to the reference environment',
|
|
46
|
-
type: 'list',
|
|
47
|
-
choices,
|
|
48
|
-
}]);
|
|
49
|
-
return response.environment;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
17
|
/**
|
|
53
18
|
* Get command configuration (merge env configuration with command context).
|
|
54
19
|
* @returns {Object} The command configuration, including its envSecret correctly set.
|
|
@@ -73,12 +38,12 @@ class DeployCommand extends AbstractAuthenticatedCommand {
|
|
|
73
38
|
* @param {Object} environment - The environment containing the layout changes to deploy.
|
|
74
39
|
* @returns {Boolean} Return true if user has confirmed.
|
|
75
40
|
*/
|
|
76
|
-
async confirm(
|
|
41
|
+
async confirm() {
|
|
77
42
|
const response = await this.inquirer
|
|
78
43
|
.prompt([{
|
|
79
44
|
type: 'confirm',
|
|
80
45
|
name: 'confirm',
|
|
81
|
-
message:
|
|
46
|
+
message: 'Deploy layout changes to reference?',
|
|
82
47
|
}]);
|
|
83
48
|
return response.confirm;
|
|
84
49
|
}
|
|
@@ -90,15 +55,12 @@ class DeployCommand extends AbstractAuthenticatedCommand {
|
|
|
90
55
|
async runIfAuthenticated() {
|
|
91
56
|
try {
|
|
92
57
|
const config = await this.getConfig();
|
|
93
|
-
const environment = await this.getEnvironment(config);
|
|
94
|
-
|
|
95
|
-
if (environment === undefined) throw new Error('Environment not found.');
|
|
96
58
|
|
|
97
|
-
if (!config.force && !(await this.confirm(
|
|
59
|
+
if (!config.force && !(await this.confirm())) return;
|
|
98
60
|
|
|
99
|
-
await new EnvironmentManager(config).deploy(
|
|
61
|
+
await new EnvironmentManager(config).deploy();
|
|
100
62
|
|
|
101
|
-
this.logger.success(
|
|
63
|
+
this.logger.success('Deployed layout changes to reference environment.');
|
|
102
64
|
} catch (error) {
|
|
103
65
|
this.logger.error(handleBranchError(error));
|
|
104
66
|
this.exit(2);
|
|
@@ -108,7 +70,7 @@ class DeployCommand extends AbstractAuthenticatedCommand {
|
|
|
108
70
|
|
|
109
71
|
DeployCommand.aliases = ['environments:deploy'];
|
|
110
72
|
|
|
111
|
-
DeployCommand.description = 'Deploy layout changes of
|
|
73
|
+
DeployCommand.description = 'Deploy layout changes of the current branch to the reference one.';
|
|
112
74
|
|
|
113
75
|
DeployCommand.flags = {
|
|
114
76
|
help: AbstractAuthenticatedCommand.flags.boolean({
|
|
@@ -125,8 +87,4 @@ DeployCommand.flags = {
|
|
|
125
87
|
}),
|
|
126
88
|
};
|
|
127
89
|
|
|
128
|
-
DeployCommand.args = [{
|
|
129
|
-
name: 'ENVIRONMENT_NAME', required: false, description: 'The name of the environment containing the layout changes to deploy to the reference one.',
|
|
130
|
-
}];
|
|
131
|
-
|
|
132
90
|
module.exports = DeployCommand;
|
|
@@ -3,6 +3,7 @@ const ProjectManager = require('../../services/project-manager');
|
|
|
3
3
|
const AbstractAuthenticatedCommand = require('../../abstract-authenticated-command');
|
|
4
4
|
const withCurrentProject = require('../../services/with-current-project');
|
|
5
5
|
const { handleError } = require('../../utils/error');
|
|
6
|
+
const askForEnvironment = require('../../services/ask-for-environment');
|
|
6
7
|
|
|
7
8
|
class ResetCommand extends AbstractAuthenticatedCommand {
|
|
8
9
|
init(plan) {
|
|
@@ -13,22 +14,6 @@ class ResetCommand extends AbstractAuthenticatedCommand {
|
|
|
13
14
|
this.inquirer = inquirer;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
async askForEnvironment(config) {
|
|
17
|
-
const environments = await new EnvironmentManager(config).listEnvironments();
|
|
18
|
-
const remoteEnvironments = environments.filter((environment) => environment.type === 'remote');
|
|
19
|
-
|
|
20
|
-
if (remoteEnvironments.length) {
|
|
21
|
-
const response = await this.inquirer.prompt([{
|
|
22
|
-
name: 'environment',
|
|
23
|
-
message: 'Select the remote environment you want to reset',
|
|
24
|
-
type: 'list',
|
|
25
|
-
choices: remoteEnvironments.map(({ name }) => name),
|
|
26
|
-
}]);
|
|
27
|
-
return response.environment;
|
|
28
|
-
}
|
|
29
|
-
throw new Error('No remote environment.');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
17
|
async runIfAuthenticated() {
|
|
33
18
|
const parsed = this.parse(ResetCommand);
|
|
34
19
|
const envSecret = this.env.FOREST_ENV_SECRET;
|
|
@@ -45,7 +30,7 @@ class ResetCommand extends AbstractAuthenticatedCommand {
|
|
|
45
30
|
}
|
|
46
31
|
|
|
47
32
|
if (!config.environment) {
|
|
48
|
-
config.environment = await
|
|
33
|
+
config.environment = await askForEnvironment(config, 'Select the remote environment you want to reset', ['remote']);
|
|
49
34
|
}
|
|
50
35
|
|
|
51
36
|
if (!config.force) {
|
package/src/commands/init.js
CHANGED
|
@@ -94,7 +94,7 @@ class InitCommand extends AbstractAuthenticatedCommand {
|
|
|
94
94
|
this.spinner.continue();
|
|
95
95
|
if (databaseConfiguration) {
|
|
96
96
|
this.environmentVariables.databaseUrl = buildDatabaseUrl(databaseConfiguration);
|
|
97
|
-
this.environmentVariables.databaseSchema = databaseConfiguration.
|
|
97
|
+
this.environmentVariables.databaseSchema = databaseConfiguration.databaseSchema;
|
|
98
98
|
this.environmentVariables.databaseSSL = databaseConfiguration.ssl;
|
|
99
99
|
}
|
|
100
100
|
}
|
package/src/commands/push.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const AbstractAuthenticatedCommand = require('../abstract-authenticated-command');
|
|
2
2
|
const BranchManager = require('../services/branch-manager');
|
|
3
3
|
const ProjectManager = require('../services/project-manager');
|
|
4
|
-
const EnvironmentManager = require('../services/environment-manager');
|
|
5
4
|
const withCurrentProject = require('../services/with-current-project');
|
|
6
5
|
|
|
7
6
|
class PushCommand extends AbstractAuthenticatedCommand {
|
|
@@ -13,61 +12,40 @@ class PushCommand extends AbstractAuthenticatedCommand {
|
|
|
13
12
|
this.inquirer = inquirer;
|
|
14
13
|
}
|
|
15
14
|
|
|
16
|
-
// TODO: DWO EP17 probably update this function to handle environment selection
|
|
17
|
-
async askForEnvironment(config) {
|
|
18
|
-
const environments = await new EnvironmentManager(config).listEnvironments();
|
|
19
|
-
const remoteEnvironments = environments.filter((environment) => environment.type === 'remote');
|
|
20
|
-
|
|
21
|
-
if (remoteEnvironments.length) {
|
|
22
|
-
const response = await this.inquirer.prompt([{
|
|
23
|
-
name: 'environment',
|
|
24
|
-
message: 'Select the remote environment you want to push onto',
|
|
25
|
-
type: 'list',
|
|
26
|
-
choices: remoteEnvironments.map(({ name }) => name),
|
|
27
|
-
}]);
|
|
28
|
-
return response.environment;
|
|
29
|
-
}
|
|
30
|
-
throw new Error('No remote environment.');
|
|
31
|
-
}
|
|
32
|
-
|
|
33
15
|
async runIfAuthenticated() {
|
|
34
16
|
const parsed = this.parse(PushCommand);
|
|
35
|
-
const
|
|
17
|
+
const envSecret = this.env.FOREST_ENV_SECRET;
|
|
18
|
+
const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
|
|
19
|
+
let config;
|
|
36
20
|
|
|
37
21
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const projectManager = new ProjectManager(config);
|
|
41
|
-
const project = await projectManager.getProjectForDevWorkflow();
|
|
22
|
+
config = await withCurrentProject({ ...this.env, ...commandOptions });
|
|
42
23
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
24
|
+
if (!config.envSecret) {
|
|
25
|
+
const environment = await new ProjectManager(config)
|
|
26
|
+
.getDevelopmentEnvironmentForUser(config.projectId);
|
|
27
|
+
config.envSecret = environment.secretKey;
|
|
28
|
+
}
|
|
29
|
+
const branches = await BranchManager.getBranches(config.envSecret);
|
|
46
30
|
|
|
47
|
-
const
|
|
48
|
-
const currentBranch = developmentBranches.find((branch) => branch.isCurrent);
|
|
31
|
+
const currentBranch = branches.find((branch) => branch.isCurrent);
|
|
49
32
|
|
|
50
33
|
if (!currentBranch) {
|
|
51
34
|
throw new Error('No current branch.');
|
|
52
35
|
}
|
|
53
36
|
|
|
54
|
-
// TODO: DWO EP17 remove destination environemnt handle
|
|
55
|
-
if (!config.environment) {
|
|
56
|
-
config.environment = await this.askForEnvironment(config);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
37
|
if (!config.force) {
|
|
60
38
|
const response = await this.inquirer
|
|
61
39
|
.prompt([{
|
|
62
40
|
type: 'confirm',
|
|
63
41
|
name: 'confirm',
|
|
64
|
-
message: `Push branch ${currentBranch.name} onto ${
|
|
42
|
+
message: `Push branch ${currentBranch.name} onto ${currentBranch.originEnvironment.name}`,
|
|
65
43
|
}]);
|
|
66
44
|
if (!response.confirm) return;
|
|
67
45
|
}
|
|
68
46
|
|
|
69
|
-
await BranchManager.pushBranch(config.
|
|
70
|
-
this.logger.success(`Branch ${currentBranch.name} successfully pushed onto ${
|
|
47
|
+
await BranchManager.pushBranch(config.envSecret);
|
|
48
|
+
this.logger.success(`Branch ${currentBranch.name} successfully pushed onto ${currentBranch.originEnvironment.name}.`);
|
|
71
49
|
} catch (error) {
|
|
72
50
|
const customError = BranchManager.handleBranchError(error);
|
|
73
51
|
this.logger.error(customError);
|
|
@@ -78,14 +56,9 @@ class PushCommand extends AbstractAuthenticatedCommand {
|
|
|
78
56
|
|
|
79
57
|
PushCommand.aliases = ['branches:push'];
|
|
80
58
|
|
|
81
|
-
PushCommand.description = 'Push layout changes of your current branch to
|
|
59
|
+
PushCommand.description = 'Push layout changes of your current branch to the branch origin.';
|
|
82
60
|
|
|
83
61
|
PushCommand.flags = {
|
|
84
|
-
// TODO: DWO EP17 remove environment option
|
|
85
|
-
environment: AbstractAuthenticatedCommand.flags.string({
|
|
86
|
-
char: 'e',
|
|
87
|
-
description: 'The remote environment name to push onto.',
|
|
88
|
-
}),
|
|
89
62
|
force: AbstractAuthenticatedCommand.flags.boolean({
|
|
90
63
|
description: 'Skip push changes confirmation.',
|
|
91
64
|
}),
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const AbstractAuthenticatedCommand = require('../abstract-authenticated-command');
|
|
2
|
+
const BranchManager = require('../services/branch-manager');
|
|
3
|
+
const ProjectManager = require('../services/project-manager');
|
|
4
|
+
const askForEnvironment = require('../services/ask-for-environment');
|
|
5
|
+
const withCurrentProject = require('../services/with-current-project');
|
|
6
|
+
|
|
7
|
+
class SetOriginCommand extends AbstractAuthenticatedCommand {
|
|
8
|
+
init(plan) {
|
|
9
|
+
super.init(plan);
|
|
10
|
+
const { assertPresent, env, inquirer } = this.context;
|
|
11
|
+
assertPresent({ env, inquirer });
|
|
12
|
+
this.env = env;
|
|
13
|
+
this.inquirer = inquirer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async runIfAuthenticated() {
|
|
17
|
+
const parsed = this.parse(SetOriginCommand);
|
|
18
|
+
const envSecret = this.env.FOREST_ENV_SECRET;
|
|
19
|
+
const commandOptions = { ...parsed.flags, ...parsed.args, envSecret };
|
|
20
|
+
let config;
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
config = await withCurrentProject({ ...this.env, ...commandOptions });
|
|
24
|
+
|
|
25
|
+
if (!config.envSecret) {
|
|
26
|
+
const environment = await new ProjectManager(config)
|
|
27
|
+
.getDevelopmentEnvironmentForUser(config.projectId);
|
|
28
|
+
config.envSecret = environment.secretKey;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!config.ENVIRONMENT_NAME) {
|
|
32
|
+
config.ENVIRONMENT_NAME = await askForEnvironment(config, 'Select the environment you want to set as origin', ['remote', 'production']);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await BranchManager.setOrigin(config.ENVIRONMENT_NAME, config.envSecret);
|
|
36
|
+
this.logger.success(`Origin "${config.ENVIRONMENT_NAME}" successfully set.`);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
const customError = BranchManager.handleBranchError(error);
|
|
39
|
+
this.logger.error(customError);
|
|
40
|
+
this.exit(2);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
SetOriginCommand.aliases = ['branches:origin'];
|
|
46
|
+
|
|
47
|
+
SetOriginCommand.description = "Set an environment as your branch's origin. Your branch will build on top of that environment's layout.";
|
|
48
|
+
|
|
49
|
+
SetOriginCommand.flags = {
|
|
50
|
+
help: AbstractAuthenticatedCommand.flags.boolean({
|
|
51
|
+
description: 'Display usage information.',
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
SetOriginCommand.args = [{
|
|
56
|
+
name: 'ENVIRONMENT_NAME', required: false, description: 'The environment to set as origin.',
|
|
57
|
+
}];
|
|
58
|
+
|
|
59
|
+
module.exports = SetOriginCommand;
|
|
@@ -3,4 +3,5 @@ module.exports = (plan) => plan
|
|
|
3
3
|
.addUsingClass('environmentRenderer', () => require('../renderers/environment'))
|
|
4
4
|
.addUsingClass('environmentsRenderer', () => require('../renderers/environments'))
|
|
5
5
|
.addUsingClass('projectRenderer', () => require('../renderers/project'))
|
|
6
|
-
.addUsingClass('projectsRenderer', () => require('../renderers/projects'))
|
|
6
|
+
.addUsingClass('projectsRenderer', () => require('../renderers/projects'))
|
|
7
|
+
.addUsingClass('branchesRenderer', () => require('../renderers/branches'));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { chars } = require('./defaults');
|
|
2
|
+
|
|
3
|
+
class BranchesRenderer {
|
|
4
|
+
constructor({
|
|
5
|
+
assertPresent,
|
|
6
|
+
chalk,
|
|
7
|
+
logger,
|
|
8
|
+
Table,
|
|
9
|
+
}) {
|
|
10
|
+
assertPresent({
|
|
11
|
+
chalk,
|
|
12
|
+
logger,
|
|
13
|
+
Table,
|
|
14
|
+
});
|
|
15
|
+
this.chalk = chalk;
|
|
16
|
+
this.logger = logger;
|
|
17
|
+
this.Table = Table;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
render(branches, format) {
|
|
21
|
+
const table = new this.Table({
|
|
22
|
+
head: ['NAME', 'ORIGIN', 'IS CURRENT', 'CLOSED AT'],
|
|
23
|
+
colWidths: [20, 20, 20, 30],
|
|
24
|
+
chars,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
switch (format) {
|
|
28
|
+
case 'json':
|
|
29
|
+
this.logger.log(JSON.stringify(branches, null, 2));
|
|
30
|
+
break;
|
|
31
|
+
case 'table':
|
|
32
|
+
branches.forEach((branch) => {
|
|
33
|
+
table.push([branch.name, branch.originEnvironment.name, branch.isCurrent ? '✅' : '', branch.closedAt ? branch.closedAt : '']);
|
|
34
|
+
});
|
|
35
|
+
this.logger.log(
|
|
36
|
+
`${this.chalk.bold('BRANCHES')}`,
|
|
37
|
+
...table.toString().split('\n'),
|
|
38
|
+
);
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = BranchesRenderer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const Context = require('@forestadmin/context');
|
|
2
|
+
|
|
3
|
+
const EnvironmentManager = require('./environment-manager');
|
|
4
|
+
|
|
5
|
+
module.exports = async function askForEnvironment(config, message, availableEnvironmentTypes = []) {
|
|
6
|
+
const { assertPresent, inquirer } = Context.inject();
|
|
7
|
+
assertPresent({ inquirer });
|
|
8
|
+
|
|
9
|
+
const environments = await new EnvironmentManager(config).listEnvironments();
|
|
10
|
+
const availableEnvironments = environments.filter(
|
|
11
|
+
(environment) => availableEnvironmentTypes.includes(environment.type),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
if (availableEnvironments.length) {
|
|
15
|
+
const response = await inquirer.prompt([{
|
|
16
|
+
name: 'environment',
|
|
17
|
+
message,
|
|
18
|
+
type: 'list',
|
|
19
|
+
choices: availableEnvironments.map(({ name }) => name),
|
|
20
|
+
}]);
|
|
21
|
+
return response.environment;
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`No ${availableEnvironmentTypes.join('/')} environment.`);
|
|
24
|
+
};
|
|
@@ -115,6 +115,10 @@ function Authenticator({
|
|
|
115
115
|
* @returns {Promise<string>}
|
|
116
116
|
*/
|
|
117
117
|
this.login = async ({ email, password, token }) => {
|
|
118
|
+
if (token !== undefined && typeof token === 'string' && !token.trim()) {
|
|
119
|
+
throw new ApplicationError('The provided token is empty. Please provide a valid token.');
|
|
120
|
+
}
|
|
121
|
+
|
|
118
122
|
if (!password && !token) {
|
|
119
123
|
const sessionToken = await oidcAuthenticator.authenticate();
|
|
120
124
|
return applicationTokenService.generateApplicationToken(sessionToken);
|
|
@@ -52,7 +52,7 @@ function deleteBranch(branchName, environmentSecret) {
|
|
|
52
52
|
.send();
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
function createBranch(branchName, environmentSecret) {
|
|
55
|
+
function createBranch(branchName, environmentSecret, originName) {
|
|
56
56
|
const {
|
|
57
57
|
assertPresent,
|
|
58
58
|
authenticator,
|
|
@@ -66,11 +66,13 @@ function createBranch(branchName, environmentSecret) {
|
|
|
66
66
|
.post(`${env.FOREST_URL}/api/branches`)
|
|
67
67
|
.set('Authorization', `Bearer ${authToken}`)
|
|
68
68
|
.set('forest-secret-key', `${environmentSecret}`)
|
|
69
|
-
.send({
|
|
69
|
+
.send({
|
|
70
|
+
branchName: encodeURIComponent(branchName),
|
|
71
|
+
originName: encodeURIComponent(originName),
|
|
72
|
+
});
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
function pushBranch(destinationEnvironmentName, environmentSecret) {
|
|
75
|
+
function pushBranch(environmentSecret) {
|
|
74
76
|
const {
|
|
75
77
|
assertPresent,
|
|
76
78
|
authenticator,
|
|
@@ -84,7 +86,7 @@ function pushBranch(destinationEnvironmentName, environmentSecret) {
|
|
|
84
86
|
.post(`${env.FOREST_URL}/api/branches/push`)
|
|
85
87
|
.set('Authorization', `Bearer ${authToken}`)
|
|
86
88
|
.set('forest-secret-key', `${environmentSecret}`)
|
|
87
|
-
.send(
|
|
89
|
+
.send();
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
function switchBranch({ id }, environmentSecret) {
|
|
@@ -104,6 +106,23 @@ function switchBranch({ id }, environmentSecret) {
|
|
|
104
106
|
.send(EnvironmentSerializer.serialize({ currentBranchId: id }));
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
function setOrigin(originEnvironmentName, environmentSecret) {
|
|
110
|
+
const {
|
|
111
|
+
assertPresent,
|
|
112
|
+
authenticator,
|
|
113
|
+
env,
|
|
114
|
+
superagent: agent,
|
|
115
|
+
} = Context.inject();
|
|
116
|
+
assertPresent({ authenticator, env, superagent: agent });
|
|
117
|
+
const authToken = authenticator.getAuthToken();
|
|
118
|
+
|
|
119
|
+
return agent
|
|
120
|
+
.post(`${env.FOREST_URL}/api/branches/set-origin`)
|
|
121
|
+
.set('Authorization', `Bearer ${authToken}`)
|
|
122
|
+
.set('forest-secret-key', `${environmentSecret}`)
|
|
123
|
+
.send({ originEnvironmentName: encodeURIComponent(originEnvironmentName) });
|
|
124
|
+
}
|
|
125
|
+
|
|
107
126
|
function handleBranchError(rawError) {
|
|
108
127
|
const error = handleError(rawError);
|
|
109
128
|
switch (error) {
|
|
@@ -145,5 +164,6 @@ module.exports = {
|
|
|
145
164
|
createBranch,
|
|
146
165
|
pushBranch,
|
|
147
166
|
switchBranch,
|
|
167
|
+
setOrigin,
|
|
148
168
|
handleBranchError,
|
|
149
169
|
};
|
|
@@ -126,15 +126,13 @@ function EnvironmentManager(config) {
|
|
|
126
126
|
* Deploy layout changes of an environment to production.
|
|
127
127
|
* @param {Number} environment.id - The environment id that contains the layout changes to deploy.
|
|
128
128
|
*/
|
|
129
|
-
this.deploy = (
|
|
129
|
+
this.deploy = () => {
|
|
130
130
|
const authToken = authenticator.getAuthToken();
|
|
131
131
|
|
|
132
132
|
return agent
|
|
133
133
|
.post(`${env.FOREST_URL}/api/environments/deploy`)
|
|
134
134
|
.set('Authorization', `Bearer ${authToken}`)
|
|
135
|
-
.set('forest-secret-key', `${config.envSecret}`)
|
|
136
|
-
.set('forest-environment-id', `${id}`)
|
|
137
|
-
.send({ environmentId: id });
|
|
135
|
+
.set('forest-secret-key', `${config.envSecret}`);
|
|
138
136
|
};
|
|
139
137
|
}
|
|
140
138
|
|
|
@@ -8,21 +8,21 @@ function buildDatabaseUrl(config) {
|
|
|
8
8
|
if (config.dbConnectionUrl) {
|
|
9
9
|
connectionString = config.dbConnectionUrl;
|
|
10
10
|
} else {
|
|
11
|
-
let protocol = config.
|
|
12
|
-
let port = `:${config.
|
|
11
|
+
let protocol = config.databaseDialect;
|
|
12
|
+
let port = `:${config.databasePort}`;
|
|
13
13
|
let password = '';
|
|
14
14
|
|
|
15
|
-
if (config.
|
|
15
|
+
if (config.databaseDialect === 'mongodb' && config.mongodbSrv) {
|
|
16
16
|
protocol = 'mongodb+srv';
|
|
17
17
|
port = '';
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
if (config.
|
|
20
|
+
if (config.databasePassword) {
|
|
21
21
|
// NOTICE: Encode password string in case of special chars.
|
|
22
|
-
password = `:${encodeURIComponent(config.
|
|
22
|
+
password = `:${encodeURIComponent(config.databasePassword)}`;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
connectionString = `${protocol}://${config.
|
|
25
|
+
connectionString = `${protocol}://${config.databaseUser}${password}@${config.databaseHost}${port}/${config.databaseName}`;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
return connectionString;
|