-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
I would like to build a tool that would allow me to use PHP code to create/update/delete any files and folders and execute commands in a specific directory.
<?php
$vendor = 'ghostwriter';
$package = 'container';
$packageName = $vendor . '/' . $package;
$vendorNamespace = \ucfirst($vendor);
$packageClass = \ucfirst($package);
$packageNamespace = $vendorNamespace . '\\' . $packageClass;
$packageDescription = 'A simple DI container for PHP';
$packageAuthor = 'Nathanael Esayeas'; // $workspace->run('git config --get user.name');
$packageAuthorGithub = $vendor;
$packageAuthorEmail = '[email protected]'; // $workspace->run('git config --get user.email');
$directory = Directory::new(__DIR__);
$workspace = Workspace::new($directory);
$textDocument = $workspace->open('README.md');
$textDocument->write('# ' . $packageClass . \PHP_EOL);
$textDocument->write($packageDescription . \PHP_EOL);
$textDocument->write('## Installation' . \PHP_EOL . \PHP_EOL);
$textDocument->write('```bash' . \PHP_EOL);
$textDocument->write('composer require ' . $packageName . \PHP_EOL);
$textDocument->write('```' . \PHP_EOL . \PHP_EOL);
$textDocument->write('## Usage' . \PHP_EOL);
$textDocument->write('```php' . \PHP_EOL);
$textDocument->write('use ' . $packageNamespace . ';' . \PHP_EOL . \PHP_EOL);
$textDocument->write('$' . $package . ' = ' . $packageClass . '::new();' . \PHP_EOL . \PHP_EOL);
$textDocument->write('```' . \PHP_EOL . \PHP_EOL);
$textDocument->save();
$textDocument = $workspace->open('composer.json');
$composerJson = [];
$composerJson['name'] = $packageName;
$composerJson['description'] = $packageDescription;
$composerJson['type'] = 'library';
$composerJson['keywords'] = [$vendor, $package];
$composerJson['license'] = 'BSD-3-Clause';
$composerJson['authors']['name'] = $packageAuthor;
$composerJson['authors']['email'] = $packageAuthorEmail;
$composerJson['authors']['homepage'] = 'https://github.com/' . $vendor;
$composerJson['authors']['role'] = 'Developer';
$composerJson['homepage'] = 'https://github.com/' . $packageName;
$composerJson['funding']['type'] = 'github';
$composerJson['funding']['url'] = 'https://github.com/sponsors/' . $vendor;
$composerJson['require']['php'] = '>=8.2';
$composerJson['require-dev']['phpunit/phpunit'] = '^10.5';
$composerJson['require-dev']['vimeo/psalm'] = '^5.19';
$composerJson['autoload']['psr-4'][$packageNamespace . '\\'] = 'src';
$composerJson['autoload-dev']['psr-4'][$packageNamespace . 'Tests\\'] = 'tests';
$composerJson['scripts']['test'] = 'phpunit';
$composerJson['scripts']['psalm'] = 'psalm';
$textDocument->write(\json_encode($composerJson, \JSON_PRETTY_PRINT));
$textDocument->save();
$workspace->run('composer install');
$textDocument = $workspace->open('phpunit.xml.dist');
$phpunitXml = '...';
$textDocument->write($phpunitXml);
$textDocument->save();
$textDocument = $workspace->open('src/' . $packageClass . '.php');
$packageClassPhp = '...';
$textDocument->write($packageClassPhp);
$textDocument->save();
$textDocument = $workspace->open('tests/' . $packageClass . 'Test.php');
$packageClassTestPhp = '...';
$textDocument->write($packageClassTestPhp);
$textDocument->save();
$workspace->run('composer test');
$workspace->run('composer psalm');
Then add custom
- middleware
- events & listeners to hook into all the things
- tools ($workspace->psalm($level) )
Metadata
Metadata
Assignees
Labels
No labels