Skip to content

Commit a262fd4

Browse files
committed
upgrades dependencies and fixes #18
1 parent 26bf35d commit a262fd4

File tree

11 files changed

+179
-137
lines changed

11 files changed

+179
-137
lines changed

.github/workflows/phpunit.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
tests:
11+
strategy:
12+
fail-fast: true
13+
matrix:
14+
php: [7.2, 7.3, 7.4]
15+
dependency-version: [prefer-lowest, prefer-stable]
16+
17+
runs-on: ubuntu-latest
18+
19+
name: PHP${{ matrix.php }}- ${{ matrix.dependency-version }}
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
24+
- name: Cache dependencies
25+
uses: actions/cache@v1
26+
with:
27+
path: ~/.composer/cache/files
28+
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
29+
30+
- name: Setup PHP
31+
uses: shivammathur/setup-php@v2
32+
with:
33+
php-version: ${{ matrix.php }}
34+
coverage: none
35+
36+
37+
38+
- name: Install dependencies
39+
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest --no-progress
40+
41+
42+
- name: Run tests
43+
run: vendor/bin/phpunit tests

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
22
composer.lock
33
vendor
4-
build
4+
build
5+
.phpunit.result.cache

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
![tailwind-shift](https://i.imgur.com/Ldx09d8.png)
44

55
[![Latest Version on Packagist](https://img.shields.io/packagist/v/awssat/tailwind-shift.svg?style=flat-square)](https://packagist.org/packages/awssat/tailwind-shift)
6-
[![StyleCI](https://styleci.io/repos/177280907/shield?branch=master)](https://styleci.io/repos/177280907)
7-
[![Build Status](https://img.shields.io/travis/awssat/tailwind-shift/master.svg?style=flat-square)](https://travis-ci.org/awssat/tailwind-shift)
86

97
A helper tool to upgrade your current codes of a project to latest version of TailwindCSS without a hassle.
108
It's currently support shifting from 0.7.x to 1.0

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": [
55
"CSS",
66
"Tailwind",
7-
"Bootstrap"
7+
"TailwindCSS"
88
],
99
"homepage": "https://github.com/awssat/tailwind-shift",
1010
"license": "MIT",
@@ -16,11 +16,11 @@
1616
],
1717

1818
"require": {
19-
"php" : "~7.0",
20-
"symfony/console": "^3.0 || ^4.0"
19+
"php" : "^7.2.0",
20+
"symfony/console": "^4.0|^5.0"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "^6.4"
23+
"phpunit/phpunit": "^8"
2424
},
2525

2626
"autoload": {

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<logging>
2323
<log type="tap" target="build/report.tap"/>
2424
<log type="junit" target="build/report.junit.xml"/>
25-
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
25+
<log type="coverage-html" target="build/coverage" />
2626
<log type="coverage-text" target="build/coverage.txt"/>
2727
<log type="coverage-clover" target="build/logs/clover.xml"/>
2828
</logging>

src/ConfigFileFixer.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function fixForVersion1_0()
6767
//1: get options{} values and add em to root of 'module.exports' and add last value as theme: {..
6868
preg_match('/options:\s*\{([^\}]+)\},?/', $this->searchAndReplace->get(), $match);
6969
$options = $match[1] ?? '';
70-
$updatedToThemeKey = "module.exports = {\n".$options."\n\ntheme: {\n";
70+
$updatedToThemeKey = "module.exports = {\n" . $options . "\n\ntheme: {\n";
7171

7272
$this->searchAndReplace->perform('options:\s*\{([^\}]+)\},?', '', SearchAndReplace::NO_ESCAPE);
7373
$this->searchAndReplace->perform('module.exports\s*=\s*\{', $updatedToThemeKey, SearchAndReplace::NO_ESCAPE);
@@ -95,13 +95,13 @@ protected function fixForVersion1_0()
9595
'lists\:{regex_line}' => "listStylePosition:{regex_line}\nlistStyleType:{regex_line}",
9696
'position\:{regex_line}' => "position:{regex_line}\ninset:{regex_line}",
9797
'whitespace\:{regex_line}' => "whitespace:{regex_line}\nwordBreak:{regex_line}",
98-
'textStyle\:{regex_line}' => "fontStyle:{regex_line}\nfontSmoothing:{regex_line}".
99-
"\ntextDecoration:{regex_line}\ntextTransform:{regex_line}",
100-
'flexbox\:{regex_line}' => "flexDirection:{regex_line}\nflexWrap:{regex_line}".
101-
"\nalignItems:{regex_line}\nalignSelf:{regex_line}".
102-
"\njustifyContent:{regex_line}\nalignContent:{regex_line}".
103-
"\nflex:{regex_line}\nflexGrow:{regex_line}".
104-
"\nflexShrink:{regex_line}",
98+
'textStyle\:{regex_line}' => "fontStyle:{regex_line}\nfontSmoothing:{regex_line}" .
99+
"\ntextDecoration:{regex_line}\ntextTransform:{regex_line}",
100+
'flexbox\:{regex_line}' => "flexDirection:{regex_line}\nflexWrap:{regex_line}" .
101+
"\nalignItems:{regex_line}\nalignSelf:{regex_line}" .
102+
"\njustifyContent:{regex_line}\nalignContent:{regex_line}" .
103+
"\nflex:{regex_line}\nflexGrow:{regex_line}" .
104+
"\nflexShrink:{regex_line}",
105105
];
106106

107107
foreach ($newNames as $old => $new) {
@@ -114,46 +114,46 @@ protected function fixForVersion1_0()
114114
$containerOptions = $match[1] ?? '';
115115

116116
$this->searchAndReplace->perform('require\(\'tailwindcss\/plugins\/container\'\)\(\{([^\}]+)\}\),?', '', SearchAndReplace::NO_ESCAPE);
117-
$corePlugins = 'corePlugins: {'.(empty($containerOptions) ? "\ncontainer: false," : '')."\n}, \nplugins: [";
117+
$corePlugins = 'corePlugins: {' . (empty($containerOptions) ? "\ncontainer: false," : '') . "\n}, \nplugins: [";
118118

119119
$this->searchAndReplace->perform('plugins:\s*\[', $corePlugins, SearchAndReplace::NO_ESCAPE);
120-
$this->searchAndReplace->perform('theme:\s*\{', "theme: \n{\ncontainer: {\n".$containerOptions."\n},\n", SearchAndReplace::NO_ESCAPE);
120+
$this->searchAndReplace->perform('theme:\s*\{', "theme: \n{\ncontainer: {\n" . $containerOptions . "\n},\n", SearchAndReplace::NO_ESCAPE);
121121

122122
//8: fix colors
123-
$colors = "\n transparent: 'transparent',\n\n black: '#000',\n white: '#fff',".
124-
"\n gray: {\n100: '#f7fafc',\n200: '#edf2f7',\n300: '#e2e8f0',".
125-
"\n400: '#cbd5e0',\n500: '#a0aec0',\n600: '#718096',\n700: '#4a5568',".
126-
"\n800: '#2d3748',\n900: '#1a202c',\n},\n".
127-
"\n red: {\n100: '#fff5f5',\n200: '#fed7d7',\n300: '#feb2b2',\n400: '#fc8181',".
128-
"\n500: '#f56565',\n600: '#e53e3e',\n700: '#c53030',\n800: '#9b2c2c',".
129-
"\n900: '#742a2a',\n},\n".
130-
"\n orange: {\n100: '#fffaf0',\n200: '#feebc8',\n300: '#fbd38d',".
131-
"\n400: '#f6ad55',\n500: '#ed8936',\n600: '#dd6b20',\n700: '#c05621',".
132-
"\n800: '#9c4221',\n900: '#7b341e',\n},\n".
133-
"\n yellow: {\n100: '#fffff0',\n200: '#fefcbf',\n300: '#faf089',".
134-
"\n400: '#f6e05e',\n500: '#ecc94b',\n600: '#d69e2e',\n700: '#b7791f',".
135-
"\n800: '#975a16',\n900: '#744210',\n},\n".
136-
"\n green: {\n100: '#f0fff4',\n200: '#c6f6d5',\n300: '#9ae6b4',".
137-
"\n400: '#68d391',\n500: '#48bb78',\n600: '#38a169',\n700: '#2f855a',".
138-
"\n800: '#276749',\n900: '#22543d',\n},".
139-
"\n teal: {\n100: '#e6fffa',\n200: '#b2f5ea',\n300: '#81e6d9',".
140-
"\n400: '#4fd1c5',\n500: '#38b2ac',\n600: '#319795',\n700: '#2c7a7b',".
141-
"\n800: '#285e61',\n900: '#234e52',\n},\n".
142-
"\n blue: {\n100: '#ebf8ff',\n200: '#bee3f8',\n300: '#90cdf4',".
143-
"\n400: '#63b3ed',\n500: '#4299e1',\n600: '#3182ce',\n700: '#2b6cb0', ".
144-
"\n800: '#2c5282',\n900: '#2a4365',\n},".
145-
"\n indigo: {\n100: '#ebf4ff',\n200: '#c3dafe',\n300: '#a3bffa',".
146-
"\n400: '#7f9cf5',\n500: '#667eea',\n600: '#5a67d8',\n700: '#4c51bf',".
147-
"\n800: '#434190',\n900: '#3c366b',\n},\n".
148-
"\n purple: {\n100: '#faf5ff',\n200: '#e9d8fd',\n300: '#d6bcfa',".
149-
"\n400: '#b794f4',\n500: '#9f7aea',\n600: '#805ad5',\n700: '#6b46c1',".
150-
"\n800: '#553c9a',\n900: '#44337a',\n},\n".
151-
"\n pink: {\n100: '#fff5f7',\n200: '#fed7e2',\n300: '#fbb6ce',".
152-
"\n400: '#f687b3',\n500: '#ed64a6',\n600: '#d53f8c',\n700: '#b83280',".
153-
"\n800: '#97266d',\n900: '#702459',\n},\n";
123+
$colors = "\n transparent: 'transparent',\n\n black: '#000',\n white: '#fff'," .
124+
"\n gray: {\n100: '#f7fafc',\n200: '#edf2f7',\n300: '#e2e8f0'," .
125+
"\n400: '#cbd5e0',\n500: '#a0aec0',\n600: '#718096',\n700: '#4a5568'," .
126+
"\n800: '#2d3748',\n900: '#1a202c',\n},\n" .
127+
"\n red: {\n100: '#fff5f5',\n200: '#fed7d7',\n300: '#feb2b2',\n400: '#fc8181'," .
128+
"\n500: '#f56565',\n600: '#e53e3e',\n700: '#c53030',\n800: '#9b2c2c'," .
129+
"\n900: '#742a2a',\n},\n" .
130+
"\n orange: {\n100: '#fffaf0',\n200: '#feebc8',\n300: '#fbd38d'," .
131+
"\n400: '#f6ad55',\n500: '#ed8936',\n600: '#dd6b20',\n700: '#c05621'," .
132+
"\n800: '#9c4221',\n900: '#7b341e',\n},\n" .
133+
"\n yellow: {\n100: '#fffff0',\n200: '#fefcbf',\n300: '#faf089'," .
134+
"\n400: '#f6e05e',\n500: '#ecc94b',\n600: '#d69e2e',\n700: '#b7791f'," .
135+
"\n800: '#975a16',\n900: '#744210',\n},\n" .
136+
"\n green: {\n100: '#f0fff4',\n200: '#c6f6d5',\n300: '#9ae6b4'," .
137+
"\n400: '#68d391',\n500: '#48bb78',\n600: '#38a169',\n700: '#2f855a'," .
138+
"\n800: '#276749',\n900: '#22543d',\n}," .
139+
"\n teal: {\n100: '#e6fffa',\n200: '#b2f5ea',\n300: '#81e6d9'," .
140+
"\n400: '#4fd1c5',\n500: '#38b2ac',\n600: '#319795',\n700: '#2c7a7b'," .
141+
"\n800: '#285e61',\n900: '#234e52',\n},\n" .
142+
"\n blue: {\n100: '#ebf8ff',\n200: '#bee3f8',\n300: '#90cdf4'," .
143+
"\n400: '#63b3ed',\n500: '#4299e1',\n600: '#3182ce',\n700: '#2b6cb0', " .
144+
"\n800: '#2c5282',\n900: '#2a4365',\n}," .
145+
"\n indigo: {\n100: '#ebf4ff',\n200: '#c3dafe',\n300: '#a3bffa'," .
146+
"\n400: '#7f9cf5',\n500: '#667eea',\n600: '#5a67d8',\n700: '#4c51bf'," .
147+
"\n800: '#434190',\n900: '#3c366b',\n},\n" .
148+
"\n purple: {\n100: '#faf5ff',\n200: '#e9d8fd',\n300: '#d6bcfa'," .
149+
"\n400: '#b794f4',\n500: '#9f7aea',\n600: '#805ad5',\n700: '#6b46c1'," .
150+
"\n800: '#553c9a',\n900: '#44337a',\n},\n" .
151+
"\n pink: {\n100: '#fff5f7',\n200: '#fed7e2',\n300: '#fbb6ce'," .
152+
"\n400: '#f687b3',\n500: '#ed64a6',\n600: '#d53f8c',\n700: '#b83280'," .
153+
"\n800: '#97266d',\n900: '#702459',\n},\n";
154154

155155
$this->searchAndReplace->perform('let colors\s*=\s*\{([^\}]+)\}', '', SearchAndReplace::NO_ESCAPE);
156-
$this->searchAndReplace->perform('\s+colors:\s*colors', ' colors: {'.$colors.'}', SearchAndReplace::NO_ESCAPE);
156+
$this->searchAndReplace->perform('\s+colors:\s*colors', ' colors: {' . $colors . '}', SearchAndReplace::NO_ESCAPE);
157157
$this->searchAndReplace->perform('backgroundColor:\s*colors', 'backgroundColor: theme => theme(\'colors\')', SearchAndReplace::NO_ESCAPE);
158158
$this->searchAndReplace->perform('textColor:\s*colors', 'textColor: theme => theme(\'colors\')', SearchAndReplace::NO_ESCAPE);
159159
$this->searchAndReplace->perform('borderColor:\s*g([^\n]+)', "borderColor: theme => {\nreturn global.Object.assign({ default: theme('colors.gray.300', 'currentColor') }, theme('colors'))\n},", SearchAndReplace::NO_ESCAPE);

src/ConsoleHelper.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ public function __construct(OutputInterface $output, $recursive, $overwrite, $ex
2323

2424
public function folderConvert($folderPath)
2525
{
26-
$this->output->writeln('<question>Start Converting Folder: </question>'.$folderPath);
26+
$this->output->writeln('<question>Start Converting Folder: </question>' . $folderPath);
2727

2828
if ($this->recursive) {
2929
$iterator = new \RecursiveIteratorIterator(
3030
new \RecursiveDirectoryIterator(
31-
$folderPath, \RecursiveDirectoryIterator::SKIP_DOTS
31+
$folderPath,
32+
\RecursiveDirectoryIterator::SKIP_DOTS
3233
),
3334
\RecursiveIteratorIterator::SELF_FIRST,
3435
\RecursiveIteratorIterator::CATCH_GET_CHILD
@@ -52,7 +53,7 @@ public function fileConvert($filePath, $extension)
5253
$filePath = realpath($filePath);
5354

5455
if (!is_file($filePath)) {
55-
$this->output->writeln('<comment>Couldn\'t convert: </comment>'.basename($filePath));
56+
$this->output->writeln('<comment>Couldn\'t convert: </comment>' . basename($filePath));
5657

5758
return;
5859
}
@@ -64,51 +65,51 @@ public function fileConvert($filePath, $extension)
6465
if ($lastDotPosition !== false && !$this->overwrite) {
6566
$newFilePath = substr_replace($filePath, '.tw', $lastDotPosition, 0);
6667
} elseif (!$this->overwrite) {
67-
$newFilePath = $filePath.'.tw';
68+
$newFilePath = $filePath . '.tw';
6869
} else {
6970
// Set the new path to the old path to make sure we overwrite it
7071
$newFilePath = $filePath;
7172
}
7273

7374
$newContent = $this->updater
74-
->setContent($content)
75-
->setFileExtension($extension)
76-
->convert()
77-
->get();
75+
->setContent($content)
76+
->setFileExtension($extension)
77+
->convert()
78+
->get();
7879

7980
if ($content !== $newContent) {
80-
$this->output->writeln('<info>Converted: </info>'.basename($newFilePath));
81+
$this->output->writeln('<info>Converted: </info>' . basename($newFilePath));
8182

8283
file_put_contents($newFilePath, $newContent);
8384
} else {
84-
$this->output->writeln('<comment>Nothing to convert: </comment>'.basename($filePath));
85+
$this->output->writeln('<comment>Nothing to convert: </comment>' . basename($filePath));
8586
}
8687
}
8788

8889
public function codeConvert($code)
8990
{
9091
$convertedCode = $this->updater
91-
->setContent($code)
92-
->convert()
93-
->get();
92+
->setContent($code)
93+
->convert()
94+
->get();
9495

95-
$this->output->writeln('<info>Converted Code: </info>'.$convertedCode);
96+
$this->output->writeln('<info>Converted Code: </info>' . $convertedCode);
9697
}
9798

9899
public function fixTailwindConfig($filePath)
99100
{
100101
$originalContent = file_get_contents($filePath);
101102

102103
$fixedContent = (new ConfigFileFixer($originalContent))
103-
->fix()
104+
->fix()
104105
->get();
105106

106107
$lastDotPosition = strrpos($filePath, '.');
107108

108109
if ($lastDotPosition !== false && !$this->overwrite) {
109110
$newFilePath = substr_replace($filePath, '.tw', $lastDotPosition, 0);
110111
} elseif (!$this->overwrite) {
111-
$newFilePath = $filePath.'.tw';
112+
$newFilePath = $filePath . '.tw';
112113
} else {
113114
// Set the new path to the old path to make sure we overwrite it
114115
$newFilePath = $filePath;

src/SearchAndReplace.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function setContent(string $content)
5353
}
5454

5555
/**
56-
* Get the number of comitted changes.
56+
* Get the number of committed changes.
5757
*
5858
* @return int
5959
*/
@@ -121,12 +121,12 @@ public function perform($search, $replace, $options = null)
121121
strpos($search, 'regex_string') !== false
122122
|| strpos($search, 'regex_number') !== false
123123
|| strpos($search, 'regex_line') !== false
124-
) {
124+
) {
125125
$currentSubstitute++;
126-
foreach (['regex_string'=> '[a-zA-Z0-9]+', 'regex_number' => '[0-9]+', 'regex_line' => '[^\n]+'] as $regeName => $regexValue) {
127-
$regexMatchCount = preg_match_all('/\\\\?\{'.$regeName.'\\\\?\}/', $search);
128-
$search = preg_replace('/\\\\?\{'.$regeName.'\\\\?\}/', '(?<'.substr($regeName, 6).'_'.$currentSubstitute.'>'.$regexValue.')', $search, 1);
129-
$replace = preg_replace('/\\\\?\{'.$regeName.'\\\\?\}/', '${'.substr($regeName, 6).'_'.$currentSubstitute.'}', $replace, $regexMatchCount > 1 ? 1 : -1);
126+
foreach (['regex_string' => '[a-zA-Z0-9]+', 'regex_number' => '[0-9]+', 'regex_line' => '[^\n]+'] as $regexName => $regexValue) {
127+
$regexMatchCount = preg_match_all('/\\\\?\{' . $regexName . '\\\\?\}/', $search);
128+
$search = preg_replace('/\\\\?\{' . $regexName . '\\\\?\}/', '(?<' . substr($regexName, 6) . '_' . $currentSubstitute . '>' . $regexValue . ')', $search, 1);
129+
$replace = preg_replace('/\\\\?\{' . $regexName . '\\\\?\}/', '${' . substr($regexName, 6) . '_' . $currentSubstitute . '}', $replace, $regexMatchCount > 1 ? 1 : -1);
130130
}
131131
continue;
132132
}
@@ -136,13 +136,13 @@ public function perform($search, $replace, $options = null)
136136

137137
//class=" given given-md something-given-md"
138138
$this->givenContent = preg_replace_callback(
139-
'/'.$regexStart.'(?<given>(?<![\-_.\w\d])'.$search.'(?![\-_.\w\d]))'.$regexEnd.'/is',
139+
'/' . $regexStart . '(?<given>(?<![\-_.\w\d])' . $search . '(?![\-_.\w\d]))' . $regexEnd . '/is',
140140
function ($match) use ($replace) {
141141
$replace = preg_replace_callback('/\$\{(number|string|line)_(\d+)\}/', function ($m) use ($match) {
142-
return $match[$m[1].'_'.$m[2]];
142+
return $match[$m[1] . '_' . $m[2]];
143143
}, $replace);
144144

145-
return $match['start'].$replace.$match['end'];
145+
return $match['start'] . $replace . $match['end'];
146146
},
147147
$this->givenContent
148148
);

0 commit comments

Comments
 (0)