Sha256: fe6907b9fb427c1022d8e2306fd62f5cebb1927a8dd68fa488804f5688651f6d

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module BridgetownPluginNano
  module Commands
    class Nano < Thor
      module GeneralHelpers
        def configure_new_nano_app # rubocop:disable Metrics/MethodLength
          template "bridgetown_root/config.ru", "config.ru"
          copy_file "bridgetown_root/Rakefile", "Rakefile"

          gsub_file "start.js",
                    'sleep 4; yarn serve --port " + port',
                    'sleep 4; bundle exec rake nano:start -- --port=" + port'
          gsub_file "webpack.config.js",
                    %(const path = require("path");\n),
                    %(const path = require("path");\nconst webpack = require("webpack");\n)

          inject_into_file "webpack.config.js", <<-JS, after: "\n  plugins: [\n"
    new webpack.DefinePlugin({
      NANO_API_URL: JSON.stringify(process.env.NANO_API_URL || "")
    }),
          JS

          append_to_file "Gemfile" do
            <<~RUBY

              # Gems required by the Nano backend:
              gem "dotenv"
              gem "puma"
              gem "rails"
              gem "rack-cors"
            RUBY
          end
          Bridgetown.with_unbundled_env do
            run "bundle install", abort_on_failure: true
          end

          logger = Bridgetown.logger
          logger.info ""
          logger.info "Success!".green, "🎉 Your Nano backend was" \
                      " generated in #{folder_name.cyan}."
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bridgetown-plugin-nano-0.2.0 lib/bridgetown-plugin-nano/command_helpers/general_helpers.rb