Sha256: 67cf66bebee20abb0e10f301c0e9b92df7456b66c1b64467d78c3c70e79b498e

Contents?: true

Size: 1.34 KB

Versions: 11

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true
module Node
  module Commands
    class Serve < ShopifyCli::Command
      prerequisite_task :ensure_env, :ensure_dev_store

      options do |parser, flags|
        parser.on("--host=HOST") do |h|
          flags[:host] = h.gsub('"', "")
        end
      end

      def call(*)
        project = ShopifyCli::Project.current
        url = options.flags[:host] || ShopifyCli::Tunnel.start(@ctx)
        @ctx.abort(@ctx.message("node.serve.error.host_must_be_https")) if url.match(/^https/i).nil?
        project.env.update(@ctx, :host, url)
        ShopifyCli::Tasks::UpdateDashboardURLS.call(
          @ctx,
          url: url,
          callback_url: "/auth/callback",
        )

        if project.env.shop
          project_url = "#{project.env.host}/auth?shop=#{project.env.shop}"
          @ctx.puts("\n" + @ctx.message("node.serve.open_info", project_url) + "\n")
        end

        CLI::UI::Frame.open(@ctx.message("node.serve.running_server")) do
          env = project.env.to_h
          env["PORT"] = ShopifyCli::Tunnel::PORT.to_s
          @ctx.system("npm run dev", env: env)
        end
      end

      def self.help
        ShopifyCli::Context.message("node.serve.help", ShopifyCli::TOOL_NAME)
      end

      def self.extended_help
        ShopifyCli::Context.message("node.serve.extended_help")
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
shopify-cli-1.14.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.13.1 lib/project_types/node/commands/serve.rb
shopify-cli-1.13.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.12.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.11.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.10.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.9.1 lib/project_types/node/commands/serve.rb
shopify-cli-1.9.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.8.0 lib/project_types/node/commands/serve.rb
shopify-cli-1.7.1 lib/project_types/node/commands/serve.rb
shopify-cli-1.7.0 lib/project_types/node/commands/serve.rb