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.
- package/bin/run +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +17 -8
- package/src/abstract-authenticated-command.js +0 -46
- package/src/abstract-command.js +0 -27
- package/src/commands/branch.js +0 -136
- package/src/commands/deploy.js +0 -90
- package/src/commands/environments/copy-layout.js +0 -116
- package/src/commands/environments/create.js +0 -62
- package/src/commands/environments/delete.js +0 -81
- package/src/commands/environments/get.js +0 -48
- package/src/commands/environments/reset.js +0 -76
- package/src/commands/environments/update.js +0 -46
- package/src/commands/environments.js +0 -41
- package/src/commands/init.js +0 -169
- package/src/commands/login.js +0 -34
- package/src/commands/logout.js +0 -18
- package/src/commands/projects/create.js +0 -262
- package/src/commands/projects/get.js +0 -53
- package/src/commands/projects.js +0 -36
- package/src/commands/push.js +0 -75
- package/src/commands/schema/apply.js +0 -140
- package/src/commands/schema/update.js +0 -70
- package/src/commands/set-origin.js +0 -59
- package/src/commands/switch.js +0 -117
- package/src/commands/user.js +0 -44
- package/src/context/command-project-create-plan.js +0 -11
- package/src/context/command-projects-common-plan.js +0 -65
- package/src/context/command-schema-update-command-plan.js +0 -4
- package/src/context/dependencies-plan.js +0 -21
- package/src/context/env-plan.js +0 -27
- package/src/context/plan.js +0 -12
- package/src/context/process-plan.js +0 -3
- package/src/context/renderers-plan.js +0 -7
- package/src/context/serializers-plan.js +0 -8
- package/src/context/services-plan.js +0 -8
- package/src/context/static.js +0 -19
- package/src/context/utils-plan.js +0 -7
- package/src/deserializers/api-error.js +0 -21
- package/src/deserializers/application-token.js +0 -15
- package/src/deserializers/branch.js +0 -8
- package/src/deserializers/environment.js +0 -5
- package/src/deserializers/job.js +0 -5
- package/src/deserializers/project.js +0 -11
- package/src/errors/application-error.js +0 -9
- package/src/errors/application-token/unable-to-create-application-token-error.js +0 -16
- package/src/errors/database/empty-database-error.js +0 -5
- package/src/errors/dumper/incompatible-liana-for-update-error.js +0 -16
- package/src/errors/dumper/invalid-forest-cli-project-structure-error.js +0 -16
- package/src/errors/forest-cli-error.js +0 -32
- package/src/index.js +0 -1
- package/src/renderers/branches.js +0 -45
- package/src/renderers/defaults.js +0 -19
- package/src/renderers/environment.js +0 -51
- package/src/renderers/environments.js +0 -51
- package/src/renderers/project.js +0 -45
- package/src/renderers/projects.js +0 -45
- package/src/serializers/application-token.js +0 -11
- package/src/serializers/deployment-request.js +0 -5
- package/src/serializers/environment.js +0 -20
- package/src/serializers/job.js +0 -5
- package/src/serializers/project.js +0 -17
- package/src/serializers/schema.js +0 -116
- package/src/services/api.js +0 -110
- package/src/services/apimap-sorter.js +0 -104
- package/src/services/application-token.js +0 -56
- package/src/services/ask-for-environment.js +0 -24
- package/src/services/authenticator.js +0 -187
- package/src/services/branch-manager.js +0 -169
- package/src/services/dumper/dumper.js +0 -503
- package/src/services/dumper/handlebars/helpers/equal.js +0 -3
- package/src/services/dumper/handlebars/helpers/indent.js +0 -3
- package/src/services/dumper/handlebars/helpers/is-array.js +0 -3
- package/src/services/dumper/handlebars/helpers/is-object.js +0 -3
- package/src/services/dumper/handlebars/helpers/sum.js +0 -3
- package/src/services/dumper/handlebars/helpers/wrap-quotes.js +0 -7
- package/src/services/dumper/handlebars/loader.js +0 -10
- package/src/services/dumper/handlebars/partials/render-nested.js +0 -27
- package/src/services/dumper/templates/app/Dockerfile.hbs +0 -6
- package/src/services/dumper/templates/app/app.hbs +0 -79
- package/src/services/dumper/templates/app/config/databases.hbs +0 -49
- package/src/services/dumper/templates/app/docker-compose.hbs +0 -33
- package/src/services/dumper/templates/app/dockerignore.hbs +0 -3
- package/src/services/dumper/templates/app/env.hbs +0 -20
- package/src/services/dumper/templates/app/forest/collection.hbs +0 -13
- package/src/services/dumper/templates/app/gitignore.hbs +0 -3
- package/src/services/dumper/templates/app/middlewares/forestadmin.hbs +0 -21
- package/src/services/dumper/templates/app/middlewares/welcome.hbs +0 -7
- package/src/services/dumper/templates/app/models/index.hbs +0 -56
- package/src/services/dumper/templates/app/models/mongo-model.hbs +0 -16
- package/src/services/dumper/templates/app/models/sequelize-model.hbs +0 -48
- package/src/services/dumper/templates/app/public/favicon.png +0 -0
- package/src/services/dumper/templates/app/routes/route.hbs +0 -61
- package/src/services/dumper/templates/app/server.hbs +0 -56
- package/src/services/dumper/templates/app/views/index.hbs +0 -73
- package/src/services/environment-manager.js +0 -139
- package/src/services/init-manager.js +0 -183
- package/src/services/job-state-checker.js +0 -57
- package/src/services/logger.js +0 -125
- package/src/services/oidc/authenticator.js +0 -109
- package/src/services/oidc/error.js +0 -32
- package/src/services/project-manager.js +0 -89
- package/src/services/projects/create/command-generate-config-getter.js +0 -61
- package/src/services/projects/create/project-creator.js +0 -89
- package/src/services/prompter/abstract-prompter.js +0 -13
- package/src/services/prompter/application-prompts.js +0 -63
- package/src/services/prompter/database-prompts.js +0 -208
- package/src/services/prompter/general-prompter.js +0 -61
- package/src/services/prompter/project-prompts.js +0 -47
- package/src/services/prompter/prompter-error.js +0 -10
- package/src/services/schema/schema-service.js +0 -154
- package/src/services/schema/update/analyzer/database-analyzer.js +0 -64
- package/src/services/schema/update/analyzer/mongo-collections-analyzer.js +0 -344
- package/src/services/schema/update/analyzer/mongo-embedded-analyzer.js +0 -226
- package/src/services/schema/update/analyzer/mongo-hasmany-analyzer.js +0 -55
- package/src/services/schema/update/analyzer/mongo-references-analyzer.js +0 -51
- package/src/services/schema/update/analyzer/mysql-table-constraints-getter.js +0 -59
- package/src/services/schema/update/analyzer/sequelize-column-type-getter.js +0 -147
- package/src/services/schema/update/analyzer/sequelize-default-value.js +0 -122
- package/src/services/schema/update/analyzer/sequelize-table-constraints-getter.js +0 -298
- package/src/services/schema/update/analyzer/sequelize-tables-analyzer.js +0 -529
- package/src/services/schema/update/database.js +0 -160
- package/src/services/schema-sender.js +0 -55
- package/src/services/spinner.js +0 -130
- package/src/services/with-current-project.js +0 -41
- package/src/utils/database-url.js +0 -33
- package/src/utils/directory-existence-checker.js +0 -17
- package/src/utils/error-handler.js +0 -63
- package/src/utils/error.js +0 -21
- package/src/utils/event-sender.js +0 -80
- package/src/utils/fields.js +0 -14
- package/src/utils/key-generator.js +0 -18
- package/src/utils/messages.js +0 -7
- package/src/utils/mongo-collections.js +0 -35
- package/src/utils/mongo-primitive-type.js +0 -44
- package/src/utils/strings.js +0 -49
- package/src/utils/terminator.js +0 -38
- package/src/utils/to-valid-package-name.js +0 -24
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef {{
|
|
3
|
-
* agent: string;
|
|
4
|
-
* dbDialect: string;
|
|
5
|
-
* architecture: string;
|
|
6
|
-
* isLocal: boolean;
|
|
7
|
-
* }} ProjectMeta
|
|
8
|
-
*
|
|
9
|
-
* @typedef {{
|
|
10
|
-
* applicationName: string
|
|
11
|
-
* appHostname: string
|
|
12
|
-
* appPort: number
|
|
13
|
-
* }} ProjectConfig
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
class ProjectCreator {
|
|
17
|
-
/**
|
|
18
|
-
* @param {{
|
|
19
|
-
* api: import('../../api')
|
|
20
|
-
* chalk: import('chalk')
|
|
21
|
-
* keyGenerator: import('../../../utils/key-generator')
|
|
22
|
-
* messages: import('../../../utils/messages')
|
|
23
|
-
* terminator: import('../../../utils/terminator')
|
|
24
|
-
* }} dependencies
|
|
25
|
-
*/
|
|
26
|
-
constructor({
|
|
27
|
-
assertPresent,
|
|
28
|
-
api,
|
|
29
|
-
chalk,
|
|
30
|
-
keyGenerator,
|
|
31
|
-
messages,
|
|
32
|
-
terminator,
|
|
33
|
-
}) {
|
|
34
|
-
assertPresent({
|
|
35
|
-
api,
|
|
36
|
-
chalk,
|
|
37
|
-
keyGenerator,
|
|
38
|
-
messages,
|
|
39
|
-
terminator,
|
|
40
|
-
});
|
|
41
|
-
this.api = api;
|
|
42
|
-
this.chalk = chalk;
|
|
43
|
-
this.keyGenerator = keyGenerator;
|
|
44
|
-
this.messages = messages;
|
|
45
|
-
this.terminator = terminator;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @param {string} sessionToken
|
|
50
|
-
* @param {{
|
|
51
|
-
*
|
|
52
|
-
* }} config
|
|
53
|
-
* @param {ProjectMeta} meta
|
|
54
|
-
* @returns {Promise<void>}
|
|
55
|
-
*/
|
|
56
|
-
async create(sessionToken, config, meta) {
|
|
57
|
-
try {
|
|
58
|
-
const newProjectPayload = {
|
|
59
|
-
name: config.applicationName,
|
|
60
|
-
agent: meta.agent,
|
|
61
|
-
architecture: meta.architecture,
|
|
62
|
-
databaseType: meta.dbDialect,
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const newProject = await this.api.createProject(config, sessionToken, newProjectPayload);
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
id: newProject.id,
|
|
69
|
-
envSecret: newProject.defaultEnvironment.secretKey,
|
|
70
|
-
authSecret: this.keyGenerator.generate(),
|
|
71
|
-
};
|
|
72
|
-
} catch (error) {
|
|
73
|
-
let message;
|
|
74
|
-
if (error.message === 'Unauthorized') {
|
|
75
|
-
message = `Your session has expired. Please log back in with the command \`${this.chalk.cyan('forest login')}\`.`;
|
|
76
|
-
} else if (error.message === 'Conflict') {
|
|
77
|
-
message = 'A project with this name already exists. Please choose another name.';
|
|
78
|
-
} else {
|
|
79
|
-
message = `${this.messages.ERROR_UNEXPECTED} ${this.chalk.red(error)}`;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return this.terminator.terminate(1, {
|
|
83
|
-
logs: [message],
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
module.exports = ProjectCreator;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
const AbstractPrompter = require('./abstract-prompter');
|
|
2
|
-
|
|
3
|
-
class ApplicationPrompts extends AbstractPrompter {
|
|
4
|
-
constructor(requests, knownAnswers, prompts, programArguments) {
|
|
5
|
-
super(requests);
|
|
6
|
-
this.knownAnswers = knownAnswers;
|
|
7
|
-
this.prompts = prompts;
|
|
8
|
-
this.programArguments = programArguments;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async handlePrompts() {
|
|
12
|
-
this.handleHostname();
|
|
13
|
-
this.handlePort();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
handleHostname() {
|
|
17
|
-
if (this.isOptionRequested('appHostname')) {
|
|
18
|
-
this.knownAnswers.applicationHost = this.programArguments.applicationHost;
|
|
19
|
-
if (!this.programArguments.applicationHost && !this.knownAnswers.applicationHost) {
|
|
20
|
-
this.prompts.push({
|
|
21
|
-
type: 'input',
|
|
22
|
-
name: 'applicationHost',
|
|
23
|
-
message: 'What\'s the IP/hostname on which your application will be running?',
|
|
24
|
-
default: 'http://localhost',
|
|
25
|
-
validate: (hostname) => {
|
|
26
|
-
if (!/^https?:\/\/.*/i.test(hostname)) {
|
|
27
|
-
return 'Application hostname must be a valid url.';
|
|
28
|
-
}
|
|
29
|
-
if (!/^http((s:\/\/.*)|(s?:\/\/(localhost|127\.0\.0\.1).*))/i.test(hostname)) {
|
|
30
|
-
return 'HTTPS protocol is mandatory, except for localhost and 127.0.0.1.';
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
handlePort() {
|
|
40
|
-
if (this.isOptionRequested('appPort')) {
|
|
41
|
-
this.knownAnswers.applicationPort = this.programArguments.applicationPort;
|
|
42
|
-
if (!this.programArguments.applicationPort && !this.knownAnswers.applicationPort) {
|
|
43
|
-
this.prompts.push({
|
|
44
|
-
type: 'input',
|
|
45
|
-
name: 'applicationPort',
|
|
46
|
-
message: 'What\'s the port on which your application will be running?',
|
|
47
|
-
default: '3310',
|
|
48
|
-
validate: (port) => {
|
|
49
|
-
if (!/^\d+$/.test(port)) {
|
|
50
|
-
return 'The port must be a number.';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const parsedPort = parseInt(port, 10);
|
|
54
|
-
if (parsedPort > 0 && parsedPort < 65536) { return true; }
|
|
55
|
-
return 'This is not a valid port.';
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
module.exports = ApplicationPrompts;
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
const os = require('os');
|
|
2
|
-
const AbstractPrompter = require('./abstract-prompter');
|
|
3
|
-
const PrompterError = require('./prompter-error');
|
|
4
|
-
const messages = require('../../utils/messages');
|
|
5
|
-
|
|
6
|
-
const MAPPING_DIALECT_TO_PORT = {
|
|
7
|
-
postgres: '5432',
|
|
8
|
-
mysql: '3306',
|
|
9
|
-
mssql: '1433',
|
|
10
|
-
mongodb: '27017',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const dbDialectOptions = [
|
|
14
|
-
{ name: 'mongodb', value: 'mongodb' },
|
|
15
|
-
{ name: 'mssql', value: 'mssql' },
|
|
16
|
-
{ name: 'mysql / mariadb', value: 'mysql' },
|
|
17
|
-
{ name: 'postgres', value: 'postgres' },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
class DatabasePrompts extends AbstractPrompter {
|
|
21
|
-
constructor(requests, knownAnswers, prompts, programArguments) {
|
|
22
|
-
super(requests);
|
|
23
|
-
this.knownAnswers = knownAnswers;
|
|
24
|
-
this.prompts = prompts;
|
|
25
|
-
this.programArguments = programArguments;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async handlePrompts() {
|
|
29
|
-
this.handleConnectionUrl();
|
|
30
|
-
this.handleDialect();
|
|
31
|
-
this.handleName();
|
|
32
|
-
this.handleSchema();
|
|
33
|
-
this.handleHostname();
|
|
34
|
-
this.handlePort();
|
|
35
|
-
this.handleUser();
|
|
36
|
-
this.handlePassword();
|
|
37
|
-
this.handleSsl();
|
|
38
|
-
this.handleMongodbSrv();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async handleConnectionUrl() {
|
|
42
|
-
if (this.isOptionRequested('dbConnectionUrl')) {
|
|
43
|
-
this.knownAnswers.databaseConnectionURL = this.programArguments.databaseConnectionURL;
|
|
44
|
-
try {
|
|
45
|
-
[, this.knownAnswers.databaseDialect] = this.knownAnswers.databaseConnectionURL.match(/(.*):\/\//);
|
|
46
|
-
if (this.knownAnswers.databaseDialect === 'mongodb+srv') { this.knownAnswers.databaseDialect = 'mongodb'; }
|
|
47
|
-
} catch (error) {
|
|
48
|
-
throw new PrompterError(
|
|
49
|
-
messages.ERROR_NOT_PARSABLE_CONNECTION_URL,
|
|
50
|
-
[
|
|
51
|
-
messages.ERROR_NOT_PARSABLE_CONNECTION_URL,
|
|
52
|
-
],
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
handleDialect() {
|
|
59
|
-
if (!this.knownAnswers.databaseDialect) {
|
|
60
|
-
this.knownAnswers.databaseDialect = this.programArguments.databaseDialect;
|
|
61
|
-
}
|
|
62
|
-
if (this.isOptionRequested('dbDialect') && this.programArguments.databaseDialect === undefined) {
|
|
63
|
-
const prompt = {
|
|
64
|
-
type: 'list',
|
|
65
|
-
name: 'databaseDialect',
|
|
66
|
-
message: 'What\'s the database type?',
|
|
67
|
-
choices: dbDialectOptions,
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// NOTICE: use a rawlist on Windows because of this issue:
|
|
71
|
-
// https://github.com/SBoudrias/Inquirer.js/issues/303
|
|
72
|
-
if (/^win/.test(os.platform())) {
|
|
73
|
-
prompt.type = 'rawlist';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
this.prompts.push(prompt);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
handleName() {
|
|
81
|
-
if (this.isOptionRequested('dbName') && this.programArguments.databaseName === undefined) {
|
|
82
|
-
this.prompts.push({
|
|
83
|
-
type: 'input',
|
|
84
|
-
name: 'databaseName',
|
|
85
|
-
message: 'What\'s the database name?',
|
|
86
|
-
validate: (dbName) => {
|
|
87
|
-
if (dbName) { return true; }
|
|
88
|
-
return 'Please specify the database name.';
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
handleSchema() {
|
|
95
|
-
if (!this.knownAnswers.databaseSchema) {
|
|
96
|
-
this.knownAnswers.databaseSchema = this.programArguments.databaseSchema;
|
|
97
|
-
}
|
|
98
|
-
if (this.isOptionRequested('dbSchema') && this.programArguments.databaseSchema === undefined) {
|
|
99
|
-
if (!this.knownAnswers.databaseSchema) {
|
|
100
|
-
this.prompts.push({
|
|
101
|
-
type: 'input',
|
|
102
|
-
name: 'databaseSchema',
|
|
103
|
-
message: 'What\'s the database schema? [optional]',
|
|
104
|
-
description: 'Leave blank by default',
|
|
105
|
-
when: (answers) => {
|
|
106
|
-
// NOTICE: MongoDB and MySQL do not require a Schema.
|
|
107
|
-
const skipDatabases = ['mongodb', 'mysql'];
|
|
108
|
-
return !skipDatabases.includes(
|
|
109
|
-
answers.databaseDialect || this.knownAnswers.databaseDialect,
|
|
110
|
-
);
|
|
111
|
-
},
|
|
112
|
-
default: (answers) => {
|
|
113
|
-
if (answers.databaseDialect === 'postgres' || this.knownAnswers.databaseDialect === 'postgres') {
|
|
114
|
-
return 'public';
|
|
115
|
-
}
|
|
116
|
-
return '';
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
handleHostname() {
|
|
124
|
-
if (this.isOptionRequested('dbHostname') && this.programArguments.databaseHost === undefined) {
|
|
125
|
-
this.prompts.push({
|
|
126
|
-
type: 'input',
|
|
127
|
-
name: 'databaseHost',
|
|
128
|
-
message: 'What\'s the database hostname?',
|
|
129
|
-
default: 'localhost',
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
handlePort() {
|
|
135
|
-
if (this.isOptionRequested('dbPort') && this.programArguments.databasePort === undefined) {
|
|
136
|
-
this.prompts.push({
|
|
137
|
-
type: 'input',
|
|
138
|
-
name: 'databasePort',
|
|
139
|
-
message: 'What\'s the database port?',
|
|
140
|
-
default: (args) => MAPPING_DIALECT_TO_PORT[args.databaseDialect],
|
|
141
|
-
validate: (port) => {
|
|
142
|
-
if (!/^\d+$/.test(port)) {
|
|
143
|
-
return 'The port must be a number.';
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const parsedPort = parseInt(port, 10);
|
|
147
|
-
if (parsedPort > 0 && parsedPort < 65536) { return true; }
|
|
148
|
-
return 'This is not a valid port.';
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
handleUser() {
|
|
155
|
-
if (this.isOptionRequested('dbUser') && this.programArguments.databaseUser === undefined) {
|
|
156
|
-
this.prompts.push({
|
|
157
|
-
type: 'input',
|
|
158
|
-
name: 'databaseUser',
|
|
159
|
-
message: 'What\'s the database user?',
|
|
160
|
-
default: (args) => {
|
|
161
|
-
if (args.databaseDialect === 'mongodb') {
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
return 'root';
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
handlePassword() {
|
|
171
|
-
if (this.isOptionRequested('dbPassword') && this.programArguments.databasePassword === undefined) {
|
|
172
|
-
this.prompts.push({
|
|
173
|
-
type: 'password',
|
|
174
|
-
name: 'databasePassword',
|
|
175
|
-
message: 'What\'s the database password? [optional]',
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
handleSsl() {
|
|
181
|
-
this.knownAnswers.databaseSSL = this.programArguments.databaseSSL;
|
|
182
|
-
if (this.isOptionRequested('ssl') && this.programArguments.databaseSSL === undefined) {
|
|
183
|
-
this.prompts.push({
|
|
184
|
-
type: 'confirm',
|
|
185
|
-
name: 'databaseSSL',
|
|
186
|
-
message: 'Does your database require a SSL connection?',
|
|
187
|
-
default: false,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
handleMongodbSrv() {
|
|
193
|
-
if (this.isOptionRequested('mongodbSrv') && this.programArguments.mongoDBSRV === undefined) {
|
|
194
|
-
this.prompts.push({
|
|
195
|
-
type: 'confirm',
|
|
196
|
-
name: 'mongoDBSRV',
|
|
197
|
-
message: 'Use a SRV connection string?',
|
|
198
|
-
when: (answers) => answers.databaseDialect === 'mongodb',
|
|
199
|
-
default: false,
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
module.exports = {
|
|
206
|
-
DatabasePrompts,
|
|
207
|
-
dbDialectOptions,
|
|
208
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
const Context = require('@forestadmin/context');
|
|
2
|
-
|
|
3
|
-
const ApplicationPrompts = require('./application-prompts');
|
|
4
|
-
const { DatabasePrompts } = require('./database-prompts');
|
|
5
|
-
const ProjectPrompts = require('./project-prompts');
|
|
6
|
-
const PromptError = require('./prompter-error');
|
|
7
|
-
|
|
8
|
-
class GeneralPrompter {
|
|
9
|
-
constructor(requests, programArguments) {
|
|
10
|
-
this.prompts = [];
|
|
11
|
-
this.programArguments = programArguments;
|
|
12
|
-
this.knownAnswers = {};
|
|
13
|
-
|
|
14
|
-
this.projectPrompt = new ProjectPrompts(
|
|
15
|
-
requests, this.knownAnswers, this.prompts, programArguments,
|
|
16
|
-
);
|
|
17
|
-
this.databasePrompt = new DatabasePrompts(
|
|
18
|
-
requests, this.knownAnswers, this.prompts, programArguments,
|
|
19
|
-
);
|
|
20
|
-
this.applicationPrompt = new ApplicationPrompts(
|
|
21
|
-
requests, this.knownAnswers, this.prompts, programArguments,
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async getConfig() {
|
|
26
|
-
const { inquirer, terminator } = Context.inject();
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
await this.projectPrompt.handlePrompts();
|
|
30
|
-
await this.databasePrompt.handlePrompts();
|
|
31
|
-
await this.applicationPrompt.handlePrompts();
|
|
32
|
-
} catch (error) {
|
|
33
|
-
if (error instanceof PromptError) {
|
|
34
|
-
await terminator.terminate(1, {
|
|
35
|
-
errorCode: error.errorCode,
|
|
36
|
-
errorMessage: error.errorMessage,
|
|
37
|
-
logs: error.logs,
|
|
38
|
-
});
|
|
39
|
-
} else {
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
this.promptAnswers = await inquirer.prompt(this.prompts);
|
|
45
|
-
|
|
46
|
-
this.cleanConfigOptions();
|
|
47
|
-
|
|
48
|
-
return { ...this.programArguments, ...this.knownAnswers, ...this.promptAnswers };
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
cleanConfigOptions() {
|
|
52
|
-
if (!this.promptAnswers) { return; }
|
|
53
|
-
|
|
54
|
-
// NOTICE: Remove the database password if not set.
|
|
55
|
-
if (!this.promptAnswers.databasePassword) {
|
|
56
|
-
delete this.promptAnswers.databasePassword;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
module.exports = GeneralPrompter;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const chalk = require('chalk');
|
|
2
|
-
const DirectoryExistenceChecker = require('../../utils/directory-existence-checker');
|
|
3
|
-
const AbstractPrompter = require('./abstract-prompter');
|
|
4
|
-
const PrompterError = require('./prompter-error');
|
|
5
|
-
const messages = require('../../utils/messages');
|
|
6
|
-
|
|
7
|
-
class ProjectPrompts extends AbstractPrompter {
|
|
8
|
-
constructor(requests, knownAnswers, prompts, programArguments) {
|
|
9
|
-
super(requests);
|
|
10
|
-
this.knownAnswers = knownAnswers;
|
|
11
|
-
this.prompts = prompts;
|
|
12
|
-
this.programArguments = programArguments;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
async handlePrompts() {
|
|
16
|
-
await this.handleName();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
async handleName() {
|
|
20
|
-
if (this.isOptionRequested('applicationName')) {
|
|
21
|
-
const projectName = this.programArguments.applicationName;
|
|
22
|
-
|
|
23
|
-
if (!projectName) {
|
|
24
|
-
throw new PrompterError(
|
|
25
|
-
messages.ERROR_MISSING_PROJECT_NAME,
|
|
26
|
-
[
|
|
27
|
-
messages.ERROR_MISSING_PROJECT_NAME,
|
|
28
|
-
messages.HINT_MISSING_PROJECT_NAME,
|
|
29
|
-
],
|
|
30
|
-
);
|
|
31
|
-
} else if (new DirectoryExistenceChecker(projectName).perform()) {
|
|
32
|
-
const message = `File or directory "${chalk.red(`${projectName}`)}" already exists.`;
|
|
33
|
-
throw new PrompterError(
|
|
34
|
-
message,
|
|
35
|
-
[
|
|
36
|
-
message,
|
|
37
|
-
messages.HINT_DIRECTORY_ALREADY_EXISTS,
|
|
38
|
-
],
|
|
39
|
-
);
|
|
40
|
-
} else {
|
|
41
|
-
this.knownAnswers.applicationName = projectName;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
module.exports = ProjectPrompts;
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
const ForestCLIError = require('../../errors/forest-cli-error');
|
|
2
|
-
|
|
3
|
-
module.exports = class SchemaService {
|
|
4
|
-
constructor({
|
|
5
|
-
assertPresent,
|
|
6
|
-
constants,
|
|
7
|
-
database,
|
|
8
|
-
databaseAnalyzer,
|
|
9
|
-
dumper,
|
|
10
|
-
env,
|
|
11
|
-
errorHandler,
|
|
12
|
-
fs,
|
|
13
|
-
logger,
|
|
14
|
-
path,
|
|
15
|
-
spinner,
|
|
16
|
-
}) {
|
|
17
|
-
assertPresent({
|
|
18
|
-
constants,
|
|
19
|
-
database,
|
|
20
|
-
databaseAnalyzer,
|
|
21
|
-
dumper,
|
|
22
|
-
env,
|
|
23
|
-
errorHandler,
|
|
24
|
-
fs,
|
|
25
|
-
logger,
|
|
26
|
-
path,
|
|
27
|
-
spinner,
|
|
28
|
-
});
|
|
29
|
-
this.constants = constants;
|
|
30
|
-
this.database = database;
|
|
31
|
-
this.databaseAnalyzer = databaseAnalyzer;
|
|
32
|
-
this.dumper = dumper;
|
|
33
|
-
this.env = env;
|
|
34
|
-
this.errorHandler = errorHandler;
|
|
35
|
-
this.fs = fs;
|
|
36
|
-
this.logger = logger;
|
|
37
|
-
this.path = path;
|
|
38
|
-
this.spinner = spinner;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
_assertOutputDirectory(outputDirectory) {
|
|
42
|
-
if (!outputDirectory) {
|
|
43
|
-
this.dumper.checkForestCLIProjectStructure();
|
|
44
|
-
} else if (this.fs.existsSync(outputDirectory)) {
|
|
45
|
-
throw new ForestCLIError(`The output directory "${outputDirectory}" already exists.`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
_getDatabasesConfig(path) {
|
|
50
|
-
const configPath = this.path.resolve(this.constants.CURRENT_WORKING_DIRECTORY, path);
|
|
51
|
-
if (!this.fs.existsSync(configPath)) {
|
|
52
|
-
throw new ForestCLIError(`The configuration file "${configPath}" does not exist.`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
56
|
-
const databasesConfig = require(configPath);
|
|
57
|
-
if (!this.database.areAllDatabasesOfTheSameType(databasesConfig)) {
|
|
58
|
-
throw new ForestCLIError(`The "${configPath}" file contains different databases types.`);
|
|
59
|
-
}
|
|
60
|
-
return databasesConfig;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
async _connectToDatabases(databasesConfig) {
|
|
64
|
-
this.spinner.start({ text: 'Connecting to your database(s)' });
|
|
65
|
-
const databasesConnectionPromise = this.database.connectFromDatabasesConfig(databasesConfig);
|
|
66
|
-
return this.spinner.attachToPromise(databasesConnectionPromise);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async _disconnectFromDatabases(databaseConnections) {
|
|
70
|
-
this.spinner.start({ text: 'Disconnecting from your database(s)' });
|
|
71
|
-
const databasesConnectionPromise = this.database.disconnectFromDatabases(databaseConnections);
|
|
72
|
-
return this.spinner.attachToPromise(databasesConnectionPromise);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async _analyzeDatabases(databasesConnection, dbSchema) {
|
|
76
|
-
this.spinner.start({ text: 'Analyzing the database(s)' });
|
|
77
|
-
const databasesSchemaPromise = Promise.all(
|
|
78
|
-
databasesConnection
|
|
79
|
-
.map(async (databaseConnection) => {
|
|
80
|
-
const analyzerOptions = {
|
|
81
|
-
dbDialect: this.database.getDialect(databaseConnection.connection.url),
|
|
82
|
-
dbSchema,
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const schema = await this.databaseAnalyzer
|
|
86
|
-
.analyze(databaseConnection.connectionInstance, analyzerOptions, true);
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
...databaseConnection,
|
|
90
|
-
schema,
|
|
91
|
-
analyzerOptions,
|
|
92
|
-
};
|
|
93
|
-
}),
|
|
94
|
-
);
|
|
95
|
-
return this.spinner.attachToPromise(databasesSchemaPromise);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async _dumpSchemas(databasesSchema, applicationName, isUpdate, useMultiDatabase) {
|
|
99
|
-
this.spinner.start({ text: 'Generating your files' });
|
|
100
|
-
|
|
101
|
-
const dumperOptions = {
|
|
102
|
-
applicationName,
|
|
103
|
-
isUpdate,
|
|
104
|
-
useMultiDatabase,
|
|
105
|
-
modelsExportPath: '', // Value is defined below, it's different for each schema
|
|
106
|
-
dbDialect: null, // Value is defined below, it's coming from each analyzerOptions
|
|
107
|
-
dbSchema: null, // Value is defined below, it's coming from each analyzerOptions
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const dumpPromise = Promise.all(databasesSchema.map((databaseSchema) =>
|
|
111
|
-
this.dumper.dump(databaseSchema.schema, {
|
|
112
|
-
...dumperOptions,
|
|
113
|
-
modelsExportPath: this.path.relative('models', databaseSchema.modelsDir),
|
|
114
|
-
dbDialect: databaseSchema.analyzerOptions.dbDialect,
|
|
115
|
-
dbSchema: databaseSchema.analyzerOptions.dbSchema,
|
|
116
|
-
})));
|
|
117
|
-
return this.spinner.attachToPromise(dumpPromise);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
_warnIfSingleToMulti(outputDirectory, useMultiDatabase) {
|
|
121
|
-
const fromSingleToMultipleDatabases = !outputDirectory
|
|
122
|
-
&& useMultiDatabase
|
|
123
|
-
&& !this.dumper.hasMultipleDatabaseStructure();
|
|
124
|
-
if (fromSingleToMultipleDatabases) {
|
|
125
|
-
this.logger.warn('It looks like you are switching from a single to a multiple databases.');
|
|
126
|
-
this.logger.log('You will need to move the models files from your existing database to'
|
|
127
|
-
+ ' the dedicated folder, or simply remove them.');
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async _update({
|
|
132
|
-
isUpdate, outputDirectory, dbSchema, dbConfigPath,
|
|
133
|
-
}) {
|
|
134
|
-
this.dumper.checkLianaCompatiblityForUpdate();
|
|
135
|
-
this._assertOutputDirectory(outputDirectory);
|
|
136
|
-
const databasesConfig = this._getDatabasesConfig(dbConfigPath);
|
|
137
|
-
const databasesConnection = await this._connectToDatabases(databasesConfig);
|
|
138
|
-
const databasesSchema = await this._analyzeDatabases(databasesConnection, dbSchema);
|
|
139
|
-
await this._disconnectFromDatabases(databasesConnection);
|
|
140
|
-
const useMultiDatabase = databasesSchema.length > 1;
|
|
141
|
-
|
|
142
|
-
await this._dumpSchemas(databasesSchema, outputDirectory, isUpdate, useMultiDatabase);
|
|
143
|
-
|
|
144
|
-
this._warnIfSingleToMulti(outputDirectory, useMultiDatabase);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
async update(options) {
|
|
148
|
-
try {
|
|
149
|
-
await this._update(options);
|
|
150
|
-
} catch (error) {
|
|
151
|
-
await this.errorHandler.handle(error);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
};
|