@automattic/vip 2.0.12 → 2.2.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.
Files changed (70) hide show
  1. package/CONTRIBUTING.md +34 -1
  2. package/README.md +95 -0
  3. package/assets/{dev-environment.lando.template.yml.ejs → dev-env.lando.template.yml.ejs} +61 -50
  4. package/assets/dev-env.nginx.template.conf.ejs +13 -0
  5. package/dist/bin/vip-app.js +9 -9
  6. package/dist/bin/vip-config-envvar-delete.js +93 -0
  7. package/dist/bin/vip-config-envvar-get-all.js +94 -0
  8. package/dist/bin/vip-config-envvar-get.js +79 -0
  9. package/dist/bin/vip-config-envvar-list.js +91 -0
  10. package/dist/bin/vip-config-envvar-set.js +112 -0
  11. package/dist/bin/vip-config-envvar.js +23 -0
  12. package/dist/bin/vip-config.js +20 -0
  13. package/dist/bin/vip-dev-env-create.js +27 -12
  14. package/dist/bin/vip-dev-env-destroy.js +6 -7
  15. package/dist/bin/vip-dev-env-exec.js +9 -10
  16. package/dist/bin/vip-dev-env-import-media.js +45 -0
  17. package/dist/bin/vip-dev-env-import-sql.js +70 -0
  18. package/dist/bin/vip-dev-env-import.js +32 -0
  19. package/dist/bin/vip-dev-env-info.js +5 -6
  20. package/dist/bin/vip-dev-env-start.js +24 -4
  21. package/dist/bin/vip-dev-env-stop.js +4 -5
  22. package/dist/bin/vip-dev-env.js +2 -2
  23. package/dist/bin/vip-import-media-abort.js +4 -4
  24. package/dist/bin/vip-import-media.js +6 -6
  25. package/dist/bin/vip-import-sql.js +8 -3
  26. package/dist/bin/vip-search-replace.js +1 -1
  27. package/dist/bin/vip-sync.js +11 -11
  28. package/dist/bin/vip-wp.js +14 -14
  29. package/dist/bin/vip.js +15 -16
  30. package/dist/lib/api.js +3 -1
  31. package/dist/lib/cli/apiConfig.js +3 -17
  32. package/dist/lib/cli/command.js +45 -31
  33. package/dist/lib/cli/format.js +19 -15
  34. package/dist/lib/cli/prompt.js +2 -2
  35. package/dist/lib/client-file-uploader.js +7 -7
  36. package/dist/lib/constants/dev-environment.js +2 -1
  37. package/dist/lib/dev-environment/dev-environment-cli.js +57 -26
  38. package/dist/lib/dev-environment/dev-environment-core.js +113 -29
  39. package/dist/lib/dev-environment/dev-environment-lando.js +90 -15
  40. package/dist/lib/envvar/api-delete.js +56 -0
  41. package/dist/lib/envvar/api-get-all.js +59 -0
  42. package/dist/lib/envvar/api-get.js +24 -0
  43. package/dist/lib/envvar/api-list.js +60 -0
  44. package/dist/lib/envvar/api-set.js +58 -0
  45. package/dist/lib/envvar/api.js +104 -0
  46. package/dist/lib/envvar/input.js +55 -0
  47. package/dist/lib/envvar/logging.js +33 -0
  48. package/dist/lib/envvar/read-file.js +43 -0
  49. package/dist/lib/keychain/insecure.js +6 -6
  50. package/dist/lib/keychain.js +5 -5
  51. package/dist/lib/media-import/progress.js +0 -5
  52. package/dist/lib/media-import/status.js +8 -3
  53. package/dist/lib/search-and-replace.js +1 -1
  54. package/dist/lib/site-import/status.js +6 -5
  55. package/dist/lib/token.js +7 -7
  56. package/dist/lib/tracker.js +4 -4
  57. package/dist/lib/validations/is-multi-site-sql-dump.js +3 -3
  58. package/dist/lib/validations/line-by-line.js +1 -1
  59. package/dist/lib/validations/sql.js +0 -18
  60. package/helpers/check-version.js +5 -1
  61. package/jest.setupMocks.js +1 -0
  62. package/package.json +35 -25
  63. package/assets/dev-environment.wp-config-defaults.php +0 -109
  64. package/dist/bin/vip-dev-environment-create.js +0 -58
  65. package/dist/bin/vip-dev-environment-destroy.js +0 -48
  66. package/dist/bin/vip-dev-environment-info.js +0 -58
  67. package/dist/bin/vip-dev-environment-start.js +0 -54
  68. package/dist/bin/vip-dev-environment-stop.js +0 -56
  69. package/dist/bin/vip-dev-environment.js +0 -23
  70. package/dist/lib/dev-environment.js +0 -335
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.listEnvVarsCommand = listEnvVarsCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _format = require("../lib/cli/format");
23
+
24
+ var _api = require("../lib/envvar/api");
25
+
26
+ var _logging = require("../lib/envvar/logging");
27
+
28
+ var _rollbar = require("../lib/rollbar");
29
+
30
+ var _tracker = require("../lib/tracker");
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
33
+
34
+ /**
35
+ * Internal dependencies
36
+ */
37
+ const usage = 'vip config envvar list'; // Command examples
38
+
39
+ const examples = [{
40
+ usage,
41
+ description: 'Lists all environment variables (names only)'
42
+ }];
43
+
44
+ async function listEnvVarsCommand(arg, opt) {
45
+ const trackingParams = {
46
+ app_id: opt.app.id,
47
+ command: usage,
48
+ env_id: opt.env.id,
49
+ format: opt.format,
50
+ org_id: opt.app.organization.id
51
+ };
52
+ (0, _logging.debug)(`Request: list environment variables for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
53
+ await (0, _tracker.trackEvent)('envvar_list_command_execute', trackingParams);
54
+ const envvars = await (0, _api.listEnvVars)(opt.app.id, opt.env.id).catch(async err => {
55
+ _rollbar.rollbar.error(err);
56
+
57
+ await (0, _tracker.trackEvent)('envvar_list_query_error', { ...trackingParams,
58
+ error: err.message
59
+ });
60
+ throw err;
61
+ });
62
+ await (0, _tracker.trackEvent)('envvar_list_command_success', trackingParams);
63
+
64
+ if (0 === envvars.length) {
65
+ console.log(_chalk.default.yellow('There are no environment variables'));
66
+ process.exit();
67
+ } // Vary data by expected format.
68
+
69
+
70
+ let key = 'name';
71
+
72
+ if ('keyValue' === opt.format) {
73
+ key = 'key';
74
+ } else if ('ids' === opt.format) {
75
+ key = 'id';
76
+ } // Format as an object for formatData.
77
+
78
+
79
+ const envvarsObject = envvars.map(name => ({
80
+ [key]: name
81
+ }));
82
+ console.log((0, _format.formatData)(envvarsObject, opt.format));
83
+ }
84
+
85
+ (0, _command.default)({
86
+ appContext: true,
87
+ appQuery: _api.appQuery,
88
+ envContext: true,
89
+ format: true,
90
+ usage
91
+ }).examples(examples).argv(process.argv, listEnvVarsCommand);
@@ -0,0 +1,112 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ Object.defineProperty(exports, "__esModule", {
14
+ value: true
15
+ });
16
+ exports.setEnvVarCommand = setEnvVarCommand;
17
+
18
+ var _chalk = _interopRequireDefault(require("chalk"));
19
+
20
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
21
+
22
+ var _api = require("../lib/envvar/api");
23
+
24
+ var _input = require("../lib/envvar/input");
25
+
26
+ var _logging = require("../lib/envvar/logging");
27
+
28
+ var _readFile = require("../lib/envvar/read-file");
29
+
30
+ var _rollbar = require("../lib/rollbar");
31
+
32
+ var _tracker = require("../lib/tracker");
33
+
34
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
35
+
36
+ /**
37
+ * Internal dependencies
38
+ */
39
+ const baseUsage = 'vip config envvar set'; // Command examples
40
+
41
+ const examples = [{
42
+ usage: `${baseUsage} MY_VARIABLE`,
43
+ description: 'Sets the environment variable "MY_VARIABLE" and prompts for its value'
44
+ }];
45
+
46
+ async function setEnvVarCommand(arg, opt) {
47
+ // Help the user by uppercasing input.
48
+ const name = arg[0].trim().toUpperCase();
49
+ const trackingParams = {
50
+ app_id: opt.app.id,
51
+ command: `${baseUsage} ${name}`,
52
+ env_id: opt.env.id,
53
+ from_file: !!opt.fromFile,
54
+ org_id: opt.app.organization.id,
55
+ skip_confirm: !!opt.skipConfirmation,
56
+ variable_name: name
57
+ };
58
+ (0, _logging.debug)(`Request: Set environment variable ${JSON.stringify(name)} for ${(0, _logging.getEnvContext)(opt.app, opt.env)}`);
59
+ await (0, _tracker.trackEvent)('envvar_set_command_execute', trackingParams);
60
+
61
+ if (!(0, _api.validateNameWithMessage)(name)) {
62
+ await (0, _tracker.trackEvent)('envvar_set_invalid_name', trackingParams);
63
+ process.exit(1);
64
+ }
65
+
66
+ let value;
67
+
68
+ if (opt.fromFile) {
69
+ value = await (0, _readFile.readVariableFromFile)(opt.fromFile);
70
+ } else {
71
+ console.log(`For multiline input, use the ${_chalk.default.bold('--from-file')} option.`);
72
+ console.log();
73
+ value = await (0, _input.promptForValue)(`Enter the value for ${name}:`).catch(async () => {
74
+ await (0, _tracker.trackEvent)('envvar_set_user_cancelled_input', trackingParams);
75
+ (0, _input.cancel)();
76
+ });
77
+ }
78
+
79
+ if (!opt.skipConfirmation) {
80
+ // Print input if it was loaded from file.
81
+ if (opt.fromFile) {
82
+ console.log('===== Received value printed below =====');
83
+ console.log(value);
84
+ console.log('===== Received value printed above =====');
85
+ console.log();
86
+ }
87
+
88
+ if (!(await (0, _input.confirm)(`Please ${_chalk.default.bold('confirm')} the input value above (y/N)`))) {
89
+ await (0, _tracker.trackEvent)('envvar_set_user_cancelled_confirmation', trackingParams);
90
+ (0, _input.cancel)();
91
+ }
92
+ }
93
+
94
+ await (0, _api.setEnvVar)(opt.app.id, opt.env.id, name, value).catch(async err => {
95
+ _rollbar.rollbar.error(err);
96
+
97
+ await (0, _tracker.trackEvent)('envvar_set_mutation_error', { ...trackingParams,
98
+ error: err.message
99
+ });
100
+ throw err;
101
+ });
102
+ await (0, _tracker.trackEvent)('envvar_set_command_success', trackingParams);
103
+ console.log(_chalk.default.green(`Successfully set environment variable ${JSON.stringify(name)}`));
104
+ }
105
+
106
+ (0, _command.default)({
107
+ appContext: true,
108
+ appQuery: _api.appQuery,
109
+ envContext: true,
110
+ requiredArgs: 1,
111
+ usage: `${baseUsage} <VARIABLE_NAME>`
112
+ }).option('from-file', 'Read environment variable value from file (useful for multiline input)').option('skip-confirmation', 'Skip manual confirmation of input (USE WITH CAUTION)', false).examples(examples).argv(process.argv, setEnvVarCommand);
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ "use strict";
16
+
17
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
18
+
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+
21
+ (0, _command.default)({
22
+ requiredArgs: 1
23
+ }).command('delete', 'Permanently delete an environment variable').command('get', 'Get the value of an environment variable').command('get-all', 'Get the values of all environment variable').command('list', 'List the names of all environment variables').command('set', 'Add or update an environment variable').argv(process.argv);
@@ -0,0 +1,20 @@
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
+
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ (0, _command.default)({
17
+ requiredArgs: 2
18
+ }).command('envvar', 'Manage environment variables for an application environment').argv(process.argv, async () => {
19
+ process.exit(0);
20
+ });
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  *
5
- * @fomat
5
+ * @format
6
6
  */
7
7
 
8
8
  /**
@@ -33,8 +33,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
33
  /**
34
34
  * Internal dependencies
35
35
  */
36
- const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment'); // Command examples
37
-
36
+ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
38
37
  const examples = [{
39
38
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create`,
40
39
  description: 'Creates a local dev environment'
@@ -46,16 +45,28 @@ const examples = [{
46
45
  description: 'Creates a local dev environment for prodaction site for id 123 aliased as "my_site"'
47
46
  }, {
48
47
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create --slug test`,
49
- description: 'Creates a blank local dev environment with custom name "test", this enables to create multiple independend environments'
48
+ description: 'Creates a blank local dev environment with custom name "test", this enables to create multiple independent environments'
50
49
  }, {
51
- usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create --multisite --wordpress "5.6" --client-code "~/git/my_code"`,
52
- description: 'Creates a local dev environment that is multisite and is using WP 5.6 and client code is expected to be in "~/git/my_code"'
50
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} create --multisite --wordpress "5.8" --client-code "~/git/my_code"`,
51
+ description: 'Creates a local multisite dev environment using WP 5.8 and client code is expected to be in "~/git/my_code"'
53
52
  }];
54
53
  (0, _command.default)().option('slug', 'Custom name of the dev environment').option('title', 'Title for the WordPress site (default: "VIP Dev")').option('multisite', 'Enable multisite install', undefined, value => {
55
54
  var _value$toLowerCase;
56
55
 
57
56
  return 'false' !== (value === null || value === void 0 ? void 0 : (_value$toLowerCase = value.toLowerCase) === null || _value$toLowerCase === void 0 ? void 0 : _value$toLowerCase.call(value));
58
- }).option('php', 'Use a specific PHP version').option('wordpress', 'Use a specific WordPress version or local directory (default: last stable)').option('mu-plugins', 'Use a specific mu-plugins changeset or local directory (default: "auto": last commit in master)').option('client-code', 'Use the client code from a local directory or VIP skeleton (default: use the VIP skeleton)').examples(examples).argv(process.argv, async (arg, opt) => {
57
+ }).option('wordpress', 'Use a specific WordPress version or local directory (default: last stable)').option(['u', 'mu-plugins'], 'Use a specific mu-plugins changeset or local directory (default: "auto": last commit in master)').option('client-code', 'Use the client code from a local directory or VIP skeleton (default: use the VIP skeleton)').option('statsd', 'Enable statsd component. By default it is disabled', undefined, value => {
58
+ var _value$toLowerCase2;
59
+
60
+ return 'false' !== (value === null || value === void 0 ? void 0 : (_value$toLowerCase2 = value.toLowerCase) === null || _value$toLowerCase2 === void 0 ? void 0 : _value$toLowerCase2.call(value));
61
+ }).option('phpmyadmin', 'Enable PHPMyAdmin component. By default it is disabled', undefined, value => {
62
+ var _value$toLowerCase3;
63
+
64
+ return 'false' !== (value === null || value === void 0 ? void 0 : (_value$toLowerCase3 = value.toLowerCase) === null || _value$toLowerCase3 === void 0 ? void 0 : _value$toLowerCase3.call(value));
65
+ }).option('xdebug', 'Enable XDebug. By default it is disabled', undefined, value => {
66
+ var _value$toLowerCase4;
67
+
68
+ return 'false' !== (value === null || value === void 0 ? void 0 : (_value$toLowerCase4 = value.toLowerCase) === null || _value$toLowerCase4 === void 0 ? void 0 : _value$toLowerCase4.call(value));
69
+ }).option('elasticsearch', 'Explicitly choose Elasticsearch version to use').option('mariadb', 'Explicitly choose MariaDB version to use').option('media-redirect-domain', 'Domain to redirect for missing media files. This can be used to still have images without the need to import them locally.').examples(examples).argv(process.argv, async (arg, opt) => {
59
70
  const slug = (0, _devEnvironmentCli.getEnvironmentName)(opt);
60
71
  debug('Args: ', arg, 'Options: ', opt);
61
72
 
@@ -74,15 +85,19 @@ const examples = [{
74
85
  if (opt.app) {
75
86
  appInfo = await (0, _devEnvironmentCore.getApplicationInformation)(opt.app, opt.env);
76
87
  }
77
- } catch (e) {
88
+ } catch (error) {
78
89
  const message = `failed to fetch application "${opt.app}" information`;
79
- debug(`WARNING: ${message}`, e.message);
90
+ debug(`WARNING: ${message}`, error.message);
80
91
  console.log(_chalk.default.yellow('Warning:'), message);
81
92
  }
82
93
 
83
94
  const instanceData = await (0, _devEnvironmentCli.promptForArguments)(opt, appInfo);
84
95
  const instanceDataWithSlug = { ...instanceData,
85
- siteSlug: slug
96
+ siteSlug: slug,
97
+ statsd: opt.statsd || false,
98
+ phpmyadmin: opt.phpmyadmin || false,
99
+ xdebug: opt.xdebug || false,
100
+ mediaRedirectDomain: opt.mediaRedirectDomain || ''
86
101
  };
87
102
 
88
103
  try {
@@ -90,7 +105,7 @@ const examples = [{
90
105
  await (0, _devEnvironmentCore.printEnvironmentInfo)(slug);
91
106
  const message = '\n' + _chalk.default.green('✓') + ` environment created.\n\nTo start it please run:\n\n${startCommand}\n`;
92
107
  console.log(message);
93
- } catch (e) {
94
- exit.withError(e.message);
108
+ } catch (error) {
109
+ exit.withError(error.message);
95
110
  }
96
111
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  *
5
- * @fomat
5
+ * @format
6
6
  */
7
7
 
8
8
  /**
@@ -33,11 +33,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
33
  /**
34
34
  * Internal dependencies
35
35
  */
36
- const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment'); // Command examples
37
-
36
+ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
38
37
  const examples = [{
39
38
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} destroy`,
40
- description: 'Destroys a default local dev environment'
39
+ description: 'Destroys the default local dev environment'
41
40
  }, {
42
41
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} destroy --slug foo`,
43
42
  description: 'Destroys a local dev environment named foo'
@@ -49,9 +48,9 @@ const examples = [{
49
48
  try {
50
49
  const removeFiles = !(opt.soft || false);
51
50
  await (0, _devEnvironmentCore.destroyEnvironment)(slug, removeFiles);
52
- const message = _chalk.default.green('✓') + ' environment destroyed.\n';
51
+ const message = _chalk.default.green('✓') + ' Environment destroyed.\n';
53
52
  console.log(message);
54
- } catch (e) {
55
- exit.withError(e.message);
53
+ } catch (error) {
54
+ exit.withError(error.message);
56
55
  }
57
56
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  *
5
- * @fomat
5
+ * @format
6
6
  */
7
7
 
8
8
  /**
@@ -24,7 +24,6 @@ var _devEnvironment = require("../lib/constants/dev-environment");
24
24
 
25
25
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
26
 
27
- // Command examples
28
27
  const examples = [{
29
28
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} exec -- wp post list`,
30
29
  description: 'Use dev-environment to run `wp post list`'
@@ -41,22 +40,22 @@ const examples = [{
41
40
  const slug = (0, _devEnvironmentCli.getEnvironmentName)(opt);
42
41
 
43
42
  try {
44
- // to avoid confusion let's enforce -- as a spliter for arguments for this command and wp itself
45
- const argSpliterIx = process.argv.findIndex(argument => '--' === argument);
46
- const argSpliterFound = argSpliterIx > -1;
43
+ // to avoid confusion let's enforce -- as a splitter for arguments for this command and wp itself
44
+ const argSplitterIx = process.argv.findIndex(argument => '--' === argument);
45
+ const argSplitterFound = argSplitterIx > -1;
47
46
 
48
- if (unmatchedArgs.length > 0 && !argSpliterFound) {
47
+ if (unmatchedArgs.length > 0 && !argSplitterFound) {
49
48
  throw new Error('Please provide "--" argument to separate arguments for "vip" and command to be executed (see "--help" for examples)');
50
49
  }
51
50
 
52
51
  let arg = [];
53
52
 
54
- if (argSpliterFound && argSpliterIx + 1 < process.argv.length) {
55
- arg = process.argv.slice(argSpliterIx + 1);
53
+ if (argSplitterFound && argSplitterIx + 1 < process.argv.length) {
54
+ arg = process.argv.slice(argSplitterIx + 1);
56
55
  }
57
56
 
58
57
  await (0, _devEnvironmentCore.exec)(slug, arg);
59
- } catch (e) {
60
- (0, _devEnvironmentCli.handleCLIException)(e);
58
+ } catch (error) {
59
+ (0, _devEnvironmentCli.handleCLIException)(error);
61
60
  }
62
61
  });
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ "use strict";
16
+
17
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
18
+
19
+ var _devEnvironmentCli = require("../lib/dev-environment/dev-environment-cli");
20
+
21
+ var _devEnvironmentCore = require("../lib/dev-environment/dev-environment-core");
22
+
23
+ var _devEnvironment = require("../lib/constants/dev-environment");
24
+
25
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26
+
27
+ const examples = [{
28
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import media path/to/wp-content/uploads`,
29
+ description: 'Import contents of the given WP uploads folder file into the media library of the default dev environment'
30
+ }, {
31
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import media path/to/wp-content/uploads --slug mysite`,
32
+ description: 'Import contents of the given WP uploads folder file into the media library of a dev environment named `mysite`'
33
+ }];
34
+ (0, _command.default)({
35
+ requiredArgs: 1
36
+ }).examples(examples).option('slug', 'Custom name of the dev environment').argv(process.argv, async (unmatchedArgs, opt) => {
37
+ const [filePath] = unmatchedArgs;
38
+ const slug = (0, _devEnvironmentCli.getEnvironmentName)(opt);
39
+
40
+ try {
41
+ await (0, _devEnvironmentCore.importMediaPath)(slug, filePath);
42
+ } catch (error) {
43
+ (0, _devEnvironmentCli.handleCLIException)(error);
44
+ }
45
+ });
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+ "use strict";
12
+
13
+ var _fs = _interopRequireDefault(require("fs"));
14
+
15
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
16
+
17
+ var _devEnvironmentCli = require("../lib/dev-environment/dev-environment-cli");
18
+
19
+ var _devEnvironmentCore = require("../lib/dev-environment/dev-environment-core");
20
+
21
+ var _devEnvironment = require("../lib/constants/dev-environment");
22
+
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24
+
25
+ /**
26
+ * Internal dependencies
27
+ */
28
+ const examples = [{
29
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import sql some-wp-db-file.sql`,
30
+ description: 'Import the contents of a WordPress database from an SQL file'
31
+ }, {
32
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import sql wordpress.sql --slug my_site`,
33
+ description: 'Import the contents of a WordPress database from an SQL file into `my_site`'
34
+ }, {
35
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import sql wordpress.sql --search-replace="testsite.com,test-site.go-vip.net"`,
36
+ description: 'Import the contents of a WordPress database from an SQL file and replace the occurrences of `testsite.com` with `test-site.go-vip.net`'
37
+ }, {
38
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import sql wordpress.sql --search-replace="testsite.com,test-site.go-vip.net" --in-place`,
39
+ description: 'Import the contents of a WordPress database from an SQL file and replace the occurrences of `testsite.com` with `test-site.go-vip.net` in place (modifies the original SQL file)'
40
+ }];
41
+ (0, _command.default)({
42
+ requiredArgs: 1
43
+ }).option('slug', 'Custom name of the dev environment').option('search-replace', 'Perform Search and Replace on the specified SQL file').option('in-place', 'Search and Replace explicitly on the given input file').examples(examples).argv(process.argv, async (unmatchedArgs, opt) => {
44
+ const [fileName] = unmatchedArgs;
45
+ const {
46
+ searchReplace,
47
+ inPlace
48
+ } = opt;
49
+ const slug = (0, _devEnvironmentCli.getEnvironmentName)(opt);
50
+
51
+ try {
52
+ const {
53
+ resolvedPath,
54
+ inContainerPath
55
+ } = await (0, _devEnvironmentCore.resolveImportPath)(slug, fileName, searchReplace, inPlace);
56
+ const importArg = ['wp', 'db', 'import', inContainerPath];
57
+ await (0, _devEnvironmentCore.exec)(slug, importArg);
58
+
59
+ if (searchReplace && searchReplace.length && !inPlace) {
60
+ _fs.default.unlinkSync(resolvedPath);
61
+ }
62
+
63
+ const cacheArg = ['wp', 'cache', 'flush'];
64
+ await (0, _devEnvironmentCore.exec)(slug, cacheArg);
65
+ const addUserArg = ['wp', 'user', 'create', 'vipgo', 'vipgo@go-vip.net', '--user_pass=password', '--role=administrator'];
66
+ await (0, _devEnvironmentCore.exec)(slug, addUserArg);
67
+ } catch (error) {
68
+ (0, _devEnvironmentCli.handleCLIException)(error);
69
+ }
70
+ });
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ *
5
+ * @format
6
+ */
7
+
8
+ /**
9
+ * External dependencies
10
+ */
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ "use strict";
16
+
17
+ var _command = _interopRequireDefault(require("../lib/cli/command"));
18
+
19
+ var _devEnvironment = require("../lib/constants/dev-environment");
20
+
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+
23
+ const examples = [{
24
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import sql file.sql`,
25
+ description: 'Import the given SQL file to your site'
26
+ }, {
27
+ usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} import media path/to/wp-content/uploads`,
28
+ description: 'Import contents of the given WP uploads folder file into the media library of the default dev environment'
29
+ }];
30
+ (0, _command.default)({
31
+ requiredArgs: 1
32
+ }).examples(examples).command('sql', 'Import SQL to your dev-env database from a file').command('media', 'Import media files to the dev environment of your application from a compressed web archive. ' + 'This command will copy the contents of a folder to the `uploads` folder of the target dev environment.').argv(process.argv);
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  *
5
- * @fomat
5
+ * @format
6
6
  */
7
7
 
8
8
  /**
@@ -25,8 +25,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
25
25
  /**
26
26
  * Internal dependencies
27
27
  */
28
- const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment'); // Command examples
29
-
28
+ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment');
30
29
  const examples = [{
31
30
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} info -all`,
32
31
  description: 'Return information about all local dev environments'
@@ -37,7 +36,7 @@ const examples = [{
37
36
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} info -slug my_site`,
38
37
  description: 'Return information about a local dev environment named "my_site"'
39
38
  }];
40
- (0, _command.default)().option('slug', 'Custom name of the dev environment').option('all', 'Show Info for all local dev environemnts').examples(examples).argv(process.argv, async (arg, opt) => {
39
+ (0, _command.default)().option('slug', 'Custom name of the dev environment').option('all', 'Show Info for all local dev environments').examples(examples).argv(process.argv, async (arg, opt) => {
41
40
  const slug = (0, _devEnvironmentCli.getEnvironmentName)(opt);
42
41
  debug('Args: ', arg, 'Options: ', opt);
43
42
 
@@ -47,7 +46,7 @@ const examples = [{
47
46
  } else {
48
47
  await (0, _devEnvironmentCore.printEnvironmentInfo)(slug);
49
48
  }
50
- } catch (e) {
51
- (0, _devEnvironmentCli.handleCLIException)(e);
49
+ } catch (error) {
50
+ (0, _devEnvironmentCli.handleCLIException)(error);
52
51
  }
53
52
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  /**
4
4
  *
5
- * @fomat
5
+ * @format
6
6
  */
7
7
 
8
8
  /**
@@ -10,8 +10,12 @@
10
10
  */
11
11
  "use strict";
12
12
 
13
+ var _chalk = _interopRequireDefault(require("chalk"));
14
+
13
15
  var _debug = _interopRequireDefault(require("debug"));
14
16
 
17
+ var _child_process = require("child_process");
18
+
15
19
  var _command = _interopRequireDefault(require("../lib/cli/command"));
16
20
 
17
21
  var _devEnvironmentCore = require("../lib/dev-environment/dev-environment-core");
@@ -25,8 +29,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
25
29
  /**
26
30
  * Internal dependencies
27
31
  */
28
- const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment'); // Command examples
32
+ const debug = (0, _debug.default)('@automattic/vip:bin:dev-environment'); // PowerShell command for Windows Docker patch
29
33
 
34
+ const dockerWindowsPathCmd = 'wsl -d docker-desktop bash -c "sysctl -w vm.max_map_count=262144"';
30
35
  const examples = [{
31
36
  usage: `${_devEnvironment.DEV_ENVIRONMENT_FULL_COMMAND} start`,
32
37
  description: 'Starts a local dev environment'
@@ -39,8 +44,23 @@ const examples = [{
39
44
  };
40
45
 
41
46
  try {
47
+ if (process.platform === 'win32') {
48
+ debug('Windows platform detected. Applying Docker patch...');
49
+ (0, _child_process.exec)(dockerWindowsPathCmd, {
50
+ shell: 'powershell.exe'
51
+ }, (error, stdout) => {
52
+ if (error != null) {
53
+ debug(error);
54
+ console.log(`${_chalk.default.red('✕')} There was an error while applying the Windows Docker patch.`);
55
+ } else {
56
+ debug(stdout);
57
+ console.log(`${_chalk.default.green('✓')} Docker patch for Windows applied.`);
58
+ }
59
+ });
60
+ }
61
+
42
62
  await (0, _devEnvironmentCore.startEnvironment)(slug, options);
43
- } catch (e) {
44
- (0, _devEnvironmentCli.handleCLIException)(e);
63
+ } catch (error) {
64
+ (0, _devEnvironmentCli.handleCLIException)(error);
45
65
  }
46
66
  });