diff --git a/.github/dependabot.yml b/.github/dependabot.yml index c3293d8f..dcf4c111 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,12 +4,12 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "daily" + interval: "weekly" target-branch: main - package-ecosystem: npm directory: "/" schedule: - interval: "daily" + interval: "weekly" target-branch: main versioning-strategy: increase diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f5da1ba..129a92e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,6 @@ jobs: - name: Install shards run: shards install - name: Setup Lucky - run: script/setup + run: crystal ./script/setup.cr - name: Run tests run: crystal spec diff --git a/Dockerfile b/Dockerfile index 4c49844a..899db5f0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM crystallang/crystal:1.7.3 +FROM crystallang/crystal:1.16.3 ENV LANG en_US.UTF-8 ENV LANGUAGE en_US:en ENV LC_ALL en_US.UTF-8 @@ -9,7 +9,7 @@ EXPOSE 5000 RUN apt-get update && \ apt-get install -y libnss3 libgconf-2-4 chromium-browser curl libreadline-dev golang-go postgresql postgresql-contrib locales && \ # Set up node and yarn - curl --silent --location https://deb.nodesource.com/setup_11.x | bash - && \ + curl --silent --location https://deb.nodesource.com/setup_18.x | bash - && \ apt-get install -y nodejs && \ npm install -g yarn && \ # Lucky cli diff --git a/Procfile.dev b/Procfile.dev index c3652cdb..33f13b9b 100644 --- a/Procfile.dev +++ b/Procfile.dev @@ -1,3 +1,3 @@ -system_check: script/system_check && sleep 100000 +system_check: crystal ./script/system_check.cr web: lucky watch -r assets: yarn watch diff --git a/script/helpers/function_helpers b/script/helpers/function_helpers deleted file mode 100644 index 388fa67e..00000000 --- a/script/helpers/function_helpers +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env bash - -# 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 $1 is not found -# example: -# if command_not_found "yarn"; then -# echo "no yarn" -# fi -command_not_found() { - ! command -v $1 > /dev/null - return $? -} - -# Returns true if the command $1 is not running -# You must supply the full command to check as an argument -# example: -# if command_not_running "redis-cli ping"; then -# print_error "Redis is not running" -# fi -command_not_running() { - $1 - if [ $? -ne 0 ]; then - true - else - false - fi -} - -# Returns true if the OS is macOS -# example: -# if is_mac; then -# echo "do mac stuff" -# fi -is_mac() { - if [[ "$OSTYPE" == "darwin"* ]]; then - true - else - false - fi -} - -# Returns true if the OS is linux based -# example: -# if is_linux; then -# echo "do linux stuff" -# fi -is_linux() { - if [[ "$OSTYPE" == "linux"* ]]; then - true - else - false - fi -} - -# Prints error and exit. -# example: -# print_error "Redis is not running. Run it with some_command" -print_error() { - printf "${BOLD_RED_COLOR}There is a problem with your system setup:\n\n" - printf "${BOLD_RED_COLOR}$1 \n\n" | indent - exit 1 -} diff --git a/script/helpers/function_helpers.cr b/script/helpers/function_helpers.cr new file mode 100644 index 00000000..8abcb6a2 --- /dev/null +++ b/script/helpers/function_helpers.cr @@ -0,0 +1,32 @@ +require "colorize" + +# These are helper methods provided to help keep your code +# clean. Add new methods, or alter these as needed. + +def notice(message : String) : Nil + puts "\n▸ #{message}" +end + +def print_done : Nil + puts "✔ Done" +end + +def print_error(message : String) : Nil + puts "There is a problem with your system setup:\n".colorize.red.bold + puts "#{message}\n".colorize.red.bold + Process.exit(1) +end + +def command_not_found(command : String) : Bool + Process.find_executable(command).nil? +end + +def command_not_running(command : String, *args) : Bool + output = IO::Memory.new + code = Process.run(command, args, output: output).exit_code + code > 0 +end + +def run_command(command : String, *args) : Nil + Process.run(command, args, output: STDOUT, error: STDERR, input: STDIN) +end diff --git a/script/helpers/text_helpers b/script/helpers/text_helpers deleted file mode 100644 index 34b77a8c..00000000 --- a/script/helpers/text_helpers +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -# 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: -# printf "Hello" | indent -indent() { - while read LINE; do - echo " $LINE" || true - done -} - -# Prints out an arrow to your custom notice -# example: -# notice "Installing new magic" -notice() { - printf "\n▸ $1\n" -} - -# Prints out a check mark and Done. -# example: -# print_done -print_done() { - printf "✔ Done\n" | indent -} diff --git a/script/setup b/script/setup deleted file mode 100755 index 6442b5ec..00000000 --- a/script/setup +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -# Exit if any subcommand fails -set -e -set -o pipefail - -source script/helpers/text_helpers - - -notice "Running System Check" -./script/system_check -print_done - -notice "Installing node dependencies" -yarn install --no-progress | indent - -notice "Compiling assets" -yarn dev | indent - -print_done - -notice "Installing shards" -shards install | indent - -if [ ! -f ".env" ]; then - notice "No .env found. Creating one." - touch .env - print_done -fi - -print_done -notice "Run 'lucky dev' to start the app" diff --git a/script/setup.cr b/script/setup.cr new file mode 100644 index 00000000..ab05bc18 --- /dev/null +++ b/script/setup.cr @@ -0,0 +1,36 @@ +require "./helpers/*" + +notice "Running System Check" + +require "./system_check" + +print_done + +notice "Installing node dependencies" +run_command "yarn", "install", "--no-progress" + +notice "Compiling assets" +run_command "yarn", "dev" + +print_done + +notice "Installing shards" +run_command "shards", "install" + +if !File.exists?(".env") + notice "No .env found. Creating one." + File.touch ".env" + print_done +end + +# The Lucky Website does not use a database +# notice "Setting up the database" + +# run_command "lucky", "db.setup" + +# notice "Seeding the database with required and sample records" +# run_command "lucky", "db.seed.required_data" +# run_command "lucky", "db.seed.sample_data" + +print_done +notice "Run 'lucky dev' to start the app" diff --git a/script/system_check b/script/system_check.cr old mode 100755 new mode 100644 similarity index 61% rename from script/system_check rename to script/system_check.cr index 4868e41f..c56ce3e9 --- a/script/system_check +++ b/script/system_check.cr @@ -1,11 +1,8 @@ -#!/usr/bin/env bash - -source script/helpers/text_helpers -source script/helpers/function_helpers +require "./helpers/*" # 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 helper functions are provided to keep the code simple. See the +# script/helpers/function_helpers.cr file for more examples. # # A few examples you might use here: # * 'lucky db.verify_connection' to test postgres can be connected @@ -13,12 +10,12 @@ source script/helpers/function_helpers # * Note: Booting additional processes for things like mail, background jobs, etc... # should go in your Procfile.dev. -if command_not_found "yarn"; then +if command_not_found "yarn" print_error "Yarn is not installed\n See https://yarnpkg.com/lang/en/docs/install/ for install instructions." -fi +end -## CUSTOM PRE-BOOT CHECKS ## +# CUSTOM PRE-BOOT CHECKS # example: -# if command_not_running "redis-cli ping"; then +# if command_not_running "redis-cli", "ping" # print_error "Redis is not running." -# fi +# end diff --git a/shard.lock b/shard.lock index 3689d410..679031f4 100644 --- a/shard.lock +++ b/shard.lock @@ -1,4 +1,3 @@ -# NOTICE: This lockfile contains some overrides from shard.override.yml version: 2.0 shards: ameba: @@ -15,7 +14,7 @@ shards: backtracer: git: https://github.com/sija/backtracer.cr.git - version: 1.2.2 + version: 1.2.4 cadmium_transliterator: git: https://github.com/cadmiumcr/transliterator.git @@ -23,7 +22,7 @@ shards: carbon: git: https://github.com/luckyframework/carbon.git - version: 0.6.0 + version: 0.6.1 carbon_sendgrid_adapter: git: https://github.com/luckyframework/carbon_sendgrid_adapter.git @@ -31,7 +30,7 @@ shards: cmark: git: https://github.com/amauryt/cr-cmark-gfm.git - version: 0.1.3+git.commit.9e6b023c72a077142d03e1c1fd2c3cedb4a93e56 + version: 0.1.3+git.commit.f73c9a23b4d29c27bbb5c83da40edca41c0c5f09 cry: git: https://github.com/luckyframework/cry.git @@ -53,7 +52,7 @@ shards: git: https://github.com/naqvis/crystal-fnv.git version: 0.1.3 - habitat: # Overridden + habitat: git: https://github.com/luckyframework/habitat.git version: 0.4.9 @@ -67,11 +66,15 @@ shards: lucky: git: https://github.com/luckyframework/lucky.git - version: 1.3.0 + version: 1.4.0 + + lucky_cache: + git: https://github.com/luckyframework/lucky_cache.git + version: 0.1.1 lucky_env: git: https://github.com/luckyframework/lucky_env.git - version: 0.2.0 + version: 0.3.0 lucky_flow: git: https://github.com/luckyframework/lucky_flow.git @@ -105,9 +108,13 @@ shards: git: https://github.com/jwoertink/sitemapper.git version: 0.9.0 + splay_tree_map: + git: https://github.com/wyhaines/splay_tree_map.cr.git + version: 0.3.0 + webdrivers: git: https://github.com/crystal-loot/webdrivers.cr.git - version: 0.4.3 + version: 0.4.4 webless: git: https://github.com/crystal-loot/webless.git @@ -115,7 +122,7 @@ shards: wordsmith: git: https://github.com/luckyframework/wordsmith.git - version: 0.4.0 + version: 0.5.0 xpath2: git: https://github.com/naqvis/crystal-xpath2.git diff --git a/shard.override.yml b/shard.override.yml index 84fc596e..2ef28d32 100644 --- a/shard.override.yml +++ b/shard.override.yml @@ -1,4 +1,4 @@ -dependencies: - habitat: - github: luckyframework/habitat - version: ~> 0.4.9 +# dependencies: +# habitat: +# github: luckyframework/habitat +# version: ~> 0.4.9 diff --git a/shard.yml b/shard.yml index 33d83f78..d194f42b 100644 --- a/shard.yml +++ b/shard.yml @@ -13,7 +13,7 @@ crystal: ">= 1.10.0" dependencies: lucky: github: luckyframework/lucky - version: ~> 1.3.0 + version: ~> 1.4.0 carbon: github: luckyframework/carbon version: ~> 0.6.0 @@ -22,7 +22,7 @@ dependencies: version: ~> 0.6.0 lucky_env: github: luckyframework/lucky_env - version: ~> 0.2.0 + version: ~> 0.3.0 cmark: github: amauryt/cr-cmark-gfm branch: master diff --git a/src/models/lucky_cli_version.cr b/src/models/lucky_cli_version.cr index d3febdf7..4a02df90 100644 --- a/src/models/lucky_cli_version.cr +++ b/src/models/lucky_cli_version.cr @@ -8,7 +8,7 @@ module LuckyCliVersion end def current_version : SemanticVersion - SemanticVersion.new(1, 3, 0) + SemanticVersion.new(1, 4, 0) end def min_compatible_crystal_version : SemanticVersion @@ -16,6 +16,6 @@ module LuckyCliVersion end def max_compatible_crystal_version : SemanticVersion - SemanticVersion.new(1, 14, 0) + SemanticVersion.new(1, 16, 3) end end diff --git a/src/serializers/base_serializer.cr b/src/serializers/base_serializer.cr index 3ad0a669..8e76d02c 100644 --- a/src/serializers/base_serializer.cr +++ b/src/serializers/base_serializer.cr @@ -1,4 +1,6 @@ -abstract class BaseSerializer < Lucky::Serializer +abstract class BaseSerializer + include Lucky::Serializable + def self.for_collection(collection : Enumerable, *args, **named_args) collection.map do |object| new(object, *args, **named_args) diff --git a/src/serializers/error_serializer.cr b/src/serializers/error_serializer.cr index 21a53aa2..b7b55283 100644 --- a/src/serializers/error_serializer.cr +++ b/src/serializers/error_serializer.cr @@ -4,7 +4,7 @@ class ErrorSerializer < BaseSerializer def initialize( @message : String, @details : String? = nil, - @param : String? = nil # so you can track which param (if any) caused the problem + @param : String? = nil, # so you can track which param (if any) caused the problem ) end diff --git a/src/shards.cr b/src/shards.cr index 534c3b9b..206450c9 100644 --- a/src/shards.cr +++ b/src/shards.cr @@ -1,7 +1,8 @@ # Require your shards here require "lucky_env" -LuckyEnv.load?(".env") +LuckyEnv.init_env(".env") +LuckyEnv.load(".env") require "lucky" require "carbon"