roda-project 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25bc9c837d828281d16cc27a589316eeebcb26389a14a3bcb512d83072e532c2
4
- data.tar.gz: 8aa90aeb23cae8f188bfc8355a46b8b7fc89bf697ba3a0f1a39b3199f3d7c038
3
+ metadata.gz: aeff4fdaddf4c0b61eb4fe2f5f2f89b025897eda318d92ecf1a786ee9ff110d1
4
+ data.tar.gz: 50891c013749f5b94378d1259834d5b6c8dafb7bc92ec3092aef74b5ac24080f
5
5
  SHA512:
6
- metadata.gz: 3d146d6279989b6ee8cea4017f932931bd353623f9c0293022793a6e56c153f0e902fe05522b76696092b6e962aae44a57e34ab4835b53aa233d2e8308bb2983
7
- data.tar.gz: 9d2e04b540e188cd4b986cc761c8e3319fa216f2dc7ef1c892e2358e771fee3f936a9189f4b998d809a63813d175a42ef6c9b31f79b250986f1a9cd1bf212950
6
+ metadata.gz: 9bc4575aeb9625e2728ef01c6b5ce699c3b8d1c86a55936e75c5bf2a76105a6b91eaafbd2bca11c47118bd57ae30145b83e7ffda4e17099d09d1ea993f802211
7
+ data.tar.gz: b57e42ba6d7e0c9867801bf52ddb25b341914b0d575761f23a6190ff12b36660ad9db8afb78535847b83ee06496ff78cce8ed422b0f4879e96e52c95371a8dab
@@ -45,6 +45,7 @@ module Roda
45
45
  @database = val
46
46
  end
47
47
 
48
+ # rubocop:disable Lint/InterpolationCheck
48
49
  def database_type=(val)
49
50
  if ![mysql_id, postgresql_id, sqlite_id].include?(val)
50
51
  raise InvalidValue, "Invalid database option"
@@ -63,6 +64,7 @@ module Roda
63
64
  @db_gem = "sqlite3"
64
65
  end
65
66
  end
67
+ # rubocop:enable Lint/InterpolationCheck
66
68
 
67
69
  def project_name=(val)
68
70
  if !(val =~ VALID_PROJECT_NAME_REGEX)
@@ -133,7 +135,7 @@ module Roda
133
135
  end
134
136
 
135
137
  def const_project_name
136
- @const_project_name ||= project_name.split('_').map(&:capitalize).join
138
+ @const_project_name ||= project_name.split("_").map(&:capitalize).join
137
139
  end
138
140
  end
139
141
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Roda
4
4
  module Project
5
- VERSION = "0.1.3"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
data/lib/roda/project.rb CHANGED
@@ -50,7 +50,7 @@ module Roda
50
50
  ['"Start where you are. Use what you have. Do what you can." - Arthur Ashe'],
51
51
  ['"A goal is a dream with a deadline." - Napoleon Hill'],
52
52
  ['"Things do not happen. Things are made to happen." - John F. Kennedy'],
53
- ['"Quality is not an act, it is a habit." - Aristotle'],
53
+ ['"Quality is not an act, it is a habit." - Aristotle']
54
54
  ]
55
55
  end
56
56
  end
@@ -14,7 +14,7 @@ class App < Roda
14
14
 
15
15
  route do |r|
16
16
  r.root do
17
- { message: "Hello world" }
17
+ {message: "Hello world"}
18
18
  end
19
19
  end
20
20
 
@@ -1,4 +1,4 @@
1
- require_relative 'boot'
1
+ require_relative "boot"
2
2
  # Rack::Attack.throttle('signup/ip', limit: 3, period: 15.minutes) do |req|
3
3
  # req.ip if req.path == '/signup'
4
4
  # end
@@ -137,7 +137,7 @@ namespace :g do<% if context.database? %>
137
137
  exit 1
138
138
  end
139
139
 
140
- must_generate_views = Dir.exist?(File.expand_path("../../app/views", __dir__))
140
+ must_generate_views = Dir.exist?(File.expand_path("./app/views", __dir__))
141
141
  ensure_and_get_path = proc do |path|
142
142
  base_path = File.expand_path(path, __dir__)
143
143
  full_path_dir = File.join(base_path, File.dirname(branch_name))
@@ -145,14 +145,14 @@ namespace :g do<% if context.database? %>
145
145
 
146
146
  base_path
147
147
  end
148
- parse_route_string = proc do
148
+ parse_route_string = proc do |route_str|
149
149
  name, method = route_str.split(":", 2)
150
150
  method ||= "get"
151
151
  [method, name]
152
152
  end
153
153
 
154
154
  # Generate routes
155
- filename = File.join(ensure_and_get_path.call("../../app/routes"), "#{branch_name}.rb")
155
+ filename = File.join(ensure_and_get_path.call("./app/routes"), "#{branch_name}.rb")
156
156
  route_definitions = routes_list.map do |route_str|
157
157
  method, name = parse_route_string.call(route_str)
158
158
  view_line = (method == "get" && must_generate_views) ? "\n view('#{name}')" : ""
@@ -171,7 +171,7 @@ namespace :g do<% if context.database? %>
171
171
 
172
172
  # Generate views
173
173
  if must_generate_views
174
- branch_views_dir = File.join(File.expand_path("../../app/views", __dir__), branch_name)
174
+ branch_views_dir = File.join(File.expand_path("./app/views", __dir__), branch_name)
175
175
  FileUtils.mkdir_p(branch_views_dir)
176
176
  routes_list.each do |route_str|
177
177
  method, name = parse_route_string.call(route_str)
@@ -184,7 +184,7 @@ namespace :g do<% if context.database? %>
184
184
  end
185
185
 
186
186
  # Generate tests
187
- test_filename = File.join(ensure_and_get_path.call("../../spec/app/routes"), "#{branch_name}_spec.rb")
187
+ test_filename = File.join(ensure_and_get_path.call("./spec/app/routes"), "#{branch_name}_spec.rb")
188
188
  nesting_level = branch_name.count("/")
189
189
  relative_spec_helper_path = "../" * (2 + nesting_level) + "spec_helper"
190
190
 
@@ -9,15 +9,25 @@ module Config
9
9
  i18n: {
10
10
  translations: ["app/config/locales", "app/config/locales/foo"],
11
11
  locale: ["en", "pt-br"]
12
- },<% if context.database? %>
12
+ }<% if context.database? %>,
13
13
  db: {
14
14
  url: not_production? ? <%= context.dev_db_url %> : ENV["DATABASE_URL"]
15
+ }<% end %><% if context.fullstack? %>,
16
+ assets: {
17
+ host: '/public/assets',
18
+ manifest:
15
19
  }<% end %>
16
20
  }
17
21
  end
18
22
 
19
- def not_production? = environment != "production"
23
+ def not_production? = environment != "production"<% if context.fullstack? %>
24
+ def manifest
25
+ manifest_path = File.expand_path("../../public/assets/manifest.json", __dir__)
26
+ return JSON.parse(File.read(manifest_path)) if File.exist?(manifest_path)
20
27
 
28
+ {}
29
+ end
30
+ <% end %>
21
31
  def environment
22
32
  ENV["RACK_ENV"] || "development"
23
33
  end
@@ -10,6 +10,22 @@ module Views
10
10
  @foo = Views::Foo::Html.new
11
11
  end
12
12
 
13
+ def js_entrypoint_tag(entrypoint)
14
+ if Config.not_production?
15
+ "<script src=\"/public/assets/#{entrypoint}.js\" defer></script>"
16
+ else
17
+ "<script src=\"#{Config.get[:assets][:host]}/#{Config.get[:assets][:manifest]["#{entrypoint}.js"]}\" defer></script>"
18
+ end
19
+ end
20
+
21
+ def css_entrypoint_tag(entrypoint)
22
+ if Config.not_production?
23
+ "<link rel=\"stylesheet\" href=\"/public/assets/#{entrypoint}.css\" />"
24
+ else
25
+ "<link rel=\"stylesheet\" href=\"#{Config.get[:assets][:host]}/#{Config.get[:assets][:manifest]["#{entrypoint}.css"]}\" />"
26
+ end
27
+ end
28
+
13
29
  def navbar
14
30
  html_slice do
15
31
  div class: "navbar" do
@@ -1,7 +1,9 @@
1
1
  <html>
2
2
  <head>
3
3
  <meta charset='utf-8' />
4
- <link rel="stylesheet" type="text/css" href="/public/css/app.css">
4
+
5
+ <%= html.css_entrypoint_tag(:app) %>
6
+ <%= html.js_entrypoint_tag(:app) %>
5
7
  </head>
6
8
  <body>
7
9
  <img src='/public/images/roda-project.png' />
@@ -1,33 +1,40 @@
1
1
  const esbuild = require('esbuild');
2
-
2
+ const manifestPlugin = require('esbuild-plugin-manifest');
3
3
  const isWatchMode = process.argv.includes('--watch');
4
+ const isProduction = process.env.RACK_ENV === 'production';
5
+
6
+ const cssEntryPoints = ['app']
7
+ const jsEntryPoints = ['app']
4
8
 
5
- const entrypoints = [
6
- 'js/app.js',
7
- 'css/app.css'
8
- ]
9
+ function config() {
10
+ const assetsEntryPoints =
11
+ cssEntryPoints.map((e) => `css/${e}.css`)
12
+ .concat(
13
+ jsEntryPoints.map((e) => `js/${e}.js`)
14
+ )
9
15
 
10
- function configFor(name) {
11
16
  return {
12
- entryPoints: [`app/assets/${name}`],
17
+ entryPoints: assetsEntryPoints.map((name) => `app/assets/${name}`),
13
18
  bundle: true,
14
- minify: true,
15
- outfile: `public/${name}`,
19
+ minify: isProduction,
20
+ outdir: "public/assets",
21
+ entryNames: isProduction ? '[name]-[hash]' : '[name]',
22
+ plugins: isProduction ? [
23
+ manifestPlugin({ shortNames: true })
24
+ ] : [],
16
25
  }
17
26
  }
18
27
 
19
28
  async function build() {
20
29
  try {
21
30
  if (isWatchMode) {
22
- entrypoints.forEach(async (entrypoint) => {
23
- const jsCtx = await esbuild.context(configFor(entrypoint));
24
- await jsCtx.watch();
25
- })
26
- console.log(`Watching for css and js changes in '${entrypoints.join(', ')}'...`);
31
+ const ctx = await esbuild.context(config());
32
+ await ctx.watch();
33
+
34
+ console.log(`Watching for css and js changes in '${assetsEntryPoints.join(', ')}'...`);
27
35
  } else {
28
- entrypoints.forEach(async () => {
29
- await esbuild.build(configFor(entrypoint));
30
- })
36
+ await esbuild.build(config());
37
+
31
38
  console.log(`Build complete.`);
32
39
  }
33
40
  } catch (error) {
@@ -15,6 +15,7 @@
15
15
  },
16
16
  "devDependencies": {
17
17
  "esbuild": "^0.19.0",
18
+ "esbuild-plugin-manifest": "^1.0.5",
18
19
  "path": "^0.12.7"
19
20
  }
20
21
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-project
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique F. Teixeira
@@ -95,10 +95,10 @@ files:
95
95
  - lib/roda/templates/base/scaffold/app/routes/foo.rb.erb
96
96
  - lib/roda/templates/base/scaffold/boot.rb.erb
97
97
  - lib/roda/templates/base/scaffold/config.ru.erb
98
- - lib/roda/templates/base/scaffold/public/css/app.css
98
+ - lib/roda/templates/base/scaffold/public/assets/app.css
99
+ - lib/roda/templates/base/scaffold/public/assets/app.js
99
100
  - lib/roda/templates/base/scaffold/public/exception_page.css
100
101
  - lib/roda/templates/base/scaffold/public/images/roda-project.png
101
- - lib/roda/templates/base/scaffold/public/js/app.js
102
102
  - lib/roda/templates/database/app/config/providers/db/conn.rb
103
103
  - lib/roda/templates/database/db/seeds.rb
104
104
  - lib/roda/templates/front-end/app/assets/css/app.css