option('output') ?: resource_path('css/material-scheme.css'); $data = preg_replace('/\.css$/', '', $stylesheet).'.json'; $result = Process::run([ config('livewire-material.node', 'node'), __DIR__.'/../../resources/node/scheme.mjs', json_encode([ 'seed' => $this->argument('seed'), 'variant' => $this->option('variant'), 'contrast' => (float) $this->option('contrast'), 'success' => $this->option('success'), 'warning' => $this->option('warning'), 'info' => $this->option('info'), ]), ]); if ($result->failed()) { $this->components->error(trim($result->errorOutput()) ?: 'Node could not run the scheme generator. Is `node` installed and on the PATH?'); return self::FAILURE; } try { /** @var array{seed: string, variant: string, spec: string, contrast: float, light: array, dark: array} $scheme */ $scheme = json_decode($result->output(), true, flags: JSON_THROW_ON_ERROR); } catch (JsonException) { $this->components->error('The scheme generator answered with something other than JSON.'); return self::FAILURE; } $files->ensureDirectoryExists(dirname($stylesheet)); $files->put($stylesheet, $this->stylesheet($scheme)); $files->put($data, json_encode($scheme, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)."\n"); $this->components->info("Wrote {$stylesheet} and {$data}."); return self::SUCCESS; } /** * @param array{seed: string, variant: string, spec: string, contrast: float, light: array, dark: array} $scheme */ protected function stylesheet(array $scheme): string { $command = sprintf( 'php artisan material:scheme "%s" --variant=%s%s', $scheme['seed'], $scheme['variant'], $scheme['contrast'] != 0 ? ' --contrast='.$scheme['contrast'] : '', ); $block = fn (array $roles): string => collect($roles) ->map(fn (string $hex, string $role): string => " --md-sys-color-{$role}: {$hex};") ->implode("\n"); return <<