@automattic/vip 3.25.1 → 3.25.2

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.
@@ -16,6 +16,9 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
16
16
  const examples = [{
17
17
  usage: 'vip @example-app.develop db phpmyadmin',
18
18
  description: "Generate access to a read-only phpMyAdmin web interface for the environment's database."
19
+ }, {
20
+ usage: 'vip @example-app.develop db phpmyadmin --print',
21
+ description: 'Print the phpMyAdmin URL to stdout instead of opening it in a browser.'
19
22
  }];
20
23
  const appQuery = `
21
24
  id,
@@ -35,16 +38,20 @@ void (0, _command.default)({
35
38
  module: 'phpmyadmin',
36
39
  requiredArgs: 0,
37
40
  usage: 'vip db phpmyadmin'
38
- }).examples(examples).argv(process.argv, async (arg, {
41
+ }).option('print', 'Print the phpMyAdmin URL to stdout instead of opening it in a browser.').option('silent', 'Do not print any output to the console.').examples(examples).argv(process.argv, async (arg, {
39
42
  app,
40
- env
43
+ env,
44
+ print: printUrl,
45
+ silent
41
46
  }) => {
42
47
  const trackerFn = (0, _tracker.makeCommandTracker)('phpmyadmin', {
43
48
  app: app.id,
44
49
  env: env.uniqueLabel
45
50
  });
46
51
  await trackerFn('execute');
47
- const cmd = new _phpmyadmin.PhpMyAdminCommand(app, env, trackerFn);
48
- await cmd.run();
52
+ const cmd = new _phpmyadmin.PhpMyAdminCommand(app, env, trackerFn, silent);
53
+ await cmd.run({
54
+ print: printUrl
55
+ });
49
56
  await trackerFn('success');
50
57
  });
@@ -4,6 +4,6 @@
4
4
  var _command = _interopRequireDefault(require("../lib/cli/command"));
5
5
  var _tracker = require("../lib/tracker");
6
6
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
- (0, _command.default)().command('sql', 'Import a SQL database file to an environment.').command('validate-sql', 'Validate a local SQL database file prior to import.').command('validate-files', 'Validate the directory structure and contents of a local media file directory prior to archiving and uploading it to a publicly accessible URL.').command('media', 'Import media files to an environment from an archived file located at a publicly accessible URL.').example('vip @example-app.develop import sql example-file.sql', 'Import the local SQL database file "example-file.sql" to the develop environment.').example('vip @example-app.production import media https://www.example.com/uploads.tar.gz', 'Import an archived file from a publicly accessible URL to the production environment.').argv(process.argv, async () => {
7
+ (0, _command.default)().command('sql', 'Import a SQL database file to an environment.').command('validate-sql', 'Validate a local SQL database file prior to import.').command('validate-files', 'Validate that the directory structure and contents of a local media file directory can be successfully imported.').command('media', 'Import media files to a production environment from an archived file at a local path or a publicly accessible remote URL.').example('vip @example-app.develop import sql example-file.sql', 'Import the local SQL database file "example-file.sql" to the develop environment.').example('vip @example-app.production import media https://www.example.com/uploads.tar.gz', 'Import an archived file from a publicly accessible URL to the production environment.').argv(process.argv, async () => {
8
8
  await (0, _tracker.trackEvent)('vip_import_command_execute');
9
9
  });
@@ -4,6 +4,7 @@ exports.__esModule = true;
4
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
5
  var _chalk = _interopRequireDefault(require("chalk"));
6
6
  var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
7
+ var _promises = require("node:timers/promises");
7
8
  var _api = _interopRequireWildcard(require("../lib/api"));
8
9
  var exit = _interopRequireWildcard(require("../lib/cli/exit"));
9
10
  var _progress = require("../lib/cli/progress");
@@ -94,6 +95,45 @@ async function getPhpMyAdminStatus(appId, envId) {
94
95
  (0, _api.enableGlobalGraphQLErrorHandling)();
95
96
  return resp.data?.app?.environments?.[0]?.phpMyAdminStatus?.status ?? '';
96
97
  }
98
+ class MyProgressTracker extends _progress.ProgressTracker {
99
+ constructor(steps, silent) {
100
+ super(steps);
101
+ this.silent = silent;
102
+ }
103
+ setSilent(silent) {
104
+ this.silent = silent;
105
+ }
106
+ print() {
107
+ if (!this.silent) {
108
+ super.print();
109
+ }
110
+ }
111
+ startPrinting(prePrintCallback) {
112
+ if (!this.silent) {
113
+ super.startPrinting(prePrintCallback);
114
+ }
115
+ }
116
+ stopPrinting() {
117
+ if (!this.silent) {
118
+ super.stopPrinting();
119
+ }
120
+ }
121
+ stepRunning(stepId, additionalInfo) {
122
+ if (!this.silent) {
123
+ super.stepRunning(stepId, additionalInfo);
124
+ }
125
+ }
126
+ stepSuccess(stepId, additionalInfo) {
127
+ if (!this.silent) {
128
+ super.stepSuccess(stepId, additionalInfo);
129
+ }
130
+ }
131
+ stepFailed(stepId, additionalInfo) {
132
+ if (!this.silent) {
133
+ super.stepFailed(stepId, additionalInfo);
134
+ }
135
+ }
136
+ }
97
137
  class PhpMyAdminCommand {
98
138
  silent;
99
139
  steps = {
@@ -101,23 +141,23 @@ class PhpMyAdminCommand {
101
141
  GENERATE: 'generate'
102
142
  };
103
143
  progressTracker;
104
- constructor(app, env, track = async () => {}) {
144
+ constructor(app, env, track = async () => {}, silent = false) {
105
145
  this.app = app;
106
146
  this.env = env;
107
147
  this.track = track;
108
- this.progressTracker = new _progress.ProgressTracker([{
148
+ this.silent = silent;
149
+ this.progressTracker = new MyProgressTracker([{
109
150
  id: this.steps.ENABLE,
110
- name: 'Enabling PHPMyAdmin for this environment'
151
+ name: 'Enabling phpMyAdmin for this environment'
111
152
  }, {
112
153
  id: this.steps.GENERATE,
113
154
  name: 'Generating access link'
114
- }]);
155
+ }], silent);
115
156
  }
116
157
  log(msg) {
117
- if (this.silent) {
118
- return;
158
+ if (!this.silent) {
159
+ console.log(msg);
119
160
  }
120
- console.log(msg);
121
161
  }
122
162
  stopProgressTracker() {
123
163
  this.progressTracker.print();
@@ -141,19 +181,22 @@ class PhpMyAdminCommand {
141
181
  await (0, _utils.pollUntil)(this.getStatus.bind(this), 1000, sts => sts === 'running');
142
182
 
143
183
  // Additional 30s for LB routing to be updated
144
- await new Promise(resolve => setTimeout(resolve, 30000));
184
+ await (0, _promises.setTimeout)(30_000);
145
185
  }
146
186
  }
147
- async run(silent = false) {
148
- this.silent = silent;
187
+ async run({
188
+ print = false
189
+ } = {}) {
149
190
  if (!this.app.id) {
150
191
  exit.withError('No app was specified');
151
192
  }
152
193
  if (!this.env.id) {
153
194
  exit.withError('No environment was specified');
154
195
  }
155
- const message = 'Note: PHPMyAdmin sessions are read-only. If you run a query that writes to DB, it will fail.';
156
- console.log(_chalk.default.yellow(message));
196
+ if (!this.silent) {
197
+ const message = 'Note: PHPMyAdmin sessions are read-only. If you run a query that writes to DB, it will fail.';
198
+ console.log(_chalk.default.yellow(message));
199
+ }
157
200
  this.progressTracker.startPrinting();
158
201
  try {
159
202
  this.progressTracker.stepRunning(this.steps.ENABLE);
@@ -171,7 +214,7 @@ class PhpMyAdminCommand {
171
214
  if (error.graphQLErrors?.find(gqlError => gqlError.message === 'Unauthorized')) {
172
215
  exit.withError('You do not have sufficient permission to access phpMyAdmin for this environment.');
173
216
  }
174
- exit.withError('Failed to enable PhpMyAdmin. Please try again. If the problem persists, please contact support.');
217
+ exit.withError('Failed to enable phpMyAdmin. Please try again. If the problem persists, please contact support.');
175
218
  }
176
219
  let url;
177
220
  try {
@@ -187,11 +230,16 @@ class PhpMyAdminCommand {
187
230
  stack: error.stack
188
231
  });
189
232
  this.stopProgressTracker();
190
- exit.withError(`Failed to generate PhpMyAdmin URL: ${error.message}`);
233
+ exit.withError(`Failed to generate phpMyAdmin URL: ${error.message}`);
191
234
  }
192
- void this.openUrl(url);
193
235
  this.stopProgressTracker();
194
- this.log('PhpMyAdmin is opened in your default browser.');
236
+ if (print) {
237
+ // Output only the URL to stdout for scripting/automation use
238
+ console.log(url);
239
+ } else {
240
+ void this.openUrl(url);
241
+ this.log('phpMyAdmin is opened in your default browser.');
242
+ }
195
243
  }
196
244
  }
197
245
  exports.PhpMyAdminCommand = PhpMyAdminCommand;