Sha256: 64175219c5128e784f30f60aa55ab7aa60c1faf24f13af9a8e329868e4ca8d35

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
module Node
  class Command
    class Serve < ShopifyCLI::SubCommand
      include ShopifyCLI::CommandOptions::CommandServeOptions

      prerequisite_task ensure_project_type: :node
      prerequisite_task :ensure_env, :ensure_dev_store

      parse_host_option
      parse_port_option

      def call(*)
        project = ShopifyCLI::Project.current
        tunnel_port = port.to_s
        url = host || ShopifyCLI::Tunnel.start(@ctx, port: tunnel_port)
        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"] = tunnel_port
          @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

3 entries across 3 versions & 1 rubygems

Version Path
shopify-cli-2.6.6 lib/project_types/node/commands/serve.rb
shopify-cli-2.6.5 lib/project_types/node/commands/serve.rb
shopify-cli-2.6.4 lib/project_types/node/commands/serve.rb