From 482be4808edaac1aeeb22d12377cfb80e95ef3d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Salinas?= Date: Mon, 22 Aug 2016 02:21:37 +0200 Subject: [PATCH 1/3] Added script prefill.php to replace all :variables --- README.md | 2 +- prefill.php | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 prefill.php diff --git a/README.md b/README.md index fcf4862..2b68f47 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Quality Score][ico-code-quality]][link-code-quality] [![Total Downloads][ico-downloads]][link-downloads] -**Note:** Replace ```:author_name``` ```:author_username``` ```:author_website``` ```:author_email``` ```:vendor``` ```:package_name``` ```:package_description``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md) and [composer.json](composer.json) files, then delete this line. +**Note:** Replace ```:author_name``` ```:author_username``` ```:author_website``` ```:author_email``` ```:vendor``` ```:package_name``` ```:package_description``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md) and [composer.json](composer.json) files, then delete this line. You can run `$ php prefill.php` in the command line to make all replacements at once. This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors. diff --git a/prefill.php b/prefill.php new file mode 100644 index 0000000..4967278 --- /dev/null +++ b/prefill.php @@ -0,0 +1,107 @@ + ['Your name', '', ''], + 'author_github_username' => ['Your Github username', ' in https://github.com/username', ''], + 'author_email' => ['Your email address', '', ''], + 'author_twitter' => ['Your twitter username', '', '@{author_github_username}'], + 'author_website' => ['Your website', '', 'https://github.com/{author_github_username}'], + + 'package_vendor' => ['Package vendor', ' in https://github.com/vendor/package', '{author_github_username}'], + 'package_name' => ['Package name', ' in https://github.com/vendor/package', ''], + 'package_description' => ['Package very short description', '', ''], + + 'psr4_namespace' => ['PSR-4 namespace', 'usually, Vendor\\Package', '{package_vendor}\\{package_name}'], +]; + +$values = []; + +$replacements = [ + ':vendor\\\\:package_name\\\\' => function () use(&$values) { return str_replace('\\', '\\\\', $values['psr4_namespace']) . '\\\\'; }, + ':author_name' => function () use(&$values) { return $values['author_name']; }, + ':author_username' => function () use(&$values) { return $values['author_github_username']; }, + ':author_website' => function () use(&$values) { return $values['author_website'] ?: ('https://github.com/' . $values['author_github_username']); }, + ':author_email' => function () use(&$values) { return $values['author_email'] ?: ($values['author_github_username'] . '@example.com'); }, + ':vendor' => function () use(&$values) { return $values['package_vendor']; }, + ':package_name' => function () use(&$values) { return $values['package_name']; }, + ':package_description' => function () use(&$values) { return $values['package_description']; }, + 'League\\Skeleton' => function () use(&$values) { return $values['psr4_namespace']; }, +]; + +function read_from_console ($prompt) { + if ( function_exists('readline') ) { + $line = trim(readline($prompt)); + if (!empty($line)) { + readline_add_history($line); + } + } else { + echo $prompt; + $line = trim(fgets(STDIN)); + } + return $line; +} + +function interpolate ($text, $values) { + if ( !preg_match_all('/\{(\w+)\}/', $text, $m) ) { + return $text; + } + foreach ( $m[0] as $k => $str ) { + $f = $m[1][$k]; + $text = str_replace($str, $values[$f], $text); + } + return $text; +} + +$modify = 'n'; +do { + if ( $modify == 'q' ) { + exit; + } + + $values = []; + + echo "----------------------------------------------------------------------\n"; + echo "Please, provide the following information:\n"; + echo "----------------------------------------------------------------------\n"; + foreach ( $fields as $f => $field) { + $default = isset($field[COL_DEFAULT]) ? interpolate($field[COL_DEFAULT], $values): ''; + $prompt = sprintf('%s%s%s: ', + $field[COL_DESCRIPTION], + $field[COL_HELP] ? ' (' . $field[COL_HELP] . ')': '', + $field[COL_DEFAULT] !== '' ? ' [' . $default . ']': ''); + $values[$f] = read_from_console($prompt); + if ( empty($values[$f]) ) { + $values[$f] = $default; + } + } + echo "\n"; + + echo "----------------------------------------------------------------------\n"; + echo "Please, check that everything is correct:\n"; + echo "----------------------------------------------------------------------\n"; + foreach ( $fields as $f => $field ) { + echo $field[COL_DESCRIPTION] . ": $values[$f]\n"; + } + echo "\n"; +} while ( ($modify = strtolower(read_from_console('Modify files with these values? [y/N/q] '))) != 'y' ); +echo "\n"; + +$files = array_merge ( + glob(__DIR__ . '/*.md'), + glob(__DIR__ . '/composer.json'), + glob(__DIR__ . '/src/*.php') +); +foreach ($files as $f) { + $contents = file_get_contents($f); + foreach ($replacements as $str => $func) { + $contents = str_replace($str, $func(), $contents); + } + file_put_contents($f, $contents); +} + +echo "Done.\n"; +echo "Now you can remove the file '" . basename(__FILE__) . "'.\n"; From 5a65b42450f6799b415e0b21047e66084d391001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Salinas?= Date: Mon, 22 Aug 2016 02:51:31 +0200 Subject: [PATCH 2/3] Added script prefill.php to replace all :variables --- README.md | 2 +- prefill.php | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 prefill.php diff --git a/README.md b/README.md index fcf4862..ef12e33 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Quality Score][ico-code-quality]][link-code-quality] [![Total Downloads][ico-downloads]][link-downloads] -**Note:** Replace ```:author_name``` ```:author_username``` ```:author_website``` ```:author_email``` ```:vendor``` ```:package_name``` ```:package_description``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md) and [composer.json](composer.json) files, then delete this line. +**Note:** Replace ```:author_name``` ```:author_username``` ```:author_website``` ```:author_email``` ```:vendor``` ```:package_name``` ```:package_description``` with their correct values in [README.md](README.md), [CHANGELOG.md](CHANGELOG.md), [CONTRIBUTING.md](CONTRIBUTING.md), [LICENSE.md](LICENSE.md) and [composer.json](composer.json) files, then delete this line. You can run `$ php prefill.php` in the command line to make all replacements at once. Delete the file prefill.php as well. This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors. diff --git a/prefill.php b/prefill.php new file mode 100644 index 0000000..80532ab --- /dev/null +++ b/prefill.php @@ -0,0 +1,128 @@ + ['Your name', '', ''], + 'author_github_username' => ['Your Github username', ' in https://github.com/username', ''], + 'author_email' => ['Your email address', '', ''], + 'author_twitter' => ['Your twitter username', '', '@{author_github_username}'], + 'author_website' => ['Your website', '', 'https://github.com/{author_github_username}'], + + 'package_vendor' => ['Package vendor', ' in https://github.com/vendor/package', '{author_github_username}'], + 'package_name' => ['Package name', ' in https://github.com/vendor/package', ''], + 'package_description' => ['Package very short description', '', ''], + + 'psr4_namespace' => ['PSR-4 namespace', 'usually, Vendor\\Package', '{package_vendor}\\{package_name}'], +]; + +$values = []; + +$replacements = [ + ':vendor\\\\:package_name\\\\' => function () use (&$values) { + return str_replace('\\', '\\\\', $values['psr4_namespace']) . '\\\\'; + }, + ':author_name' => function () use (&$values) { + return $values['author_name']; + }, + ':author_username' => function () use (&$values) { + return $values['author_github_username']; + }, + ':author_website' => function () use (&$values) { + return $values['author_website'] ?: ('https://github.com/' . $values['author_github_username']); + }, + ':author_email' => function () use (&$values) { + return $values['author_email'] ?: ($values['author_github_username'] . '@example.com'); + }, + ':vendor' => function () use (&$values) { + return $values['package_vendor']; + }, + ':package_name' => function () use (&$values) { + return $values['package_name']; + }, + ':package_description' => function () use (&$values) { + return $values['package_description']; + }, + 'League\\Skeleton' => function () use (&$values) { + return $values['psr4_namespace']; + }, +]; + +function read_from_console($prompt) +{ + if (function_exists('readline')) { + $line = trim(readline($prompt)); + if (!empty($line)) { + readline_add_history($line); + } + } else { + echo $prompt; + $line = trim(fgets(STDIN)); + } + return $line; +} + +function interpolate($text, $values) +{ + if (!preg_match_all('/\{(\w+)\}/', $text, $m)) { + return $text; + } + foreach ($m[0] as $k => $str) { + $f = $m[1][$k]; + $text = str_replace($str, $values[$f], $text); + } + return $text; +} + +$modify = 'n'; +do { + if ($modify == 'q') { + exit; + } + + $values = []; + + echo "----------------------------------------------------------------------\n"; + echo "Please, provide the following information:\n"; + echo "----------------------------------------------------------------------\n"; + foreach ($fields as $f => $field) { + $default = isset($field[COL_DEFAULT]) ? interpolate($field[COL_DEFAULT], $values): ''; + $prompt = sprintf( + '%s%s%s: ', + $field[COL_DESCRIPTION], + $field[COL_HELP] ? ' (' . $field[COL_HELP] . ')': '', + $field[COL_DEFAULT] !== '' ? ' [' . $default . ']': '' + ); + $values[$f] = read_from_console($prompt); + if (empty($values[$f])) { + $values[$f] = $default; + } + } + echo "\n"; + + echo "----------------------------------------------------------------------\n"; + echo "Please, check that everything is correct:\n"; + echo "----------------------------------------------------------------------\n"; + foreach ($fields as $f => $field) { + echo $field[COL_DESCRIPTION] . ": $values[$f]\n"; + } + echo "\n"; +} while (($modify = strtolower(read_from_console('Modify files with these values? [y/N/q] '))) != 'y'); +echo "\n"; + +$files = array_merge( + glob(__DIR__ . '/*.md'), + glob(__DIR__ . '/composer.json'), + glob(__DIR__ . '/src/*.php') +); +foreach ($files as $f) { + $contents = file_get_contents($f); + foreach ($replacements as $str => $func) { + $contents = str_replace($str, $func(), $contents); + } + file_put_contents($f, $contents); +} + +echo "Done.\n"; +echo "Now you can remove the file '" . basename(__FILE__) . "'.\n"; From d2f0d5cbcb9a53e867761a388a68b03d1ebf8ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Salinas?= Date: Tue, 23 Aug 2016 20:19:57 +0200 Subject: [PATCH 3/3] Use PHP-specific examples --- ISSUE_TEMPLATE.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ISSUE_TEMPLATE.md b/ISSUE_TEMPLATE.md index 8989aec..5b48c57 100644 --- a/ISSUE_TEMPLATE.md +++ b/ISSUE_TEMPLATE.md @@ -20,9 +20,8 @@ Not obligatory, but suggest an idea for implementing addition or change. Include as many relevant details about the environment you experienced the bug in and how to reproduce it. -* Version used: -* Environment name and version (e.g. Chrome 39, node.js 5.4): -* Operating System and version (desktop or mobile): +* Version used (e.g. PHP 5.6, HHVM 3): +* Operating system and version (e.g. Ubuntu 16.04, Windows 7): * Link to your project: * ... * ...