mirror of
https://github.com/archtechx/airwire.git
synced 2025-12-12 10:44:03 +00:00
initial
This commit is contained in:
commit
d26fa93f1e
35 changed files with 2388 additions and 0 deletions
72
src/Commands/GenerateDefinitions.php
Normal file
72
src/Commands/GenerateDefinitions.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace Airwire\Commands;
|
||||
|
||||
use Airwire\Airwire;
|
||||
use Airwire\TypehintConverter;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class GenerateDefinitions extends Command
|
||||
{
|
||||
public static string $dir;
|
||||
|
||||
protected $signature = 'airwire:generate';
|
||||
|
||||
protected $description = 'Command description';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$defaults = [];
|
||||
|
||||
$components = '';
|
||||
|
||||
$typemap = "type TypeMap = {\n";
|
||||
|
||||
$converter = (new TypehintConverter);
|
||||
foreach (Airwire::$components as $alias => $class) {
|
||||
$defaults[$alias] = (new $class([]))->getState();
|
||||
|
||||
$components .= $converter->convertComponent(new $class([])) . "\n\n";
|
||||
$className = $converter->getClassName($class);
|
||||
$typemap .= " '{$alias}': {$className}\n";
|
||||
}
|
||||
|
||||
$namedTypes = '';
|
||||
foreach ($converter->namedTypes as $alias => $type) {
|
||||
$namedTypes .= "type {$alias} = {$type};\n\n";
|
||||
}
|
||||
|
||||
$typemap .= "}";
|
||||
|
||||
$defaults = json_encode($defaults);
|
||||
|
||||
file_put_contents(resource_path('js/airwire.ts'), <<<JS
|
||||
// This file is generated by Airwire
|
||||
export const componentDefaults = {$defaults}
|
||||
|
||||
import Airwire from './../../vendor/archtechx/airwire/resources/js';
|
||||
|
||||
export default window.Airwire = new Airwire(componentDefaults)
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Airwire: Airwire
|
||||
}
|
||||
}
|
||||
JS);
|
||||
|
||||
file_put_contents(resource_path('js/airwired.d.ts'), <<<JS
|
||||
|
||||
declare global {
|
||||
{$namedTypes}
|
||||
}
|
||||
|
||||
import './../../vendor/archtechx/airwire/resources/js/airwired'
|
||||
|
||||
declare module 'airwire' {
|
||||
export {$typemap}
|
||||
{$components}
|
||||
}
|
||||
JS);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue