@automattic/vip 2.37.0 → 2.38.0-dev.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.
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ "use strict";
11
+
12
+ var _phpmyadmin = require("../commands/phpmyadmin");
13
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
14
+ var _tracker = require("../lib/tracker");
15
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
+ const examples = [{
17
+ usage: 'vip db phpmyadmin @mysite.develop',
18
+ description: 'Open PhpMyAdmin console for the database of the @mysite.develop environment'
19
+ }];
20
+ const appQuery = `
21
+ id,
22
+ name,
23
+ type,
24
+ organization { id, name },
25
+ environments{
26
+ id
27
+ appId
28
+ type
29
+ name
30
+ primaryDomain { name }
31
+ uniqueLabel
32
+ }
33
+ `;
34
+ void (0, _command.default)({
35
+ appContext: true,
36
+ appQuery,
37
+ envContext: true,
38
+ module: 'phpmyadmin',
39
+ requiredArgs: 0,
40
+ usage: 'vip db phpmyadmin'
41
+ }).examples(examples).argv(process.argv, async (arg, {
42
+ app,
43
+ env
44
+ }) => {
45
+ const trackerFn = (0, _tracker.makeCommandTracker)('phpmyadmin', {
46
+ app: app.id,
47
+ env: env.uniqueLabel
48
+ });
49
+ await trackerFn('execute');
50
+ const cmd = new _phpmyadmin.PhpMyAdminCommand(app, env, trackerFn);
51
+ await cmd.run();
52
+ await trackerFn('success');
53
+ });
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * External dependencies
5
+ */
6
+
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+ "use strict";
11
+
12
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
13
+ var _tracker = require("../lib/tracker");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ void (0, _command.default)({
16
+ usage: 'vip db'
17
+ }).command('phpmyadmin', 'Open PhpMyAdmin console for your application database').example('vip db phpmyadmin @mysite.develop', 'Open PhpMyAdmin console for your database of the @mysite.develop environment').argv(process.argv, async () => {
18
+ await (0, _tracker.trackEvent)('vip_db_command_execute');
19
+ });
@@ -34,7 +34,7 @@ const examples = [{
34
34
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create --multisite=subdirectory --wordpress="5.8" --app-code="~/git/my_code"`,
35
35
  description: 'Creates a local multisite dev environment with a subdirectory URL structure using WP 5.8 and application code is expected to be in "~/git/my_code"'
36
36
  }];
37
- const cmd = (0, _command.default)().option('slug', 'Custom name of the dev environment').option('title', 'Title for the WordPress site').option('multisite', 'Enable multisite install', undefined, _devEnvironmentCli.processStringOrBooleanOption);
37
+ const cmd = (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('title', 'Title for the WordPress site').option('multisite', 'Enable multisite install', undefined, _devEnvironmentCli.processStringOrBooleanOption);
38
38
  (0, _devEnvironmentCli.addDevEnvConfigurationOptions)(cmd);
39
39
  cmd.examples(examples);
40
40
  cmd.argv(process.argv, async (arg, opt) => {
@@ -82,8 +82,7 @@ cmd.argv(process.argv, async (arg, opt) => {
82
82
  let preselectedOptions = opt;
83
83
  let suppressPrompts = false;
84
84
  if (Object.keys(configurationFileOptions).length > 0) {
85
- console.log('\nUsing configuration from file.');
86
- (0, _devEnvironmentConfigurationFile.printConfigurationFile)(configurationFileOptions);
85
+ // Merge configuration from file
87
86
  preselectedOptions = (0, _devEnvironmentConfigurationFile.mergeConfigurationFileOptions)(opt, configurationFileOptions);
88
87
  suppressPrompts = true;
89
88
  }
@@ -18,7 +18,7 @@ const examples = [{
18
18
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} destroy --slug=foo`,
19
19
  description: 'Destroys a local dev environment named foo'
20
20
  }];
21
- (0, _command.default)().option('slug', 'Custom name of the dev environment').option('soft', 'Keep config files needed to start an environment intact').examples(examples).argv(process.argv, async (arg, opt) => {
21
+ (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('soft', 'Keep config files needed to start an environment intact').examples(examples).argv(process.argv, async (arg, opt) => {
22
22
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
23
23
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
24
24
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug);
@@ -21,7 +21,7 @@ const examples = [{
21
21
  }];
22
22
  (0, _command.default)({
23
23
  wildcardCommand: true
24
- }).option('slug', 'Custom name of the dev environment').option('force', 'Disable validations before task execution', undefined, _devEnvironmentCli.processBooleanOption).option('quiet', 'Suppress output', undefined, _devEnvironmentCli.processBooleanOption).examples(examples).argv(process.argv, async (unmatchedArgs, opt) => {
24
+ }).option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('force', 'Disable validations before task execution', undefined, _devEnvironmentCli.processBooleanOption).option('quiet', 'Suppress output', undefined, _devEnvironmentCli.processBooleanOption).examples(examples).argv(process.argv, async (unmatchedArgs, opt) => {
25
25
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
26
26
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
27
27
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug, opt.quiet);
@@ -16,7 +16,7 @@ const examples = [{
16
16
  }];
17
17
  (0, _command.default)({
18
18
  requiredArgs: 1
19
- }).examples(examples).option('slug', 'Custom name of the dev environment').argv(process.argv, async (unmatchedArgs, opt) => {
19
+ }).examples(examples).option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).argv(process.argv, async (unmatchedArgs, opt) => {
20
20
  const [filePath] = unmatchedArgs;
21
21
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
22
22
  const trackingInfo = (0, _devEnvironmentCli.getEnvTrackingInfo)(slug);
@@ -22,7 +22,7 @@ const examples = [{
22
22
  }];
23
23
  (0, _command.default)({
24
24
  requiredArgs: 1
25
- }).option('slug', 'Custom name of the dev environment').option(['r', 'search-replace'], 'Perform Search and Replace on the specified SQL file').option('in-place', 'Search and Replace explicitly on the given input file').option('skip-validate', 'Do not perform file validation').option(['k', 'skip-reindex'], 'Do not reindex data in Elasticsearch after import').option('quiet', 'Suppress prompts and informational messages').examples(examples).argv(process.argv, async (unmatchedArgs, opt) => {
25
+ }).option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option(['r', 'search-replace'], 'Perform Search and Replace on the specified SQL file').option('in-place', 'Search and Replace explicitly on the given input file').option('skip-validate', 'Do not perform file validation').option(['k', 'skip-reindex'], 'Do not reindex data in Elasticsearch after import').option('quiet', 'Suppress prompts and informational messages').examples(examples).argv(process.argv, async (unmatchedArgs, opt) => {
26
26
  const [fileName] = unmatchedArgs;
27
27
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
28
28
  const cmd = new _devEnvImportSql.DevEnvImportSQLCommand(fileName, opt, slug);
@@ -17,7 +17,7 @@ const examples = [{
17
17
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} info --slug=my_site`,
18
18
  description: 'Return information about a local dev environment named "my_site"'
19
19
  }];
20
- (0, _command.default)().option('slug', 'Custom name of the dev environment').option('all', 'Show Info for all local dev environments').option('extended', 'Show extended information about the dev environment').examples(examples).argv(process.argv, async (arg, opt) => {
20
+ (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('all', 'Show Info for all local dev environments').option('extended', 'Show extended information about the dev environment').examples(examples).argv(process.argv, async (arg, opt) => {
21
21
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
22
22
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
23
23
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug);
@@ -20,7 +20,7 @@ const examples = [{
20
20
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} logs --slug=my_site --service=elasticsearch -f`,
21
21
  description: 'Follow logs from the "elasticsearch" service from a local dev environment named "my_site"'
22
22
  }];
23
- (0, _command.default)().option('slug', 'Custom name of the dev environment').option(['f', 'follow'], 'Follow logs for a specific service in local dev environment').option('service', 'Show logs for a specific service in local dev environment. Defaults to all if none passed in.').examples(examples).argv(process.argv, async (arg, opt) => {
23
+ (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option(['f', 'follow'], 'Follow logs for a specific service in local dev environment').option('service', 'Show logs for a specific service in local dev environment. Defaults to all if none passed in.').examples(examples).argv(process.argv, async (arg, opt) => {
24
24
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
25
25
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
26
26
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug);
@@ -54,7 +54,7 @@ function getCommand(args) {
54
54
  }
55
55
  (0, _command.default)({
56
56
  wildcardCommand: true
57
- }).option('slug', 'Custom name of the dev environment').option('root', 'Spawn a root shell').option('service', 'Spawn a shell in a specific service (php if omitted)').examples(examples).argv(process.argv, async (args, opt) => {
57
+ }).option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('root', 'Spawn a root shell').option('service', 'Spawn a shell in a specific service (php if omitted)').examples(examples).argv(process.argv, async (args, opt) => {
58
58
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
59
59
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
60
60
  await (0, _devEnvironmentCli.validateDependencies)(lando, '', true);
@@ -17,7 +17,7 @@ const examples = [{
17
17
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} start --vscode`,
18
18
  description: 'Start a local environment and generate a Workspace file for developing in Visual Studio Code'
19
19
  }];
20
- (0, _command.default)().option('slug', 'Custom name of the dev environment').option('skip-rebuild', 'Only start stopped services').option(['w', 'skip-wp-versions-check'], 'Skip prompt to update WordPress version if not on latest').option('vscode', 'Generate a Visual Studio Code Workspace file').examples(examples).argv(process.argv, async (arg, opt) => {
20
+ (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('skip-rebuild', 'Only start stopped services').option(['w', 'skip-wp-versions-check'], 'Skip prompt to update WordPress version if not on latest').option('vscode', 'Generate a Visual Studio Code Workspace file').examples(examples).argv(process.argv, async (arg, opt) => {
21
21
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
22
22
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
23
23
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug);
@@ -15,7 +15,7 @@ const examples = [{
15
15
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} stop`,
16
16
  description: 'Stops a local dev environment'
17
17
  }];
18
- (0, _command.default)().option('slug', 'Custom name of the dev environment').examples(examples).argv(process.argv, async (arg, opt) => {
18
+ (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).examples(examples).argv(process.argv, async (arg, opt) => {
19
19
  const slug = await (0, _devEnvironmentCli.getEnvironmentName)(opt);
20
20
  const lando = await (0, _devEnvironmentLando.bootstrapLando)();
21
21
  await (0, _devEnvironmentCli.validateDependencies)(lando, slug);
@@ -42,7 +42,7 @@ const appQuery = `
42
42
  envContext: true,
43
43
  requiredArgs: 0,
44
44
  module: 'dev-env-sync-sql'
45
- }).option('slug', 'Custom name of the dev environment').option('force', 'Disable validations before running sync', undefined, _devEnvironmentCli.processBooleanOption).examples(examples).argv(process.argv, async (arg, opt) => {
45
+ }).option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug).option('force', 'Disable validations before running sync', undefined, _devEnvironmentCli.processBooleanOption).examples(examples).argv(process.argv, async (arg, opt) => {
46
46
  const {
47
47
  app,
48
48
  env
@@ -16,7 +16,7 @@ const examples = [{
16
16
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} update`,
17
17
  description: 'Retriggers setup wizard in order to change environment configuration'
18
18
  }];
19
- const cmd = (0, _command.default)().option('slug', 'Custom name of the dev environment');
19
+ const cmd = (0, _command.default)().option('slug', 'Custom name of the dev environment', undefined, _devEnvironmentCli.processSlug);
20
20
  (0, _devEnvironmentCli.addDevEnvConfigurationOptions)(cmd);
21
21
  cmd.examples(examples);
22
22
  cmd.argv(process.argv, async (arg, opt) => {
@@ -112,7 +112,7 @@ const getTokenForCommand = async (appId, envId, command) => {
112
112
  });
113
113
  };
114
114
 
115
- // eslint-disable-next-line no-unused-vars
115
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
116
116
  const cancelCommand = async guid => {
117
117
  const api = await (0, _api.default)();
118
118
  return api.mutate({
package/dist/bin/vip.js CHANGED
@@ -21,7 +21,7 @@ if (_config.default && _config.default.environment !== 'production') {
21
21
  const tokenURL = 'https://dashboard.wpvip.com/me/cli/token';
22
22
  const runCmd = async function () {
23
23
  const cmd = (0, _command.default)();
24
- cmd.command('logout', 'Logout from your current session').command('app', 'List and modify your VIP applications').command('backup', 'Generate a backup for VIP applications').command('cache', 'Manage page cache for your VIP applications').command('config', 'Set configuration for your VIP applications').command('dev-env', 'Use local dev-environment').command('export', 'Export data from your VIP application').command('import', 'Import media or SQL files into your VIP applications').command('logs', 'Get logs from your VIP applications').command('search-replace', 'Perform search and replace tasks on files').command('slowlogs', 'Get slowlogs from your VIP applications').command('sync', 'Sync production to a development environment').command('whoami', 'Display details about the currently logged-in user').command('validate', 'Validate your VIP application and environment').command('wp', 'Run WP CLI commands against an environment');
24
+ cmd.command('logout', 'Logout from your current session').command('app', 'List and modify your VIP applications').command('backup', 'Generate a backup for VIP applications').command('cache', 'Manage page cache for your VIP applications').command('config', 'Set configuration for your VIP applications').command('dev-env', 'Use local dev-environment').command('export', 'Export data from your VIP application').command('import', 'Import media or SQL files into your VIP applications').command('logs', 'Get logs from your VIP applications').command('search-replace', 'Perform search and replace tasks on files').command('slowlogs', 'Get slowlogs from your VIP applications').command('db', 'Run operations on your VIP application database').command('sync', 'Sync production to a development environment').command('whoami', 'Display details about the currently logged-in user').command('validate', 'Validate your VIP application and environment').command('wp', 'Run WP CLI commands against an environment');
25
25
  cmd.argv(process.argv);
26
26
  };
27
27
 
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.PhpMyAdminCommand = exports.GET_PHP_MY_ADMIN_STATUS_QUERY = exports.GENERATE_PHP_MY_ADMIN_URL_MUTATION = exports.ENABLE_PHP_MY_ADMIN_MUTATION = void 0;
5
+ var _chalk = _interopRequireDefault(require("chalk"));
6
+ var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
7
+ var _api = _interopRequireWildcard(require("../lib/api"));
8
+ var exit = _interopRequireWildcard(require("../lib/cli/exit"));
9
+ var _progress = require("../lib/cli/progress");
10
+ var _utils = require("../lib/utils");
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ /**
15
+ * External dependencies
16
+ */
17
+
18
+ /**
19
+ * Internal dependencies
20
+ */
21
+
22
+ const GENERATE_PHP_MY_ADMIN_URL_MUTATION = exports.GENERATE_PHP_MY_ADMIN_URL_MUTATION = (0, _graphqlTag.default)`
23
+ mutation GeneratePhpMyAdminAccess($input: GeneratePhpMyAdminAccessInput) {
24
+ generatePHPMyAdminAccess(input: $input) {
25
+ expiresAt
26
+ url
27
+ }
28
+ }
29
+ `;
30
+ const GET_PHP_MY_ADMIN_STATUS_QUERY = exports.GET_PHP_MY_ADMIN_STATUS_QUERY = (0, _graphqlTag.default)`
31
+ query PhpMyAdminStatus($appId: Int!, $envId: Int!) {
32
+ app(id: $appId) {
33
+ environments(id: $envId) {
34
+ phpMyAdminStatus {
35
+ status
36
+ }
37
+ }
38
+ }
39
+ }
40
+ `;
41
+ const ENABLE_PHP_MY_ADMIN_MUTATION = exports.ENABLE_PHP_MY_ADMIN_MUTATION = (0, _graphqlTag.default)`
42
+ mutation EnablePhpMyAdmin($input: EnablePhpMyAdminInput) {
43
+ enablePHPMyAdmin(input: $input) {
44
+ success
45
+ }
46
+ }
47
+ `;
48
+ async function generatePhpMyAdminAccess(envId) {
49
+ // Disable global error handling so that we can handle errors ourselves
50
+ (0, _api.disableGlobalGraphQLErrorHandling)();
51
+ const api = await (0, _api.default)();
52
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
53
+ const resp = await api.mutate({
54
+ mutation: GENERATE_PHP_MY_ADMIN_URL_MUTATION,
55
+ variables: {
56
+ input: {
57
+ environmentId: envId
58
+ }
59
+ }
60
+ });
61
+
62
+ // Re-enable global error handling
63
+ (0, _api.enableGlobalGraphQLErrorHandling)();
64
+
65
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
66
+ return resp?.data?.generatePHPMyAdminAccess?.url;
67
+ }
68
+ async function enablePhpMyAdmin(envId) {
69
+ // Disable global error handling so that we can handle errors ourselves
70
+ (0, _api.disableGlobalGraphQLErrorHandling)();
71
+ const api = await (0, _api.default)();
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ const resp = await api.mutate({
74
+ mutation: ENABLE_PHP_MY_ADMIN_MUTATION,
75
+ variables: {
76
+ input: {
77
+ environmentId: envId
78
+ }
79
+ }
80
+ });
81
+
82
+ // Re-enable global error handling
83
+ (0, _api.enableGlobalGraphQLErrorHandling)();
84
+
85
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
86
+ return resp?.data?.generatePHPMyAdminAccess?.url;
87
+ }
88
+ async function getPhpMyAdminStatus(appId, envId) {
89
+ // Disable global error handling so that we can handle errors ourselves
90
+ (0, _api.disableGlobalGraphQLErrorHandling)();
91
+ const api = await (0, _api.default)();
92
+
93
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
+ const resp = await api.query({
95
+ query: GET_PHP_MY_ADMIN_STATUS_QUERY,
96
+ variables: {
97
+ appId,
98
+ envId
99
+ },
100
+ fetchPolicy: 'network-only'
101
+ });
102
+
103
+ // Re-enable global error handling
104
+ (0, _api.enableGlobalGraphQLErrorHandling)();
105
+
106
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
107
+ return resp?.data?.app?.environments?.[0]?.phpMyAdminStatus?.status;
108
+ }
109
+ class PhpMyAdminCommand {
110
+ app;
111
+ env;
112
+ silent;
113
+ track;
114
+ steps = {
115
+ ENABLE: 'enable',
116
+ GENERATE: 'generate'
117
+ };
118
+ progressTracker;
119
+ constructor(app, env, trackerFn = async () => {}) {
120
+ this.app = app;
121
+ this.env = env;
122
+ this.track = trackerFn;
123
+ this.progressTracker = new _progress.ProgressTracker([{
124
+ id: this.steps.ENABLE,
125
+ name: 'Enabling PHPMyAdmin for this site'
126
+ }, {
127
+ id: this.steps.GENERATE,
128
+ name: 'Generating access link'
129
+ }]);
130
+ }
131
+ log(msg) {
132
+ if (this.silent) {
133
+ return;
134
+ }
135
+ console.log(msg);
136
+ }
137
+ stopProgressTracker() {
138
+ this.progressTracker.print();
139
+ this.progressTracker.stopPrinting();
140
+ }
141
+ async openUrl(url) {
142
+ const {
143
+ default: open
144
+ } = await import('open');
145
+ void open(url, {
146
+ wait: false
147
+ });
148
+ }
149
+ async getStatus() {
150
+ try {
151
+ return await getPhpMyAdminStatus(this.app.id, this.env.id);
152
+ } catch (err) {
153
+ exit.withError('Failed to get PhpMyAdmin status. Please try again. If the problem persists, please contact support.');
154
+ }
155
+ }
156
+ async maybeEnablePhpMyAdmin() {
157
+ const status = await this.getStatus();
158
+ if (!['running', 'enabled'].includes(status)) {
159
+ await enablePhpMyAdmin(this.env.id);
160
+ await (0, _utils.pollUntil)(this.getStatus.bind(this), 1000, sts => sts === 'running');
161
+
162
+ // Additional 30s for LB routing to be updated
163
+ await new Promise(resolve => setTimeout(resolve, 30000));
164
+ }
165
+ }
166
+ async run(silent = false) {
167
+ this.silent = silent;
168
+ if (!this.app.id) {
169
+ exit.withError('No app was specified');
170
+ }
171
+ if (!this.env.id) {
172
+ exit.withError('No environment was specified');
173
+ }
174
+ const message = 'Note: PHPMyAdmin sessions are read-only. If you run a query that writes to DB, it will fail.';
175
+ console.log(_chalk.default.yellow(message));
176
+ this.progressTracker.startPrinting();
177
+ try {
178
+ this.progressTracker.stepRunning(this.steps.ENABLE);
179
+ await this.maybeEnablePhpMyAdmin();
180
+ this.progressTracker.stepSuccess(this.steps.ENABLE);
181
+ } catch (err) {
182
+ this.progressTracker.stepFailed(this.steps.ENABLE);
183
+ exit.withError('Failed to enable PhpMyAdmin');
184
+ }
185
+ let url;
186
+ try {
187
+ this.progressTracker.stepRunning(this.steps.GENERATE);
188
+ url = await generatePhpMyAdminAccess(this.env.id);
189
+ this.progressTracker.stepSuccess(this.steps.GENERATE);
190
+ } catch (err) {
191
+ this.progressTracker.stepFailed(this.steps.GENERATE);
192
+ const error = err;
193
+ void this.track('error', {
194
+ error_type: 'generate_pma_url',
195
+ error_message: error.message,
196
+ stack: error.stack
197
+ });
198
+ exit.withError(`Failed to generate PhpMyAdmin URL: ${error.message}`);
199
+ }
200
+ void this.openUrl(url);
201
+ this.stopProgressTracker();
202
+ this.log('PhpMyAdmin is opened in your default browser.');
203
+ }
204
+ }
205
+ exports.PhpMyAdminCommand = PhpMyAdminCommand;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.DEFAULT_SLUG = void 0;
4
+ exports.DEFAULT_SLUG = exports.CONFIGURATION_FOLDER = void 0;
5
5
  exports.addDevEnvConfigurationOptions = addDevEnvConfigurationOptions;
6
6
  exports.getEnvTrackingInfo = getEnvTrackingInfo;
7
7
  exports.getEnvironmentName = getEnvironmentName;
@@ -14,6 +14,7 @@ exports.postStart = postStart;
14
14
  exports.printTable = printTable;
15
15
  exports.processBooleanOption = processBooleanOption;
16
16
  exports.processComponentOptionInput = processComponentOptionInput;
17
+ exports.processSlug = processSlug;
17
18
  exports.processStringOrBooleanOption = processStringOrBooleanOption;
18
19
  exports.processVersionOption = processVersionOption;
19
20
  exports.promptForArguments = promptForArguments;
@@ -47,6 +48,7 @@ var _userError = _interopRequireDefault(require("../user-error"));
47
48
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
49
  const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
49
50
  const DEFAULT_SLUG = exports.DEFAULT_SLUG = 'vip-local';
51
+ const CONFIGURATION_FOLDER = exports.CONFIGURATION_FOLDER = '.wpvip';
50
52
  let isStdinTTY = Boolean(process.stdin.isTTY);
51
53
 
52
54
  /**
@@ -176,9 +178,9 @@ async function getEnvironmentName(options) {
176
178
  throw new _userError.default(message);
177
179
  }
178
180
  const configurationFileOptions = await (0, _devEnvironmentConfigurationFile.getConfigurationFileOptions)();
179
- if (configurationFileOptions.slug) {
181
+ if (configurationFileOptions.slug && configurationFileOptions.meta) {
180
182
  const slug = configurationFileOptions.slug;
181
- console.log(`Using environment ${_chalk.default.blue.bold(slug)} from ${_chalk.default.gray(_devEnvironmentConfigurationFile.CONFIGURATION_FILE_NAME)}\n`);
183
+ console.log(`Using environment ${_chalk.default.blue.bold(slug)} from ${_chalk.default.gray(configurationFileOptions.meta['configuration-path'])}\n`);
182
184
  return slug;
183
185
  }
184
186
  const envs = (0, _devEnvironmentCore.getAllEnvironmentNames)();
@@ -619,6 +621,10 @@ function processStringOrBooleanOption(value) {
619
621
  }
620
622
  return value;
621
623
  }
624
+ function processSlug(value) {
625
+ // eslint-disable-next-line @typescript-eslint/no-base-to-string
626
+ return (value ?? '').toString().toLowerCase();
627
+ }
622
628
  function processVersionOption(value) {
623
629
  if (typeof value === 'string' || typeof value === 'number') {
624
630
  if (!isNaN(value) && Number(value) % 1 === 0) {