Skip to content

Commit 36239d4

Browse files
Merge pull request #2 from ivankristianto/develop
Develop
2 parents 2e4c4c1 + ec007d1 commit 36239d4

File tree

8 files changed

+63
-24
lines changed

8 files changed

+63
-24
lines changed

.DS_Store

-6 KB
Binary file not shown.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ jspm_packages
4242

4343
# Lib
4444
lib
45+
46+
# Others
47+
.DS_Store

CHANGELOGS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
create-wp-site Changelogs
22
==============
33

4+
## v0.1.5
5+
6+
* Allow to run with directly passed the directory name as first param. sample: `create-wp-site mylocaldocker`
7+
* Compatibility with yarn create. Sample: `yarn create wp-site mylocaldocker`
8+
49
## v0.1.x
510

611
* Release minimal version

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ $ create-wp-site
4444
4545
Examples:
4646
47-
$ create-wp-site create
47+
$ create-wp-site <directory-name>
48+
```
49+
50+
### Using Yarn
51+
```
52+
$ yarn create wp-site <directory-name>
4853
```
4954

5055
For more help on specific command, supply `-h` or `--help`.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "create-wp-site",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "Create local WordPress development with 10up/wp-local-docker",
55
"bin": {
66
"create-wp-site": "bin/create-wp-site"
@@ -21,7 +21,11 @@
2121
"docker",
2222
"cli"
2323
],
24-
"author": "Ivan Kristianto <[email protected]>",
24+
"author": {
25+
"name": "Ivan Kristianto",
26+
"email": "[email protected]",
27+
"url": "https://www.ivankristianto.com"
28+
},
2529
"license": "MIT",
2630
"dependencies": {
2731
"archiver": "^1.3.0",

src/cli.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* External dependencies
33
*/
44
import cli from 'commander';
5+
import create from './commands/create';
56

67
/**
78
* Internal dependencies
@@ -16,7 +17,7 @@ function main() {
1617
.on( '--help', function() {
1718
console.log( ' Examples:' );
1819
console.log( '' );
19-
console.log( ' $ create-wp-site create' );
20+
console.log( ' $ create-wp-site <foldername>' );
2021
console.log( '' );
2122
} );
2223

@@ -56,8 +57,8 @@ function runCommand() {
5657
const passedCmd = process.argv.slice( 2 );
5758

5859
// No command specified or invalid command.
59-
if ( ! passedCmd.length && ! commands[ passedCmd[ 0 ] ] ) {
60-
cli.help();
60+
if ( ! passedCmd.length || ! ( passedCmd in commands ) ) {
61+
create( { directory: passedCmd[ 0 ] } );
6162
}
6263

6364
cli.parse( process.argv );

src/commands/create.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@ const ghURL = 'https://github.com/10up/wp-local-docker.git';
1313

1414
export default ( args, config ) => {
1515
const params = getParams( args, config );
16-
const promptOpt = prompts.getCreatePrompts();
17-
prompts.ask( promptOpt ).then( handlePrompt, e => {
16+
const promptOpt = prompts.getCreatePrompts( params );
17+
const createPromptHandler = ( args, config ) =>
18+
function( data ) {
19+
return handlePrompt( data, args, config );
20+
};
21+
prompts.ask( promptOpt ).then( createPromptHandler( args, config ), e => {
1822
log.error( e.toString() );
1923
} );
2024
};
2125

2226
function getParams( args, config ) {
23-
const dir = args.dir || '';
27+
const directory = args.directory || '';
2428
return {
25-
dir,
29+
directory,
2630
};
2731
}
2832

29-
function handlePrompt( data ) {
33+
function handlePrompt( data, args, config ) {
3034
try {
35+
const params = getParams( args, config );
36+
data = Object.assign( data, params );
37+
3138
log.info( 'Checking if directory exist' );
3239
is_directory_exist( data.directory );
3340

@@ -55,12 +62,12 @@ function handlePrompt( data ) {
5562
return data;
5663
}
5764

58-
function is_directory_exist( dir ) {
59-
if ( ! dir ) {
65+
function is_directory_exist( directory ) {
66+
if ( ! directory ) {
6067
throw new Error( 'We need directory name.' );
6168
}
6269

63-
if ( ! fs.emptyDirSync( dir ) ) {
70+
if ( ! fs.emptyDirSync( directory ) ) {
6471
throw new Error( 'Directory exist, exit now.' );
6572
}
6673

@@ -134,8 +141,10 @@ function installWp( data ) {
134141
log.info( wp.install( data ) );
135142
}
136143

137-
function successInfo( data ){
138-
log.success( 'Congratulations! Your local WordPress site now has been created.' );
144+
function successInfo( data ) {
145+
log.success(
146+
'Congratulations! Your local WordPress site now has been created.'
147+
);
139148
log.success( 'Url: http://' + data.domain );
140149
log.success( 'Username: admin' );
141150
log.success( 'Password: password' );

src/utils/prompts.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
import inquirer from 'inquirer';
22

3-
function getCreatePrompts() {
3+
function getCreatePrompts( params ) {
44
const prompts = [
55
{
66
type: 'input',
77
name: 'directory',
88
message: 'Name of new site directory:',
9-
validate: function (text) {
10-
if (text.length == 0) {
9+
validate: function( text ) {
10+
if ( text.length == 0 ) {
1111
return 'You must specify the directory name';
1212
}
1313
return true;
14-
}
14+
},
15+
'default': function() {
16+
if ( '' === params.directory ) {
17+
return 'wplocaldocker';
18+
}
19+
return params.directory + '.dev';
20+
},
21+
when: function( answers ) {
22+
return '' === params.directory;
23+
},
1524
},
1625
{
1726
type: 'input',
1827
name: 'domain',
1928
message: 'Domain to use:',
20-
default: function (answers) {
21-
return answers.directory+'.dev';
29+
'default': function( answers ) {
30+
if ( '' === params.directory ) {
31+
return answers.directory + '.dev';
32+
}
33+
return params.directory + '.dev';
2234
},
23-
filter: function (val) {
35+
filter: function( val ) {
2436
return val.toLowerCase();
25-
}
37+
},
2638
},
2739
/*
2840
//TODO: Work in Progress

0 commit comments

Comments
 (0)