wp-blank-scripts 2.5.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/settings.js +159 -0
- package/index.js +12 -0
- package/lib/addSettings.js +64 -0
- package/lib/index.js +2 -0
- package/package.json +1 -1
package/cli/settings.js
ADDED
|
@@ -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
|
+
};
|
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
|
};
|