Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .dev.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
### Local developer tooling overrides for `dev` commands.
###
### Enable overrides: `cp .dev.env.example .dev.env`
###
### This file is NOT for sample app configuration. Keep storefront values in .env.
###
### Unlike .env, this file is never generated or rewritten by tooling, so your
### overrides here are safe.
### ------------------------------------------------------------------------------

### Editor used by `dev react-native open` and `dev web open` to open JS
### workspaces. This file is the only source for DEV_EDITOR; setting it inline
### (e.g. `DEV_EDITOR=code dev rn open`) is NOT picked up. Accepts any command on
### your PATH, e.g. code, cursor, subl, zed, webstorm, nvim. When unset, `dev`
### falls back to `open` (macOS default app).
DEV_EDITOR=code
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ captures/
# Android local config / secrets
local.properties
.env

# Local developer tooling preferences (see .dev.env.example)
.dev.env
upload-keystore.jks
51 changes: 51 additions & 0 deletions dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,18 @@ commands:
desc: Clean Android Gradle build outputs
run: cd platforms/android && ./gradlew clean

open:
desc: Open the Android library or sample app in Android Studio
long_desc: |
Opens an Android project in Android Studio.

dev android open Open the demo app (default)
dev android open demo Open the demo app (aliases: sample, samples)
dev android open lib Open the Android SDK library project (alias: library)
syntax:
optional: "[lib|demo]"
run: ./scripts/dev-open android "$@"

api:
desc: Validate or update the public API baseline (lib/api/lib.api)
run: |
Expand Down Expand Up @@ -263,6 +275,18 @@ commands:
desc: Run Swift lint checks
run: /opt/dev/bin/dev swift lint

open:
desc: Open the Swift package or sample app in Xcode
long_desc: |
Opens a Swift workspace in Xcode via `xed`.

dev swift open Open the demo app workspace (default)
dev swift open demo Open the demo app workspace (aliases: sample, samples)
dev swift open lib Open the ShopifyCheckoutKit Swift package (aliases: library, package)
syntax:
optional: "[lib|demo]"
run: ./scripts/dev-open swift "$@"

clean:
desc: Clean Swift packages and sample app build artifacts
run: |
Expand Down Expand Up @@ -416,6 +440,20 @@ commands:
optional: --local
run: cd platforms/react-native && pnpm run pod-install -- "$@"

open:
desc: Open the React Native workspace root or native sample projects
long_desc: |
Opens platforms/react-native in the editor set by DEV_EDITOR in
.dev.env, otherwise `open` (see .dev.env.example). The --ios and
--android flags open the sample app's native projects.

dev rn open Open platforms/react-native
dev rn open --ios Open the sample iOS workspace in Xcode
dev rn open --android Open the sample Android project in Android Studio
syntax:
optional: "[--ios|--android]"
run: ./scripts/dev-open react-native "$@"

rn:
desc: "Alias for React Native Checkout Kit commands"
long_desc: |
Expand Down Expand Up @@ -484,3 +522,16 @@ commands:
verify:
desc: Run Web package verification
run: cd platforms/web && pnpm verify

open:
desc: Open the Web package or sample app in an editor
long_desc: |
Opens a Web workspace in the editor set by DEV_EDITOR in .dev.env,
otherwise `open` (see .dev.env.example).

dev web open Open the sample app (default)
dev web open demo Open the sample app (aliases: sample, samples)
dev web open lib Open the @shopify/checkout-kit package (aliases: library, package)
syntax:
optional: "[lib|demo]"
run: ./scripts/dev-open web "$@"
44 changes: 44 additions & 0 deletions scripts/dev-open
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'English'

$LOAD_PATH.unshift(File.expand_path('lib', __dir__))

require 'checkout_kit/cli'

require_relative 'dev_open/commands/swift'
require_relative 'dev_open/commands/android'
require_relative 'dev_open/commands/react_native'
require_relative 'dev_open/commands/web'

module DevOpen
COMMANDS = {
'swift' => Commands::Swift,
'android' => Commands::Android,
'react-native' => Commands::ReactNative,
'rn' => Commands::ReactNative,
'web' => Commands::Web,
}.freeze
end

repo_root = File.expand_path('..', __dir__)
platform = ARGV.shift
command = DevOpen::COMMANDS[platform]

begin
if command.nil?
warn "Usage: #{File.basename($PROGRAM_NAME)} <swift|android|react-native|web> [lib|demo] [flags]"
exit 1
end

command.run(ARGV, repo_root: repo_root)
rescue DevOpen::UsageError => e
warn e.message
exit 1
rescue Interrupt
exit 130
rescue CheckoutKit::CLI::Error => e
warn "ERROR: #{e.message}"
exit 1
end
29 changes: 29 additions & 0 deletions scripts/dev_open/commands/android.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative 'base'

module DevOpen
module Commands
# Opens the Android library or sample app in Android Studio.
class Android < Base
DEMO = 'platforms/android/samples/CheckoutKitAndroidDemo'
LIB = 'platforms/android'

def run(argv)
arg = argv.shift
raise UsageError, usage unless argv.empty?

case target(arg)
when :demo then open_in_android_studio(DEMO)
when :lib then open_in_android_studio(LIB)
end
end

private

def usage
'Usage: dev android open [lib|demo]'
end
end
end
end
57 changes: 57 additions & 0 deletions scripts/dev_open/commands/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# frozen_string_literal: true

require 'checkout_kit/cli'

require_relative '../support/error'
require_relative '../support/editor'

module DevOpen
module Commands
# Shared behaviour for `dev <platform> open` commands: target aliasing,
# path resolution against the repo root, and the open mechanisms.
class Base
DEMO_ALIASES = %w[demo sample samples].freeze
LIB_ALIASES = %w[lib library package module].freeze

def self.run(argv, repo_root:)
new(repo_root).run(argv)
end

def initialize(repo_root)
@repo_root = repo_root
end

private

attr_reader :repo_root

# Maps a positional argument to :demo (default) or :lib.
def target(arg)
return :demo if arg.nil? || DEMO_ALIASES.include?(arg)
return :lib if LIB_ALIASES.include?(arg)

raise UsageError, usage
end

# Resolves a path relative to the repo root, ensuring it exists.
def path(relative)
absolute = File.join(repo_root, relative)
raise CheckoutKit::CLI::Error, "Path not found: #{relative}" unless File.exist?(absolute)

absolute
end

def open_in_editor(relative)
CheckoutKit::CLI::Shell.launch(*Editor.command(repo_root), path(relative))
end

def open_in_xcode(relative)
CheckoutKit::CLI::Shell.launch('xed', path(relative))
end

def open_in_android_studio(relative)
CheckoutKit::CLI::Shell.launch('open', '-a', 'Android Studio', path(relative))
end
end
end
end
33 changes: 33 additions & 0 deletions scripts/dev_open/commands/react_native.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

require_relative 'base'

module DevOpen
module Commands
# Opens the React Native workspace root in the configured editor, or the
# sample app's native project in Xcode / Android Studio.
class ReactNative < Base
WORKSPACE = 'platforms/react-native'
SAMPLE = 'platforms/react-native/sample'
SAMPLE_IOS = "#{SAMPLE}/ios/CheckoutKitReactNativeDemo.xcworkspace".freeze
SAMPLE_ANDROID = "#{SAMPLE}/android".freeze

def run(argv)
raise UsageError, usage if argv.size > 1

case argv.first
when nil then open_in_editor(WORKSPACE)
when '--ios' then open_in_xcode(SAMPLE_IOS)
when '--android' then open_in_android_studio(SAMPLE_ANDROID)
else raise UsageError, usage
end
end

private

def usage
'Usage: dev rn open [--ios|--android]'
end
end
end
end
29 changes: 29 additions & 0 deletions scripts/dev_open/commands/swift.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative 'base'

module DevOpen
module Commands
# Opens the Swift package or sample app workspace in Xcode via `xed`.
class Swift < Base
DEMO = 'platforms/swift/Samples/Samples.xcworkspace'
LIB = 'platforms/swift'

def run(argv)
arg = argv.shift
raise UsageError, usage unless argv.empty?

case target(arg)
when :demo then open_in_xcode(DEMO)
when :lib then open_in_xcode(LIB)
end
end

private

def usage
'Usage: dev swift open [lib|demo]'
end
end
end
end
29 changes: 29 additions & 0 deletions scripts/dev_open/commands/web.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require_relative 'base'

module DevOpen
module Commands
# Opens the Web package or sample app in the configured editor.
class Web < Base
DEMO = 'platforms/web/sample'
LIB = 'platforms/web'

def run(argv)
arg = argv.shift
raise UsageError, usage unless argv.empty?

case target(arg)
when :demo then open_in_editor(DEMO)
when :lib then open_in_editor(LIB)
end
end

private

def usage
'Usage: dev web open [lib|demo]'
end
end
end
end
27 changes: 27 additions & 0 deletions scripts/dev_open/support/editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

require 'shellwords'
require 'checkout_kit/cli'

module DevOpen
# Resolves the editor used to open JS workspaces (React Native, Web).
#
# Configured solely via DEV_EDITOR in <repo>/.dev.env (see .dev.env.example).
# Setting DEV_EDITOR inline (`DEV_EDITOR=code dev rn open`) is intentionally
# NOT consulted, so behaviour is consistent regardless of how `dev` is invoked.
module Editor
DEFAULT = 'open'

module_function

# The editor as an argv array, e.g. ["code"] or ["code", "-n"].
def command(repo_root)
Shellwords.split(resolve(repo_root))
end

def resolve(repo_root)
value = CheckoutKit::CLI::Dotenv.read(File.join(repo_root, '.dev.env'))['DEV_EDITOR']
value.nil? || value.empty? ? DEFAULT : value
end
end
end
9 changes: 9 additions & 0 deletions scripts/dev_open/support/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

require 'checkout_kit/cli'

module DevOpen
# Raised when arguments are invalid; the message is the command usage line.
# Inherits the shared CLI error so the entrypoint can rescue a single type.
UsageError = Class.new(CheckoutKit::CLI::Error)
end
20 changes: 20 additions & 0 deletions scripts/lib/checkout_kit/cli.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Shared support modules for Checkout Kit's Ruby CLIs (scripts/dev-open,
# platforms/react-native/scripts/validate_release, ...).
#
# Add scripts/lib to the load path from an entrypoint, then `require
# 'checkout_kit/cli'` to pull in everything below.

require_relative 'cli/error'
require_relative 'cli/env'
require_relative 'cli/dotenv'
require_relative 'cli/redaction'
require_relative 'cli/shell'
require_relative 'cli/json_file'
require_relative 'cli/config_summary'

module CheckoutKit
module CLI
end
end
Loading
Loading