This repository was archived by the owner on Sep 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsaofile.js
More file actions
172 lines (161 loc) · 5.11 KB
/
saofile.js
File metadata and controls
172 lines (161 loc) · 5.11 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const path = require('path');
const { exec } = require('child_process');
module.exports = {
prompts: [
{
name: 'name',
type: 'string',
message: 'Project name',
default: 'www.fqdn.com',
},
{
name: 'slug',
type: 'string',
message: 'Project slug (used as plugins prefix and theme name)',
default: 'studiometa',
},
{
name: 'url',
type: 'string',
message: 'Project URL',
default: ({ name }) => `https://${name}`,
},
{
name: 'description',
type: 'string',
message: 'Project description',
default: ({ url }) => `Repository for ${url}.`,
},
{
name: 'hub',
message: 'Where is the project’s repository?',
type: 'list',
choices: [
{ name: 'GitLab', value: 'git@gitlab.com:studiometa' },
{ name: 'GitHub', value: 'git@github.com:studiometa' },
],
default: 'git@gitlab.com:studiometa',
},
{
name: 'repository',
type: 'string',
message: 'Project repository',
default: ({ name, hub }) => `${hub}/${name}.git`,
},
{
name: 'features',
message: 'Choose features to add',
type: 'checkbox',
choices: [
{ name: 'ACF', value: 'acf' },
{ name: 'Classic editor', value: 'classicEditor' },
{ name: 'Wordfence', value: 'wordfence' },
{ name: 'WP Rocket', value: 'wpRocket' },
{ name: 'Rank Math', value: 'rankMath' },
],
default: ['acf', 'wpRocket', 'classicEditor'],
},
],
templateData() {
const { features } = this.answers;
const acf = features.includes('acf');
const classicEditor = features.includes('classicEditor');
const wordfence = features.includes('wordfence');
const wpRocket = features.includes('wpRocket');
const rankMath = features.includes('rankMath');
return {
acf,
classicEditor,
wordfence,
wpRocket,
rankMath,
};
},
actions() {
const actions = [
{
type: 'add',
files: '**',
filters: {
'*.DS_Store': false,
'/node_modules/*': false,
'/vendor/*': false,
},
templateDir: 'template',
},
{
type: 'move',
patterns: {
'web/wp-content/themes/<%= slug %>': `web/wp-content/themes/${this.answers.slug}`,
_gitattributes: '.gitattributes',
_gitignore: '.gitignore',
},
},
];
// Remove GitLab files based on the selected hub
if (!this.answers.hub.includes('gitlab.com')) {
actions.push({
type: 'remove',
files: '.gitlab-ci.yml',
});
}
// Remove `ACFManager` if ACF has not been selected
if (!this.answers.features.includes('acf')) {
actions.push({
type: 'remove',
files: 'web/wp-content/themes/<%= slug %>/app/Managers/ACFManager.php',
});
}
return actions;
},
async completed() {
const { outDir } = this.sao.opts;
// Allow execution of the shell scripts
[
'bin/cleanup-composer-install.sh',
'bin/db-export.sh',
'bin/db-import.sh',
'bin/generate-wp-config.sh',
'bin/get-wp-salts.sh',
].forEach((file) => {
this.fs.chmodSync(path.resolve(outDir, file), 0o765);
});
// Execute installation related shell scripts
['bin/generate-wp-config.sh'].forEach((file) => {
exec(path.resolve(outDir, file));
});
// Init Git and install NPM dependencies
this.gitInit();
await this.npmInstall({ npmClient: 'npm' });
// Display useful informations
const { chalk } = this;
const isNewFolder = this.outDir !== process.cwd();
const relativeOutFolder = path.relative(process.cwd(), this.outDir);
const tab = ' ';
console.log();
console.log(chalk`${tab}🎉 {bold Successfully created project} {cyan ${this.answers.name}}!`);
console.log();
console.log(chalk`${tab}{bold To get started:}\n`);
if (isNewFolder) {
console.log(chalk`${tab}Go in your project's directory:`);
console.log(chalk`${tab}{cyan cd ${relativeOutFolder}}\n`);
}
console.log(chalk`${tab}Create your .env file based on .env.example and fill it:`);
console.log(chalk`${tab}{cyan cp .env.example .env}\n`);
console.log(chalk`${tab}Generate your project's salt keys:`);
console.log(chalk`${tab}{cyan bin/get-wp-salts.sh}\n`);
console.log(chalk`${tab}Install the composer dependencies:`);
console.log(chalk`${tab}{cyan composer install}\n`);
console.log(chalk`${tab}Create Database (using info from .env):`);
console.log(chalk`${tab}{cyan ./vendor/bin/wp db create}\n`);
console.log(chalk`${tab}Install WordPress:`);
console.log(
chalk`${tab}{cyan ./vendor/bin/wp core install --url="${this.answers.url}" --admin_user="<ADMIN_USER>" --admin_email="<ADMIN_EMAIL>" --title="<SITE_TITLE>"}\n`
);
console.log(chalk`${tab}Install development dependencies:`);
console.log(chalk`${tab}{cyan npm i}\n`);
console.log(chalk`${tab}Start the development server:`);
console.log(chalk`${tab}{cyan npm run dev}\n`);
console.log(chalk`${tab}🎊 {bold Happy coding!}\n`);
},
};