@dynamicweb/cli 1.0.16 → 1.1.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.
@@ -1,155 +1,174 @@
1
- import { updateConfig, getConfig } from './config.js'
2
- import { Agent as HttpAgent } from 'http';
3
- import { Agent as HttpsAgent } from 'https';
4
- import yargsInteractive from 'yargs-interactive';
5
-
6
- const httpAgent = new HttpAgent({
7
- rejectUnauthorized: false
8
- })
9
-
10
- const httpsAgent = new HttpsAgent({
11
- rejectUnauthorized: false
12
- })
13
-
14
- export function getAgent(protocol) {
15
- return protocol === 'http' ? httpAgent : httpsAgent;
16
- }
17
-
18
- export function envCommand() {
19
- return {
20
- command: 'env [env]',
21
- describe: 'If environment is specified, changes the current environment to the environment specified, otherwise sets up the config for a new environment',
22
- builder: (yargs) => {
23
- return yargs
24
- .positional('env', {
25
- describe: 'Environment'
26
- })
27
- .option('list', {
28
- alias: 'l',
29
- type: 'boolean',
30
- description: 'List all existing environments'
31
- })
32
- .option('users', {
33
- alias: 'u',
34
- type: 'boolean',
35
- description: 'List all users in environment, uses positional [env] if used, otherwise current env'
36
- })
37
- },
38
- handler: (argv) => handleEnv(argv)
39
- }
40
- }
41
-
42
- export async function setupEnv(argv) {
43
- let env = {};
44
- let askEnv = true;
45
-
46
- if (argv.host) {
47
- askEnv = false;
48
- env.host = argv.host;
49
- if (argv.protocol) {
50
- env.protocol = argv.protocol;
51
- } else {
52
- env.protocol = 'https';
53
- }
54
- }
55
-
56
- if (askEnv && getConfig().env) {
57
- env = getConfig().env[argv.env] || getConfig().env[getConfig()?.current?.env];
58
- if (!env.protocol) {
59
- console.log('Protocol for environment not set, defaulting to https');
60
- env.protocol = 'https';
61
- }
62
- }
63
- else if (askEnv) {
64
- console.log('Current environment not set, please set it')
65
- await interactiveEnv(argv, {
66
- environment: {
67
- type: 'input'
68
- },
69
- interactive: {
70
- default: true
71
- }
72
- })
73
- env = getConfig().env[getConfig()?.current?.env];
74
- }
75
- return env;
76
- }
77
-
78
- async function handleEnv(argv) {
79
- if (argv.users) {
80
- let env = argv.env || getConfig().current.env;
81
- console.log(`Users in environment ${env}: ${Object.keys(getConfig().env[env].users || {})}`);
82
- } else if (argv.env) {
83
- changeEnv(argv)
84
- } else if (argv.list) {
85
- console.log(`Existing environments: ${Object.keys(getConfig().env || {})}`)
86
- } else {
87
- interactiveEnv(argv, {
88
- environment: {
89
- type: 'input'
90
- },
91
- host: {
92
- describe: 'Enter your host including protocol, i.e "https://yourHost.com":',
93
- type: 'input'
94
- },
95
- interactive: {
96
- default: true
97
- }
98
- })
99
- }
100
- }
101
-
102
- export async function interactiveEnv(argv, options) {
103
- if (argv.verbose) console.info('Setting up new environment')
104
- await yargsInteractive()
105
- .interactive(options)
106
- .then(async (result) => {
107
- getConfig().env = getConfig().env || {};
108
- getConfig().env[result.environment] = getConfig().env[result.environment] || {};
109
- if (result.host) {
110
- var hostSplit = result.host.split("://");
111
- if (hostSplit.length == 1) {
112
- getConfig().env[result.environment].protocol = 'https';
113
- getConfig().env[result.environment].host = hostSplit[0];
114
- } else if (hostSplit.length == 2) {
115
- getConfig().env[result.environment].protocol = hostSplit[0];
116
- getConfig().env[result.environment].host = hostSplit[1];
117
- } else {
118
- console.log(`Issues resolving host ${result.host}`);
119
- return;
120
- }
121
- }
122
- if (result.environment) {
123
- getConfig().current = getConfig().current || {};
124
- getConfig().current.env = result.environment;
125
- }
126
- updateConfig();
127
- console.log(`Your current environment is now ${getConfig().current.env}`);
128
- console.log(`To change the host of your environment, use the command 'dw env'`)
129
- });
130
- }
131
-
132
- async function changeEnv(argv) {
133
- if (!Object.keys(getConfig().env).includes(argv.env)) {
134
- console.log(`The specified environment ${argv.env} doesn't exist, please create it`);
135
- await interactiveEnv(argv, {
136
- environment: {
137
- type: 'input',
138
- default: argv.env,
139
- prompt: 'never'
140
- },
141
- host: {
142
- describe: 'Enter your host including protocol, i.e "https://yourHost.com":',
143
- type: 'input',
144
- prompt: 'always'
145
- },
146
- interactive: {
147
- default: true
148
- }
149
- })
150
- } else {
151
- getConfig().current.env = argv.env;
152
- updateConfig();
153
- console.log(`Your current environment is now ${getConfig().current.env}`);
154
- }
155
- }
1
+ import { updateConfig, getConfig } from './config.js'
2
+ import { Agent as HttpAgent } from 'http';
3
+ import { Agent as HttpsAgent } from 'https';
4
+ import { input } from '@inquirer/prompts';
5
+
6
+ const httpAgent = new HttpAgent({
7
+ keepAlive: true,
8
+ maxSockets: 8,
9
+ maxFreeSockets: 4,
10
+ keepAliveMsecs: 10_000
11
+ });
12
+
13
+ const httpsAgent = new HttpsAgent({
14
+ keepAlive: true,
15
+ maxSockets: 8,
16
+ maxFreeSockets: 4,
17
+ keepAliveMsecs: 10_000,
18
+ rejectUnauthorized: false
19
+ });
20
+
21
+ export function getAgent(protocol) {
22
+ return protocol === 'http' ? httpAgent : httpsAgent;
23
+ }
24
+
25
+ export function envCommand() {
26
+ return {
27
+ command: 'env [env]',
28
+ describe: 'If environment is specified, changes the current environment to the environment specified, otherwise sets up the config for a new environment',
29
+ builder: (yargs) => {
30
+ return yargs
31
+ .positional('env', {
32
+ describe: 'Environment'
33
+ })
34
+ .option('list', {
35
+ alias: 'l',
36
+ type: 'boolean',
37
+ description: 'List all existing environments'
38
+ })
39
+ .option('users', {
40
+ alias: 'u',
41
+ type: 'boolean',
42
+ description: 'List all users in environment, uses positional [env] if used, otherwise current env'
43
+ })
44
+ },
45
+ handler: (argv) => handleEnv(argv)
46
+ }
47
+ }
48
+
49
+ export async function setupEnv(argv) {
50
+ let env = {};
51
+ let askEnv = true;
52
+
53
+ if (argv.host) {
54
+ askEnv = false;
55
+ env.host = argv.host;
56
+ if (argv.protocol) {
57
+ env.protocol = argv.protocol;
58
+ } else {
59
+ env.protocol = 'https';
60
+ }
61
+ }
62
+
63
+ if (askEnv && getConfig().env) {
64
+ env = getConfig().env[argv.env] || getConfig().env[getConfig()?.current?.env];
65
+ if (!env.protocol) {
66
+ console.log('Protocol for environment not set, defaulting to https');
67
+ env.protocol = 'https';
68
+ }
69
+ }
70
+ else if (askEnv) {
71
+ console.log('Current environment not set, please set it')
72
+ await interactiveEnv(argv, {
73
+ environment: {
74
+ type: 'input'
75
+ },
76
+ interactive: {
77
+ default: true
78
+ }
79
+ })
80
+ env = getConfig().env[getConfig()?.current?.env];
81
+ }
82
+ return env;
83
+ }
84
+
85
+ async function handleEnv(argv) {
86
+ if (argv.users) {
87
+ let env = argv.env || getConfig().current.env;
88
+ console.log(`Users in environment ${env}: ${Object.keys(getConfig().env[env].users || {})}`);
89
+ } else if (argv.env) {
90
+ changeEnv(argv)
91
+ } else if (argv.list) {
92
+ console.log(`Existing environments: ${Object.keys(getConfig().env || {})}`)
93
+ } else {
94
+ await interactiveEnv(argv, {
95
+ environment: {
96
+ type: 'input'
97
+ },
98
+ host: {
99
+ describe: 'Enter your host including protocol, i.e "https://yourHost.com":',
100
+ type: 'input'
101
+ },
102
+ interactive: {
103
+ default: true
104
+ }
105
+ })
106
+ }
107
+ }
108
+
109
+ export async function interactiveEnv(argv, options) {
110
+ if (argv.verbose) console.info('Setting up new environment')
111
+ const result = {};
112
+ for (const [key, config] of Object.entries(options)) {
113
+ if (key === 'interactive') continue;
114
+ if (config.prompt === 'never') {
115
+ result[key] = config.default;
116
+ continue;
117
+ }
118
+ result[key] = await input({
119
+ message: config.describe || key,
120
+ default: config.default
121
+ });
122
+ }
123
+ getConfig().env = getConfig().env || {};
124
+ if (!result.environment || !result.environment.trim()) {
125
+ console.log('Environment name cannot be empty');
126
+ return;
127
+ }
128
+ getConfig().env[result.environment] = getConfig().env[result.environment] || {};
129
+ if (result.host) {
130
+ const hostSplit = result.host.split("://");
131
+ if (hostSplit.length == 1) {
132
+ getConfig().env[result.environment].protocol = 'https';
133
+ getConfig().env[result.environment].host = hostSplit[0];
134
+ } else if (hostSplit.length == 2) {
135
+ getConfig().env[result.environment].protocol = hostSplit[0];
136
+ getConfig().env[result.environment].host = hostSplit[1];
137
+ } else {
138
+ console.log(`Issues resolving host ${result.host}`);
139
+ return;
140
+ }
141
+ }
142
+ if (result.environment) {
143
+ getConfig().current = getConfig().current || {};
144
+ getConfig().current.env = result.environment;
145
+ }
146
+ updateConfig();
147
+ console.log(`Your current environment is now ${getConfig().current.env}`);
148
+ console.log(`To change the host of your environment, use the command 'dw env'`)
149
+ }
150
+
151
+ async function changeEnv(argv) {
152
+ if (!Object.keys(getConfig().env).includes(argv.env)) {
153
+ console.log(`The specified environment ${argv.env} doesn't exist, please create it`);
154
+ await interactiveEnv(argv, {
155
+ environment: {
156
+ type: 'input',
157
+ default: argv.env,
158
+ prompt: 'never'
159
+ },
160
+ host: {
161
+ describe: 'Enter your host including protocol, i.e "https://yourHost.com":',
162
+ type: 'input',
163
+ prompt: 'always'
164
+ },
165
+ interactive: {
166
+ default: true
167
+ }
168
+ })
169
+ } else {
170
+ getConfig().current.env = argv.env;
171
+ updateConfig();
172
+ console.log(`Your current environment is now ${getConfig().current.env}`);
173
+ }
174
+ }