generated from mattbrictson/gem
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support generating apps with npm instead of yarn (#122)
If you select options that require a JavaScript runtime (postcss, Vite, ESLint, etc.), nextgen will now ask what package manager you'd like to use: ``` Which JavaScript package manager will you use? ‣ yarn (default) npm ``` If you choose npm, nextgen will scrub yarn references from the files that Rails provides (Dockerfile, Procfile.dev) and replace them with appropriate npm commands. The `bin/setup` script provided by nextgen now autodetects yarn vs npm and runs the correct install command as well. Yarn remains the default option. Closes #118.
- Loading branch information
1 parent
6d7f80a
commit 7bccc2c
Showing
19 changed files
with
265 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# frozen_string_literal: true | ||
|
||
module Nextgen | ||
module Actions::Javascript | ||
def add_js_packages(*packages, dev: false) | ||
command = yarn? ? +"yarn add" : +"npm install --fund=false --audit-false" | ||
command << " -D" if dev | ||
run_js_command "#{command} #{packages.map(&:shellescape).join(" ")}" | ||
end | ||
alias add_js_package add_js_packages | ||
|
||
def remove_js_packages(*packages, capture: false) | ||
command = yarn? ? "yarn remove" : "npm uninstall" | ||
run_js_command "#{command} #{packages.map(&:shellescape).join(" ")}", capture: | ||
end | ||
alias remove_js_package remove_js_packages | ||
|
||
def add_package_json_scripts(scripts) | ||
scripts.each do |name, script| | ||
cmd = "npm pkg set scripts.#{name.to_s.shellescape}=#{script.shellescape}" | ||
say_status :run, cmd.truncate(60), :green | ||
run! cmd, verbose: false | ||
end | ||
end | ||
alias add_package_json_script add_package_json_scripts | ||
|
||
def remove_package_json_script(name) | ||
cmd = "npm pkg delete scripts.#{name.to_s.shellescape}" | ||
say_status :run, cmd.truncate(60), :green | ||
run! cmd, verbose: false | ||
end | ||
|
||
def js_package_manager | ||
File.exist?("yarn.lock") ? :yarn : :npm | ||
end | ||
|
||
def yarn? | ||
js_package_manager == :yarn | ||
end | ||
|
||
def run_js_command(cmd, capture: false) | ||
say_status(*cmd.split(" ", 2), :green) | ||
output = run! cmd, capture: true, verbose: false | ||
return output if capture | ||
return puts(output) unless output.match?(/^success /) | ||
|
||
puts output.lines.grep(/^(warning|success) /).join | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
remove_file "yarn.lock" | ||
run! "npm install --fund=false --audit=false" | ||
|
||
gsub_file "README.md", "\n- Yarn 1.x (classic)", "" | ||
gsub_file "README.md", "\nbrew install yarn", "" | ||
|
||
gsub_file "Procfile.dev", "yarn build", "npm run build --" if File.exist?("Procfile.dev") | ||
|
||
if File.exist?("Dockerfile") | ||
gsub_file "Dockerfile", /^\s*ARG YARN_VERSION.*\n/, "" | ||
gsub_file "Dockerfile", /^\s*npm install -g yarn.*\n/, "" | ||
gsub_file "Dockerfile", "yarn.lock", "package-lock.json" | ||
gsub_file "Dockerfile", /RUN yarn install.*/, "RUN npm ci" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.