cssbundling-rails 1.2.0 → 1.3.1

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: 3eb8589b682d3c0c276c75baa0923c706e3f09de2a554e47ea7f008e01b555c5
4
- data.tar.gz: c8c43687d5cbf5cf3fc7f2e7fcbeb35f99b80e2986227135e306cb4a42167423
3
+ metadata.gz: c0e0270ce3ff8d039ffc7b9d7a3853d7d67b7c4b2571d640078b4392a08dd601
4
+ data.tar.gz: 7973f04cf1ef54513b9e36ff0571024e087e0515986ced9a2cf8e9e5468cb00f
5
5
  SHA512:
6
- metadata.gz: 88e4959bbf33a9b580f33a8316a327f437b3ce422d69a95e2e7c55df99e2fc840e98eb636c6baa9e281421415c62e5de28e42d39db2d1b0440db46895f498959
7
- data.tar.gz: ee626b8d3329f131034b218ccac7c5590d36afa7d4191b75afa0a06ed5f27268fe5c1720cdd64d347102ec71d5bdff34c993d12b460030064802c0ccc6d71899
6
+ metadata.gz: bcba15c277b4a46a8699ac641e9904b925c4a39c402a0c69ac5b7fb7856f13a5d8ab2ece33b389533e1b5e9013bca180a52dd139842fcb6fff79d2db0f268361
7
+ data.tar.gz: 29e8e279c1811baefff15f8baa4a1b4926701ed6a3c2e8d4b4a744c57aa50ffc48c68824b4dc96dd9d313a6bc3f0e3e16b6da4b8975366c86b1965f689ee127b
@@ -1,3 +1,3 @@
1
1
  module Cssbundling
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -0,0 +1,2 @@
1
+ web: env RUBY_DEBUG_OPEN=true bin/rails server
2
+ css: bun run build:css --watch
@@ -0,0 +1,2 @@
1
+ web: env RUBY_DEBUG_OPEN=true bin/rails server
2
+ css: yarn build:css --watch
@@ -1,7 +1,10 @@
1
+ require_relative "../helpers"
2
+ self.extend Helpers
3
+
1
4
  say "Install Bootstrap with Bootstrap Icons, Popperjs/core and Autoprefixer"
2
5
  copy_file "#{__dir__}/application.bootstrap.scss",
3
6
  "app/assets/stylesheets/application.bootstrap.scss"
4
- run "yarn add sass bootstrap bootstrap-icons @popperjs/core postcss postcss-cli autoprefixer nodemon"
7
+ run "#{bundler_cmd} add sass bootstrap bootstrap-icons @popperjs/core postcss postcss-cli autoprefixer nodemon"
5
8
 
6
9
  inject_into_file "config/initializers/assets.rb", after: /.*Rails.application.config.assets.paths.*\n/ do
7
10
  <<~RUBY
@@ -16,32 +19,14 @@ else
16
19
  say %(Add import * as bootstrap from "bootstrap" to your entry point JavaScript file), :red
17
20
  end
18
21
 
19
- def add_npm_script(name, script, run_script=true)
20
- case `npx -v`.to_f
21
- when 7.1...8.0
22
- say "Add #{name} script"
23
- run %(npm set-script #{name} "#{script}")
24
- run %(yarn #{name}) if run_script
25
- when (8.0..)
26
- say "Add #{name} script"
27
- run %(npm pkg set scripts.#{name}="#{script}")
28
- run %(yarn #{name}) if run_script
29
- else
30
- say %(Add "scripts": { "#{name}": "#{script}" } to your package.json), :green
31
- end
32
- end
33
-
34
- add_npm_script("build:css:compile", "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules")
35
- add_npm_script("build:css:prefix", "postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css")
36
- add_npm_script("build:css", "yarn build:css:compile && yarn build:css:prefix")
37
- add_npm_script("watch:css", "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \\\"yarn build:css\\\"", false)
22
+ add_package_json_script("build:css:compile", "sass ./app/assets/stylesheets/application.bootstrap.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules")
23
+ add_package_json_script("build:css:prefix", "postcss ./app/assets/builds/application.css --use=autoprefixer --output=./app/assets/builds/application.css")
24
+ add_package_json_script("build:css", "#{bundler_run_cmd} build:css:compile && #{bundler_run_cmd} build:css:prefix")
25
+ add_package_json_script("watch:css", "nodemon --watch ./app/assets/stylesheets/ --ext scss --exec \"#{bundler_run_cmd} build:css\"", false)
38
26
 
39
27
  gsub_file "Procfile.dev", "build:css --watch", "watch:css"
40
28
 
41
- case `npx -v`.to_f
42
- when (7.1..)
43
- say "Add browserslist config"
44
- run %(npm pkg set browserslist[]=defaults)
45
- else
46
- say %(Add "browserslist": ["defaults"] to your package.json), :green
47
- end
29
+ package_json = JSON.parse(File.read("package.json"))
30
+ package_json["browserslist"] ||= {}
31
+ package_json["browserslist"] = ["defaults"]
32
+ File.write("package.json", JSON.pretty_generate(package_json))
@@ -1,18 +1,11 @@
1
+ require_relative "../helpers"
2
+ self.extend Helpers
3
+
1
4
  say "Install Bulma"
2
5
  copy_file "#{__dir__}/application.bulma.scss",
3
6
  "app/assets/stylesheets/application.bulma.scss"
4
- run "yarn add sass bulma"
7
+ run "#{bundler_cmd} add sass bulma"
5
8
 
6
9
  say "Add build:css script"
7
- build_script = "sass ./app/assets/stylesheets/application.bulma.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
8
-
9
- case `npx -v`.to_f
10
- when 7.1...8.0
11
- run %(npm set-script build:css "#{build_script}")
12
- run %(yarn build:css)
13
- when (8.0..)
14
- run %(npm pkg set scripts.build:css="#{build_script}")
15
- run %(yarn build:css)
16
- else
17
- say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
18
- end
10
+ add_package_json_script "build:css",
11
+ "sass ./app/assets/stylesheets/application.bulma.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
data/lib/install/dev CHANGED
@@ -5,4 +5,7 @@ if ! gem list foreman -i --silent; then
5
5
  gem install foreman
6
6
  fi
7
7
 
8
+ # Default to port 3000 if not specified
9
+ export PORT="${PORT:-3000}"
10
+
8
11
  exec foreman start -f Procfile.dev "$@"
@@ -0,0 +1,42 @@
1
+ require 'json'
2
+
3
+ module Helpers
4
+ def bundler_cmd
5
+ using_bun? ? "bun" : "yarn"
6
+ end
7
+
8
+ def bundler_run_cmd
9
+ using_bun? ? "bun run" : "yarn"
10
+ end
11
+
12
+ def using_bun?
13
+ File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
14
+ end
15
+
16
+ def tool_exists?(tool)
17
+ system "command -v #{tool} > /dev/null"
18
+ end
19
+
20
+ def add_package_json_script(name, script, run_script=true)
21
+ if using_bun?
22
+ package_json = JSON.parse(File.read("package.json"))
23
+ package_json["scripts"] ||= {}
24
+ package_json["scripts"][name] = script
25
+ File.write("package.json", JSON.pretty_generate(package_json))
26
+ run %(bun run #{name}) if run_script
27
+ else
28
+ case `npx -v`.to_f
29
+ when 7.1...8.0
30
+ say "Add #{name} script"
31
+ run %(npm set-script #{name} "#{script}")
32
+ run %(yarn #{name}) if run_script
33
+ when (8.0..)
34
+ say "Add #{name} script"
35
+ run %(npm pkg set scripts.#{name}="#{script}")
36
+ run %(yarn #{name}) if run_script
37
+ else
38
+ say %(Add "scripts": { "#{name}": "#{script}" } to your package.json), :green
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,6 @@
1
+ require_relative "helpers"
2
+ self.extend Helpers
3
+
1
4
  say "Build into app/assets/builds"
2
5
  empty_directory "app/assets/builds"
3
6
  keep_file "app/assets/builds"
@@ -41,10 +44,10 @@ unless Rails.root.join("package.json").exist?
41
44
  end
42
45
 
43
46
  if Rails.root.join("Procfile.dev").exist?
44
- append_to_file "Procfile.dev", "css: yarn build:css --watch\n"
47
+ append_to_file "Procfile.dev", "css: #{bundler_run_cmd} build:css --watch\n"
45
48
  else
46
49
  say "Add default Procfile.dev"
47
- copy_file "#{__dir__}/Procfile.dev", "Procfile.dev"
50
+ copy_file "#{__dir__}/#{using_bun? ? "Procfile_for_bun" : "Procfile_for_node"}", "Procfile.dev"
48
51
 
49
52
  say "Ensure foreman is installed"
50
53
  run "gem install foreman"
@@ -1,18 +1,11 @@
1
+ require_relative "../helpers"
2
+ self.extend Helpers
3
+
1
4
  say "Install PostCSS w/ nesting and autoprefixer"
2
5
  copy_file "#{__dir__}/postcss.config.js", "postcss.config.js"
3
6
  copy_file "#{__dir__}/application.postcss.css", "app/assets/stylesheets/application.postcss.css"
4
- run "yarn add postcss postcss-cli postcss-nesting autoprefixer"
7
+ run "#{bundler_cmd} add postcss postcss-cli postcss-import postcss-nesting autoprefixer"
5
8
 
6
9
  say "Add build:css script"
7
- build_script = "postcss ./app/assets/stylesheets/application.postcss.css -o ./app/assets/builds/application.css"
8
-
9
- case `npx -v`.to_f
10
- when 7.1...8.0
11
- run %(npm set-script build:css "#{build_script}")
12
- run %(yarn build:css)
13
- when (8.0..)
14
- run %(npm pkg set scripts.build:css="#{build_script}")
15
- run %(yarn build:css)
16
- else
17
- say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
18
- end
10
+ add_package_json_script "build:css",
11
+ "postcss ./app/assets/stylesheets/application.postcss.css -o ./app/assets/builds/application.css"
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  plugins: [
3
+ require('postcss-import'),
3
4
  require('postcss-nesting'),
4
5
  require('autoprefixer'),
5
6
  ],
@@ -1,17 +1,10 @@
1
+ require_relative "../helpers"
2
+ self.extend Helpers
3
+
1
4
  say "Install Sass"
2
5
  copy_file "#{__dir__}/application.sass.scss", "app/assets/stylesheets/application.sass.scss"
3
- run "yarn add sass"
6
+ run "#{bundler_cmd} add sass"
4
7
 
5
8
  say "Add build:css script"
6
- build_script = "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
7
-
8
- case `npx -v`.to_f
9
- when 7.1...8.0
10
- run %(npm set-script build:css "#{build_script}")
11
- run %(yarn build:css)
12
- when (8.0..)
13
- run %(npm pkg set scripts.build:css="#{build_script}")
14
- run %(yarn build:css)
15
- else
16
- say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
17
- end
9
+ add_package_json_script "build:css",
10
+ "sass ./app/assets/stylesheets/application.sass.scss:./app/assets/builds/application.css --no-source-map --load-path=node_modules"
@@ -1,18 +1,11 @@
1
+ require_relative "../helpers"
2
+ self.extend Helpers
3
+
1
4
  say "Install Tailwind (+PostCSS w/ autoprefixer)"
2
5
  copy_file "#{__dir__}/tailwind.config.js", "tailwind.config.js"
3
6
  copy_file "#{__dir__}/application.tailwind.css", "app/assets/stylesheets/application.tailwind.css"
4
- run "yarn add tailwindcss@latest postcss@latest autoprefixer@latest"
7
+ run "#{bundler_cmd} add tailwindcss@latest postcss@latest autoprefixer@latest"
5
8
 
6
9
  say "Add build:css script"
7
- build_script = "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
8
-
9
- case `npx -v`.to_f
10
- when 7.1...8.0
11
- run %(npm set-script build:css "#{build_script}")
12
- run %(yarn build:css)
13
- when (8.0..)
14
- run %(npm pkg set scripts.build:css="#{build_script}")
15
- run %(yarn build:css)
16
- else
17
- say %(Add "scripts": { "build:css": "#{build_script}" } to your package.json), :green
18
- end
10
+ add_package_json_script "build:css",
11
+ "tailwindcss -i ./app/assets/stylesheets/application.tailwind.css -o ./app/assets/builds/application.css --minify"
@@ -1,8 +1,40 @@
1
1
  namespace :css do
2
+ desc "Install JavaScript dependencies"
3
+ task :install do
4
+ command = Cssbundling::Tasks.install_command
5
+ unless system(command)
6
+ raise "cssbundling-rails: Command install failed, ensure #{command.split.first} is installed"
7
+ end
8
+ end
9
+
2
10
  desc "Build your CSS bundle"
3
- task :build do
4
- unless system "yarn install && yarn build:css"
5
- raise "cssbundling-rails: Command css:build failed, ensure yarn is installed and `yarn build:css` runs without errors or use SKIP_CSS_BUILD env variable"
11
+ build_task = task :build do
12
+ command = Cssbundling::Tasks.build_command
13
+ unless system(command)
14
+ raise "cssbundling-rails: Command build failed, ensure `#{command}` runs without errors"
15
+ end
16
+ end
17
+ build_task.prereqs << :install unless ENV["SKIP_YARN_INSTALL"] || ENV["SKIP_BUN_INSTALL"]
18
+ end
19
+
20
+ module Cssbundling
21
+ module Tasks
22
+ extend self
23
+
24
+ def install_command
25
+ return "bun install" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
26
+ return "yarn install" if File.exist?('yarn.lock') || tool_exists?('yarn')
27
+ raise "cssbundling-rails: No suitable tool found for installing JavaScript dependencies"
28
+ end
29
+
30
+ def build_command
31
+ return "bun run build:css" if File.exist?('bun.lockb') || (tool_exists?('bun') && !File.exist?('yarn.lock'))
32
+ return "yarn build:css" if File.exist?('yarn.lock') || tool_exists?('yarn')
33
+ raise "cssbundling-rails: No suitable tool found for building CSS"
34
+ end
35
+
36
+ def tool_exists?(tool)
37
+ system "command -v #{tool} > /dev/null"
6
38
  end
7
39
  end
8
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cssbundling-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-06-19 00:00:00.000000000 Z
12
+ date: 2023-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
@@ -36,12 +36,14 @@ files:
36
36
  - lib/cssbundling-rails.rb
37
37
  - lib/cssbundling/engine.rb
38
38
  - lib/cssbundling/version.rb
39
- - lib/install/Procfile.dev
39
+ - lib/install/Procfile_for_bun.dev
40
+ - lib/install/Procfile_for_node.dev
40
41
  - lib/install/bootstrap/application.bootstrap.scss
41
42
  - lib/install/bootstrap/install.rb
42
43
  - lib/install/bulma/application.bulma.scss
43
44
  - lib/install/bulma/install.rb
44
45
  - lib/install/dev
46
+ - lib/install/helpers.rb
45
47
  - lib/install/install.rb
46
48
  - lib/install/package.json
47
49
  - lib/install/postcss/application.postcss.css
@@ -1,2 +0,0 @@
1
- web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
2
- css: yarn build:css --watch