-
Notifications
You must be signed in to change notification settings - Fork 200
class ShopifyCli::Project
ShopifyCli::Project captures the current project that the user is working on.
This class can be used to fetch and save project environment as well as the
project config .shopify-cli.yml
.
current(force_reload: false)
will get an instance of the project that the user is currently operating on.
This is used for access to project resources.
-
force_reload
- whether to force a reload of the project files
-
project
- a Project instance if the user is currently in the project.
-
ShopifyCli::Abort
- If the cli is not currently in a project directory then this will be raised with a message implying that the user is not in a project directory.
project = ShopifyCli::Project.current
see source
# File lib/shopify-cli/project.rb, line 36
def current(force_reload: false)
clear if force_reload
at(Dir.pwd)
end
has_current?()
will return true if the command line is currently within a project
-
has_current?
- boolean, true if there is a current project
see source
# File lib/shopify-cli/project.rb, line 48
def has_current?
!directory(Dir.pwd).nil?
end
current_project_type()
will fetch the project type of the current project. This is mostly used for
internal project type loading, you should not normally need this.
-
type
- a symbol of the name of the project type identifier. i.e. [rails, node] This will be nil if the user is not in a current project.
type = ShopifyCli::Project.current_project_type
see source
# File lib/shopify-cli/project.rb, line 65
def current_project_type
return unless has_current?
current.config["project_type"].to_sym
end
write(ctx, project_type:, organization_id:, **identifiers)
writes out the .shopify-cli.yml
file. You should use this when creating a
project type so that the rest of your project type commands will load in this
project, in the future.
-
ctx
- the current running context of your command -
project_type
- a string or symbol of your project type name -
organization_id
- the id of the partner organization that the app is owned by. Used for metrics -
identifiers
- an optional hash of other app identifiers
type = ShopifyCli::Project.current_project_type
see source
# File lib/shopify-cli/project.rb, line 86
def write(ctx, project_type:, organization_id:, **identifiers)
require "yaml" # takes 20ms, so deferred as late as possible.
content = Hash[{ project_type: project_type, organization_id: organization_id.to_i }
.merge(identifiers)
.collect { |k, v| [k.to_s, v] }]
content["shopify_organization"] = true if Shopifolk.acting_as_shopify_organization?
ctx.write(".shopify-cli.yml", YAML.dump(content))
clear
end
project_name()
see source
# File lib/shopify-cli/project.rb, line 97
def project_name
File.basename(current.directory)
end
clear()
see source
# File lib/shopify-cli/project.rb, line 101
def clear
@at = nil
@dir = nil
end
env()
will read, parse and return the envfile for the project
-
env
- An instance of a ShopifyCli::Resources::EnvFile
ShopifyCli::Project.current.env
see source
# File lib/shopify-cli/project.rb, line 145
def env
@env ||= begin
Resources::EnvFile.read(directory)
rescue Errno::ENOENT
nil
end
end
config()
will read, parse and return the .shopify-cli.yml for the project
-
config
- A hash of configuration
-
ShopifyCli::Abort
- If the yml is invalid or poorly formatted -
ShopifyCli::Abort
- If the yml file does not exist
ShopifyCli::Project.current.config
see source
# File lib/shopify-cli/project.rb, line 169
def config
@config ||= begin
config = load_yaml_file(".shopify-cli.yml")
unless config.is_a?(Hash)
raise ShopifyCli::Abort, Context.message("core.yaml.error.not_hash", ".shopify-cli.yml")
end
# The app_type key was deprecated in favour of project_type, so replace it
if config.key?("app_type")
config["project_type"] = config["app_type"]
config.delete("app_type")
end
config
end
end
- SmartProperties