wp-lemon-create 1.3.2 → 1.3.3

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.
Files changed (2) hide show
  1. package/lib/index.js +344 -344
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -1,344 +1,344 @@
1
- /**
2
- * External dependencies
3
- */
4
- const { program } = require('commander');
5
- var shell = require('shelljs');
6
- const commandName = 'wp-lemon-create';
7
- const { engines, version } = require('../package.json');
8
- const prompt = require('prompt-sync')();
9
-
10
- program
11
- .name(commandName)
12
- .description(
13
- 'Generates PHP, JS and CSS code for registering a block for a WordPress plugin.\n\n' +
14
- '[slug] is optional. When provided it triggers the quick mode where ' +
15
- 'it is used as the block slug used for its identification, the output ' +
16
- 'location for scaffolded files, and the name of the WordPress plugin.' +
17
- 'The rest of the configuration is set to all default values unless ' +
18
- 'overridden with some of the options listed below.',
19
- )
20
- .version(version)
21
- .action((name, options, command) => {
22
- var project_repository = '';
23
- var username = '';
24
- var email = '';
25
- var password = '';
26
- var DBuser = '';
27
- var DBpassword = '';
28
- var is_wsl = false;
29
- var child_theme_folder = '';
30
- var plugins_searchwp = false;
31
- var plugins_wpml = false;
32
- var is_spinup = false;
33
- var skipGit = false;
34
- var branch = false;
35
-
36
- console.log(`Starting $${commandName} @${version}`);
37
-
38
- if (!shell.which('git')) {
39
- shell.echo('Sorry, this script requires git');
40
- shell.exit(1);
41
- }
42
- {
43
- shell.echo('✔️ Git installed');
44
- }
45
-
46
- if (!shell.which('composer')) {
47
- shell.echo('Sorry, this script requires composer');
48
- shell.exit(1);
49
- }
50
- {
51
- shell.echo('✔️ composer installed');
52
- }
53
-
54
- if (!shell.which('yarn')) {
55
- shell.echo('Sorry, this script requires yarn');
56
- shell.exit(1);
57
- }
58
- {
59
- shell.echo('✔️ yarn installed');
60
- }
61
-
62
- if (!shell.which('wp')) {
63
- shell.echo('Sorry, this script requires wp cli');
64
- shell.exit(1);
65
- }
66
- {
67
- shell.echo('✔️ wp-cli installed');
68
- }
69
-
70
- if (shell.exec('wp dotenv --help', { silent: true }).code !== 0) {
71
- shell.echo('Sorry, this script requires wp-cli dotenv package');
72
- shell.exit(1);
73
- }
74
- {
75
- shell.echo('✔️ wp-cli dotenv package installed');
76
- }
77
-
78
- if (shell.exec('grep -q Microsoft /proc/version', { silent: true }).code == 0) {
79
- is_wsl = true;
80
- }
81
-
82
- shell.echo('\n');
83
- const projectname = prompt('What is the project name (only lowercase and -, no spaces. Do not add tld (.local/.test):');
84
- child_theme_folder = projectname;
85
- const tld = prompt('What is the project tld? (defaults to .local):', '.local');
86
-
87
- const projecttype = prompt('Project type? new or existing (defaults to new):', 'new');
88
- shell.echo('\n');
89
-
90
- if (projecttype == 'new') {
91
- shell.echo('Please create a new Git repository and fill in the link in ssh format.');
92
- project_repository = prompt('Git repository link or enter "none" to skip GIT setup:', 'none');
93
- username = prompt('WordPress username:');
94
- email = prompt('WordPress email:');
95
- password = prompt('WordPress password:', { echo: '*' });
96
- plugins_searchwp = prompt('Add plugin: SearchWP? yes/no (defaults to no)', 'no');
97
- plugins_wpml = prompt('Add plugin: WPML? yes/no (defaults to no)', 'no');
98
- is_spinup = prompt('Does the project run on Spinup-wp? (defaults to no)', 'no');
99
-
100
- if (project_repository == 'none') {
101
- skipGit = true;
102
- }
103
- } else if (projecttype == 'existing') {
104
- project_repository = prompt('Existing repository link in ssh format:');
105
- branch = prompt('Branch to checkout (defaults to master):', 'master');
106
- } else {
107
- shell.echo('no valid command. Exiting.');
108
- shell.exit(1);
109
- }
110
-
111
- DBuser = prompt('Database user. Defaults to root:', 'root');
112
- DBpassword = prompt('Database password. Defaults to root:', 'root');
113
-
114
- shell.echo('\n');
115
- shell.echo(`🎉 Setting up ${projecttype} wp-lemon project with url ${projectname + tld}\n`);
116
-
117
- if (projecttype == 'new') {
118
- shell.echo('Downloading Bedrock. This may take a minute or so.\n');
119
-
120
- /**
121
- * cloning bedrock and removing unneeded dirs
122
- */
123
- shell.exec('composer create-project roots/bedrock .', { silent: true });
124
- shell.echo('✔️ Bedrock installed.\n');
125
- shell.rm('-rf', 'CHANGELOG.MD');
126
- shell.rm('-rf', 'LICENSE.MD');
127
- shell.rm('-rf', 'composer.lock');
128
-
129
- /**
130
- * Add bulldozer extended config
131
- */
132
- shell.sed('-i', 'env;', 'env;\nuse HighGround\\Bulldozer\\Bulldozer;\n\nBulldozer::extend_roots_config();', 'config/application.php');
133
-
134
- /**
135
- * configuring composer
136
- */
137
- shell.exec('composer config repositories.1 composer https://packagist.studiolemon.nl/satispress/', { silent: true });
138
-
139
- /**
140
- * Add composer packages
141
- */
142
- shell.echo('Installing plugins, master theme and packages. This may take a while\n');
143
-
144
- shell.exec('composer require composer/installers ~1.0', { silent: true });
145
-
146
- // Add libraries and parent theme
147
- shell.exec('composer require highground/bulldozer timber/timber satispress/wp-lemon --with-all-dependencies', { silent: true });
148
-
149
- shell.exec(
150
- 'composer require satispress/advanced-custom-fields-pro satispress/fluentformpro satispress/lemon-blocks satispress/quartermaster satispress/wp-migrate-db-pro satispress/wp-migrate-db-pro-media-files wpackagist-plugin/limit-login-attempts-reloaded log1x/acf-editor-palette wpackagist-plugin/cookie-law-info wpackagist-plugin/fluentform wpackagist-plugin/seo-by-rank-math wpackagist-plugin/simple-custom-post-order wpackagist-plugin/worker wpackagist-plugin/fluent-smtp --with-all-dependencies',
151
- { silent: true },
152
- );
153
-
154
- shell.exec('composer remove squizlabs/php_codesnifferes roave/security-advisories', { silent: true });
155
-
156
- if (is_spinup == 'yes') {
157
- shell.exec('composer require wpackagist-plugin/spinupwp', { silent: true });
158
- } else {
159
- shell.exec('composer require satispress/wp-rocket', { silent: true });
160
- }
161
-
162
- if (plugins_searchwp == 'yes') {
163
- shell.exec('composer require satispress/searchwp wpackagist-plugin/searchwp-live-ajax-search', { silent: true });
164
- }
165
-
166
- if (plugins_wpml == 'yes') {
167
- shell.exec('composer require satispress/sitepress-multilingual-cms satispress/acfml satispress/wpml-string-translation', { silent: true });
168
- }
169
-
170
- shell.echo('✔️ Installing plugins, master theme and packages done \n');
171
-
172
- /**
173
- * Git init & add repository
174
- */
175
- if (!skipGit) {
176
- shell.exec('git init', { silent: true });
177
- shell.exec(`git remote add origin ${project_repository}`);
178
- shell.echo(`✔️ Setting up empty local git repository and adding ${project_repository} as remote.\n`);
179
- }
180
-
181
- /**
182
- * Git ignore
183
- */
184
- shell.exec("echo '.vscode/*' >> .gitignore");
185
- shell.exec("echo 'web/app/themes/wp-lemon' >> .gitignore");
186
- shell.exec("echo 'web/app/wp-rocket-config/' >> .gitignore");
187
- shell.exec("echo 'web/app/cache' >> .gitignore");
188
-
189
- /**
190
- * Downloading child theme
191
- */
192
- shell.echo('Downloading child theme.\n');
193
- shell.cd('web/app/themes/');
194
-
195
- shell.exec(`composer create-project --repository https://packagist.studiolemon.nl/satispress/ satispress/wp-lemon-child ${child_theme_folder} --no-dev`, { silent: true });
196
-
197
- shell.cd(child_theme_folder);
198
- shell.rm('-rf', '.github');
199
- shell.echo('✔️ Downloading child theme succesful.');
200
- } else {
201
- /**
202
- * Task: existing project.
203
- */
204
- shell.echo(`Cloning repository from : ${project_repository}`);
205
-
206
- if (shell.exec(`git clone ${project_repository} .`).code !== 0) {
207
- shell.echo('Error: Git clone failed');
208
- shell.exit(1);
209
- }
210
-
211
- if (branch) {
212
- shell.echo(`Checking out branch: ${branch}`);
213
- shell.exec(`git checkout ${branch}`);
214
- }
215
-
216
- shell.cd('web/app/themes/');
217
- if (shell.cd(child_theme_folder).code !== 0) {
218
- shell.echo('Error: Child theme not found');
219
- var child_theme_folder = prompt('Folder name of child theme:');
220
- shell.cd(child_theme_folder);
221
- }
222
- }
223
- /**
224
- * Create child theme config file
225
- */
226
- shell.cp('resources/assets/config.json.example', 'resources/assets/config.json');
227
- shell.sed('-i', 'http://wplemon.local', `http://${projectname + tld}`, 'resources/assets/config.json');
228
- shell.sed('-i', 'wp-lemon-child', child_theme_folder, 'resources/assets/config.json');
229
- shell.sed('-i', 'wp-lemon child', projectname, 'style.css');
230
- shell.echo('✔️ Configuring child theme succesful.\n');
231
-
232
- /**
233
- * Installing node modules in child theme and parent theme.
234
- */
235
- shell.echo('Installing npm dependencies. This may take a while.\n');
236
- if (shell.exec(`yarn run bootstrap-project`, { silent: true }).code !== 0) {
237
- shell.echo('Error: yarn run bootstrap-project failed. Please install node dependencies manually by running yarn run bootstrap-project in your child theme.');
238
- } else {
239
- shell.echo('✔️ Installing npm dependencies succesful.');
240
- shell.exec(`yarn run dev`, { silent: true });
241
- shell.echo('✔️ First webpack build succesful.\n');
242
- }
243
-
244
- /**
245
- * Wait until user adds site and presses a key.
246
- */
247
- prompt('Script will generate .env file. Please add your new site to your AMP stack before pressing enter to continue.');
248
-
249
- /**
250
- * cd back to root folder.
251
- */
252
- shell.cd('../../../../');
253
-
254
- /**
255
- * reload host file so browsersync works without a restart.
256
- */
257
- if (is_wsl) {
258
- shell.exec('sudo cp /mnt/c/Windows/System32/drivers/etc/hosts /etc/hosts');
259
- }
260
-
261
- /**
262
- * Creating .env file
263
- */
264
- shell.echo('Creating .env file\n');
265
- shell.exec(`wp dotenv init --template=.env.example --with-salts`, { silent: true });
266
- shell.exec(`wp dotenv set DB_NAME ${projectname}`, { silent: true });
267
- shell.exec(`wp dotenv set DB_USER ${DBuser}`, { silent: true });
268
- shell.exec(`wp dotenv set DB_PASSWORD ${DBpassword}`, { silent: true });
269
- shell.exec(`wp dotenv set WP_HOME http://${projectname + tld}`, { silent: true });
270
- shell.exec(`wp dotenv salts generate`, { silent: true });
271
- shell.echo('✔️ Generating .env succesful.\n');
272
-
273
- if (is_wsl) {
274
- shell.echo('Uncommenting #DB_host and changing to 127.0.0.1 for allowing connection in WSL\n');
275
- shell.sed('-i', '# DB_HOST', 'DB_HOST', '.env');
276
- shell.sed('-i', 'localhost', '127.0.0.1', '.env');
277
- }
278
-
279
- if (projecttype == 'new') {
280
- shell.echo('Installing WordPress.\n');
281
-
282
- if (shell.exec(`wp db create`, { silent: true }).code !== 0) {
283
- shell.echo('Database creation failed.');
284
- } else {
285
- shell.echo('✔️ Database created');
286
- }
287
-
288
- if (
289
- shell.exec(
290
- `wp core install --skip-email --url="http://${projectname + tld}" --title="${projectname}" --admin_user="${username}" --admin_password="${password}" --admin_email="${email}"`,
291
- { silent: true },
292
- ).code !== 0
293
- ) {
294
- shell.echo('Error: Installing WordPress failed.');
295
- shell.exit(1);
296
- }
297
-
298
- shell.echo('✔️ Installing WordPress succesful.');
299
- shell.exec(`wp rewrite structure '/%postname%/'`, { silent: true });
300
- shell.echo('✔️ Setting permalink structure.');
301
-
302
- shell.exec(`wp theme activate ${child_theme_folder}`, { silent: true });
303
- shell.echo(`✔️ Activating child theme ${child_theme_folder}`);
304
-
305
- shell.exec(`wp post update 2 --post_title='Home'`, { silent: true });
306
- shell.exec(`wp option update show_on_front 'page'`, { silent: true });
307
- shell.exec(`wp option update page_on_front 2`, { silent: true });
308
- shell.exec(`wp post delete 1 --force`, { silent: true });
309
- shell.exec(`wp comment delete 1 --force`, { silent: true });
310
- shell.echo('✔️ Create homepage and set as front-page.');
311
- // Set language
312
- shell.exec(`wp language core install nl_NL`, { silent: true });
313
- shell.exec(`wp language plugin install nl_NL --all`, { silent: true });
314
- shell.exec(`wp language core activate nl_NL`, { silent: true });
315
- shell.echo('✔️ Installed Dutch language.');
316
- // set menu
317
- shell.exec(`wp menu create "Hoofdmenu"`, { silent: true });
318
- shell.exec(`wp menu item add-post Hoofdmenu 2`, { silent: true });
319
- shell.exec(`wp menu location assign Hoofdmenu primary_navigation`, { silent: true });
320
- shell.echo('✔️ Created primary menu.');
321
- } else {
322
- shell.echo('Creating Database.\n');
323
-
324
- if (shell.exec(`wp db create`, { silent: true }).code !== 0) {
325
- shell.echo('Database creation failed.');
326
- } else {
327
- shell.echo('✔️ Database created.');
328
- }
329
-
330
- /**
331
- * Wait until user adds site and presses a key.
332
- */
333
- shell.echo('You can import your database by placing the .sql dump in the project root and run wp db import databasename.sql.');
334
- prompt('Please import your database and uploads. After that press enter to continue.');
335
-
336
- // Flush rewrite rules
337
- shell.exec(`wp rewrite flush`);
338
- }
339
-
340
- shell.echo(`\n`);
341
- shell.echo(`🎉 All done! Happy developing!`);
342
- shell.echo(`🌐 You can now navigate to http://${projectname + tld}`);
343
- })
344
- .parse(process.argv);
1
+ /**
2
+ * External dependencies
3
+ */
4
+ const { program } = require('commander');
5
+ var shell = require('shelljs');
6
+ const commandName = 'wp-lemon-create';
7
+ const { engines, version } = require('../package.json');
8
+ const prompt = require('prompt-sync')();
9
+
10
+ program
11
+ .name(commandName)
12
+ .description(
13
+ 'Generates PHP, JS and CSS code for registering a block for a WordPress plugin.\n\n' +
14
+ '[slug] is optional. When provided it triggers the quick mode where ' +
15
+ 'it is used as the block slug used for its identification, the output ' +
16
+ 'location for scaffolded files, and the name of the WordPress plugin.' +
17
+ 'The rest of the configuration is set to all default values unless ' +
18
+ 'overridden with some of the options listed below.',
19
+ )
20
+ .version(version)
21
+ .action((name, options, command) => {
22
+ var project_repository = '';
23
+ var username = '';
24
+ var email = '';
25
+ var password = '';
26
+ var DBuser = '';
27
+ var DBpassword = '';
28
+ var is_wsl = false;
29
+ var child_theme_folder = '';
30
+ var plugins_searchwp = false;
31
+ var plugins_wpml = false;
32
+ var is_spinup = false;
33
+ var skipGit = false;
34
+ var branch = false;
35
+
36
+ console.log(`Starting $${commandName} @${version}`);
37
+
38
+ if (!shell.which('git')) {
39
+ shell.echo('Sorry, this script requires git');
40
+ shell.exit(1);
41
+ }
42
+ {
43
+ shell.echo('✔️ Git installed');
44
+ }
45
+
46
+ if (!shell.which('composer')) {
47
+ shell.echo('Sorry, this script requires composer');
48
+ shell.exit(1);
49
+ }
50
+ {
51
+ shell.echo('✔️ composer installed');
52
+ }
53
+
54
+ if (!shell.which('yarn')) {
55
+ shell.echo('Sorry, this script requires yarn');
56
+ shell.exit(1);
57
+ }
58
+ {
59
+ shell.echo('✔️ yarn installed');
60
+ }
61
+
62
+ if (!shell.which('wp')) {
63
+ shell.echo('Sorry, this script requires wp cli');
64
+ shell.exit(1);
65
+ }
66
+ {
67
+ shell.echo('✔️ wp-cli installed');
68
+ }
69
+
70
+ if (shell.exec('wp dotenv --help', { silent: true }).code !== 0) {
71
+ shell.echo('Sorry, this script requires wp-cli dotenv package');
72
+ shell.exit(1);
73
+ }
74
+ {
75
+ shell.echo('✔️ wp-cli dotenv package installed');
76
+ }
77
+
78
+ if (shell.exec('grep -q Microsoft /proc/version', { silent: true }).code == 0) {
79
+ is_wsl = true;
80
+ }
81
+
82
+ shell.echo('\n');
83
+ const projectname = prompt('What is the project name (only lowercase and -, no spaces. Do not add tld (.local/.test):');
84
+ child_theme_folder = projectname;
85
+ const tld = prompt('What is the project tld? (defaults to .local):', '.local');
86
+
87
+ const projecttype = prompt('Project type? new or existing (defaults to new):', 'new');
88
+ shell.echo('\n');
89
+
90
+ if (projecttype == 'new') {
91
+ shell.echo('Please create a new Git repository and fill in the link in ssh format.');
92
+ project_repository = prompt('Git repository link or enter "none" to skip GIT setup:', 'none');
93
+ username = prompt('WordPress username:');
94
+ email = prompt('WordPress email:');
95
+ password = prompt('WordPress password:', { echo: '*' });
96
+ plugins_searchwp = prompt('Add plugin: SearchWP? yes/no (defaults to no)', 'no');
97
+ plugins_wpml = prompt('Add plugin: WPML? yes/no (defaults to no)', 'no');
98
+ is_spinup = prompt('Does the project run on Spinup-wp? (defaults to no)', 'no');
99
+
100
+ if (project_repository == 'none') {
101
+ skipGit = true;
102
+ }
103
+ } else if (projecttype == 'existing') {
104
+ project_repository = prompt('Existing repository link in ssh format:');
105
+ branch = prompt('Branch to checkout (defaults to master):', 'master');
106
+ } else {
107
+ shell.echo('no valid command. Exiting.');
108
+ shell.exit(1);
109
+ }
110
+
111
+ DBuser = prompt('Database user. Defaults to root:', 'root');
112
+ DBpassword = prompt('Database password. Defaults to root:', 'root');
113
+
114
+ shell.echo('\n');
115
+ shell.echo(`🎉 Setting up ${projecttype} wp-lemon project with url ${projectname + tld}\n`);
116
+
117
+ if (projecttype == 'new') {
118
+ shell.echo('Downloading Bedrock. This may take a minute or so.\n');
119
+
120
+ /**
121
+ * cloning bedrock and removing unneeded dirs
122
+ */
123
+ shell.exec('composer create-project roots/bedrock .', { silent: true });
124
+ shell.echo('✔️ Bedrock installed.\n');
125
+ shell.rm('-rf', 'CHANGELOG.MD');
126
+ shell.rm('-rf', 'LICENSE.MD');
127
+ shell.rm('-rf', 'composer.lock');
128
+
129
+ /**
130
+ * Add bulldozer extended config
131
+ */
132
+ shell.sed('-i', 'env;', 'env;\nuse HighGround\\Bulldozer\\Bulldozer;\n\nBulldozer::extend_roots_config();', 'config/application.php');
133
+
134
+ /**
135
+ * configuring composer
136
+ */
137
+ shell.exec('composer config repositories.1 composer https://packagist.studiolemon.nl/satispress/', { silent: true });
138
+
139
+ /**
140
+ * Add composer packages
141
+ */
142
+ shell.echo('Installing plugins, master theme and packages. This may take a while\n');
143
+
144
+ shell.exec('composer require composer/installers ~1.0', { silent: true });
145
+
146
+ // Add libraries and parent theme
147
+ shell.exec('composer require highground/bulldozer timber/timber satispress/wp-lemon --with-all-dependencies', { silent: true });
148
+
149
+ shell.exec(
150
+ 'composer require satispress/advanced-custom-fields-pro satispress/fluentformpro satispress/lemon-blocks satispress/quartermaster satispress/wp-migrate-db-pro wpackagist-plugin/limit-login-attempts-reloaded log1x/acf-editor-palette wpackagist-plugin/cookie-law-info wpackagist-plugin/fluentform wpackagist-plugin/seo-by-rank-math wpackagist-plugin/simple-custom-post-order wpackagist-plugin/worker wpackagist-plugin/fluent-smtp --with-all-dependencies',
151
+ { silent: true },
152
+ );
153
+
154
+ shell.exec('composer remove squizlabs/php_codesnifferes roave/security-advisories', { silent: true });
155
+
156
+ if (is_spinup == 'yes') {
157
+ shell.exec('composer require wpackagist-plugin/spinupwp', { silent: true });
158
+ } else {
159
+ shell.exec('composer require satispress/wp-rocket', { silent: true });
160
+ }
161
+
162
+ if (plugins_searchwp == 'yes') {
163
+ shell.exec('composer require satispress/searchwp wpackagist-plugin/searchwp-live-ajax-search', { silent: true });
164
+ }
165
+
166
+ if (plugins_wpml == 'yes') {
167
+ shell.exec('composer require satispress/sitepress-multilingual-cms satispress/acfml satispress/wpml-string-translation', { silent: true });
168
+ }
169
+
170
+ shell.echo('✔️ Installing plugins, master theme and packages done \n');
171
+
172
+ /**
173
+ * Git init & add repository
174
+ */
175
+ if (!skipGit) {
176
+ shell.exec('git init', { silent: true });
177
+ shell.exec(`git remote add origin ${project_repository}`);
178
+ shell.echo(`✔️ Setting up empty local git repository and adding ${project_repository} as remote.\n`);
179
+ }
180
+
181
+ /**
182
+ * Git ignore
183
+ */
184
+ shell.exec("echo '.vscode/*' >> .gitignore");
185
+ shell.exec("echo 'web/app/themes/wp-lemon' >> .gitignore");
186
+ shell.exec("echo 'web/app/wp-rocket-config/' >> .gitignore");
187
+ shell.exec("echo 'web/app/cache' >> .gitignore");
188
+
189
+ /**
190
+ * Downloading child theme
191
+ */
192
+ shell.echo('Downloading child theme.\n');
193
+ shell.cd('web/app/themes/');
194
+
195
+ shell.exec(`composer create-project --repository https://packagist.studiolemon.nl/satispress/ satispress/wp-lemon-child ${child_theme_folder} --no-dev`, { silent: true });
196
+
197
+ shell.cd(child_theme_folder);
198
+ shell.rm('-rf', '.github');
199
+ shell.echo('✔️ Downloading child theme succesful.');
200
+ } else {
201
+ /**
202
+ * Task: existing project.
203
+ */
204
+ shell.echo(`Cloning repository from : ${project_repository}`);
205
+
206
+ if (shell.exec(`git clone ${project_repository} .`).code !== 0) {
207
+ shell.echo('Error: Git clone failed');
208
+ shell.exit(1);
209
+ }
210
+
211
+ if (branch) {
212
+ shell.echo(`Checking out branch: ${branch}`);
213
+ shell.exec(`git checkout ${branch}`);
214
+ }
215
+
216
+ shell.cd('web/app/themes/');
217
+ if (shell.cd(child_theme_folder).code !== 0) {
218
+ shell.echo('Error: Child theme not found');
219
+ var child_theme_folder = prompt('Folder name of child theme:');
220
+ shell.cd(child_theme_folder);
221
+ }
222
+ }
223
+ /**
224
+ * Create child theme config file
225
+ */
226
+ shell.cp('resources/assets/config.json.example', 'resources/assets/config.json');
227
+ shell.sed('-i', 'http://wplemon.local', `http://${projectname + tld}`, 'resources/assets/config.json');
228
+ shell.sed('-i', 'wp-lemon-child', child_theme_folder, 'resources/assets/config.json');
229
+ shell.sed('-i', 'wp-lemon child', projectname, 'style.css');
230
+ shell.echo('✔️ Configuring child theme succesful.\n');
231
+
232
+ /**
233
+ * Installing node modules in child theme and parent theme.
234
+ */
235
+ shell.echo('Installing npm dependencies. This may take a while.\n');
236
+ if (shell.exec(`yarn run bootstrap-project`, { silent: true }).code !== 0) {
237
+ shell.echo('Error: yarn run bootstrap-project failed. Please install node dependencies manually by running yarn run bootstrap-project in your child theme.');
238
+ } else {
239
+ shell.echo('✔️ Installing npm dependencies succesful.');
240
+ shell.exec(`yarn run dev`, { silent: true });
241
+ shell.echo('✔️ First webpack build succesful.\n');
242
+ }
243
+
244
+ /**
245
+ * Wait until user adds site and presses a key.
246
+ */
247
+ prompt('Script will generate .env file. Please add your new site to your AMP stack before pressing enter to continue.');
248
+
249
+ /**
250
+ * cd back to root folder.
251
+ */
252
+ shell.cd('../../../../');
253
+
254
+ /**
255
+ * reload host file so browsersync works without a restart.
256
+ */
257
+ if (is_wsl) {
258
+ shell.exec('sudo cp /mnt/c/Windows/System32/drivers/etc/hosts /etc/hosts');
259
+ }
260
+
261
+ /**
262
+ * Creating .env file
263
+ */
264
+ shell.echo('Creating .env file\n');
265
+ shell.exec(`wp dotenv init --template=.env.example --with-salts`, { silent: true });
266
+ shell.exec(`wp dotenv set DB_NAME ${projectname}`, { silent: true });
267
+ shell.exec(`wp dotenv set DB_USER ${DBuser}`, { silent: true });
268
+ shell.exec(`wp dotenv set DB_PASSWORD ${DBpassword}`, { silent: true });
269
+ shell.exec(`wp dotenv set WP_HOME http://${projectname + tld}`, { silent: true });
270
+ shell.exec(`wp dotenv salts generate`, { silent: true });
271
+ shell.echo('✔️ Generating .env succesful.\n');
272
+
273
+ if (is_wsl) {
274
+ shell.echo('Uncommenting #DB_host and changing to 127.0.0.1 for allowing connection in WSL\n');
275
+ shell.sed('-i', '# DB_HOST', 'DB_HOST', '.env');
276
+ shell.sed('-i', 'localhost', '127.0.0.1', '.env');
277
+ }
278
+
279
+ if (projecttype == 'new') {
280
+ shell.echo('Installing WordPress.\n');
281
+
282
+ if (shell.exec(`wp db create`, { silent: true }).code !== 0) {
283
+ shell.echo('Database creation failed.');
284
+ } else {
285
+ shell.echo('✔️ Database created');
286
+ }
287
+
288
+ if (
289
+ shell.exec(
290
+ `wp core install --skip-email --url="http://${projectname + tld}" --title="${projectname}" --admin_user="${username}" --admin_password="${password}" --admin_email="${email}"`,
291
+ { silent: true },
292
+ ).code !== 0
293
+ ) {
294
+ shell.echo('Error: Installing WordPress failed.');
295
+ shell.exit(1);
296
+ }
297
+
298
+ shell.echo('✔️ Installing WordPress succesful.');
299
+ shell.exec(`wp rewrite structure '/%postname%/'`, { silent: true });
300
+ shell.echo('✔️ Setting permalink structure.');
301
+
302
+ shell.exec(`wp theme activate ${child_theme_folder}`, { silent: true });
303
+ shell.echo(`✔️ Activating child theme ${child_theme_folder}`);
304
+
305
+ shell.exec(`wp post update 2 --post_title='Home'`, { silent: true });
306
+ shell.exec(`wp option update show_on_front 'page'`, { silent: true });
307
+ shell.exec(`wp option update page_on_front 2`, { silent: true });
308
+ shell.exec(`wp post delete 1 --force`, { silent: true });
309
+ shell.exec(`wp comment delete 1 --force`, { silent: true });
310
+ shell.echo('✔️ Create homepage and set as front-page.');
311
+ // Set language
312
+ shell.exec(`wp language core install nl_NL`, { silent: true });
313
+ shell.exec(`wp language plugin install nl_NL --all`, { silent: true });
314
+ shell.exec(`wp language core activate nl_NL`, { silent: true });
315
+ shell.echo('✔️ Installed Dutch language.');
316
+ // set menu
317
+ shell.exec(`wp menu create "Hoofdmenu"`, { silent: true });
318
+ shell.exec(`wp menu item add-post Hoofdmenu 2`, { silent: true });
319
+ shell.exec(`wp menu location assign Hoofdmenu primary_navigation`, { silent: true });
320
+ shell.echo('✔️ Created primary menu.');
321
+ } else {
322
+ shell.echo('Creating Database.\n');
323
+
324
+ if (shell.exec(`wp db create`, { silent: true }).code !== 0) {
325
+ shell.echo('Database creation failed.');
326
+ } else {
327
+ shell.echo('✔️ Database created.');
328
+ }
329
+
330
+ /**
331
+ * Wait until user adds site and presses a key.
332
+ */
333
+ shell.echo('You can import your database by placing the .sql dump in the project root and run wp db import databasename.sql.');
334
+ prompt('Please import your database and uploads. After that press enter to continue.');
335
+
336
+ // Flush rewrite rules
337
+ shell.exec(`wp rewrite flush`);
338
+ }
339
+
340
+ shell.echo(`\n`);
341
+ shell.echo(`🎉 All done! Happy developing!`);
342
+ shell.echo(`🌐 You can now navigate to http://${projectname + tld}`);
343
+ })
344
+ .parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wp-lemon-create",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Bootstrap your wp-lemon project",
5
5
  "main": "index.js",
6
6
  "author": "Erik van der bas",