Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ninsuo/code-generator-bundle

A visual "maker-bundle" to quickly create code skeletons
https://github.com/ninsuo/code-generator-bundle

Last synced: about 1 month ago
JSON representation

A visual "maker-bundle" to quickly create code skeletons

Awesome Lists containing this project

README

        

# Code generator

### What is it?

It's a code generator heavily inspired from the Symfony maker, developed in a web interface.

Create snippets:

- Add your context in YAML
- Enrich it with PHP code
- Write down your Twig templates

Use snippets

- Either use "Copy" buttons in the UX
- Or use the interactive maker-like command-line

Share snippets:

- Easily export and import snippets in the UX
- Share snippets in a project using fixtures

![intro](docs/images/0-intro.png)

Check out more details and screenshots [here](docs/index.md).

### Standalone install

You can install this generator standalone if needed, just download a new symfony project.

Ensure [symfony cli](https://symfony.com/download) is installed and run:

```
symfony new codegen --full
```

You'll need to set up a storage, in `.env` you may uncomment:

```
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
```

### Bundle install

#### Use composer

```shell
composer require --dev ninsuo/code-generator-bundle
```

or in `composer.json`:

```json
{
"require": {
"ninsuo/code-generator-bundle": "dev-main"
}
}
```

#### Add the bundle

The PHP enricher is a beautiful RCE vulnerability, so please enable this bundle in development environment only!

In `config/bundles.php`:

```php
['dev' => true],
];
```

#### Add the routing

In `config/routes/annotations.yaml`:

```yaml
snippet:
resource: '@CodeGeneratorBundle/Controller/'
type: annotation
```

#### Generate schema

Run the following command:

```shell
php bin/console make:migration
```

Edit the generated file to ensure migration will only run on dev environment.

```php
public function up(Schema $schema): void
{
if ('dev' !== $_ENV['APP_ENV']) {
return;
}

// ...
}

public function down(Schema $schema): void
{
if ('dev' !== $_ENV['APP_ENV']) {
return;
}

// ...
}
```

Then, run:

```
php bin/console doctrine:migrations:migrate
```

#### Run

Run `symfony start` and go to `http://127.0.0.1:8000/snippet` route

### Sharing snippets

Use the import / export feature at the bottom to share snippets with crewmates.

If you are using this bundle inside a project, you can also use fixtures to share snippets:

```php
snippetRepository = $snippetRepository;
}

public function load(ObjectManager $manager)
{
$this->snippetRepository->import(
'eyJuIjoiSGVsbG8sIHdvcmxkIiwiYyI6ImZvbzogYmFyIiwiZSI6IiRjb250ZXh0WydiYXonXSA9IHN0cnRvdXBwZXIoJGNvbnRleHRbJ2ZvbyddKTsiLCJmIjpbeyJkIjoiaWYgeW91IHNlYXJjaCBmb3IgbWUsIGknbSBhdCB0aGUge3sgYmF6IH19IiwidCI6IkhlbGxvLCB7eyBmb28gfX0ifV19'
);
}
}
```