-
Notifications
You must be signed in to change notification settings - Fork 1
/
vip.js
60 lines (47 loc) · 1.6 KB
/
vip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const fs = require('fs-extra'),
path = require('path'),
replace = require('replace-in-file'),
mkdirp = require('mkdirp'),
chalk = require('chalk'),
pull = require('./pull.js'),
config = require('./package.json').config,
siteIsVIP = config.vip,
sourceFolder = path.resolve('src');
if (siteIsVIP) {
const wordpressFolder = path.resolve('.wp'),
vipFolders = [
'client-mu-plugins',
'images',
'languages',
'private',
'vip-config',
];
const wordpressVIPMuPlugins = `Automattic/vip-go-mu-plugins-built`;
const createFolderInWordpressContentFolder = (folderPath, done) => {
if (!done) {
done = (err) => {
if (err) console.error(err)
};
}
mkdirp(path.join(wordpressFolder, 'wp-content', folderPath), done);
}
if (fs.existsSync(wordpressFolder)) {
for (const folderPath of vipFolders) {
createFolderInWordpressContentFolder(folderPath);
}
pull(wordpressVIPMuPlugins, `${sourceFolder}/mu-plugins`);
// Add the vip-config to the wp-config
const editAfterString = `/* That's all, stop editing! Happy publishing. */`;
const insertWpConfigString = `if ( file_exists( __DIR__ . '/wp-content/vip-config/vip-config.php' ) ) {\r\trequire_once( __DIR__ . '/wp-content/vip-config/vip-config.php' );\r}`;
const replaceOptions = {
files: path.resolve(`${wordpressFolder}/wp-config.php`),
from: editAfterString,
to: `${insertWpConfigString}\r\n${editAfterString}`,
};
replace(replaceOptions).then((changes) => {
console.log(chalk.green('Wordpres Config Successfully Updated'));
})
} else {
console.error(chalk.red('wp folder does not exist'), wordpressFolder);
}
}