Skip to content

Commit

Permalink
Update a template again
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWayfer committed Aug 21, 2020
1 parent bdeb352 commit a1e8cdf
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 179 deletions.
4 changes: 3 additions & 1 deletion template/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ rules:
- avoidEscape: true
semi:
- error
- always
- never
no-multi-spaces:
- error
keyword-spacing:
Expand Down Expand Up @@ -61,6 +61,8 @@ rules:
- allow:
- error
- warn
no-var:
- error
arrow-body-style:
- warn
arrow-parens:
Expand Down
2 changes: 2 additions & 0 deletions template/.remarkrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
plugins:
- remark-preset-lint-recommended
2 changes: 1 addition & 1 deletion template/.stylelintrc.yml → template/.stylelintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rules:
- tab

max-line-length:
- 80
- 100
- ignorePattern: /// https?:///

at-rule-no-unknown:
Expand Down
20 changes: 8 additions & 12 deletions template/.toys/.toys.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

include :bundler, static: true

config_dir = "#{__dir__}/../config"

require "#{config_dir}/base"
root_dir = "#{__dir__}/.."
config_dir = "#{root_dir}/config"
require "#{root_dir}/constants"

require 'benchmark_toys'
expand BenchmarkToys::Template
alias_tool :b, :benchmark

application_proc = proc do
require_relative '../application'
require "#{config_dir}/main"
<%= @short_module_name %>::Application
end

config_proc = proc { application_proc.call.config }

require 'config_toys'
expand ConfigToys::Template, config_dir: config_dir

Expand All @@ -27,10 +29,7 @@ expand SequelMigrationsToys::Template, db_connection_proc: db_connection_proc

require 'psql_toys'
expand PSQLToys::Template,
db_config_proc: (proc do
## For full config, not base
application_proc.call.config[:database]
end),
db_config_proc: proc { config_proc.call[:database] },
db_connection_proc: db_connection_proc,
db_extensions: %w[citext pgcrypto].freeze

Expand All @@ -46,10 +45,7 @@ require 'flame_routes_toys'
expand FlameRoutesToys::Template, application_proc: application_proc

require 'flame_server_toys'
expand FlameServerToys::Template,
config_proc: (proc do
<%= @short_module_name %>::Config::Base.new
end)
expand FlameServerToys::Template, config_proc: config_proc

require 'locales_toys'
expand LocalesToys::Template
Expand Down
13 changes: 2 additions & 11 deletions template/application.rb.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
# frozen_string_literal: true

require_relative 'config/base'
config = <%= @module_name %>::Config::Base.new

## Require gems
require 'bundler/setup'
Bundler.require(
:system, :server, :database,
:translations, :forms, :views, :assets, :mails, :others,
config[:environment]
:system, :server, :database, :translations, :forms, :views, :assets, :mails, :others
)

require 'erubi/capture_end'
Expand All @@ -27,9 +22,7 @@ require 'pp'

# require 'money/bank/google_currency'

## Load full application config, with dependencies from Bundler
require_relative 'config/full'
<%= @module_name %>.complete_config config
require_relative 'constants'

module <%= @module_name %>
## Class for application
Expand Down Expand Up @@ -74,5 +67,3 @@ module <%= @module_name %>
end
end
end

<%= @short_module_name %>::Application.config = config
4 changes: 0 additions & 4 deletions template/assets/scripts/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ parserOptions:
## Libs:
# google: true
# Cccombo: true

rules:
no-var:
- error
8 changes: 0 additions & 8 deletions template/babel.config.json

This file was deleted.

2 changes: 2 additions & 0 deletions template/browserslist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
> 1%
not IE 11
110 changes: 0 additions & 110 deletions template/config/base.rb.erb

This file was deleted.

16 changes: 0 additions & 16 deletions template/config/full.rb.erb

This file was deleted.

68 changes: 68 additions & 0 deletions template/config/main.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# frozen_string_literal: true

require_relative '../application'

config = <%= @short_module_name %>::Application.config

class << config
private

def find_config_file(filename, required:)
file_path = nil

loop do
file_path = super
break
rescue Flame::Errors::ConfigFileNotFoundError => e
puts e.message

next if ask_to_check_config_files

required ? abort : break
end

file_path
end

def ask_to_check_config_files
highline.choose do |menu|
menu.layout = :one_line

menu.prompt = 'Do you want to check config files? '

menu.choice(:yes) do
system 'toys config check'
true
end

menu.choice(:no) { false }
end
end

def highline
@highline ||= begin
require 'highline'
HighLine.new
end
end
end

using GorillaPatch::Inflections

config.instance_exec do
self[:root_dir] = File.realpath "#{__dir__}/.."

self[:pids_dir] = "#{self[:tmp_dir]}/pids"

self[:stdout_file] = "#{self[:log_dir]}/out"
self[:stderr_file] = "#{self[:log_dir]}/err"

%i[session site].each do |config_name|
load_yaml config_name, required: true
end

%w[Server Sentry R18n Mail Sequel Shrine].each do |processor_name|
require_relative "processors/#{processor_name.underscore}"
<%= @short_module_name %>::Config::Processors.const_get(processor_name).new self
end
end
2 changes: 1 addition & 1 deletion template/config/processors/sentry.rb.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'raven'
require_relative '../../lib/flame/raven_context'

module <%= @module_name %>
module Config
Expand Down
2 changes: 2 additions & 0 deletions template/config/processors/server.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ module <%= @module_name %>
environment = config[:environment] =
ENV['RACK_ENV'] ||= server_config[:environment] || 'development'

Bundler.require environment

server_config = config[:server] = server_config[environment]

server_config[:puma_pid_file] = "#{config[:pids_dir]}/#{server_config[:puma_pid_file]}"
Expand Down
10 changes: 6 additions & 4 deletions template/config/puma.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
require 'fileutils'
require 'etc'

require_relative 'base'
require_relative 'main'

config = <%= @module_name %>::Config::Base.new
config = <%= @module_name %>::Application.config

server_config = config[:server]

environment config[:environment]

directory config[:root_dir]

prune_bundler
## Don't call phase-restart
## https://github.com/puma/puma/issues/2319
# prune_bundler

rackup 'config.ru'

Expand All @@ -24,7 +26,7 @@ FileUtils.mkdir_p pids_dir
pidfile File.join pids_dir, 'puma.pid'
state_path File.join pids_dir, 'puma.state'

FileUtils.mkdir_p config[:logs_dir]
FileUtils.mkdir_p config[:log_dir]

if server_config[:daemonize]
stdout_redirect(
Expand Down
16 changes: 16 additions & 0 deletions template/constants.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module <%= @module_name %>
::<%= @short_module_name %> = ::<%= @module_name %>

APP_DIRS = [
'lib',
'config',
'models',
# 'policies',
'helpers',
'mailers',
# 'actions',
'forms',
# 'view_objects',
'controllers'
].freeze
end
Loading

0 comments on commit a1e8cdf

Please sign in to comment.