Skip to content

Commit e9b76e9

Browse files
committed
TASK: initial commit
0 parents  commit e9b76e9

File tree

7 files changed

+189
-0
lines changed

7 files changed

+189
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
namespace Skrull\Node\Migration\Generator\Command;
3+
4+
/*
5+
* This file is part of the Skrull.Node.Migration.Generator package.
6+
*
7+
* (C) 2023 Simon Krull
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE.md file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\Flow\Cli\CommandController;
15+
use Neos\Flow\Cli\Exception\StopCommandException;
16+
use Neos\Flow\Package\Exception\UnknownPackageException;
17+
use Neos\Flow\Package\PackageManager;
18+
use Neos\Utility\Exception\FilesException;
19+
use Skrull\Node\Migration\Generator\Service\GeneratorService;
20+
use Neos\Flow\Annotations as Flow;
21+
22+
/**
23+
* Command controller for the Node Migration generator.
24+
*
25+
*/
26+
class SkrullCommandController extends CommandController
27+
{
28+
/**
29+
* @Flow\Inject
30+
* @var PackageManager
31+
*/
32+
protected PackageManager $packageManager;
33+
34+
/**
35+
* @Flow\Inject
36+
* @var GeneratorService
37+
*/
38+
protected GeneratorService $generatorService;
39+
40+
/**
41+
* Creates a node migration for the given package Key.
42+
*
43+
* @param string $packageKey The packageKey for the given package
44+
* @return void
45+
* @throws UnknownPackageException
46+
* @throws FilesException
47+
* @throws StopCommandException
48+
*/
49+
public function migrationCreateCommand(string $packageKey): void
50+
{
51+
if (!$this->packageManager->isPackageAvailable($packageKey)) {
52+
$this->outputLine('Package "%s" is not available.', [$packageKey]);
53+
$this->quit(1);
54+
}
55+
56+
$createdMigration = $this->generatorService->createNodeMigration($packageKey);
57+
$this->outputLine($createdMigration);
58+
$this->outputLine('Your node migration has been created successfully.');
59+
}
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
namespace Skrull\Node\Migration\Generator\Service;
3+
4+
/*
5+
* This file is part of the Skrull.Node.Migration.Generator package.
6+
*
7+
* (C) 2023 Simon Krull
8+
*
9+
* This package is Open Source Software. For the full copyright and license
10+
* information, please view the LICENSE.md file which was distributed with this
11+
* source code.
12+
*/
13+
14+
use Neos\Flow\Package\Exception\UnknownPackageException;
15+
use Neos\Flow\Package\PackageManager;
16+
use Neos\Utility\Exception\FilesException;
17+
use Neos\Utility\Files;
18+
use Neos\Flow\Annotations as Flow;
19+
20+
/**
21+
* Service for the Node Migration generator
22+
*
23+
*/
24+
class GeneratorService
25+
{
26+
27+
/**
28+
* @Flow\Inject
29+
* @var PackageManager
30+
*/
31+
protected PackageManager $packageManager;
32+
33+
/**
34+
* Creates a node migration for the given $packageKey
35+
*
36+
* @param string $packageKey the package key
37+
* @return string
38+
* @throws UnknownPackageException
39+
* @throws FilesException
40+
*/
41+
public function createNodeMigration(string $packageKey): string
42+
{
43+
$templatePath = 'resource://Skrull.Node.Migration.Generator/Private/Generator/Migrations/ContentRepository/NodeMigrationTemplate.yaml.tmpl';
44+
$nodeMigrationPath = Files::concatenatePaths([$this->packageManager->getPackage($packageKey)->getPackagePath(), 'Migrations/ContentRepository']) . '/';
45+
46+
$timeStamp = (new \DateTimeImmutable())->format('YmdHis');
47+
$nodeMigrationFileName = 'Version' . $timeStamp . '.yaml';
48+
49+
$targetPathAndFilename = $nodeMigrationPath . $nodeMigrationFileName;
50+
$fileContent = file_get_contents($templatePath);
51+
52+
if (!is_dir(dirname($targetPathAndFilename))) {
53+
Files::createDirectoryRecursively(dirname($targetPathAndFilename));
54+
}
55+
56+
file_put_contents($targetPathAndFilename, $fileContent);
57+
58+
return $packageKey . '/Migrations/ContentRepository/' . $nodeMigrationFileName;
59+
}
60+
}

Documentation/demo.gif

497 KB
Loading

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 Simon Krull
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Skull.Node.Migration.Generator
2+
> A tiny Neos package for creating node migrations via the command line.
3+
4+
## Installation
5+
6+
```bash
7+
composer require skrull/node-migration-generator
8+
```
9+
10+
## Demo
11+
![Demo Video](Documentation/demo.gif)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#############################################################################################################################################################################
2+
# For more information about node migrations in Neos, checkout the documentation: https://neos.readthedocs.io/en/stable/References/NodeMigrations.html?highlight=migrations #
3+
#############################################################################################################################################################################
4+
up:
5+
comments: 'Migration description'
6+
migration:
7+
-
8+
filters:
9+
-
10+
11+
down:
12+
comments: 'No down migration available'

composer.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"description": "Create node migrations from the command line",
3+
"type": "neos-plugin",
4+
"name": "skrull/node-migration-generator",
5+
"license": "MIT",
6+
"keywords": [
7+
"neoscms",
8+
"flow",
9+
"terminal",
10+
"console"
11+
],
12+
"require": {
13+
"neos/neos": "^7.3 || ^8.0 || dev-master"
14+
},
15+
"autoload": {
16+
"psr-4": {
17+
"Skrull\\Node\\Migration\\Generator\\": "Classes/"
18+
}
19+
},
20+
"extra": {
21+
"neos": {
22+
"package-key": "Skrull.Node.Migration.Generator"
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)