Skip to content

Commit

Permalink
Update make and composer require
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-memo-ict committed Jul 28, 2022
1 parent a45df81 commit ebd638d
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 2 deletions.
33 changes: 31 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,45 @@ help:

install: ## Installs all production dependencies
@composer install --no-dev
@cd src/Resources/app/administration && npm install --production
@cd src/Resources/app/storefront && npm install --production

dev: ## Installs all dev dependencies
@composer install
@cd src/Resources/app/administration && npm install
@cd src/Resources/app/storefront && npm install

clean: ## Cleans all dependencies
rm -rf vendor
rm -rf .reports | true
@make clean-node

clean-node: ## Removes node_modules
rm -rf src/Resources/app/administration/node_modules
rm -rf src/Resources/app/storefront/node_modules

# ------------------------------------------------------------------------------------------------------------

release: ## Creates a new ZIP package
build: ## Builds the package
@rm -rf src/Resources/app/storefront/dist
@cd ../../.. && php bin/console plugin:refresh
@cd ../../.. && php bin/console plugin:install MyPaShopware --activate --clearCache | true
@cd ../../.. && php bin/console plugin:refresh
@cd ../../.. && php bin/console theme:dump
@cd ../../.. && PUPPETEER_SKIP_DOWNLOAD=1 ./bin/build-js.sh
@cd ../../.. && php bin/console theme:refresh
@cd ../../.. && php bin/console theme:compile
@cd ../../.. && php bin/console theme:refresh

release: ## Create a new release
@make clean
@make install
@make build
@make zip

zip: ## Creates a new ZIP package
@php update-composer-require.php --shopware=^6.3.0 --env=prod
@cd .. && echo "\nCreating Zip file MyPaShopware-$(PLUGIN_VERSION).zip\n"
@cd .. && rm -rf MyPaShopware-$(PLUGIN_VERSION).zip
@cd .. && zip -qq -r -0 MyPaShopware-$(PLUGIN_VERSION).zip MyPaShopware/ -x '.editorconfig' '*.git*' '*.reports*' '*.travis.yml*' '*/tests*' '*/makefile' '*.DS_Store' '*/phpunit.xml' '*/.phpstan.neon' '*/.php_cs.php' '*/phpinsights.php'
@cd .. && zip -qq -r -0 MyPaShopware-$(PLUGIN_VERSION).zip MyPaShopware/ -x '*.editorconfig' '*.git*' '*.reports*' '*.travis.yml*' '*/tests*' '*/makefile' '*.DS_Store' '*/phpunit.xml' '*/.phpstan.neon' '*/.php_cs.php' '*/phpinsights.php' '*node_modules*' '*administration/build*' '*storefront/build*' '*/update-composer-require.php'
@php update-composer-require.php --shopware=^6.3.0 --env=dev
131 changes: 131 additions & 0 deletions update-composer-require.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php declare(strict_types=1);

$output = new Output();

$opts = getopt("", ['env::', 'shopware:']);

if (!$opts) {
$output->error('No options set. Option "env" is required.');
return;
}

switch ($opts['env']) {
case 'dev':
case 'develop':
case 'development':
$env = 'development';
$require = 'require-dev';
break;
case 'prod':
case 'production':
$env = 'production';
$require = 'require';
break;
}

if(!isset($require)) {
$output->error('Env needs to be one of: dev, develop, development, prod, production');
return;
}

$shopware = '*';

if(isset($opts['shopware'])) {
$shopware = (string)$opts['shopware'];
}

try {
$composerContent = file_get_contents(__DIR__ . '/composer.json');
$composerContent = json_decode($composerContent, true);

unset($composerContent['require']['shopware/core']);
unset($composerContent['require']['shopware/administration']);
unset($composerContent['require']['shopware/storefront']);
unset($composerContent['require-dev']['shopware/core']);
unset($composerContent['require-dev']['shopware/administration']);
unset($composerContent['require-dev']['shopware/storefront']);

if(empty($composerContent['require'])) {
unset($composerContent['require']);
}

if(empty($composerContent['require-dev'])) {
unset($composerContent['require-dev']);
}

$composerContent[$require]['shopware/core'] = $shopware;
$composerContent[$require]['shopware/administration'] = $shopware;
$composerContent[$require]['shopware/storefront'] = $shopware;

file_put_contents(__DIR__ . '/composer.json', json_encode($composerContent, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));

$output->info(sprintf('Switched composer.json to %s requiring Shopware version %s', $env, $shopware));
} catch (\Exception $e) {
$output->error($e->getMessage());
}

class Output
{
const COLORS = [
'black' => 0,
'red' => 1,
'green' => 2,
'yellow' => 3,
'blue' => 4,
'magenta' => 5,
'cyan' => 6,
'white' => 7,
'default' => 9,
];

public function info($text)
{
$this->writeLn($this->createBlock([$text]), self::COLORS['black'], self::COLORS['green']);
}

public function error($text)
{
$this->writeLn($this->createBlock([$text]), self::COLORS['white'], self::COLORS['red']);
}

public function writeLn($messages, $fg = self::COLORS['default'], $bg = self::COLORS['default'])
{
if (!is_iterable($messages)) {
$messages = [$messages];
}

$fg = '3' . $fg;
$bg = '4' . $bg;

foreach ($messages as $message) {
echo sprintf("\033[%s;%sm%s\033[0m%s", $fg, $bg, $message, PHP_EOL);
}
}

public function createBlock(iterable $messages, int $indentLength = 2)
{
$lines = [];
$lineLength = 80;

$lineIndentation = str_repeat(' ', $indentLength);

foreach ($messages as $message) {
$messageLineLength = $lineLength - ($indentLength * 2);
$messageLines = explode(\PHP_EOL, wordwrap($message, $messageLineLength, \PHP_EOL, true));

foreach ($messageLines as $messageLine) {
$lines[] = $messageLine;
}
}

array_unshift($lines, '');
$lines[] = '';

foreach ($lines as &$line) {
$line = $lineIndentation . $line;
$line .= str_repeat(' ', max($lineLength - strlen($line), 0));
}

return $lines;
}
}

0 comments on commit ebd638d

Please sign in to comment.