Skip to content

Commit

Permalink
Merge pull request #2 from ivankristianto/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ivankristianto committed Jun 2, 2017
2 parents 2e4c4c1 + ec007d1 commit 36239d4
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 24 deletions.
Binary file removed .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ jspm_packages

# Lib
lib

# Others
.DS_Store
5 changes: 5 additions & 0 deletions CHANGELOGS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
create-wp-site Changelogs
==============

## v0.1.5

* Allow to run with directly passed the directory name as first param. sample: `create-wp-site mylocaldocker`
* Compatibility with yarn create. Sample: `yarn create wp-site mylocaldocker`

## v0.1.x

* Release minimal version
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ $ create-wp-site
Examples:
$ create-wp-site create
$ create-wp-site <directory-name>
```

### Using Yarn
```
$ yarn create wp-site <directory-name>
```

For more help on specific command, supply `-h` or `--help`.
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-wp-site",
"version": "0.1.4",
"version": "0.1.5",
"description": "Create local WordPress development with 10up/wp-local-docker",
"bin": {
"create-wp-site": "bin/create-wp-site"
Expand All @@ -21,7 +21,11 @@
"docker",
"cli"
],
"author": "Ivan Kristianto <ivan@ivankristianto.com>",
"author": {
"name": "Ivan Kristianto",
"email": "ivan@ivankristianto.com",
"url": "https://www.ivankristianto.com"
},
"license": "MIT",
"dependencies": {
"archiver": "^1.3.0",
Expand Down
7 changes: 4 additions & 3 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* External dependencies
*/
import cli from 'commander';
import create from './commands/create';

/**
* Internal dependencies
Expand All @@ -16,7 +17,7 @@ function main() {
.on( '--help', function() {
console.log( ' Examples:' );
console.log( '' );
console.log( ' $ create-wp-site create' );
console.log( ' $ create-wp-site <foldername>' );
console.log( '' );
} );

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

// No command specified or invalid command.
if ( ! passedCmd.length && ! commands[ passedCmd[ 0 ] ] ) {
cli.help();
if ( ! passedCmd.length || ! ( passedCmd in commands ) ) {
create( { directory: passedCmd[ 0 ] } );
}

cli.parse( process.argv );
Expand Down
29 changes: 19 additions & 10 deletions src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ const ghURL = 'https://github.com/10up/wp-local-docker.git';

export default ( args, config ) => {
const params = getParams( args, config );
const promptOpt = prompts.getCreatePrompts();
prompts.ask( promptOpt ).then( handlePrompt, e => {
const promptOpt = prompts.getCreatePrompts( params );
const createPromptHandler = ( args, config ) =>
function( data ) {
return handlePrompt( data, args, config );
};
prompts.ask( promptOpt ).then( createPromptHandler( args, config ), e => {
log.error( e.toString() );
} );
};

function getParams( args, config ) {
const dir = args.dir || '';
const directory = args.directory || '';
return {
dir,
directory,
};
}

function handlePrompt( data ) {
function handlePrompt( data, args, config ) {
try {
const params = getParams( args, config );
data = Object.assign( data, params );

log.info( 'Checking if directory exist' );
is_directory_exist( data.directory );

Expand Down Expand Up @@ -55,12 +62,12 @@ function handlePrompt( data ) {
return data;
}

function is_directory_exist( dir ) {
if ( ! dir ) {
function is_directory_exist( directory ) {
if ( ! directory ) {
throw new Error( 'We need directory name.' );
}

if ( ! fs.emptyDirSync( dir ) ) {
if ( ! fs.emptyDirSync( directory ) ) {
throw new Error( 'Directory exist, exit now.' );
}

Expand Down Expand Up @@ -134,8 +141,10 @@ function installWp( data ) {
log.info( wp.install( data ) );
}

function successInfo( data ){
log.success( 'Congratulations! Your local WordPress site now has been created.' );
function successInfo( data ) {
log.success(
'Congratulations! Your local WordPress site now has been created.'
);
log.success( 'Url: http://' + data.domain );
log.success( 'Username: admin' );
log.success( 'Password: password' );
Expand Down
28 changes: 20 additions & 8 deletions src/utils/prompts.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
import inquirer from 'inquirer';

function getCreatePrompts() {
function getCreatePrompts( params ) {
const prompts = [
{
type: 'input',
name: 'directory',
message: 'Name of new site directory:',
validate: function (text) {
if (text.length == 0) {
validate: function( text ) {
if ( text.length == 0 ) {
return 'You must specify the directory name';
}
return true;
}
},
'default': function() {
if ( '' === params.directory ) {
return 'wplocaldocker';
}
return params.directory + '.dev';
},
when: function( answers ) {
return '' === params.directory;
},
},
{
type: 'input',
name: 'domain',
message: 'Domain to use:',
default: function (answers) {
return answers.directory+'.dev';
'default': function( answers ) {
if ( '' === params.directory ) {
return answers.directory + '.dev';
}
return params.directory + '.dev';
},
filter: function (val) {
filter: function( val ) {
return val.toLowerCase();
}
},
},
/*
//TODO: Work in Progress
Expand Down

0 comments on commit 36239d4

Please sign in to comment.