shopify-cli 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/CODEOWNERS +1 -0
- data/.github/CODE_OF_CONDUCT.md +73 -0
- data/.github/CONTRIBUTING.md +51 -0
- data/.github/DESIGN.md +153 -0
- data/.github/ISSUE_TEMPLATE.md +38 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +22 -0
- data/.github/probots.yml +3 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +47 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +77 -0
- data/LICENSE.md +7 -0
- data/README.md +13 -0
- data/Rakefile +101 -0
- data/SECURITY.md +59 -0
- data/Vagrantfile +17 -0
- data/bin/load_shopify.rb +20 -0
- data/bin/shopify +32 -0
- data/dev.yml +17 -0
- data/docs/Gemfile +5 -0
- data/docs/Gemfile.lock +248 -0
- data/docs/_config.yml +16 -0
- data/docs/_data/nav.yml +26 -0
- data/docs/_includes/footer.html +15 -0
- data/docs/_includes/head.html +19 -0
- data/docs/_includes/sidebar_nav.html +22 -0
- data/docs/_includes/toc.html +112 -0
- data/docs/_layouts/default.html +79 -0
- data/docs/app/node/commands/index.md +82 -0
- data/docs/app/node/index.md +35 -0
- data/docs/app/rails/commands/index.md +80 -0
- data/docs/app/rails/index.md +36 -0
- data/docs/core/index.md +70 -0
- data/docs/css/docs.css +157 -0
- data/docs/getting-started/index.md +61 -0
- data/docs/help/start-app/index.md +6 -0
- data/docs/images/header.png +0 -0
- data/docs/index.md +27 -0
- data/docs/installing-ruby.md +28 -0
- data/ext/shopify-cli/extconf.rb +27 -0
- data/install.sh +7 -0
- data/lib/docgen/class_template.md.erb +81 -0
- data/lib/docgen/index_template.md.erb +5 -0
- data/lib/docgen/markdown.rb +101 -0
- data/lib/graphql/admin_introspection.graphql +87 -0
- data/lib/graphql/all_organizations.graphql +19 -0
- data/lib/graphql/all_orgs_with_apps.graphql +30 -0
- data/lib/graphql/api_versions.graphql +6 -0
- data/lib/graphql/convert_dev_to_test_store.graphql +10 -0
- data/lib/graphql/create_app.graphql +20 -0
- data/lib/graphql/create_customer.graphql +9 -0
- data/lib/graphql/create_draft_order.graphql +8 -0
- data/lib/graphql/create_product.graphql +9 -0
- data/lib/graphql/extension_create.graphql +21 -0
- data/lib/graphql/extension_update_draft.graphql +18 -0
- data/lib/graphql/find_organization.graphql +17 -0
- data/lib/graphql/get_app_urls.graphql +6 -0
- data/lib/graphql/update_dashboard_urls.graphql +8 -0
- data/lib/project_types/extension/cli.rb +71 -0
- data/lib/project_types/extension/commands/build.rb +29 -0
- data/lib/project_types/extension/commands/create.rb +49 -0
- data/lib/project_types/extension/commands/extension_command.rb +22 -0
- data/lib/project_types/extension/commands/push.rb +69 -0
- data/lib/project_types/extension/commands/register.rb +78 -0
- data/lib/project_types/extension/commands/serve.rb +24 -0
- data/lib/project_types/extension/commands/tunnel.rb +69 -0
- data/lib/project_types/extension/extension_project.rb +85 -0
- data/lib/project_types/extension/extension_project_keys.rb +10 -0
- data/lib/project_types/extension/features/argo.rb +48 -0
- data/lib/project_types/extension/features/argo_dependencies.rb +28 -0
- data/lib/project_types/extension/features/argo_setup.rb +54 -0
- data/lib/project_types/extension/features/argo_setup_step.rb +31 -0
- data/lib/project_types/extension/features/argo_setup_steps.rb +53 -0
- data/lib/project_types/extension/features/tunnel_url.rb +20 -0
- data/lib/project_types/extension/forms/create.rb +52 -0
- data/lib/project_types/extension/forms/register.rb +48 -0
- data/lib/project_types/extension/messages/message_loading.rb +37 -0
- data/lib/project_types/extension/messages/messages.rb +126 -0
- data/lib/project_types/extension/models/app.rb +14 -0
- data/lib/project_types/extension/models/registration.rb +19 -0
- data/lib/project_types/extension/models/type.rb +76 -0
- data/lib/project_types/extension/models/types/checkout_post_purchase.rb +20 -0
- data/lib/project_types/extension/models/types/subscription_management.rb +20 -0
- data/lib/project_types/extension/models/validation_error.rb +17 -0
- data/lib/project_types/extension/models/version.rb +15 -0
- data/lib/project_types/extension/tasks/converters/registration_converter.rb +26 -0
- data/lib/project_types/extension/tasks/converters/validation_error_converter.rb +25 -0
- data/lib/project_types/extension/tasks/converters/version_converter.rb +28 -0
- data/lib/project_types/extension/tasks/create_extension.rb +31 -0
- data/lib/project_types/extension/tasks/get_apps.rb +34 -0
- data/lib/project_types/extension/tasks/update_draft.rb +29 -0
- data/lib/project_types/extension/tasks/user_errors.rb +45 -0
- data/lib/project_types/node/cli.rb +37 -0
- data/lib/project_types/node/commands/create.rb +117 -0
- data/lib/project_types/node/commands/deploy.rb +22 -0
- data/lib/project_types/node/commands/deploy/heroku.rb +91 -0
- data/lib/project_types/node/commands/generate.rb +51 -0
- data/lib/project_types/node/commands/generate/billing.rb +37 -0
- data/lib/project_types/node/commands/generate/page.rb +55 -0
- data/lib/project_types/node/commands/generate/webhook.rb +33 -0
- data/lib/project_types/node/commands/open.rb +16 -0
- data/lib/project_types/node/commands/populate.rb +23 -0
- data/lib/project_types/node/commands/populate/customer.rb +31 -0
- data/lib/project_types/node/commands/populate/draft_order.rb +28 -0
- data/lib/project_types/node/commands/populate/product.rb +30 -0
- data/lib/project_types/node/commands/serve.rb +45 -0
- data/lib/project_types/node/commands/tunnel.rb +39 -0
- data/lib/project_types/node/forms/create.rb +87 -0
- data/lib/project_types/node/messages/messages.rb +260 -0
- data/lib/project_types/rails/cli.rb +41 -0
- data/lib/project_types/rails/commands/create.rb +126 -0
- data/lib/project_types/rails/commands/deploy.rb +22 -0
- data/lib/project_types/rails/commands/deploy/heroku.rb +113 -0
- data/lib/project_types/rails/commands/generate.rb +49 -0
- data/lib/project_types/rails/commands/generate/webhook.rb +39 -0
- data/lib/project_types/rails/commands/open.rb +16 -0
- data/lib/project_types/rails/commands/populate.rb +23 -0
- data/lib/project_types/rails/commands/populate/customer.rb +31 -0
- data/lib/project_types/rails/commands/populate/draft_order.rb +28 -0
- data/lib/project_types/rails/commands/populate/product.rb +30 -0
- data/lib/project_types/rails/commands/serve.rb +47 -0
- data/lib/project_types/rails/commands/tunnel.rb +39 -0
- data/lib/project_types/rails/forms/create.rb +116 -0
- data/lib/project_types/rails/gem.rb +56 -0
- data/lib/project_types/rails/messages/messages.rb +283 -0
- data/lib/project_types/rails/ruby.rb +17 -0
- data/lib/project_types/script/cli.rb +76 -0
- data/lib/project_types/script/commands/create.rb +45 -0
- data/lib/project_types/script/commands/disable.rb +36 -0
- data/lib/project_types/script/commands/enable.rb +46 -0
- data/lib/project_types/script/commands/push.rb +39 -0
- data/lib/project_types/script/config/extension_points.yml +18 -0
- data/lib/project_types/script/errors.rb +16 -0
- data/lib/project_types/script/forms/create.rb +29 -0
- data/lib/project_types/script/forms/enable.rb +24 -0
- data/lib/project_types/script/forms/push.rb +19 -0
- data/lib/project_types/script/forms/script_form.rb +66 -0
- data/lib/project_types/script/graphql/app_script_update_or_create.graphql +27 -0
- data/lib/project_types/script/graphql/script_service_proxy.graphql +8 -0
- data/lib/project_types/script/graphql/shop_script_delete.graphql +14 -0
- data/lib/project_types/script/graphql/shop_script_update_or_create.graphql +28 -0
- data/lib/project_types/script/layers/application/build_script.rb +43 -0
- data/lib/project_types/script/layers/application/create_script.rb +47 -0
- data/lib/project_types/script/layers/application/disable_script.rb +19 -0
- data/lib/project_types/script/layers/application/enable_script.rb +21 -0
- data/lib/project_types/script/layers/application/extension_points.rb +17 -0
- data/lib/project_types/script/layers/application/project_dependencies.rb +34 -0
- data/lib/project_types/script/layers/application/push_script.rb +30 -0
- data/lib/project_types/script/layers/domain/errors.rb +25 -0
- data/lib/project_types/script/layers/domain/extension_point.rb +29 -0
- data/lib/project_types/script/layers/domain/push_package.rb +29 -0
- data/lib/project_types/script/layers/domain/script.rb +18 -0
- data/lib/project_types/script/layers/infrastructure/assemblyscript_dependency_manager.rb +73 -0
- data/lib/project_types/script/layers/infrastructure/assemblyscript_tsconfig.rb +38 -0
- data/lib/project_types/script/layers/infrastructure/assemblyscript_wasm_builder.rb +39 -0
- data/lib/project_types/script/layers/infrastructure/dependency_manager.rb +36 -0
- data/lib/project_types/script/layers/infrastructure/errors.rb +38 -0
- data/lib/project_types/script/layers/infrastructure/extension_point_repository.rb +31 -0
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +47 -0
- data/lib/project_types/script/layers/infrastructure/script_builder.rb +34 -0
- data/lib/project_types/script/layers/infrastructure/script_repository.rb +89 -0
- data/lib/project_types/script/layers/infrastructure/script_service.rb +165 -0
- data/lib/project_types/script/layers/infrastructure/test_suite_repository.rb +59 -0
- data/lib/project_types/script/messages/messages.rb +204 -0
- data/lib/project_types/script/script_project.rb +37 -0
- data/lib/project_types/script/templates/ts/as-pect.config.js +21 -0
- data/lib/project_types/script/ui/error_handler.rb +136 -0
- data/lib/project_types/script/ui/strict_spinner.rb +22 -0
- data/lib/rubygems_plugin.rb +18 -0
- data/lib/shopify-cli/admin_api.rb +99 -0
- data/lib/shopify-cli/admin_api/populate_resource_command.rb +165 -0
- data/lib/shopify-cli/admin_api/schema.rb +32 -0
- data/lib/shopify-cli/api.rb +104 -0
- data/lib/shopify-cli/command.rb +67 -0
- data/lib/shopify-cli/commands.rb +28 -0
- data/lib/shopify-cli/commands/connect.rb +108 -0
- data/lib/shopify-cli/commands/create.rb +50 -0
- data/lib/shopify-cli/commands/help.rb +79 -0
- data/lib/shopify-cli/commands/logout.rb +23 -0
- data/lib/shopify-cli/commands/system.rb +135 -0
- data/lib/shopify-cli/commands/version.rb +15 -0
- data/lib/shopify-cli/context.rb +372 -0
- data/lib/shopify-cli/core.rb +9 -0
- data/lib/shopify-cli/core/entry_point.rb +40 -0
- data/lib/shopify-cli/core/executor.rb +21 -0
- data/lib/shopify-cli/core/help_resolver.rb +20 -0
- data/lib/shopify-cli/core/monorail.rb +118 -0
- data/lib/shopify-cli/db.rb +114 -0
- data/lib/shopify-cli/form.rb +40 -0
- data/lib/shopify-cli/git.rb +141 -0
- data/lib/shopify-cli/helpers.rb +5 -0
- data/lib/shopify-cli/helpers/haikunator.rb +92 -0
- data/lib/shopify-cli/heroku.rb +97 -0
- data/lib/shopify-cli/js_deps.rb +110 -0
- data/lib/shopify-cli/js_system.rb +98 -0
- data/lib/shopify-cli/messages/messages.rb +287 -0
- data/lib/shopify-cli/oauth.rb +192 -0
- data/lib/shopify-cli/oauth/servlet.rb +61 -0
- data/lib/shopify-cli/options.rb +40 -0
- data/lib/shopify-cli/packager.rb +116 -0
- data/lib/shopify-cli/partners_api.rb +114 -0
- data/lib/shopify-cli/partners_api/organizations.rb +32 -0
- data/lib/shopify-cli/process_supervision.rb +187 -0
- data/lib/shopify-cli/project.rb +191 -0
- data/lib/shopify-cli/project_type.rb +83 -0
- data/lib/shopify-cli/resources.rb +5 -0
- data/lib/shopify-cli/resources/env_file.rb +96 -0
- data/lib/shopify-cli/sub_command.rb +15 -0
- data/lib/shopify-cli/task.rb +10 -0
- data/lib/shopify-cli/tasks.rb +32 -0
- data/lib/shopify-cli/tasks/create_api_client.rb +29 -0
- data/lib/shopify-cli/tasks/ensure_dev_store.rb +41 -0
- data/lib/shopify-cli/tasks/ensure_env.rb +31 -0
- data/lib/shopify-cli/tasks/ensure_loopback_url.rb +20 -0
- data/lib/shopify-cli/tasks/update_dashboard_urls.rb +44 -0
- data/lib/shopify-cli/tunnel.rb +154 -0
- data/lib/shopify-cli/version.rb +3 -0
- data/lib/shopify_cli.rb +132 -0
- data/shopify-cli.gemspec +40 -0
- data/shopify.fish +12 -0
- data/shopify.sh +11 -0
- data/vendor/deps/cli-kit/REVISION +1 -0
- data/vendor/deps/cli-kit/lib/cli/kit.rb +60 -0
- data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +21 -0
- data/vendor/deps/cli-kit/lib/cli/kit/base_command.rb +49 -0
- data/vendor/deps/cli-kit/lib/cli/kit/command_registry.rb +94 -0
- data/vendor/deps/cli-kit/lib/cli/kit/config.rb +133 -0
- data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +115 -0
- data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +81 -0
- data/vendor/deps/cli-kit/lib/cli/kit/ini.rb +102 -0
- data/vendor/deps/cli-kit/lib/cli/kit/levenshtein.rb +82 -0
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +76 -0
- data/vendor/deps/cli-kit/lib/cli/kit/resolver.rb +60 -0
- data/vendor/deps/cli-kit/lib/cli/kit/ruby_backports/enumerable.rb +6 -0
- data/vendor/deps/cli-kit/lib/cli/kit/support.rb +9 -0
- data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +244 -0
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +207 -0
- data/vendor/deps/cli-kit/lib/cli/kit/util.rb +189 -0
- data/vendor/deps/cli-kit/lib/cli/kit/version.rb +5 -0
- data/vendor/deps/cli-ui/REVISION +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui.rb +187 -0
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +153 -0
- data/vendor/deps/cli-ui/lib/cli/ui/box.rb +15 -0
- data/vendor/deps/cli-ui/lib/cli/ui/color.rb +79 -0
- data/vendor/deps/cli-ui/lib/cli/ui/formatter.rb +179 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +310 -0
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +78 -0
- data/vendor/deps/cli-ui/lib/cli/ui/progress.rb +88 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +248 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +472 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/options_handler.rb +24 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +48 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/async.rb +40 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +241 -0
- data/vendor/deps/cli-ui/lib/cli/ui/stdout_router.rb +227 -0
- data/vendor/deps/cli-ui/lib/cli/ui/terminal.rb +36 -0
- data/vendor/deps/cli-ui/lib/cli/ui/truncater.rb +102 -0
- data/vendor/deps/cli-ui/lib/cli/ui/version.rb +5 -0
- data/vendor/deps/smart_properties/REVISION +1 -0
- data/vendor/deps/smart_properties/lib/smart_properties.rb +174 -0
- data/vendor/deps/smart_properties/lib/smart_properties/errors.rb +114 -0
- data/vendor/deps/smart_properties/lib/smart_properties/property.rb +162 -0
- data/vendor/deps/smart_properties/lib/smart_properties/property_collection.rb +83 -0
- data/vendor/deps/smart_properties/lib/smart_properties/validations.rb +8 -0
- data/vendor/deps/smart_properties/lib/smart_properties/validations/ancestor.rb +27 -0
- data/vendor/deps/smart_properties/lib/smart_properties/version.rb +3 -0
- data/vendor/lib/semantic/LICENSE +20 -0
- data/vendor/lib/semantic/semantic.rb +4 -0
- data/vendor/lib/semantic/version.rb +180 -0
- metadata +374 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Rails
|
3
|
+
class Project < ShopifyCli::ProjectType
|
4
|
+
# hidden_project_type
|
5
|
+
creator 'Ruby on Rails App', 'Rails::Commands::Create'
|
6
|
+
|
7
|
+
register_command('Rails::Commands::Deploy', "deploy")
|
8
|
+
register_command('Rails::Commands::Generate', "generate")
|
9
|
+
register_command('Rails::Commands::Open', "open")
|
10
|
+
register_command('Rails::Commands::Populate', "populate")
|
11
|
+
register_command('Rails::Commands::Serve', "serve")
|
12
|
+
register_command('Rails::Commands::Tunnel', "tunnel")
|
13
|
+
# register_task('Rails::Tasks::RailsTask', 'rails_task')
|
14
|
+
|
15
|
+
require Project.project_filepath('messages/messages')
|
16
|
+
register_messages(Rails::Messages::MESSAGES)
|
17
|
+
end
|
18
|
+
|
19
|
+
# define/autoload project specific Commands
|
20
|
+
module Commands
|
21
|
+
autoload :Create, Project.project_filepath('commands/create')
|
22
|
+
autoload :Deploy, Project.project_filepath('commands/deploy')
|
23
|
+
autoload :Generate, Project.project_filepath('commands/generate')
|
24
|
+
autoload :Open, Project.project_filepath('commands/open')
|
25
|
+
autoload :Populate, Project.project_filepath('commands/populate')
|
26
|
+
autoload :Serve, Project.project_filepath('commands/serve')
|
27
|
+
autoload :Tunnel, Project.project_filepath('commands/tunnel')
|
28
|
+
end
|
29
|
+
|
30
|
+
# define/autoload project specific Tasks
|
31
|
+
module Tasks
|
32
|
+
end
|
33
|
+
|
34
|
+
# define/autoload project specific Forms
|
35
|
+
module Forms
|
36
|
+
autoload :Create, Project.project_filepath('forms/create')
|
37
|
+
end
|
38
|
+
|
39
|
+
autoload :Ruby, Project.project_filepath('ruby')
|
40
|
+
autoload :Gem, Project.project_filepath('gem')
|
41
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Rails
|
3
|
+
module Commands
|
4
|
+
class Create < ShopifyCli::SubCommand
|
5
|
+
USER_AGENT_CODE = <<~USERAGENT
|
6
|
+
module ShopifyAPI
|
7
|
+
class Base < ActiveResource::Base
|
8
|
+
self.headers['User-Agent'] << " | ShopifyApp/\#{ShopifyApp::VERSION} | Shopify App CLI"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
USERAGENT
|
12
|
+
|
13
|
+
DEFAULT_RAILS_FLAGS = %w(--skip-spring)
|
14
|
+
|
15
|
+
options do |parser, flags|
|
16
|
+
# backwards compatibility allow 'title' for now
|
17
|
+
parser.on('--title=TITLE') { |t| flags[:title] = t }
|
18
|
+
parser.on('--name=NAME') { |t| flags[:title] = t }
|
19
|
+
parser.on('--organization_id=ID') { |url| flags[:organization_id] = url }
|
20
|
+
parser.on('--shop_domain=MYSHOPIFYDOMAIN') { |url| flags[:shop_domain] = url }
|
21
|
+
parser.on('--type=APPTYPE') { |url| flags[:type] = url }
|
22
|
+
parser.on('--db=DB') { |db| flags[:db] = db }
|
23
|
+
parser.on('--rails_opts=RAILSOPTS') { |opts| flags[:rails_opts] = opts }
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(args, _name)
|
27
|
+
form = Forms::Create.ask(@ctx, args, options.flags)
|
28
|
+
return @ctx.puts(self.class.help) if form.nil?
|
29
|
+
|
30
|
+
@ctx.abort(@ctx.message('rails.create.error.invalid_ruby_version')) unless
|
31
|
+
Ruby.version(@ctx).satisfies?('~>2.5')
|
32
|
+
|
33
|
+
build(form.name, form.db)
|
34
|
+
set_custom_ua
|
35
|
+
ShopifyCli::Project.write(
|
36
|
+
@ctx,
|
37
|
+
project_type: 'rails',
|
38
|
+
organization_id: form.organization_id,
|
39
|
+
)
|
40
|
+
|
41
|
+
api_client = ShopifyCli::Tasks::CreateApiClient.call(
|
42
|
+
@ctx,
|
43
|
+
org_id: form.organization_id,
|
44
|
+
title: form.title,
|
45
|
+
type: form.type,
|
46
|
+
)
|
47
|
+
|
48
|
+
ShopifyCli::Resources::EnvFile.new(
|
49
|
+
api_key: api_client["apiKey"],
|
50
|
+
secret: api_client["apiSecretKeys"].first["secret"],
|
51
|
+
shop: form.shop_domain,
|
52
|
+
scopes: 'write_products,write_customers,write_draft_orders',
|
53
|
+
).write(@ctx)
|
54
|
+
|
55
|
+
partners_url = "https://partners.shopify.com/#{form.organization_id}/apps/#{api_client['id']}"
|
56
|
+
|
57
|
+
@ctx.puts(@ctx.message('rails.create.info.created', form.title, partners_url))
|
58
|
+
@ctx.puts(@ctx.message('rails.create.info.serve', form.name, ShopifyCli::TOOL_NAME))
|
59
|
+
@ctx.puts(@ctx.message('rails.create.info.install', partners_url, form.title))
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.help
|
63
|
+
ShopifyCli::Context.message('rails.create.help', ShopifyCli::TOOL_NAME, ShopifyCli::TOOL_NAME)
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def build(name, db)
|
69
|
+
install_gem('rails')
|
70
|
+
CLI::UI::Frame.open(@ctx.message('rails.create.installing_bundler')) do
|
71
|
+
install_gem('bundler', '~>1.0')
|
72
|
+
install_gem('bundler', '~>2.0')
|
73
|
+
end
|
74
|
+
|
75
|
+
CLI::UI::Frame.open(@ctx.message('rails.create.generating_app', name)) do
|
76
|
+
new_command = %w(rails new)
|
77
|
+
new_command += DEFAULT_RAILS_FLAGS
|
78
|
+
new_command << "--database=#{db}"
|
79
|
+
new_command += options.flags[:rails_opts].split unless options.flags[:rails_opts].nil?
|
80
|
+
new_command << name
|
81
|
+
|
82
|
+
syscall(new_command)
|
83
|
+
end
|
84
|
+
|
85
|
+
@ctx.root = File.join(@ctx.root, name)
|
86
|
+
|
87
|
+
File.open(File.join(@ctx.root, '.gitignore'), 'a') { |f| f.write('.env') }
|
88
|
+
|
89
|
+
@ctx.puts(@ctx.message('rails.create.adding_shopify_gem'))
|
90
|
+
File.open(File.join(@ctx.root, 'Gemfile'), 'a') do |f|
|
91
|
+
f.puts "\ngem 'shopify_app', '>=11.3.0'"
|
92
|
+
end
|
93
|
+
CLI::UI::Frame.open(@ctx.message('rails.create.running_bundle_install')) do
|
94
|
+
syscall(%w(bundle install))
|
95
|
+
end
|
96
|
+
|
97
|
+
CLI::UI::Frame.open(@ctx.message('rails.create.running_generator')) do
|
98
|
+
begin
|
99
|
+
syscall(%w(spring stop))
|
100
|
+
rescue
|
101
|
+
end
|
102
|
+
syscall(%w(rails generate shopify_app))
|
103
|
+
end
|
104
|
+
|
105
|
+
CLI::UI::Frame.open(@ctx.message('rails.create.running_migrations')) do
|
106
|
+
syscall(%w(rails db:create))
|
107
|
+
syscall(%w(rails db:migrate RAILS_ENV=development))
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def set_custom_ua
|
112
|
+
ua_path = File.join('config', 'initializers', 'user_agent.rb')
|
113
|
+
@ctx.write(ua_path, USER_AGENT_CODE)
|
114
|
+
end
|
115
|
+
|
116
|
+
def syscall(args)
|
117
|
+
args[0] = Gem.binary_path_for(@ctx, args[0])
|
118
|
+
@ctx.system(*args, chdir: @ctx.root)
|
119
|
+
end
|
120
|
+
|
121
|
+
def install_gem(name, version = nil)
|
122
|
+
Gem.install(@ctx, name, version)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'shopify_cli'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Commands
|
6
|
+
class Deploy < ShopifyCli::Command
|
7
|
+
subcommand :Heroku, 'heroku', Project.project_filepath('commands/deploy/heroku')
|
8
|
+
|
9
|
+
def call(*)
|
10
|
+
@ctx.puts(self.class.help)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.help
|
14
|
+
ShopifyCli::Context.message('rails.deploy.help', ShopifyCli::TOOL_NAME)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.extended_help
|
18
|
+
ShopifyCli::Context.message('rails.deploy.extended_help', ShopifyCli::TOOL_NAME)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'shopify_cli'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Commands
|
6
|
+
class Deploy
|
7
|
+
class Heroku < ShopifyCli::SubCommand
|
8
|
+
DB_CHECK_CMD = 'bundle exec rails runner "puts ActiveRecord::Base.connection.adapter_name.downcase"'
|
9
|
+
|
10
|
+
def self.help
|
11
|
+
ShopifyCli::Context.message('rails.deploy.heroku.help', ShopifyCli::TOOL_NAME)
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(*)
|
15
|
+
CLI::UI::Frame.open(@ctx.message('rails.deploy.heroku.db_check.validating')) do
|
16
|
+
CLI::UI::Spinner.spin(@ctx.message('rails.deploy.heroku.db_check.checking')) do |spinner|
|
17
|
+
db_type, err = check_db(@ctx)
|
18
|
+
@ctx.abort(@ctx.message(err)) unless err.nil?
|
19
|
+
spinner.update_title(@ctx.message('rails.deploy.heroku.db_check.validated', db_type))
|
20
|
+
end
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
spin_group = CLI::UI::SpinGroup.new
|
25
|
+
heroku_service = ShopifyCli::Heroku.new(@ctx)
|
26
|
+
|
27
|
+
spin_group.add(@ctx.message('rails.deploy.heroku.downloading')) do |spinner|
|
28
|
+
heroku_service.download
|
29
|
+
spinner.update_title(@ctx.message('rails.deploy.heroku.downloaded'))
|
30
|
+
end
|
31
|
+
spin_group.wait
|
32
|
+
|
33
|
+
spin_group.add(@ctx.message('rails.deploy.heroku.installing')) do |spinner|
|
34
|
+
heroku_service.install
|
35
|
+
spinner.update_title(@ctx.message('rails.deploy.heroku.installed'))
|
36
|
+
end
|
37
|
+
spin_group.add(@ctx.message('rails.deploy.heroku.git.checking')) do |spinner|
|
38
|
+
ShopifyCli::Git.init(@ctx)
|
39
|
+
spinner.update_title(@ctx.message('rails.deploy.heroku.git.initialized'))
|
40
|
+
end
|
41
|
+
spin_group.wait
|
42
|
+
|
43
|
+
if (account = heroku_service.whoami)
|
44
|
+
@ctx.puts(@ctx.message('rails.deploy.heroku.authenticated_with_account', account))
|
45
|
+
else
|
46
|
+
CLI::UI::Frame.open(
|
47
|
+
@ctx.message('rails.deploy.heroku.authenticating'),
|
48
|
+
success_text: @ctx.message('rails.deploy.heroku.authenticated')
|
49
|
+
) do
|
50
|
+
heroku_service.authenticate
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
if (app_name = heroku_service.app)
|
55
|
+
@ctx.puts(@ctx.message('rails.deploy.heroku.app.selected', app_name))
|
56
|
+
else
|
57
|
+
app_type = CLI::UI::Prompt.ask(@ctx.message('rails.deploy.heroku.app.no_apps_found')) do |handler|
|
58
|
+
handler.option(@ctx.message('rails.deploy.heroku.app.create')) { :new }
|
59
|
+
handler.option(@ctx.message('rails.deploy.heroku.app.select')) { :existing }
|
60
|
+
end
|
61
|
+
|
62
|
+
if app_type == :existing
|
63
|
+
app_name = CLI::UI::Prompt.ask(@ctx.message('rails.deploy.heroku.app.name'))
|
64
|
+
CLI::UI::Frame.open(
|
65
|
+
@ctx.message('rails.deploy.heroku.app.selecting', app_name),
|
66
|
+
success_text: @ctx.message('rails.deploy.heroku.app.selected', app_name)
|
67
|
+
) do
|
68
|
+
heroku_service.select_existing_app(app_name)
|
69
|
+
end
|
70
|
+
elsif app_type == :new
|
71
|
+
CLI::UI::Frame.open(
|
72
|
+
@ctx.message('rails.deploy.heroku.app.creating'),
|
73
|
+
success_text: @ctx.message('rails.deploy.heroku.app.created')
|
74
|
+
) do
|
75
|
+
heroku_service.create_new_app
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
branches = ShopifyCli::Git.branches(@ctx)
|
81
|
+
if branches.length == 1
|
82
|
+
branch_to_deploy = branches[0]
|
83
|
+
@ctx.puts(@ctx.message('rails.deploy.heroku.git.branch_selected', branch_to_deploy))
|
84
|
+
else
|
85
|
+
branch_to_deploy = CLI::UI::Prompt.ask(@ctx.message('rails.deploy.heroku.git.what_branch')) do |handler|
|
86
|
+
branches.each do |branch|
|
87
|
+
handler.option(branch) { branch }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
CLI::UI::Frame.open(
|
93
|
+
@ctx.message('rails.deploy.heroku.deploying'),
|
94
|
+
success_text: @ctx.message('rails.deploy.heroku.deployed')
|
95
|
+
) do
|
96
|
+
heroku_service.deploy(branch_to_deploy)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def check_db(ctx)
|
101
|
+
out, stat = ctx.capture2e(DB_CHECK_CMD)
|
102
|
+
if stat.success? && out.strip == 'sqlite'
|
103
|
+
['sqlite', 'rails.deploy.heroku.db_check.sqlite']
|
104
|
+
elsif !stat.success?
|
105
|
+
[nil, 'rails.deploy.heroku.db_check.problem']
|
106
|
+
else
|
107
|
+
[out.strip, nil]
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'shopify_cli'
|
3
|
+
|
4
|
+
module Rails
|
5
|
+
module Commands
|
6
|
+
class Generate < ShopifyCli::Command
|
7
|
+
subcommand :Webhook, 'webhook', Project.project_filepath('commands/generate/webhook')
|
8
|
+
|
9
|
+
def call(*)
|
10
|
+
@ctx.puts(self.class.help)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.help
|
14
|
+
ShopifyCli::Context.message('rails.generate.help', ShopifyCli::TOOL_NAME)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.extended_help
|
18
|
+
extended_help = "{{bold:Subcommands:}}\n"
|
19
|
+
subcommand_registry.resolved_commands.sort.each do |name, klass|
|
20
|
+
extended_help += " {{cyan:#{name}}}: "
|
21
|
+
|
22
|
+
if (subcmd_help = klass.help)
|
23
|
+
extended_help += subcmd_help.gsub("\n ", "\n ")
|
24
|
+
end
|
25
|
+
extended_help += "\n"
|
26
|
+
end
|
27
|
+
extended_help += ShopifyCli::Context.message('rails.generate.extended_help', ShopifyCli::TOOL_NAME)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.run_generate(script, name, ctx)
|
31
|
+
stat = ctx.system(script)
|
32
|
+
unless stat.success?
|
33
|
+
ctx.abort(response(stat.exitstatus, name, ctx))
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.response(code, name, ctx)
|
38
|
+
case code
|
39
|
+
when 1
|
40
|
+
ctx.message('rails.generate.error.generic', name)
|
41
|
+
when 2
|
42
|
+
ctx.message('rails.generate.error.name_exists', name)
|
43
|
+
else
|
44
|
+
ctx.message('rails.error.generic')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'shopify_cli'
|
2
|
+
require 'json'
|
3
|
+
module Rails
|
4
|
+
module Commands
|
5
|
+
class Generate
|
6
|
+
class Webhook < ShopifyCli::SubCommand
|
7
|
+
def call(args, _name)
|
8
|
+
selected_type = args.first
|
9
|
+
schema = ShopifyCli::AdminAPI::Schema.get(@ctx)
|
10
|
+
webhooks = schema.get_names_from_type('WebhookSubscriptionTopic')
|
11
|
+
unless selected_type && webhooks.include?(selected_type)
|
12
|
+
selected_type = CLI::UI::Prompt.ask(@ctx.message('rails.generate.webhook.select')) do |handler|
|
13
|
+
webhooks.each do |type|
|
14
|
+
handler.option(type) { type }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
spin_group = CLI::UI::SpinGroup.new
|
19
|
+
spin_group.add(@ctx.message('rails.generate.webhook.selected', selected_type)) do |spinner|
|
20
|
+
Rails::Commands::Generate.run_generate(generate_command(selected_type), selected_type, @ctx)
|
21
|
+
spinner.update_title("{{green:#{selected_type}}} config/initializers/shopify_app.rb")
|
22
|
+
end
|
23
|
+
spin_group.wait
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.help
|
27
|
+
ShopifyCli::Context.message('rails.generate.webhook.help', ShopifyCli::TOOL_NAME)
|
28
|
+
end
|
29
|
+
|
30
|
+
def generate_command(selected_type)
|
31
|
+
parts = selected_type.downcase.split("_")
|
32
|
+
env = ShopifyCli::Project.current.env.host
|
33
|
+
selected_type = parts[0..-2].join("_") + "/" + parts[-1]
|
34
|
+
"rails g shopify_app:add_webhook -t #{selected_type} -a #{env}/webhooks/#{selected_type.downcase}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'shopify_cli'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Commands
|
5
|
+
class Open < ShopifyCli::Command
|
6
|
+
def call(*)
|
7
|
+
project = ShopifyCli::Project.current
|
8
|
+
@ctx.open_url!("#{project.env.host}/login?shop=#{project.env.shop}")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.help
|
12
|
+
ShopifyCli::Context.message('rails.open.help', ShopifyCli::TOOL_NAME)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'shopify_cli'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Commands
|
5
|
+
class Populate < ShopifyCli::Command
|
6
|
+
subcommand :Product, 'products', Project.project_filepath('commands/populate/product')
|
7
|
+
subcommand :Customer, 'customers', Project.project_filepath('commands/populate/customer')
|
8
|
+
subcommand :DraftOrder, 'draftorders', Project.project_filepath('commands/populate/draft_order')
|
9
|
+
|
10
|
+
def call(_args, _name)
|
11
|
+
@ctx.puts(self.class.help)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.help
|
15
|
+
ShopifyCli::Context.message('rails.populate.help', ShopifyCli::TOOL_NAME)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.extended_help
|
19
|
+
ShopifyCli::Context.message('rails.populate.extended_help', ShopifyCli::TOOL_NAME)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'shopify_cli'
|
2
|
+
|
3
|
+
module Rails
|
4
|
+
module Commands
|
5
|
+
class Populate
|
6
|
+
class Customer < ShopifyCli::AdminAPI::PopulateResourceCommand
|
7
|
+
@input_type = :CustomerInput
|
8
|
+
|
9
|
+
def defaults
|
10
|
+
first_name, last_name = ShopifyCli::Helpers::Haikunator.name
|
11
|
+
{
|
12
|
+
firstName: first_name,
|
13
|
+
lastName: last_name,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def message(data)
|
18
|
+
ret = data['customerCreate']['customer']
|
19
|
+
id = ShopifyCli::API.gid_to_id(ret['id'])
|
20
|
+
@ctx.message(
|
21
|
+
'rails.populate.customer.added',
|
22
|
+
ret['displayName'],
|
23
|
+
ShopifyCli::Project.current.env.shop,
|
24
|
+
admin_url,
|
25
|
+
id
|
26
|
+
)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|