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 Sep 19, 2020
1 parent bdeb352 commit 87d36c4
Show file tree
Hide file tree
Showing 26 changed files with 184 additions and 248 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Metrics/BlockLength:
- 'spec/**/*'
- '*.gemspec'

RSpec/MultipleMemoizedHelpers:
Enabled: false
## Because of we're testing CLI through native calls
RSpec/DescribeClass:
Enabled: false
Expand Down
20 changes: 4 additions & 16 deletions .toys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,14 @@

include :bundler, static: true

subtool_apply do
include :exec, exit_on_nonzero_status: true, log_level: Logger::UNKNOWN unless include? :exec
end

require 'gem_toys'
expand GemToys::Template

alias_tool :g, :gem

tool :rspec do
def run
exec 'rspec'
end
end
expand :rspec

alias_tool :spec, :rspec
alias_tool :test, :rspec
alias_tool :rspec, :spec
alias_tool :test, :spec

tool :rubocop do
def run
exec 'rubocop'
end
end
expand :rubocop
4 changes: 2 additions & 2 deletions flame-cli.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'gem_toys', '~> 0.3.0'
spec.add_development_dependency 'toys', '~> 0.10.4'
spec.add_development_dependency 'toys', '~> 0.11.0'

spec.add_development_dependency 'codecov', '~> 0.2.0'
spec.add_development_dependency 'rspec', '~> 3.9'
spec.add_development_dependency 'simplecov', '~> 0.18.0'

spec.add_development_dependency 'rubocop', '~> 0.88.0'
spec.add_development_dependency 'rubocop', '~> 0.90.0'
spec.add_development_dependency 'rubocop-performance', '~> 1.0'
spec.add_development_dependency 'rubocop-rspec', '~> 1.0'

Expand Down
69 changes: 33 additions & 36 deletions spec/flame/cli/new/app_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
let(:template_dir) { "#{root_dir}/template" }
let(:template_dir_pathname) { Pathname.new(template_dir) }
let(:template_ext) { '.erb' }
let(:temp_app_dir) { "#{root_dir}/#{app_name}" }

after do
FileUtils.rm_r "#{root_dir}/#{app_name}"
FileUtils.rm_r temp_app_dir
end

describe 'output' do
Expand All @@ -30,10 +31,9 @@
'- README.md',
'- application.rb',
'- config.ru',
'- config/base.rb',
'- config/database.example.yaml',
'- config/full.rb',
'- config/mail.example.yaml',
'- config/main.rb',
'- config/processors/mail.rb',
'- config/processors/r18n.rb',
'- config/processors/sentry.rb',
Expand All @@ -43,6 +43,7 @@
'- config/puma.rb',
'- config/sentry.example.yaml',
'- config/site.example.yaml',
'- constants.rb',
'- controllers/_controller.rb',
'- controllers/site/_controller.rb',
'- controllers/site/index_controller.rb',
Expand All @@ -52,6 +53,9 @@
'- mailers/mail/default.rb',
'- rollup.config.js',
'- routes.rb',
'- views/site/errors/400.html.erb',
'- views/site/errors/404.html.erb',
'- views/site/errors/500.html.erb',
'- views/site/index.html.erb',
'- views/site/layout.html.erb',
# 'Grant permissions to files...',
Expand Down Expand Up @@ -96,7 +100,7 @@
end

describe 'cleans directories' do
subject { Dir.glob("#{app_name}/**/.keep", File::FNM_DOTMATCH) }
subject { Dir.glob("#{temp_app_dir}/**/.keep", File::FNM_DOTMATCH) }

before { execute_command }

Expand All @@ -114,8 +118,7 @@
let(:expected_words) do
[
'FB::Application',
'expand FlameGenerateToys::Template, namespace: FooBar',
'FB::Config::Base.new'
'expand FlameGenerateToys::Template, namespace: FooBar'
]
end

Expand All @@ -125,10 +128,7 @@
describe 'application.rb' do
let(:expected_words) do
[
'config = FooBar::Config::Base.new',
'FooBar.complete_config config',
'module FooBar',
'class Application < Flame::Application'
'module FooBar'
]
end

Expand All @@ -150,23 +150,11 @@
it { is_expected.to match_words(*expected_words) }
end

describe 'config/base.rb' do
let(:expected_words) do
[
'module FooBar',
'::FB = ::FooBar',
'APP_DIRS ='
]
end

it { is_expected.to match_words(*expected_words) }
end

describe 'config/full.rb' do
describe 'config/main.rb' do
let(:expected_words) do
[
'module FooBar',
'FB::Config::Processors.const_get(processor_name).new config'
'config = FB::Application.config',
'FB::Config::Processors.const_get(processor_name).new self'
]
end

Expand All @@ -176,7 +164,7 @@
describe 'config/puma.rb' do
let(:expected_words) do
[
'config = FooBar::Config::Base.new'
'config = FB::Application.config'
]
end

Expand Down Expand Up @@ -277,6 +265,17 @@
it { is_expected.to match_words(*expected_words) }
end

describe 'constants.rb' do
let(:expected_words) do
[
'module FooBar',
'::FB = ::FooBar'
]
end

it { is_expected.to match_words(*expected_words) }
end

describe 'controllers/_controller.rb' do
let(:expected_words) do
[
Expand Down Expand Up @@ -506,20 +505,18 @@
end
end

around do |example|
## HACK: https://github.com/dazuma/toys/issues/57
original_toys_file_name = "#{__dir__}/../../../../.toys.rb"
File.rename original_toys_file_name, "#{original_toys_file_name}.bak"

example.run

File.rename "#{original_toys_file_name}.bak", original_toys_file_name
end

before do
Bundler.with_unbundled_env do
execute_command

## HACK: https://github.com/dazuma/toys/issues/57
toys_command = 'truncate_load_path!'
temp_app_toys_file_path = "#{temp_app_dir}/.toys/.toys.rb"
File.write(
temp_app_toys_file_path,
File.read(temp_app_toys_file_path).sub("# #{toys_command}", toys_command)
)

Dir.chdir app_name

Dir['config/*.example.yaml'].each do |config_example_file_name|
Expand Down
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
29 changes: 12 additions & 17 deletions template/.toys/.toys.rb.erb
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
# frozen_string_literal: true

include :bundler, static: true
## Uncomment if you want, read discussion here: https://github.com/dazuma/toys/issues/57
# truncate_load_path!

config_dir = "#{__dir__}/../config"
include :bundler, static: true

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 +32,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 +48,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 All @@ -65,8 +64,4 @@ expand RackConsoleToys::Template
require 'static_files_toys'
expand StaticFilesToys::Template

tool :rubocop do
def run
exec 'rubocop'
end
end
expand :rubocop
7 changes: 3 additions & 4 deletions template/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ group :system do
end

group :server do
# gem 'flame', github: 'AlexWayfer/flame'
gem 'flame', path: '~/Projects/ruby/flame'
gem 'flame', github: 'AlexWayfer/flame'
gem 'flame-flash', github: 'AlexWayfer/flame-flash'
gem 'puma'
gem 'rack-contrib'
Expand All @@ -27,7 +26,6 @@ group :server do
end

group :development do
gem 'filewatcher'
gem 'letter_opener'
end

Expand Down Expand Up @@ -100,7 +98,8 @@ group :toys do
gem 'flame_deploy_toys'
gem 'flame_generate_toys'
gem 'flame_routes_toys'
gem 'flame_server_toys'
## TODO: Switch to stable version after `filewatcher-cli` release
gem 'flame_server_toys', github: 'AlexWayfer/flame_server_toys'
gem 'locales_toys'
gem 'psql_toys'
gem 'rack_console_toys'
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
Loading

0 comments on commit 87d36c4

Please sign in to comment.