From 097ee6f874879a5bcf8dbda04c423a7453ec11c0 Mon Sep 17 00:00:00 2001
From: Tobias Munk
To enable it in your application, you need to create a git repository +and require via composer.
+EOD; + $code1 = <<Add the newly created repo to your composer.json.
+EOD; + $code2 = <<Require the package with composer
+EOD; + $code3 = <<' . highlight_string($code1, true) . ''; + $return .= $output2 . '
' . highlight_string($code2, true) . ''; + $return .= $output3 . '
' . highlight_string($code3, true) . ''; + $return .= $output4 . '
' . highlight_string($code4, true) . ''; + return $return; + } + + /** + * @inheritdoc + */ + public function requiredTemplates() + { + return ['composer.json', 'AutoloadExample.php', 'README.md']; + } + + /** + * @inheritdoc + */ + public function generate() + { + $files = []; + $modulePath = $this->getOutputPath(); + $files[] = new CodeFile( + $modulePath . '/' . $this->packageName . '/composer.json', + $this->render("composer.json") + ); + $files[] = new CodeFile( + $modulePath . '/' . $this->packageName . '/AutoloadExample.php', + $this->render("AutoloadExample.php") + ); + $files[] = new CodeFile( + $modulePath . '/' . $this->packageName . '/README.md', + $this->render("README.md") + ); + return $files; + } + + /** + * @return boolean the directory that contains the module class + */ + public function getOutputPath() + { + return Yii::getAlias($this->outputPath); + #return Yii::getAlias('@' . str_replace('\\', '/', substr($this->moduleClass, 0, strrpos($this->moduleClass, '\\')))); + } + + /** + * @return array options for type drop-down + */ + public function optsType() + { + $licenses = [ + 'yii2-extension', + 'library', + ]; + return array_combine($licenses, $licenses); + } + + /** + * @return array options for license drop-down + */ + public function optsLicense() + { + $licenses = [ + 'Apache-2.0', + 'BSD-2-Clause', + 'BSD-3-Clause', + 'BSD-4-Clause', + 'GPL-2.0', + 'GPL-2.0+', + 'GPL-3.0', + 'GPL-3.0+', + 'LGPL-2.1', + 'LGPL-2.1+', + 'LGPL-3.0', + 'LGPL-3.0+', + 'MIT' + ]; + return array_combine($licenses, $licenses); + } +} diff --git a/extensions/gii/generators/extension/form.php b/extensions/gii/generators/extension/form.php new file mode 100644 index 0000000000..7709027871 --- /dev/null +++ b/extensions/gii/generators/extension/form.php @@ -0,0 +1,30 @@ + +
myself',
+ 'packageName' => 'This is the name of the extension on packagist, eg. yii2-foobar',
+ 'namespace' => 'PSR-4, eg. myself\foobar This will be added to your autoloading by composer. Do not use yii or yii2 in the namespace.',
+ 'keywords' => 'Comma separated keywords for this extension.',
+ 'outputPath' => 'The temporary location of the generated files.',
+ 'title' => 'A more descriptive name of your application for the README file.',
'description' => 'A sentence or subline describing the main purpose of the extension.',
];
}
@@ -96,7 +122,7 @@ class Generator extends \yii\gii\Generator
*/
public function stickyAttributes()
{
- return ['vendorName','outputPath','authorName','authorEmail'];
+ return ['vendorName', 'outputPath', 'authorName', 'authorEmail'];
}
/**
@@ -108,46 +134,47 @@ class Generator extends \yii\gii\Generator
# $link = Html::a('try it now', Yii::$app->getUrlManager()->createUrl($this->moduleID), ['target' => '_blank']);
# return "The module has been generated successfully. You may $link.";
#}
-
- $output1 = <<To enable it in your application, you need to create a git repository and require via composer.
EOD; - $code1 = <<Add the newly created repo to your composer.json.
EOD; - $code2 = <<file://{$outputPath}/{$this->packageName} for testing.
Require the package with composer
EOD; - $code3 = <<' . highlight_string($code1, true) . ''; + $return = $output1 . '
' . highlight_string($code1, true) . ''; $return .= $output2 . '
' . highlight_string($code2, true) . ''; $return .= $output3 . '
' . highlight_string($code3, true) . ''; $return .= $output4 . '
' . highlight_string($code4, true) . ''; @@ -190,7 +217,14 @@ EOD; public function getOutputPath() { return Yii::getAlias($this->outputPath); - #return Yii::getAlias('@' . str_replace('\\', '/', substr($this->moduleClass, 0, strrpos($this->moduleClass, '\\')))); + } + + /** + * @return a json encoded array with the given keywords + */ + public function getKeywordsArrayJson() + { + return json_encode(explode(',', $this->keywords)); } /** diff --git a/extensions/gii/generators/extension/form.php b/extensions/gii/generators/extension/form.php index 4f72ffcc12..98a250cafc 100644 --- a/extensions/gii/generators/extension/form.php +++ b/extensions/gii/generators/extension/form.php @@ -5,6 +5,11 @@ * @var yii\gii\generators\module\Generator $generator */ ?> +
myself',
- 'packageName' => 'This is the name of the extension on packagist, eg. yii2-foobar',
- 'namespace' => 'PSR-4, eg. myself\foobar This will be added to your autoloading by composer. Do not use yii or yii2 in the namespace.',
+ 'vendorName' => 'This refers to the name of the publisher, your GitHub user name is usually a good choice, eg. myself.',
+ 'packageName' => 'This is the name of the extension on packagist, eg. yii2-foobar.',
+ 'namespace' => 'PSR-4, eg. myself\foobar\ This will be added to your autoloading by composer. Do not use yii or yii2 in the namespace.',
'keywords' => 'Comma separated keywords for this extension.',
'outputPath' => 'The temporary location of the generated files.',
'title' => 'A more descriptive name of your application for the README file.',
@@ -151,7 +151,7 @@ git remote add origin https://path.to/your/repo
git push -u origin master
EOD;
$output2 = <<The next step is just for initial development, skip it if you directly publish the extension on packagist.org
Add the newly created repo to your composer.json.
EOD; $code2 = <<' . highlight_string($code1, true) . ''; $return .= $output2 . '
' . highlight_string($code2, true) . ''; $return .= $output3 . '
' . highlight_string($code3, true) . ''; $return .= $output4 . '
' . highlight_string($code4, true) . ''; + $return .= $output5; return $return; } From c624f91dc354c36345fc952da47a87cad81090af Mon Sep 17 00:00:00 2001 From: Tobias Munk
To enable it in your application, you need to create a git repository -and require via composer.
+and require it via composer. EOD; $code1 = <<When you have finished development register your extension at packagist.org.
EOD; - $return = $output1 . '' . highlight_string($code1, true) . ''; + $return = $output1 . '
' . highlight_string($code1, true) . ''; $return .= $output2 . '
' . highlight_string($code2, true) . ''; $return .= $output3 . '
' . highlight_string($code3, true) . ''; $return .= $output4 . '
' . highlight_string($code4, true) . ''; diff --git a/extensions/gii/generators/extension/templates/README.md b/extensions/gii/generators/extension/templates/README.md index 99de991924..c2934943fe 100644 --- a/extensions/gii/generators/extension/templates/README.md +++ b/extensions/gii/generators/extension/templates/README.md @@ -12,13 +12,13 @@ The preferred way to install this extension is through [composer](http://getcomp Either run ``` -php composer.phar require --prefer-dist = $generator->vendorName ?>/yii2-= $generator->packageName ?> "*" +php composer.phar require --prefer-dist = $generator->vendorName ?>/= $generator->packageName ?> "*" ``` or add ``` -"= $generator->vendorName ?>/yii2-= $generator->packageName ?>": "*" +"= $generator->vendorName ?>/= $generator->packageName ?>": "*" ``` to the require section of your `composer.json` file. From 3bd6c1ac27c59fe5a8acca2911b8ea35f57e8a67 Mon Sep 17 00:00:00 2001 From: Tobias Munk