mirror of
https://github.com/flarum/core.git
synced 2025-08-02 14:37:49 +02:00
Remove extension generator
This commit is contained in:
@@ -1,125 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Flarum.
|
||||
*
|
||||
* (c) Toby Zerner <toby.zerner@gmail.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Flarum\Console\Command;
|
||||
|
||||
use Flarum\Foundation\Application;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
|
||||
class GenerateExtensionCommand extends AbstractCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this
|
||||
->setName('generate:extension')
|
||||
->setDescription('Generate a Flarum extension skeleton');
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
protected function fire()
|
||||
{
|
||||
do {
|
||||
$name = $this->ask('Extension name:');
|
||||
} while (! preg_match('/^([a-z0-9-]+)$/i', $name));
|
||||
|
||||
do {
|
||||
$namespace = $this->ask('Namespace:');
|
||||
} while (! preg_match('/^([a-z0-9_\\\\]+)$/i', $namespace));
|
||||
|
||||
do {
|
||||
$title = $this->ask('Title:');
|
||||
} while (! $title);
|
||||
|
||||
$description = $this->ask('Description:');
|
||||
|
||||
$authorName = $this->ask('Author name:');
|
||||
|
||||
$authorEmail = $this->ask('Author email:');
|
||||
|
||||
$license = $this->ask('License:');
|
||||
|
||||
$this->info('Generating extension skeleton for "'.$name.'"...');
|
||||
|
||||
$dir = public_path().'/extensions/'.$name;
|
||||
|
||||
$replacements = [
|
||||
'{{namespace}}' => $namespace,
|
||||
'{{escapedNamespace}}' => str_replace('\\', '\\\\', $namespace),
|
||||
'{{name}}' => $name
|
||||
];
|
||||
|
||||
$this->copyStub($dir, $replacements);
|
||||
|
||||
$manifest = [
|
||||
'name' => $name,
|
||||
'title' => $title,
|
||||
'description' => $description,
|
||||
'keywords' => [],
|
||||
'version' => '0.1.0',
|
||||
'author' => [
|
||||
'name' => $authorName,
|
||||
'email' => $authorEmail,
|
||||
'homepage' => ''
|
||||
],
|
||||
'license' => $license,
|
||||
'require' => [
|
||||
'flarum' => '>='.Application::VERSION
|
||||
],
|
||||
'icon' => [
|
||||
'name' => '',
|
||||
'backgroundColor' => '',
|
||||
'color' => ''
|
||||
]
|
||||
];
|
||||
|
||||
file_put_contents($dir.'/flarum.json', json_encode($manifest, JSON_PRETTY_PRINT));
|
||||
|
||||
passthru("cd $dir; composer install; cd js/forum; npm install; gulp; cd ../admin; npm install; gulp");
|
||||
|
||||
$this->info('Extension "'.$name.'" generated!');
|
||||
}
|
||||
|
||||
protected function ask($question, $default = null)
|
||||
{
|
||||
$question = new Question("<question>$question</question> ", $default);
|
||||
|
||||
return $this->getHelperSet()->get('question')->ask($this->input, $this->output, $question);
|
||||
}
|
||||
|
||||
protected function copyStub($destination, $replacements = [])
|
||||
{
|
||||
$this->recursiveCopy(__DIR__.'/../../../stubs/extension', $destination, $replacements);
|
||||
}
|
||||
|
||||
protected function recursiveCopy($src, $dst, $replacements = [])
|
||||
{
|
||||
$dir = opendir($src);
|
||||
@mkdir($dst);
|
||||
|
||||
while (($file = readdir($dir)) !== false) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
if (is_dir($src.'/'.$file)) {
|
||||
$this->recursiveCopy($src.'/'.$file, $dst.'/'.$file, $replacements);
|
||||
} else {
|
||||
$contents = file_get_contents($src.'/'.$file);
|
||||
$contents = str_replace(array_keys($replacements), array_values($replacements), $contents);
|
||||
|
||||
file_put_contents($dst.'/'.$file, $contents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Flarum\Console;
|
||||
|
||||
use Flarum\Console\Command\GenerateExtensionCommand;
|
||||
use Flarum\Console\Command\GenerateMigrationCommand;
|
||||
use Flarum\Debug\Console\CacheClearCommand;
|
||||
use Flarum\Debug\Console\InfoCommand;
|
||||
@@ -42,7 +41,6 @@ class Server extends AbstractServer
|
||||
$commands = [
|
||||
InstallCommand::class,
|
||||
MigrateCommand::class,
|
||||
GenerateExtensionCommand::class,
|
||||
GenerateMigrationCommand::class,
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user