wp-blank-scripts 2.5.0 → 2.6.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/cli/deploy.js CHANGED
@@ -63,24 +63,20 @@ async function selectOptions() {
63
63
  message: answers => {
64
64
  const user = settings.server[answers.environment].user;
65
65
  const host = settings.server[answers.environment].host;
66
- return chalk.cyan(
67
- `Enter the path to your private key for user ${user} on host ${host}`
68
- );
66
+ return chalk.cyan(`Enter the path to your private key for user ${user} on host ${host}`);
69
67
  },
70
68
  default: '~/.ssh/id_rsa',
71
69
  type: 'input',
72
- when: answers =>
73
- (answers.sql || answers.mode === DEPLOY_MODES.SQL_ONLY) &&
74
- !answers.serverPassword,
70
+ when: answers => !answers.serverPassword,
75
71
  },
76
72
  ]);
77
73
 
78
74
  // Update options
79
75
  options.environment = selectedOptions.environment;
80
76
  options.mode = selectedOptions.mode || DEPLOY_MODES.SITE;
81
- options.sql =
82
- selectedOptions.sql || selectedOptions.mode === DEPLOY_MODES.SQL_ONLY;
77
+ options.sql = selectedOptions.sql || selectedOptions.mode === DEPLOY_MODES.SQL_ONLY;
83
78
  options.serverPassword = selectedOptions.serverPassword;
79
+ options.serverPrivateKey = selectedOptions.serverPrivateKey;
84
80
 
85
81
  // Only confirm options if they were entered via inquirer
86
82
  if (options.didPrompt && !optionsConfirmed) {
@@ -92,10 +88,7 @@ async function confirmOptions(selectedOptions) {
92
88
  const deploymentOptinos = [
93
89
  ['Environment', selectedOptions.environment],
94
90
  ['Mode', selectedOptions.mode],
95
- [
96
- 'SQL',
97
- selectedOptions.sql || selectedOptions.mode === DEPLOY_MODES.SQL_ONLY,
98
- ],
91
+ ['SQL', selectedOptions.sql || selectedOptions.mode === DEPLOY_MODES.SQL_ONLY],
99
92
  ];
100
93
 
101
94
  const { confirm } = await inquirer.prompt([
@@ -118,9 +111,9 @@ async function confirmOptions(selectedOptions) {
118
111
  }
119
112
 
120
113
  async function promptForCommit(options, unstagedFiles) {
121
- let warningMessage = `You are deploying changes with ${
122
- unstagedFiles.length
123
- } uncommitted file${unstagedFiles.length > 1 ? 's' : ''}`;
114
+ let warningMessage = `You are deploying changes with ${unstagedFiles.length} uncommitted file${
115
+ unstagedFiles.length > 1 ? 's' : ''
116
+ }`;
124
117
 
125
118
  logger.warn(warningMessage);
126
119
 
package/cli/import.js CHANGED
@@ -1,24 +1,12 @@
1
- const glob = require('glob');
2
- const fs = require('fs');
3
-
4
1
  const importSQL = require('../lib/importSQL');
5
2
  const logger = require('../logger');
6
3
  const getCliOptions = require('../utils/getCliOptions');
7
- const getSettings = require('../utils/projectSettings');
8
4
  const exitWithError = require('../utils/exitWithError');
9
- const settings = getSettings();
5
+ const getMostRecentSqlFile = require('../utils/getMostRecentSqlFile');
10
6
 
11
7
  // Constants
12
8
  const { ENV_OPTIONS, SQL_FILE_NAME_ENV } = require('../constants');
13
9
 
14
- function getMostRecentFile(files) {
15
- const sortedFiles = [...files].sort((a, b) => {
16
- return fs.statSync(b).mtime - fs.statSync(a).mtime;
17
- });
18
-
19
- return sortedFiles[0];
20
- }
21
-
22
10
  function getEnvironmentFromFileName(file) {
23
11
  let env;
24
12
 
@@ -33,10 +21,6 @@ function getEnvironmentFromFileName(file) {
33
21
  }
34
22
 
35
23
  module.exports = async () => {
36
- // Sql search
37
- const sqlDir = settings.directories.sql;
38
- const sqlFiles = glob.sync(`${sqlDir}/**/*.sql`);
39
-
40
24
  try {
41
25
  const options = await getCliOptions([
42
26
  {
@@ -75,7 +59,7 @@ module.exports = async () => {
75
59
  if (options.file === 'latest' && sqlFiles.length > 0) {
76
60
  // If latest is passed, grab the file and work out what environment it's for.
77
61
  // Then update the options with the new values
78
- const file = getMostRecentFile(sqlFiles);
62
+ const file = getMostRecentSqlFile();
79
63
 
80
64
  if (file) {
81
65
  options.file = file;
@@ -0,0 +1,159 @@
1
+ const chalk = require('chalk');
2
+ const inquirer = require('inquirer');
3
+
4
+ const addSettings = require('../lib/addSettings');
5
+
6
+ const logger = require('../logger');
7
+ const getCliOptions = require('../utils/getCliOptions');
8
+ const exitWithError = require('../utils/exitWithError');
9
+
10
+ // Constants
11
+ const { DEPLOY_OPTIONS } = require('../constants');
12
+
13
+ async function confirmOptions(options) {
14
+ const environment = options.environment;
15
+ let projectSettings;
16
+ if (environment === 'production') {
17
+ projectSettings = [
18
+ ['Environment', options.environment],
19
+ ['URL', options.urlProduction],
20
+ ['Host', options.hostProduction],
21
+ ['Host Username', options.userProduction],
22
+ ['Destination', options.destinationProduction],
23
+ ['DB Name', options.dbNameProduction],
24
+ ['DB Username', options.dbUserNameProduction],
25
+ ['DB Password', options.dbPasswordProduction],
26
+ ];
27
+ }
28
+ if (environment === 'staging') {
29
+ projectSettings = [
30
+ ['Environment', options.environment],
31
+ ['URL', options.urlStaging],
32
+ ['Host', options.hostStaging],
33
+ ['Host Username', options.userStaging],
34
+ ['Destination', options.destinationStaging],
35
+ ['DB Name', options.dbNameStaging],
36
+ ['DB Username', options.dbUserNameStaging],
37
+ ['DB Password', options.dbPasswordStaging],
38
+ ];
39
+ }
40
+
41
+ const res = await inquirer.prompt([
42
+ {
43
+ name: 'confirm',
44
+ message: `Please confirm your project settings:\n${projectSettings
45
+ .map(([title, value]) => `${chalk.yellow(title)}: ${value}`)
46
+ .join('\n')}`,
47
+ type: 'confirm',
48
+ default: false,
49
+ },
50
+ ]);
51
+
52
+ return res.confirm;
53
+ }
54
+
55
+ module.exports = async () => {
56
+ try {
57
+ const options = await getCliOptions([
58
+ {
59
+ name: 'environment',
60
+ message: 'What environment are you adding settings for?',
61
+ choices: DEPLOY_OPTIONS,
62
+ type: 'list',
63
+ },
64
+ {
65
+ name: 'urlProduction',
66
+ message: 'What is the production URL?',
67
+ when: answers => answers.environment === 'production',
68
+ },
69
+ {
70
+ name: 'hostProduction',
71
+ message: 'What is the production server host?',
72
+ when: answers => answers.environment === 'production',
73
+ },
74
+ {
75
+ name: 'userProduction',
76
+ message: 'What is the production server user?',
77
+ when: answers => answers.environment === 'production',
78
+ },
79
+ {
80
+ name: 'destinationProduction',
81
+ message: 'What is the production path?',
82
+ when: answers => answers.environment === 'production',
83
+ default: answers => {
84
+ const user = answers.userProduction;
85
+ return `/home/${user}/public_html`;
86
+ },
87
+ },
88
+ {
89
+ name: 'dbNameProduction',
90
+ message: 'Production database name?',
91
+ when: answers => answers.environment === 'production',
92
+ },
93
+ {
94
+ name: 'dbUserNameProduction',
95
+ message: 'Production database username?',
96
+ when: answers => answers.environment === 'production',
97
+ },
98
+ {
99
+ name: 'dbPasswordProduction',
100
+ message: 'Production database password?',
101
+ when: answers => answers.environment === 'production',
102
+ },
103
+ {
104
+ name: 'urlStaging',
105
+ message: 'What is the staging URL?',
106
+ when: answers => answers.environment === 'staging',
107
+ },
108
+ {
109
+ name: 'hostStaging',
110
+ message: 'What is the staging server host?',
111
+ when: answers => answers.environment === 'staging',
112
+ default: 'staging.vivo.digital',
113
+ },
114
+ {
115
+ name: 'userStaging',
116
+ message: 'What is the staging server user?',
117
+ when: answers => answers.environment === 'staging',
118
+ default: 'stagingvivo',
119
+ },
120
+ {
121
+ name: 'destinationStaging',
122
+ message: 'What is the staging path?',
123
+ when: answers => answers.environment === 'staging',
124
+ default: answers => {
125
+ const user = answers.userStaging;
126
+ let url = answers.urlStaging;
127
+ url = url && url.replace('https://', '');
128
+ url = url && url.replace('/', '');
129
+ return `/home/${user}/${url}`;
130
+ },
131
+ },
132
+ {
133
+ name: 'dbNameStaging',
134
+ message: 'Staging database name?',
135
+ when: answers => answers.environment === 'staging',
136
+ },
137
+ {
138
+ name: 'dbUserNameStaging',
139
+ message: 'Staging database username?',
140
+ when: answers => answers.environment === 'staging',
141
+ },
142
+ {
143
+ name: 'dbPasswordStaging',
144
+ message: 'Staging database password?',
145
+ when: answers => answers.environment === 'staging',
146
+ },
147
+ ]);
148
+
149
+ logger.log('Updating settings...');
150
+ const confirmed = options.didPrompt ? await confirmOptions(options) : true;
151
+
152
+ if (confirmed) {
153
+ await addSettings(options);
154
+ logger.success(`${options.environment} Settings updated!`);
155
+ }
156
+ } catch (err) {
157
+ exitWithError(err);
158
+ }
159
+ };
package/index.js CHANGED
@@ -11,8 +11,10 @@ const importSQL = require('./cli/import');
11
11
  const exportSQL = require('./cli/export');
12
12
  const pullSQL = require('./cli/pull');
13
13
  const upgrade = require('./cli/upgrade');
14
+ const settings = require('./cli/settings'); //@TODO rename... addDeployConfig
14
15
 
15
16
  const exitWithError = require('./utils/exitWithError');
17
+ const logger = require('./logger');
16
18
 
17
19
  const _ = () => {};
18
20
 
@@ -27,6 +29,7 @@ yargs
27
29
  }),
28
30
  build
29
31
  )
32
+
30
33
  .command('backup', 'Backup', backup) // sync
31
34
  .command(
32
35
  'setup',
@@ -122,6 +125,15 @@ yargs
122
125
  hooks
123
126
  )
124
127
  .command('upgrade', 'Upgrade to v0.4', _, upgrade)
128
+ .command(
129
+ 'settings',
130
+ 'Add Deployment Settings',
131
+ yargs =>
132
+ yargs.option('environment', {
133
+ describe: 'What environment are you adding settings for?',
134
+ }),
135
+ settings
136
+ )
125
137
  .help()
126
138
  .alias('h', 'help')
127
139
  .demandCommand()
@@ -0,0 +1,64 @@
1
+ const fs = require('fs');
2
+ const glob = require('glob');
3
+ const slugify = require('slugify');
4
+ const replace = require('replace-in-file');
5
+
6
+ const logger = require('../logger');
7
+ const getProjectPath = require('../utils/getProjectPath');
8
+
9
+ const getReplacements = options => {
10
+ if (options.environment === 'production') {
11
+ return [
12
+ ['{{url_production}}', options.urlProduction],
13
+ ['{{server_url_production}}', options.hostProduction],
14
+ ['{{server_username_production}}', options.userProduction],
15
+ ['{{server_destination_production}}', options.destinationProduction],
16
+ ['{{db_name_production}}', options.dbNameProduction],
17
+ ['{{db_username_production}}', options.dbUserNameProduction],
18
+ ['{{db_password_production}}', options.dbPasswordProduction],
19
+ ];
20
+ }
21
+ if (options.environment === 'staging') {
22
+ return [
23
+ ['{{url_staging}}', options.urlStaging],
24
+ ['{{server_url_staging}}', options.hostStaging],
25
+ ['{{server_username_staging}}', options.userStaging],
26
+ ['{{server_destination_staging}}', options.destinationStaging],
27
+ ['{{db_name_staging}}', options.dbNameStaging],
28
+ ['{{db_username_staging}}', options.dbUserNameStaging],
29
+ ['{{db_password_staging}}', options.dbPasswordStaging],
30
+ ];
31
+ }
32
+ return;
33
+ };
34
+
35
+ module.exports = async options => {
36
+ const projectPath = getProjectPath();
37
+ const filesToReplace = [
38
+ ...glob.sync('config/*', { cwd: projectPath, dot: true }),
39
+ ...glob.sync('src/**/*.php', { cwd: projectPath }),
40
+ ];
41
+
42
+ const replacements = getReplacements(options);
43
+
44
+ let files = filesToReplace;
45
+ if (getProjectPath() !== process.cwd()) {
46
+ // Check if the script is being run from outside of the project and then fix the paths
47
+ files = files.map(file => getProjectPath(file));
48
+ }
49
+
50
+ // Remove any files that don't exist
51
+ files = files.filter(fs.existsSync);
52
+
53
+ // Run sequentially to ensure replace only operates on one file at a time
54
+ for (var i = 0; i < replacements.length; i++) {
55
+ const [from, to] = replacements[i];
56
+ await replace({
57
+ files,
58
+ from: new RegExp(from, 'g'),
59
+ to,
60
+ });
61
+ }
62
+
63
+ logger.log('Made replacements');
64
+ };
@@ -4,15 +4,14 @@ const mysql = require('mysql');
4
4
  const Rsync = require('rsync');
5
5
 
6
6
  const exportSql = require('./exportSQL');
7
-
8
7
  const cleanShellPath = require('../utils/cleanShellPath');
9
8
  const tunnel = require('../utils/tunnelSsh');
10
9
  const git = require('../utils/git');
10
+ const getMostRecentSqlFile = require('../utils/getMostRecentSqlFile');
11
11
  const runProjectBuildTask = require('../utils/runProjectBuildTask');
12
12
  const bumpVersion = require('../utils/bumpVersion');
13
13
  const isCI = require('../utils/isCI');
14
14
  const { DEPLOY_MODES } = require('../constants');
15
-
16
15
  const getProjectPath = require('../utils/getProjectPath');
17
16
  const getSettings = require('../utils/projectSettings');
18
17
  const logger = require('../logger');
@@ -272,8 +271,14 @@ module.exports = async (selectOptions, callbacks) => {
272
271
  if (options.sql) {
273
272
  await createTunnel();
274
273
  await connectMySQL();
275
- const file = await exportSql({ environment: options.environment });
276
- await deployMySQL(file);
274
+ const file = isCI()
275
+ ? getMostRecentSqlFile()
276
+ : await exportSql({ environment: options.environment });
277
+
278
+ if (file) {
279
+ await deployMySQL(file);
280
+ }
281
+
277
282
  await disconnectMySQL();
278
283
  }
279
284
 
package/lib/index.js CHANGED
@@ -5,6 +5,7 @@ const devProject = require('./devProject');
5
5
  const exportSQL = require('./exportSQL');
6
6
  const importSQL = require('./importSQL');
7
7
  const setupProject = require('./setupProject');
8
+ const addSettings = require('./addSettings');
8
9
 
9
10
  module.exports = {
10
11
  backupProject,
@@ -14,4 +15,5 @@ module.exports = {
14
15
  exportSQL,
15
16
  importSQL,
16
17
  setupProject,
18
+ addSettings,
17
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-blank-scripts",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "Personal Wordpress Scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -0,0 +1,22 @@
1
+ const glob = require('glob');
2
+ const fs = require('fs');
3
+
4
+ const getSettings = require('./projectSettings');
5
+
6
+ function getMostRecentFile(files) {
7
+ const sortedFiles = [...files].sort((a, b) => {
8
+ return fs.statSync(b).mtime - fs.statSync(a).mtime;
9
+ });
10
+
11
+ return sortedFiles[0];
12
+ }
13
+
14
+ function getMostRecentSqlFile() {
15
+ const settings = getSettings();
16
+ const sqlDir = settings.directories.sql;
17
+ const sqlFiles = glob.sync(`${sqlDir}/**/*.sql`);
18
+
19
+ return getMostRecentFile(sqlFiles);
20
+ }
21
+
22
+ module.exports = getMostRecentSqlFile