Skip to content

Commit

Permalink
feat(clio): ffinished
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Oct 14, 2021
1 parent 1e522c0 commit e3a0fe3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 51 deletions.
22 changes: 9 additions & 13 deletions generator/composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ function execute_composer() {
global $cmd, $clio, $info;
clean_composer_file();
if ( !$cmd[ 'no-download' ] ) {
$clio->display( "😀 Composer install in progress (can require few minutes)" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 Composer install in progress (can require few minutes)" )->newLine();
$output = '';
$composer_cmd = 'composer update';
if ( !$cmd[ 'verbose' ] ) {
$composer_cmd .= ' 2>&1';
}

exec( 'cd "' . getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '"; ' . $composer_cmd, $output );
$clio->display( "😎 Composer install done" )->style( $info )->newLine();
exec( 'cd "' . getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '"; composer update 2>&1 > /dev/null', $output );
$clio->clear()->style( $info )->display( "😎 Composer install done" )->newLine();
}
}

Expand All @@ -38,18 +34,18 @@ function clean_composer_file() {

if ( is_empty_or_false( $config[ 'grumphp' ] ) ) {
unset( $composer[ 'require-dev' ][ 'phpro/grumphp' ] );
$clio->display( "😎 Remove GrumPHP done" )->style( $info )->newLine();
$clio->style( $info )->display( "😎 Remove GrumPHP done" )->newLine();
}

if ( is_empty_or_false( $config[ 'phpstan' ] ) ) {
unset( $composer[ 'require-dev' ][ 'szepeviktor/phpstan-wordpress' ] );
$clio->display( "😎 Remove PHPStan WordPress support done" )->style( $info )->newLine();
$clio->style( $info )->display( "😎 Remove PHPStan WordPress support done" )->newLine();
}

if ( is_empty_or_false( $config[ 'phpcs' ] ) ) {
unset( $composer[ 'require-dev' ][ 'codeatcode/codeatcs' ] );
unset( $composer[ 'require-dev' ][ 'dealerdirect/phpcodesniffer-composer-installer' ] );
$clio->display( "😎 Remove PHPCS support done" )->style( $info )->newLine();
$clio->style( $info )->display( "😎 Remove PHPCS support done" )->newLine();
}

if ( is_empty_or_false( $config[ 'unit-test' ] ) ) {
Expand All @@ -66,7 +62,7 @@ function clean_composer_file() {
unset( $composer[ 'require-dev' ][ 'codeception/codeception' ] );
unset( $composer[ 'require-dev' ][ 'codeception/codeception-progress-reporter' ] );
unset( $composer[ 'require-dev' ][ 'phpunit/phpunit' ] );
$clio->display( "😎 Remove Codeception done" )->style( $info )->newLine();
$clio->style( $info )->display( "😎 Remove Codeception done" )->newLine();
}

if ( count( $composer[ 'require-dev' ] ) === 0 ) {
Expand All @@ -83,7 +79,7 @@ function clean_composer_file() {

$composer = remove_folder_for_autoload( $composer );

$clio->display( "😎 Cleaning Composer file" )->style( $info )->newLine();
$clio->style( $info )->display( "😎 Cleaning Composer file" )->newLine();

$composer = json_encode( $composer, JSON_PRETTY_PRINT );
$composer = replace_author_strings( $composer );
Expand Down Expand Up @@ -126,7 +122,7 @@ function remove_specific_composer_respositories( $package, $composer ) {
*/
function remove_composer_packages( $composer ) {
global $config, $clio, $info;
$clio->display( "😎 Remove Composer packages" )->style( $info );
$clio->style( $info )->display( "😎 Remove Composer packages" )->newLine();
foreach ( $config as $key => $value ) {
if ( strpos( $key, 'libraries_' ) !== false ) {
if ( empty( $value ) ) {
Expand Down
20 changes: 11 additions & 9 deletions generator/init.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

define( 'WPBP_VERSION', '3.2.3' );
define( 'WPBP_VERSION', '3.2.4' );
require_once(dirname( __FILE__ ) . '/miscellaneous.php');
require_once(dirname( __FILE__ ) . '/composer.php');
require_once(dirname( __FILE__ ) . '/tools.php');
Expand All @@ -27,12 +27,14 @@
$cmd->option( 'json' )->describedAs( 'Generate a wpbp.json file in the current folder. Suggested to use the WordPress plugin folder.' )->boolean();
$cmd->option( 'no-download' )->describedAs( 'Do you want to execute composer and npm manually? This is your flag!' )->boolean();

$output = '';
exec( 'clear', $output );
set_color_scheme();
$clio->display( "(>'-')> WPBP Code Generator" )->style( $info )->newLine();
if ( $cmd[ 'dark' ] ) {
$clio->display( "!! Dark color scheme in use !!" )->style( $info )->newLine()->newLine();
$clio->clear()->display( "!! Dark color scheme in use !!" )->style( $info )->newLine()->newLine();
} else {
$clio->display( "!! Light color scheme in use !!" )->style( $info )->newLine()->newLine();
$clio->clear()->display( "!! Light color scheme in use !!" )->style( $info )->newLine()->newLine();
}

// Generate the wpbp.json file
Expand All @@ -43,20 +45,20 @@
define( 'WPBP_PLUGIN_SLUG', str_replace( ' ', '-', strtolower( $config[ 'plugin_name' ] ) ) );
// Check if a folder with that name already exist
if ( file_exists( dirname( __FILE__ ) . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG ) ) {
$clio->display( 'Folder ' . WPBP_PLUGIN_SLUG . ' already exist!' )->style( $error )->newLine();
$clio->style( $error )->display( 'Folder ' . WPBP_PLUGIN_SLUG . ' already exist!' )->newLine();
die( 0 );
}
// Unpack the boilerplate
extract_wpbp();
// Magic in progress
execute_generator( $config );
// Done!
$clio->display( "Last cleanings!" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "Last cleanings!" )->newLine();
remove_empty_folders();
// Another round to remove the folder that wasn't cleaned at first round
remove_empty_folders();
execute_composer();
$clio->display( "Done, I am superfast!" )->style( $info )->newLine()->newLine();
$clio->display( "👉 Don't forget to look on https://wpbp.github.io/wiki.html" )->style( $info )->newLine();
$clio->display( "Love WordPress-Plugin-Boilerplate-Powered? Please consider supporting our collective:" )->style( $info )->newLine();
$clio->display( "👉 https://opencollective.com/WordPress-Plugin-Boilerplate-Powered/donate" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "Done, I am superfast!" )->newLine()->newLine();
$clio->display( "👉 Don't forget to look on https://wpbp.github.io/wiki.html" )->newLine();
$clio->display( "Love WordPress-Plugin-Boilerplate-Powered? Please consider supporting our collective:" )->newLine();
$clio->display( "👉 https://opencollective.com/WordPress-Plugin-Boilerplate-Powered/donate" )->newLine()->clear();
4 changes: 2 additions & 2 deletions generator/miscellaneous.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function print_v( $label ) {
global $cmd, $clio, $notice;

if ( $cmd[ 'verbose' ] ) {
$clio->display( $label . "\n" )->style( $notice );
$clio->style( $notice )->display( $label )->newLine();
}
}

Expand Down Expand Up @@ -146,7 +146,7 @@ function copy_dir( $source, $dest ) {
function plugin_temp_exist() {
global $cmd, $clio, $info;
if ( file_exists( getcwd() . '/plugin_temp' ) ) {
$clio->display( "Boilerplate already extracted found" )->style( $info )->newLine();
$clio->style( $info )->display( "Boilerplate already extracted found" )->newLine();
if ( $cmd[ 'dev' ] ) {
copy_dir( getcwd() . '/plugin_temp', getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG );
return true;
Expand Down
2 changes: 1 addition & 1 deletion generator/rename.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function get_files( $path = null ) {
}

$files = $list = array();
$clio->display( "Rename/Remove in progress" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "Rename/Remove in progress" )->newLine();
$dir_iterator = new RecursiveDirectoryIterator( $path, FilesystemIterator::SKIP_DOTS );
$iterator = new RecursiveIteratorIterator( $dir_iterator, RecursiveIteratorIterator::SELF_FIRST );

Expand Down
20 changes: 10 additions & 10 deletions generator/tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function git_init() {

if ( $config[ 'git-repo' ] === 'true' ) {
exec( 'cd "' . getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '"; git init &> /dev/null' );
$clio->display( "😎 .git folder generated" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😎 .git folder generated" )->newLine();
$gitignore = getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '/.gitignore';
file_put_contents( $gitignore, str_replace( '/plugin-name/', '', file_get_contents( $gitignore ) ) );
$clio->display( "😎 .gitignore file generated" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😎 .gitignore file generated" )->newLine();
return;
}

Expand All @@ -38,10 +38,10 @@ function grunt() {

if ( $config[ 'grunt' ] === 'true' ) {
if ( !$cmd[ 'no-download' ] ) {
$clio->display( "😀 Grunt install in progress" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 Grunt install in progress" )->newLine();
$output = '';
exec( 'cd "' . getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '"; npm install 2>&1', $output );
$clio->display( "😎 Grunt install done" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😎 Grunt install done" )->newLine();
}

return;
Expand All @@ -50,7 +50,7 @@ function grunt() {
unlink( getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '/Gruntfile.js' );
unlink( getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '/package.json' );
remove_file_folder( getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '/assets/sass' );
$clio->display( "😀 Grunt removed" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 Grunt removed" )->newLine();
}


Expand All @@ -67,27 +67,27 @@ function grumphp() {
$grumphp = yaml_parse_file ( getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '/grumphp.yml' );
if ( !is_empty_or_false( $config[ 'grunt' ] ) ) {
unset( $grumphp[ 'parameters' ][ 'tasks' ][ 'grunt' ] );
$clio->display( "😀 Grunt removed from GrumPHP" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 Grunt removed from GrumPHP" )->newLine();
}

if ( !is_empty_or_false( $config[ 'phpstan' ] ) ) {
unset( $grumphp[ 'parameters' ][ 'tasks' ][ 'phpstan' ] );
$clio->display( "😀 PHPStan removed from GrumPHP" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 PHPStan removed from GrumPHP" )->newLine();
}

if ( !is_empty_or_false( $config[ 'unit-test' ] ) ) {
unset( $grumphp[ 'parameters' ][ 'tasks' ][ 'codeception' ] );
$clio->display( "😀 Codeception removed from GrumPHP" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 Codeception removed from GrumPHP" )->newLine();
}

if ( !is_empty_or_false( $config[ 'phpcs' ] ) ) {
unset( $grumphp[ 'parameters' ][ 'tasks' ][ 'phpcs' ] );
$clio->display( "😀 PHPCS removed from GrumPHP" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 PHPCS removed from GrumPHP" )->newLine();
}

if ( !is_empty_or_false( $config[ 'phpmd' ] ) ) {
unset( $grumphp[ 'parameters' ][ 'tasks' ][ 'phpmd' ] );
$clio->display( "😀 PHPMD removed from GrumPHP" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😀 PHPMD removed from GrumPHP" )->newLine();
}

yaml_emit_file( getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG . '/grumphp.yml', $grumphp );
Expand Down
31 changes: 15 additions & 16 deletions generator/wpbp.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,22 @@ function create_wpbp_json() {

if ( $cmd[ 'json' ] ) {
if ( !copy( dirname( __FILE__ ) . '/wpbp.json', getcwd() . '/wpbp.json' ) ) {
$clio->display( "Failed to copy wpbp.json...\n" )->style( $error );
$clio->clear()->style( $error )->display( "Failed to copy wpbp.json..." );
return;
}

$clio->display( "😀 wpbp.json generated\n" )->style( $info );
$clio->clear()->style( $info )->display( "😀 wpbp.json generated" )->newLine()->clear();
exit();

return;
}

if ( !file_exists( getcwd() . '/wpbp.json' ) ) {
$clio->display( "😡 wpbp.json file missing..." )->style( $error )->newLine();
$clio->display( "😉 Generate it with: wpbp-generator --json" )->style( $error )->newLine();
$clio->display( "Forget a hipster Q&A procedure and fill that JSON with your custom configuration!" )->style( $error )->newLine();
$clio->display( " Let's do your changes and execute the script again! Use the --dev parameter to use the development version of the boilerplate!" )->style( $error );
$clio->newLine();
$clio->display( "Help: wpbp-generator --help 😉" )->style( $info )->newLine();
$clio->clear()->style( $error )->display( "😡 wpbp.json file missing..." )->newLine();
$clio->style( $error )->display( "😉 Generate it with: wpbp-generator --json" )->newLine();
$clio->style( $error )->display( "Forget a hipster Q&A procedure and fill that JSON with your custom configuration!" )->newLine();
$clio->style( $error )->display( "👉 Let's do your changes and execute the script again! Use the --dev parameter to use the development version of the boilerplate!" )->newLine()->newLine();
$clio->clear()->style( $info )->display( "Help: wpbp-generator --help 😉" )->newLine()->clear();
exit();
}
}
Expand All @@ -55,11 +54,11 @@ function download_wpbp() {
$version = 'master';
}

$clio->display( "😎 Downloading " . $version . " package" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "😎 Downloading " . $version . " package" )->newLine();

$download = @file_get_contents( 'http://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/archive/' . $version . '.zip' );
if ( $download === false ) {
$clio->display( "😡 The " . $version . " version is not yet avalaible! Use the --dev parameter!" )->style( $error )->newLine();
$clio->clear()->style( $error )->display( "😡 The " . $version . " version is not yet avalaible! Use the --dev parameter!" )->newLine();
die();
}

Expand All @@ -81,11 +80,11 @@ function extract_wpbp() {
if ( ! plugin_temp_exist() ) {
if ( file_exists( getcwd() . '/plugin.zip' ) ) {
if ( file_exists( getcwd() . DIRECTORY_SEPARATOR . WPBP_PLUGIN_SLUG ) ) {
$clio->display( "Folder " . WPBP_PLUGIN_SLUG . " already exist!" )->style( $error )->newLine();
$clio->clear()->style( $error )->display( "Folder " . WPBP_PLUGIN_SLUG . " already exist!" )->newLine();
exit();
}

$clio->display( "Extract Boilerplate" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "Extract Boilerplate" )->newLine();
try {
$zip = new ZipArchive;
} catch (Exception $e) {
Expand All @@ -110,10 +109,10 @@ function extract_wpbp() {
remove_file_folder( getcwd() . '/plugin.zip' );
}
} catch ( Exception $e ) {
$clio->display( $e )->style( $error );
$clio->clear()->style( $error )->display( $e );
}

$clio->display( "Boilerplate Extracted" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "Boilerplate Extracted" )->newLine();
}

return;
Expand Down Expand Up @@ -149,7 +148,7 @@ function execute_generator( $config ) {
}
}

$clio->display( "Generation done, I am superfast! You: (ʘ_ʘ)\n" )->style( $info )->newLine();
$clio->clear()->style( $info )->display( "Generation done, I am superfast! You: (ʘ_ʘ)\n" )->newLine();
git_init();
grunt();
grumphp();
Expand Down Expand Up @@ -190,7 +189,7 @@ function parse_config() {
$config = json_decode( file_get_contents( getcwd() . '/wpbp.json' ), true );
// Detect a misleading json file
if ( json_last_error() !== JSON_ERROR_NONE ) {
$clio->display( "😡 Your JSON is broken!" )->style( $error )->newLine();
$clio->clear()->style( $error )->display( "😡 Your JSON is broken!" )->newLine();
exit;
}

Expand Down

0 comments on commit e3a0fe3

Please sign in to comment.