-
Notifications
You must be signed in to change notification settings - Fork 204
Core APIs
We provide a base set of core APIs to help enable you to not have to write as much code and so that every developer can access resources in a consistent way.
Platform Support
Platform APIs
- ShopifyCli::AdminApi
- ShopifyCli::DB
- ShopifyCli::Git
- ShopifyCli::Heroku
- ShopifyCli::PartnersApi
- ShopifyCli::ProcessSupervision
- ShopifyCli::Tunnel
Context is a very special object in the codebase. It is passed throughout most code and is automatically set as @ctx
on each command that is being run. The context can be used to mostly interact with the operating system and keep the context of the current working directory.
There are 3 domains that the context holds
- Console output and formatting
- File operations, writing, removing, making directories
- System calls to other commands in the users system.
-
ctx.puts(message)
: output a formatted message to the console. SeeCLI::UI::Formatter::SGR_MAP+
for available formatting options -
ctx.abort(message)
: outputs a formatted message and then throws an abort exception making the command exit immediately. -
ctx.debug(message)
: outputs a formatted message but only when a DEBUG env var exists.
-
ctx.write(filename, content)
: Create or overwrite a file at pathfilename
, with the contents ofcontents
-
ctx.rename(filename)
: Same as OSmv
-
ctx.rm(filename)
: Same as OSrm
-
ctx.rm_r(dirname)
: Same as OSrm -r
-
ctx.mkdir_p(dirname)
: Same as OSmkdir -p
meaning it will make all directories recursively.
-
ctx.os
: returns:mac
or:linux
-
ctx.mac?
: returns true if running on mac. -
ctx.linux?
: returns true if running on linux -
ctx.system?
: returns true if you have not usedload-dev
-
ctx.development?
: returns true if you usedload-dev
-
ctx.testing?
: returns true if the tests are being run -
ctx.ci?
: returns true if tests are being run on the CI -
ctx.uname
: returns the architecture of the current platform -
ctx.system(*command)
: run a command and only capture the status -
ctx.capture2(*command)
: run a command and return [STDOUT, Status] -
ctx.capture2e(*command)
: run a command and return [STDOUT+STDERR, Status] -
ctx.capture3(*command)
: run a command and return [STDOUT, STDERR, Status]
The ShopifyCli::Project helps interacting with the current project, if the user is currently in a directory where a project is.
There are 3 main things you may want from a project. Project.current.env
will return the current projects .env
file values. Project.current.config
will return the values from the .shopify-app-cli.yml
file. The .env
file is used for values that are necessary for the project to run and the .shopify-app-cli.yml
file is for values that the cli needs to understand the current project.
Auto-authenticated graphql access to a stores admin API. This requires a shop for authentication so either the shop param is required or an env-file with the shop variable defined.
ShopifyCli::AdminApi.query(ctx, query_name, api_version: nil, shop: nil, **variables)
-
ctx
: The running command context -
query_name
: the name of a graphql file inlib/graphql
to be loaded for the query -
api_version
: To be supplied if you want to specify the version, otherwiseunstable
will be used. -
shop
: can be provided if you are not using a shop from an env file -
variables
: are the variables that will be supplied to the query or mutation.
Auto-authenticated graphql access to the partner dashboard CLI schema. This will authenticate the user with identity and then make authenticated calls to the dashboard.
Note To use a local instance of the Partners Dashboard you can preface your commands with SHOPIFY_APP_CLI_LOCAL_PARTNERS
. For example SHOPIFY_APP_CLI_LOCAL_PARTNERS=1 shopify create
ShopifyCli::PartnersApi.query(ctx, query_name, **variables)
-
ctx
: The running command context -
query_name
: the name of a graphql file inlib/graphql
to be loaded for the query -
variables
: are the variables that will be supplied to the query or mutation.
Process supervision is for running long running processes concurrently in a way that we can monitor and clean up.
ShopifyCli::ProcessSupervision.for_ident(identifier)
-
identifier
: a symbol or string to refer to this process by. -
return
: a process that can be checked for status and stopped if it is currently running. If it is not running then this method returns nil
ShopifyCli::ProcessSupervision.start(identifier, command)
-
identifier
: a symbol or string to refer to this process by. -
command
: string representation of the command being executed -
return
: a process that can be checked for status and stopped if it is currently running. If it is not running then this method returns nil
example
process = ShopifyCli::ProcessSupervision.start(:ngrok, "ngrok http 8080")
ShopifyCli::ProcessSupervision.stop(identifier)
-
identifier
: a symbol or string that refers to a running process. -
return
: true if the process was stopped or not running. false if it could not be stopped.
ShopifyCli::ProcessSupervision.running?(identifier)
-
identifier
: a symbol or string that refers to a running process. -
return
: true if the process is running and false otherwise.