wp-blank-scripts 2.4.1 → 2.6.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.
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
 
@@ -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/cli/setup.js CHANGED
@@ -20,6 +20,7 @@ async function confirmOptions(options) {
20
20
  database,
21
21
  project,
22
22
  projectLocation,
23
+ projectSlug,
23
24
  agency,
24
25
  agencySlug,
25
26
  agencyWebsite,
@@ -29,6 +30,7 @@ async function confirmOptions(options) {
29
30
 
30
31
  const projectSettings = [
31
32
  ['Project Location', projectLocation],
33
+ ['Project Slug', projectSlug],
32
34
  ['Project Name', project],
33
35
  ['Agency', agency],
34
36
  ['Agency Slug', agencySlug],
@@ -61,6 +63,14 @@ async function selectOptions() {
61
63
  message: 'Where is the project located?',
62
64
  default: path.relative(documentRoot, getProjectPath()),
63
65
  },
66
+ {
67
+ name: 'projectSlug',
68
+ message: 'What is the project slug (folder name)?',
69
+ default: path
70
+ .relative(documentRoot, getProjectPath())
71
+ .split('/')
72
+ .pop(),
73
+ },
64
74
  {
65
75
  name: 'project',
66
76
  message: 'What is the project name?',
@@ -73,12 +83,12 @@ async function selectOptions() {
73
83
  },
74
84
  {
75
85
  name: 'agency',
76
- message: 'What\'s the name of the agency?',
86
+ message: "What's the name of the agency?",
77
87
  default: defaultAnswers.agency,
78
88
  },
79
89
  {
80
90
  name: 'agencySlug',
81
- message: 'What\'s the agency slug?',
91
+ message: "What's the agency slug?",
82
92
  default: defaultAnswers.agencySlug,
83
93
  },
84
94
  {
@@ -102,14 +112,9 @@ async function selectOptions() {
102
112
  database: slugify(`${res.agencySlug} ${res.project}`),
103
113
  // Ensure table prefix ends with an underscore
104
114
  tablePrefix:
105
- res.tablePrefix[res.tablePrefix.length - 1] === '_'
106
- ? res.tablePrefix
107
- : `${res.tablePrefix}_`,
115
+ res.tablePrefix[res.tablePrefix.length - 1] === '_' ? res.tablePrefix : `${res.tablePrefix}_`,
108
116
  // Make sure there is no protocol on the domain
109
- productionDomain: (res.productionDomain || '').replace(
110
- /^http(s?):\/\/(www.)?/,
111
- ''
112
- ),
117
+ productionDomain: (res.productionDomain || '').replace(/^http(s?):\/\/(www.)?/, ''),
113
118
  });
114
119
 
115
120
  // Only confirm options if they were entered via inquirer
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
+ };
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
  };
@@ -8,7 +8,7 @@ const getProjectPath = require('../utils/getProjectPath');
8
8
 
9
9
  const getReplacements = options => [
10
10
  ['{{projectLocation}}', options.projectLocation],
11
- ['{{project}}', slugify(options.project)],
11
+ ['{{projectSlug}}', slugify(options.projectSlug).toLowerCase()],
12
12
  ['{{projectName}}', options.project],
13
13
  ['{{agency}}', options.agency],
14
14
  ['{{agencySlug}}', options.agencySlug],
@@ -16,9 +16,11 @@ const getReplacements = options => [
16
16
  ['{{tablePrefix}}', options.tablePrefix],
17
17
  ['{{database}}', options.database],
18
18
  ['{{productionDomain}}', options.productionDomain],
19
+ ['{{productionDomain}}', options.productionDomain],
20
+ ['project-slug-package-json', slugify(options.projectSlug).toLowerCase()],
19
21
  ];
20
22
 
21
- module.exports = async (options) => {
23
+ module.exports = async options => {
22
24
  const projectPath = getProjectPath();
23
25
  const filesToReplace = [
24
26
  ...glob.sync('config/*', { cwd: projectPath, dot: true }),
@@ -28,6 +30,7 @@ module.exports = async (options) => {
28
30
  'README.md',
29
31
  'styleguide.html',
30
32
  'src/style.css',
33
+ 'app/config/index.js',
31
34
  ];
32
35
 
33
36
  const replacements = getReplacements(options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-blank-scripts",
3
- "version": "2.4.1",
3
+ "version": "2.6.0",
4
4
  "description": "Personal Wordpress Scripts",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -131,12 +131,6 @@ function makeBaseConfig(options) {
131
131
 
132
132
  if (fs.existsSync(mainStyleVariables)) {
133
133
  sassVariables = fs.readFileSync(mainStyleVariables, 'utf8');
134
- } else {
135
- logger.warn(
136
- `Could not find your SASS variables file. Please make sure it exists at ${chalk.yellow(
137
- 'assets/css/utils/variables.scss'
138
- )}`
139
- );
140
134
  }
141
135
 
142
136
  let loaderOverrides = {};