roda-project 0.1.3 → 0.1.4

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: 481798dedf638baf4a37f1a8f1c554086eaa1fe9ba9ad409b6301a6693d5ab32
4
+ data.tar.gz: fa9bb1b2f1f6d7d465ebda947b1e62a3d5c4a0cb9e3837db4abd59c2df3304b5
5
5
  SHA512:
6
- metadata.gz: 3d146d6279989b6ee8cea4017f932931bd353623f9c0293022793a6e56c153f0e902fe05522b76696092b6e962aae44a57e34ab4835b53aa233d2e8308bb2983
7
- data.tar.gz: 9d2e04b540e188cd4b986cc761c8e3319fa216f2dc7ef1c892e2358e771fee3f936a9189f4b998d809a63813d175a42ef6c9b31f79b250986f1a9cd1bf212950
6
+ metadata.gz: 63e2755468f18b312a2de6f09117564ea91d073bcb55422f1963737ed04268087cdb7555ae2fd60e6742f7e64ac465decfde11dac17886dd52c81a42baa5a979
7
+ data.tar.gz: e2755bb05abdd00d0fc285b2975aa07ace46b8d885a53af09f3b08be1bcd636e56877c44f7dd8daf99ce4dd2b0c3954405bf9de3f4728d1b02c03d3ae2ae0532
@@ -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.4"
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
@@ -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.4
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