Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding in setup scripts for Windows powershell users #867

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions fixtures/src_template/expected/script/helpers/function_helpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file contains a set of functions used as helpers
# for various tasks. Read the examples for each one for
# more information. Feel free to put any additional helper
# functions you may need for your app


# Returns true if the command $Command is not found
# example:
# if (CommandNotFound "yarn") {
# echo "no yarn"
# }
function CommandNotFound($Command) {
try {
Get-Command -Name $Command -ErrorAction | Out-Null
return $false
} catch {
return $true
}
}

# Returns true if the command $Command is not running
# You must supply the full command to check as an argument
# example:
# if (CommandNotRunning "redis-cli ping") {
# PrintError "Redis is not running"
# }
function CommandNotRunning($Command) {
Invoke-Expression $Command
if ($LASTEXITCODE -ne 0) {
return $true
} else {
return $false
}
}

# Prints error and exit.
# example:
# PrintError "Redis is not running. Run it with some_command"
function PrintError($Message) {
Write-Host -ForegroundColor Red "There is a problem with your system setup:`n`n"
Write-Host -ForegroundColor Red "$Message `n`n" | Indent
}
32 changes: 32 additions & 0 deletions fixtures/src_template/expected/script/helpers/text_helpers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file contains a set of functions used to format text,
# and make printing text a little easier. Feel free to put
# any additional functions you need for formatting your shell
# output text.

# Colors
$BOLD_RED_COLOR="`e[1m`e[31m"

# Indents the text 2 spaces
# example:
# Write-Host "Hello" | Indent
function Indent {
process {
foreach($Line in $_) {
Write-Host " $Line"
}
}
}

# Prints out an arrow to your custom notice
# example:
# Notice "Installing new magic"
function Notice($Message) {
Write-Host "`n▸ $Message`n"
}

# Prints out a check mark and Done.
# example:
# PrintDone
function PrintDone {
Write-Host "✔ Done`n" | Indent
}
35 changes: 35 additions & 0 deletions fixtures/src_template/expected/script/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Exit if any subcommand fails
$ErrorActionPreferences = "Stop"

.\script\helpers\text_helpers.ps1


Notice "Running System Check"
& .\script\system_check.ps1
PrintDone


Notice "Installing shards"
shards install --ignore-crystal-version | Indent

if (!Test-Path ".env") {
Notice "No .env found. Creating one."
New-Item ".env"
PrintDone
}

Notice "Creating the database"
lucky db.create | Indent

Notice "Verifying postgres connection"
lucky db.verify_connection | Indent

Notice "Migrating the database"
lucky db.migrate | Indent

Notice "Seeding the database with required and sample records"
lucky db.seed.required_data | Indent
lucky db.seed.sample_data | Indent

PrintDone
Notice "Run 'lucky dev' to start the app"
24 changes: 24 additions & 0 deletions fixtures/src_template/expected/script/system_check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.\script\helpers\text_helpers.ps1
.\script\helpers\function_helpers.ps1

# Use this script to check the system for required tools and process that your app needs.
# A few helper functions are provided to make writing bash a little easier. See the
# script/helpers/function_helpers file for more examples.
#
# A few examples you might use here:
# * 'lucky db.verify_connection' to test postgres can be connected
# * Checking that elasticsearch, redis, or postgres is installed and/or booted
# * Note: Booting additional processes for things like mail, background jobs, etc...
# should go in your Procfile.dev.

if (CommandNotFound "createdb") {
PrintError "Please install the postgres CLI tools, then try again.\nSee https://www.postgresql.org/docs/current/tutorial-install.html for install instructions."
}

## CUSTOM PRE-BOOT CHECKS ##
# example:
# if (CommandNotFound "redis-cli ping") {
# PrintError "Redis is not running."
# }


Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file contains a set of functions used as helpers
# for various tasks. Read the examples for each one for
# more information. Feel free to put any additional helper
# functions you may need for your app


# Returns true if the command $Command is not found
# example:
# if (CommandNotFound "yarn") {
# echo "no yarn"
# }
function CommandNotFound($Command) {
try {
Get-Command -Name $Command -ErrorAction | Out-Null
return $false
} catch {
return $true
}
}

# Returns true if the command $Command is not running
# You must supply the full command to check as an argument
# example:
# if (CommandNotRunning "redis-cli ping") {
# PrintError "Redis is not running"
# }
function CommandNotRunning($Command) {
Invoke-Expression $Command
if ($LASTEXITCODE -ne 0) {
return $true
} else {
return $false
}
}

# Prints error and exit.
# example:
# PrintError "Redis is not running. Run it with some_command"
function PrintError($Message) {
Write-Host -ForegroundColor Red "There is a problem with your system setup:`n`n"
Write-Host -ForegroundColor Red "$Message `n`n" | Indent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file contains a set of functions used to format text,
# and make printing text a little easier. Feel free to put
# any additional functions you need for formatting your shell
# output text.

# Colors
$BOLD_RED_COLOR="`e[1m`e[31m"

# Indents the text 2 spaces
# example:
# Write-Host "Hello" | Indent
function Indent {
process {
foreach($Line in $_) {
Write-Host " $Line"
}
}
}

# Prints out an arrow to your custom notice
# example:
# Notice "Installing new magic"
function Notice($Message) {
Write-Host "`n▸ $Message`n"
}

# Prints out a check mark and Done.
# example:
# PrintDone
function PrintDone {
Write-Host "✔ Done`n" | Indent
}
35 changes: 35 additions & 0 deletions fixtures/src_template__api_only/expected/script/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Exit if any subcommand fails
$ErrorActionPreferences = "Stop"

.\script\helpers\text_helpers.ps1


Notice "Running System Check"
& .\script\system_check.ps1
PrintDone


Notice "Installing shards"
shards install --ignore-crystal-version | Indent

if (!Test-Path ".env") {
Notice "No .env found. Creating one."
New-Item ".env"
PrintDone
}

Notice "Creating the database"
lucky db.create | Indent

Notice "Verifying postgres connection"
lucky db.verify_connection | Indent

Notice "Migrating the database"
lucky db.migrate | Indent

Notice "Seeding the database with required and sample records"
lucky db.seed.required_data | Indent
lucky db.seed.sample_data | Indent

PrintDone
Notice "Run 'lucky dev' to start the app"
24 changes: 24 additions & 0 deletions fixtures/src_template__api_only/expected/script/system_check.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.\script\helpers\text_helpers.ps1
.\script\helpers\function_helpers.ps1

# Use this script to check the system for required tools and process that your app needs.
# A few helper functions are provided to make writing bash a little easier. See the
# script/helpers/function_helpers file for more examples.
#
# A few examples you might use here:
# * 'lucky db.verify_connection' to test postgres can be connected
# * Checking that elasticsearch, redis, or postgres is installed and/or booted
# * Note: Booting additional processes for things like mail, background jobs, etc...
# should go in your Procfile.dev.

if (CommandNotFound "createdb") {
PrintError "Please install the postgres CLI tools, then try again.\nSee https://www.postgresql.org/docs/current/tutorial-install.html for install instructions."
}

## CUSTOM PRE-BOOT CHECKS ##
# example:
# if (CommandNotFound "redis-cli ping") {
# PrintError "Redis is not running."
# }


Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file contains a set of functions used as helpers
# for various tasks. Read the examples for each one for
# more information. Feel free to put any additional helper
# functions you may need for your app


# Returns true if the command $Command is not found
# example:
# if (CommandNotFound "yarn") {
# echo "no yarn"
# }
function CommandNotFound($Command) {
try {
Get-Command -Name $Command -ErrorAction | Out-Null
return $false
} catch {
return $true
}
}

# Returns true if the command $Command is not running
# You must supply the full command to check as an argument
# example:
# if (CommandNotRunning "redis-cli ping") {
# PrintError "Redis is not running"
# }
function CommandNotRunning($Command) {
Invoke-Expression $Command
if ($LASTEXITCODE -ne 0) {
return $true
} else {
return $false
}
}

# Prints error and exit.
# example:
# PrintError "Redis is not running. Run it with some_command"
function PrintError($Message) {
Write-Host -ForegroundColor Red "There is a problem with your system setup:`n`n"
Write-Host -ForegroundColor Red "$Message `n`n" | Indent
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file contains a set of functions used to format text,
# and make printing text a little easier. Feel free to put
# any additional functions you need for formatting your shell
# output text.

# Colors
$BOLD_RED_COLOR="`e[1m`e[31m"

# Indents the text 2 spaces
# example:
# Write-Host "Hello" | Indent
function Indent {
process {
foreach($Line in $_) {
Write-Host " $Line"
}
}
}

# Prints out an arrow to your custom notice
# example:
# Notice "Installing new magic"
function Notice($Message) {
Write-Host "`n▸ $Message`n"
}

# Prints out a check mark and Done.
# example:
# PrintDone
function PrintDone {
Write-Host "✔ Done`n" | Indent
}
35 changes: 35 additions & 0 deletions fixtures/src_template__generate_auth/expected/script/setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Exit if any subcommand fails
$ErrorActionPreferences = "Stop"

.\script\helpers\text_helpers.ps1


Notice "Running System Check"
& .\script\system_check.ps1
PrintDone


Notice "Installing shards"
shards install --ignore-crystal-version | Indent

if (!Test-Path ".env") {
Notice "No .env found. Creating one."
New-Item ".env"
PrintDone
}

Notice "Creating the database"
lucky db.create | Indent

Notice "Verifying postgres connection"
lucky db.verify_connection | Indent

Notice "Migrating the database"
lucky db.migrate | Indent

Notice "Seeding the database with required and sample records"
lucky db.seed.required_data | Indent
lucky db.seed.sample_data | Indent

PrintDone
Notice "Run 'lucky dev' to start the app"
Loading
Loading