Skip to content

Commit

Permalink
feat(tasks): added two tasks to switch from dev to prod environment a…
Browse files Browse the repository at this point in the history
…nd vice versa
  • Loading branch information
COil committed Oct 6, 2023
1 parent 57869f6 commit 8a20591
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
8 changes: 2 additions & 6 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ APP_DEBUG=1
APP_SECRET=3bUhVCRkHJfT2ZJTqBnvkclRFT1zy1ig
###< symfony/framework-bundle ###

# To test the production environmet, run:
# > cp .env.local.dist .env.local
# > bin/console asset-map:compile
# To test the production environment, run "make go-prod" or "castor symfony:go-prod"

# To come back to the development environment, run:
# > rm .env.local
# > rm -rf ./public/assets/*
# To come back to the development environment, run "make go-dev" or "castor symfony:go-dev"
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ stop: ## Stop the web server
@symfony server:stop


## —— Symfony 🎶 ——————————————————————————————————————————————————————————————
go-prod: ## Switch to the production environment
@cp .env.local.dist .env.local
@bin/console asset-map:compile

go-dev: ## Switch to the development environment
@rm .env.local
@rm -rf ./public/assets/*


## —— Tests ✅ —————————————————————————————————————————————————————————————————
test: ## Run all PHPUnit tests
@vendor/bin/simple-phpunit
Expand Down
30 changes: 30 additions & 0 deletions castor.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,36 @@ function stop(): void
success();
}

#[AsTask(namespace: 'symfony', description: 'Switch to the production environment')]
function go_prod(): void
{
title(__FUNCTION__, get_command());
if (io()->confirm('Are you sure you want to switch to the production environment? This will overwrite your .env.local file', false)) {
run('cp .env.local.dist .env.local', quiet: false);
run('bin/console asset-map:compile', quiet: false);
success();

return;
}

io()->comment('Aborted.');
}

#[AsTask(namespace: 'symfony', description: 'Switch to the development environment')]
function go_dev(): void
{
title(__FUNCTION__, get_command());
if (io()->confirm('Are you sure you want to switch to the development environment? This will delete your .env.local file', false)) {
run('rm .env.local', quiet: false);
run('rm -rf ./public/assets/*', quiet: false);
success();

return;
}

io()->comment('Aborted.');
}

#[AsTask(name: 'all', namespace: 'test', description: 'Run all PHPUnit tests')]
function test(): void
{
Expand Down

0 comments on commit 8a20591

Please sign in to comment.