Skip to content

Commit

Permalink
upgrades dependencies and fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
abdumu committed Jul 11, 2020
1 parent 26bf35d commit a262fd4
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 137 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
tests:
strategy:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4]
dependency-version: [prefer-lowest, prefer-stable]

runs-on: ubuntu-latest

name: PHP${{ matrix.php }}- ${{ matrix.dependency-version }}

steps:
- uses: actions/checkout@v2

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none



- name: Install dependencies
run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest --no-progress


- name: Run tests
run: vendor/bin/phpunit tests
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
composer.lock
vendor
build
build
.phpunit.result.cache
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
![tailwind-shift](https://i.imgur.com/Ldx09d8.png)

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

A helper tool to upgrade your current codes of a project to latest version of TailwindCSS without a hassle.
It's currently support shifting from 0.7.x to 1.0
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"keywords": [
"CSS",
"Tailwind",
"Bootstrap"
"TailwindCSS"
],
"homepage": "https://github.com/awssat/tailwind-shift",
"license": "MIT",
Expand All @@ -16,11 +16,11 @@
],

"require": {
"php" : "~7.0",
"symfony/console": "^3.0 || ^4.0"
"php" : "^7.2.0",
"symfony/console": "^4.0|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^6.4"
"phpunit/phpunit": "^8"
},

"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<logging>
<log type="tap" target="build/report.tap"/>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage" charset="UTF-8" yui="true" highlight="true"/>
<log type="coverage-html" target="build/coverage" />
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
</logging>
Expand Down
84 changes: 42 additions & 42 deletions src/ConfigFileFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected function fixForVersion1_0()
//1: get options{} values and add em to root of 'module.exports' and add last value as theme: {..
preg_match('/options:\s*\{([^\}]+)\},?/', $this->searchAndReplace->get(), $match);
$options = $match[1] ?? '';
$updatedToThemeKey = "module.exports = {\n".$options."\n\ntheme: {\n";
$updatedToThemeKey = "module.exports = {\n" . $options . "\n\ntheme: {\n";

$this->searchAndReplace->perform('options:\s*\{([^\}]+)\},?', '', SearchAndReplace::NO_ESCAPE);
$this->searchAndReplace->perform('module.exports\s*=\s*\{', $updatedToThemeKey, SearchAndReplace::NO_ESCAPE);
Expand Down Expand Up @@ -95,13 +95,13 @@ protected function fixForVersion1_0()
'lists\:{regex_line}' => "listStylePosition:{regex_line}\nlistStyleType:{regex_line}",
'position\:{regex_line}' => "position:{regex_line}\ninset:{regex_line}",
'whitespace\:{regex_line}' => "whitespace:{regex_line}\nwordBreak:{regex_line}",
'textStyle\:{regex_line}' => "fontStyle:{regex_line}\nfontSmoothing:{regex_line}".
"\ntextDecoration:{regex_line}\ntextTransform:{regex_line}",
'flexbox\:{regex_line}' => "flexDirection:{regex_line}\nflexWrap:{regex_line}".
"\nalignItems:{regex_line}\nalignSelf:{regex_line}".
"\njustifyContent:{regex_line}\nalignContent:{regex_line}".
"\nflex:{regex_line}\nflexGrow:{regex_line}".
"\nflexShrink:{regex_line}",
'textStyle\:{regex_line}' => "fontStyle:{regex_line}\nfontSmoothing:{regex_line}" .
"\ntextDecoration:{regex_line}\ntextTransform:{regex_line}",
'flexbox\:{regex_line}' => "flexDirection:{regex_line}\nflexWrap:{regex_line}" .
"\nalignItems:{regex_line}\nalignSelf:{regex_line}" .
"\njustifyContent:{regex_line}\nalignContent:{regex_line}" .
"\nflex:{regex_line}\nflexGrow:{regex_line}" .
"\nflexShrink:{regex_line}",
];

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

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

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

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

$this->searchAndReplace->perform('let colors\s*=\s*\{([^\}]+)\}', '', SearchAndReplace::NO_ESCAPE);
$this->searchAndReplace->perform('\s+colors:\s*colors', ' colors: {'.$colors.'}', SearchAndReplace::NO_ESCAPE);
$this->searchAndReplace->perform('\s+colors:\s*colors', ' colors: {' . $colors . '}', SearchAndReplace::NO_ESCAPE);
$this->searchAndReplace->perform('backgroundColor:\s*colors', 'backgroundColor: theme => theme(\'colors\')', SearchAndReplace::NO_ESCAPE);
$this->searchAndReplace->perform('textColor:\s*colors', 'textColor: theme => theme(\'colors\')', SearchAndReplace::NO_ESCAPE);
$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);
Expand Down
33 changes: 17 additions & 16 deletions src/ConsoleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ public function __construct(OutputInterface $output, $recursive, $overwrite, $ex

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

if ($this->recursive) {
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator(
$folderPath, \RecursiveDirectoryIterator::SKIP_DOTS
$folderPath,
\RecursiveDirectoryIterator::SKIP_DOTS
),
\RecursiveIteratorIterator::SELF_FIRST,
\RecursiveIteratorIterator::CATCH_GET_CHILD
Expand All @@ -52,7 +53,7 @@ public function fileConvert($filePath, $extension)
$filePath = realpath($filePath);

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

return;
}
Expand All @@ -64,51 +65,51 @@ public function fileConvert($filePath, $extension)
if ($lastDotPosition !== false && !$this->overwrite) {
$newFilePath = substr_replace($filePath, '.tw', $lastDotPosition, 0);
} elseif (!$this->overwrite) {
$newFilePath = $filePath.'.tw';
$newFilePath = $filePath . '.tw';
} else {
// Set the new path to the old path to make sure we overwrite it
$newFilePath = $filePath;
}

$newContent = $this->updater
->setContent($content)
->setFileExtension($extension)
->convert()
->get();
->setContent($content)
->setFileExtension($extension)
->convert()
->get();

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

file_put_contents($newFilePath, $newContent);
} else {
$this->output->writeln('<comment>Nothing to convert: </comment>'.basename($filePath));
$this->output->writeln('<comment>Nothing to convert: </comment>' . basename($filePath));
}
}

public function codeConvert($code)
{
$convertedCode = $this->updater
->setContent($code)
->convert()
->get();
->setContent($code)
->convert()
->get();

$this->output->writeln('<info>Converted Code: </info>'.$convertedCode);
$this->output->writeln('<info>Converted Code: </info>' . $convertedCode);
}

public function fixTailwindConfig($filePath)
{
$originalContent = file_get_contents($filePath);

$fixedContent = (new ConfigFileFixer($originalContent))
->fix()
->fix()
->get();

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

if ($lastDotPosition !== false && !$this->overwrite) {
$newFilePath = substr_replace($filePath, '.tw', $lastDotPosition, 0);
} elseif (!$this->overwrite) {
$newFilePath = $filePath.'.tw';
$newFilePath = $filePath . '.tw';
} else {
// Set the new path to the old path to make sure we overwrite it
$newFilePath = $filePath;
Expand Down
18 changes: 9 additions & 9 deletions src/SearchAndReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function setContent(string $content)
}

/**
* Get the number of comitted changes.
* Get the number of committed changes.
*
* @return int
*/
Expand Down Expand Up @@ -121,12 +121,12 @@ public function perform($search, $replace, $options = null)
strpos($search, 'regex_string') !== false
|| strpos($search, 'regex_number') !== false
|| strpos($search, 'regex_line') !== false
) {
) {
$currentSubstitute++;
foreach (['regex_string'=> '[a-zA-Z0-9]+', 'regex_number' => '[0-9]+', 'regex_line' => '[^\n]+'] as $regeName => $regexValue) {
$regexMatchCount = preg_match_all('/\\\\?\{'.$regeName.'\\\\?\}/', $search);
$search = preg_replace('/\\\\?\{'.$regeName.'\\\\?\}/', '(?<'.substr($regeName, 6).'_'.$currentSubstitute.'>'.$regexValue.')', $search, 1);
$replace = preg_replace('/\\\\?\{'.$regeName.'\\\\?\}/', '${'.substr($regeName, 6).'_'.$currentSubstitute.'}', $replace, $regexMatchCount > 1 ? 1 : -1);
foreach (['regex_string' => '[a-zA-Z0-9]+', 'regex_number' => '[0-9]+', 'regex_line' => '[^\n]+'] as $regexName => $regexValue) {
$regexMatchCount = preg_match_all('/\\\\?\{' . $regexName . '\\\\?\}/', $search);
$search = preg_replace('/\\\\?\{' . $regexName . '\\\\?\}/', '(?<' . substr($regexName, 6) . '_' . $currentSubstitute . '>' . $regexValue . ')', $search, 1);
$replace = preg_replace('/\\\\?\{' . $regexName . '\\\\?\}/', '${' . substr($regexName, 6) . '_' . $currentSubstitute . '}', $replace, $regexMatchCount > 1 ? 1 : -1);
}
continue;
}
Expand All @@ -136,13 +136,13 @@ public function perform($search, $replace, $options = null)

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

return $match['start'].$replace.$match['end'];
return $match['start'] . $replace . $match['end'];
},
$this->givenContent
);
Expand Down
Loading

0 comments on commit a262fd4

Please sign in to comment.