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 31, 2020
1 parent bdeb352 commit c318b49
Show file tree
Hide file tree
Showing 22 changed files with 165 additions and 217 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
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
2 changes: 1 addition & 1 deletion flame-cli.gemspec
Expand Up @@ -30,7 +30,7 @@ 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'
Expand Down
69 changes: 33 additions & 36 deletions spec/flame/cli/new/app_spec.rb
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
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
@@ -0,0 +1,2 @@
plugins:
- remark-preset-lint-recommended
2 changes: 1 addition & 1 deletion template/.stylelintrc.yml → template/.stylelintrc.yaml
Expand Up @@ -9,7 +9,7 @@ rules:
- tab

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

at-rule-no-unknown:
Expand Down
23 changes: 11 additions & 12 deletions template/.toys/.toys.rb.erb
@@ -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 Down
13 changes: 2 additions & 11 deletions template/application.rb.erb
@@ -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
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
@@ -0,0 +1,2 @@
> 1%
not IE 11

0 comments on commit c318b49

Please sign in to comment.