wp-lemon-create 1.4.2 → 1.4.4

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