Class: Jets::Commands::New
- Defined in:
- lib/jets/commands/new.rb
Class Method Summary collapse
-
.cli_options ⇒ Object
Ugly, but when the class_option is only defined in the Thor::Group class it doesnt show up with jets new help :( If anyone knows how to fix this let me know..
Instance Method Summary collapse
-
#bootstrap_install ⇒ Object
bootstrap is dependent on webpacker, options is used in webpacker_install.
- #bundle_install ⇒ Object
- #create_project ⇒ Object
- #git_init ⇒ Object
- #make_bin_executable ⇒ Object
- #set_api_mode ⇒ Object
- #user_message ⇒ Object
- #webpacker_install ⇒ Object
Methods inherited from Sequence
Class Method Details
.cli_options ⇒ Object
Ugly, but when the class_option is only defined in the Thor::Group class it doesnt show up with jets new help :( If anyone knows how to fix this let me know.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/jets/commands/new.rb', line 8 def self. [ [:repo, desc: "GitHub repo to use. Format: user/repo"], [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."], [:api, type: :boolean, default: false, desc: "API mode."], [:webpacker, type: :boolean, default: true, desc: "Install webpacker"], [:bootstrap, type: :boolean, default: true, desc: "Install bootstrap css"], # same option in WebpackerTemplate [:git, type: :boolean, default: true, desc: "Git initialize the project"], ] end |
Instance Method Details
#bootstrap_install ⇒ Object
bootstrap is dependent on webpacker, options is used in webpacker_install.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/jets/commands/new.rb', line 63 def bootstrap_install return unless @bootstrap # Add jquery and popper plugin to handle Delete of CRUD jquery =<<-JS const webpack = require('webpack') environment.plugins.prepend('Provide', new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', Popper: ['popper.js', 'default'] })) JS after = "const { environment } = require('@rails/webpacker')\n" insert_into_file("config/webpack/environment.js", jquery, after: after) run("yarn add [email protected] jquery popper.js") end |
#bundle_install ⇒ Object
47 48 49 50 51 |
# File 'lib/jets/commands/new.rb', line 47 def bundle_install Bundler.with_clean_env do system("BUNDLE_IGNORE_CONFIG=1 bundle install") end end |
#create_project ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/jets/commands/new.rb', line 35 def create_project [:repo] ? clone_project : copy_project destination_root = "#{Dir.pwd}/#{project_name}" self.destination_root = destination_root FileUtils.cd("#{Dir.pwd}/#{project_name}") end |
#git_init ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/jets/commands/new.rb', line 81 def git_init return if ![:git] return unless git_installed? return if File.exist?(".git") # this is a clone repo run("git init") run("git add .") run("git commit -m 'first commit'") end |
#make_bin_executable ⇒ Object
43 44 45 |
# File 'lib/jets/commands/new.rb', line 43 def make_bin_executable chmod "bin", 0755 & ~File.umask, verbose: false end |
#set_api_mode ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/jets/commands/new.rb', line 23 def set_api_mode # options is a frozen hash by Thor so cannot modify it. # Also had trouble unfreezing it with .dup. So using instance variables instead if [:api] @webpacker = false @bootstrap = false else @webpacker = [:webpacker] @bootstrap = [:bootstrap] end end |
#user_message ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/jets/commands/new.rb', line 91 def puts <<-EOL #{"="*64} Congrats 🎉 You have successfully created a Jets project. Cd into the project directory: cd #{project_name} To start a server and test locally: jets server # localhost:8888 should have the Jets welcome page Scaffold example: jets generate scaffold Post title:string body:text published:boolean To deploy to AWS Lambda: jets deploy EOL end |
#webpacker_install ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/jets/commands/new.rb', line 53 def webpacker_install return unless @webpacker command = "jets webpacker:install" command += " FORCE=1" if [:force] run(command) end |