-
Notifications
You must be signed in to change notification settings - Fork 5
/
tailwind-shift
executable file
·78 lines (55 loc) · 2.54 KB
/
tailwind-shift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env php
<?php
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Awssat\TailwindShift\ConsoleHelper;
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require __DIR__ . '/vendor/autoload.php';
} else {
require __DIR__ . '/../../autoload.php';
}
(new Application('tailwind-shift', '1.0.9'))
->register('tailwind-shift')
->addArgument('arg', InputArgument::OPTIONAL, 'a file path/a folder path/snippet of code')
->addOption('replace', null, InputOption::VALUE_REQUIRED, 'This will overwrite the original file.', false)
->addOption('recursive', 'r', InputOption::VALUE_OPTIONAL, 'This will recurse through all directories under the main directory', false)
->addOption('fixconfig', 'x', InputOption::VALUE_OPTIONAL, 'This must be added if given file is tailwind config file, to fix and update to latest version.', false)
->addOption('extensions', 'e', InputOption::VALUE_REQUIRED, 'This allows for custom extensions', 'php,html,css')
->setCode(function (InputInterface $input, OutputInterface $output) {
// output arguments and options
$arg = $input->getFirstArgument();
$arg = trim($arg);
if (empty($arg)) {
$output->writeln('<comment>Oops! nothing to convert.</comment>');
return -1;
}
$replace = (bool) $input->getOption('replace');
$is_recursive = (bool) $input->getOption('recursive');
$fix_config = (bool) $input->getOption('fixconfig');
$acceptedExts = array_map('trim', array_map(function ($ext) {
return trim($ext, '.');
}, array_filter(explode(',', $input->getOption('extensions')), function ($ext) {
return !empty($ext);
})));
$consoleHelper = new ConsoleHelper($output, $is_recursive, $replace, $acceptedExts);
//file?
if (is_file($arg)) {
if ($fix_config) {
return $consoleHelper->fixTailwindConfig($arg);
} else {
return $consoleHelper->fileConvert($arg, pathinfo($arg)['extension'] ?? '');
}
}
//folder ?
if (is_dir($arg)) {
return $consoleHelper->folderConvert($arg);
}
//any html/css classes
return $consoleHelper->codeConvert($arg);
})
->getApplication()
->setDefaultCommand('tailwind-shift', true)
->run();