shopify-cli 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/CHANGELOG.md +20 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +13 -13
- data/bin/load_shopify.rb +3 -1
- data/bin/shopify +2 -0
- data/docs/Gemfile.lock +23 -13
- data/docs/getting-started/install/index.md +37 -1
- data/docs/getting-started/migrate/index.md +34 -1
- data/ext/shopify-cli/extconf.rb +40 -20
- data/lib/project_types/extension/cli.rb +1 -1
- data/lib/project_types/extension/commands/build.rb +1 -1
- data/lib/project_types/extension/models/type.rb +1 -0
- data/lib/project_types/extension/tasks/create_extension.rb +1 -1
- data/lib/project_types/extension/tasks/get_app.rb +1 -1
- data/lib/project_types/extension/tasks/update_draft.rb +1 -1
- data/lib/project_types/node/commands/create.rb +4 -4
- data/lib/project_types/node/commands/deploy/heroku.rb +6 -1
- data/lib/project_types/node/commands/generate/billing.rb +6 -5
- data/lib/project_types/node/commands/generate/page.rb +8 -5
- data/lib/project_types/node/commands/generate/webhook.rb +4 -1
- data/lib/project_types/node/messages/messages.rb +3 -2
- data/lib/project_types/rails/cli.rb +0 -1
- data/lib/project_types/rails/commands/create.rb +52 -4
- data/lib/project_types/rails/commands/generate.rb +1 -0
- data/lib/project_types/rails/commands/generate/webhook.rb +3 -2
- data/lib/project_types/rails/commands/serve.rb +6 -2
- data/lib/project_types/rails/gem.rb +61 -6
- data/lib/project_types/rails/messages/messages.rb +29 -13
- data/lib/project_types/script/cli.rb +2 -3
- data/lib/project_types/script/commands/create.rb +5 -9
- data/lib/project_types/script/commands/disable.rb +4 -15
- data/lib/project_types/script/commands/enable.rb +37 -13
- data/lib/project_types/script/commands/push.rb +8 -13
- data/lib/project_types/script/config/extension_points.yml +9 -3
- data/lib/project_types/script/errors.rb +8 -0
- data/lib/project_types/script/forms/create.rb +1 -1
- data/lib/project_types/script/layers/application/create_script.rb +7 -6
- data/lib/project_types/script/layers/application/disable_script.rb +9 -7
- data/lib/project_types/script/layers/application/enable_script.rb +11 -9
- data/lib/project_types/script/layers/application/push_script.rb +6 -4
- data/lib/project_types/script/layers/domain/errors.rb +2 -0
- data/lib/project_types/script/layers/infrastructure/assemblyscript_project_creator.rb +2 -2
- data/lib/project_types/script/layers/infrastructure/assemblyscript_task_runner.rb +2 -2
- data/lib/project_types/script/layers/infrastructure/errors.rb +2 -0
- data/lib/project_types/script/layers/infrastructure/push_package_repository.rb +1 -1
- data/lib/project_types/script/layers/infrastructure/script_repository.rb +1 -1
- data/lib/project_types/script/layers/infrastructure/script_service.rb +2 -0
- data/lib/project_types/script/messages/messages.rb +25 -31
- data/lib/project_types/script/script_project.rb +8 -4
- data/lib/project_types/script/templates/ts/as-pect.config.js +6 -0
- data/lib/project_types/script/ui/error_handler.rb +8 -0
- data/lib/project_types/script/ui/printing_spinner.rb +75 -0
- data/lib/rubygems_plugin.rb +18 -10
- data/lib/shopify-cli/admin_api/populate_resource_command.rb +1 -1
- data/lib/shopify-cli/admin_api/schema.rb +20 -8
- data/lib/shopify-cli/command.rb +14 -11
- data/lib/shopify-cli/commands.rb +1 -0
- data/lib/shopify-cli/commands/config.rb +44 -0
- data/lib/shopify-cli/commands/connect.rb +8 -69
- data/lib/shopify-cli/commands/create.rb +2 -2
- data/lib/shopify-cli/commands/help.rb +1 -1
- data/lib/shopify-cli/commands/system.rb +22 -13
- data/lib/shopify-cli/context.rb +38 -1
- data/lib/shopify-cli/core.rb +0 -1
- data/lib/shopify-cli/core/entry_point.rb +1 -1
- data/lib/shopify-cli/core/executor.rb +3 -5
- data/lib/shopify-cli/core/monorail.rb +1 -1
- data/lib/shopify-cli/db.rb +1 -1
- data/lib/shopify-cli/feature.rb +97 -0
- data/lib/shopify-cli/heroku.rb +21 -5
- data/lib/shopify-cli/js_deps.rb +2 -2
- data/lib/shopify-cli/js_system.rb +2 -2
- data/lib/shopify-cli/messages/messages.rb +37 -12
- data/lib/shopify-cli/partners_api/organizations.rb +7 -7
- data/lib/shopify-cli/process_supervision.rb +60 -21
- data/lib/shopify-cli/project.rb +14 -6
- data/lib/shopify-cli/project_type.rb +5 -7
- data/lib/shopify-cli/sub_command.rb +1 -0
- data/lib/shopify-cli/task.rb +2 -2
- data/lib/shopify-cli/tasks.rb +11 -4
- data/lib/shopify-cli/tasks/ensure_env.rb +72 -16
- data/lib/shopify-cli/tasks/update_dashboard_urls.rb +4 -3
- data/lib/shopify-cli/tunnel.rb +44 -14
- data/lib/shopify-cli/version.rb +1 -1
- data/lib/shopify_cli.rb +36 -9
- data/shopify-cli.gemspec +4 -1
- data/vendor/deps/cli-kit/REVISION +1 -1
- data/vendor/deps/cli-kit/lib/cli/kit.rb +1 -1
- data/vendor/deps/cli-kit/lib/cli/kit/autocall.rb +2 -2
- data/vendor/deps/cli-kit/lib/cli/kit/error_handler.rb +12 -6
- data/vendor/deps/cli-kit/lib/cli/kit/executor.rb +9 -11
- data/vendor/deps/cli-kit/lib/cli/kit/logger.rb +8 -2
- data/vendor/deps/cli-kit/lib/cli/kit/support/test_helper.rb +7 -7
- data/vendor/deps/cli-kit/lib/cli/kit/system.rb +48 -17
- data/vendor/deps/cli-ui/REVISION +1 -1
- data/vendor/deps/cli-ui/lib/cli/ui.rb +5 -4
- data/vendor/deps/cli-ui/lib/cli/ui/ansi.rb +9 -3
- data/vendor/deps/cli-ui/lib/cli/ui/color.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame.rb +3 -2
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/box.rb +13 -5
- data/vendor/deps/cli-ui/lib/cli/ui/frame/frame_style/bracket.rb +29 -2
- data/vendor/deps/cli-ui/lib/cli/ui/glyph.rb +21 -10
- data/vendor/deps/cli-ui/lib/cli/ui/os.rb +63 -0
- data/vendor/deps/cli-ui/lib/cli/ui/prompt.rb +11 -2
- data/vendor/deps/cli-ui/lib/cli/ui/prompt/interactive_options.rb +1 -0
- data/vendor/deps/cli-ui/lib/cli/ui/spinner.rb +3 -3
- data/vendor/deps/cli-ui/lib/cli/ui/spinner/spin_group.rb +6 -8
- data/vendor/deps/cli-ui/lib/cli/ui/widgets.rb +2 -0
- data/vendor/gen/lib/gen.rb +39 -0
- data/vendor/gen/lib/gen/commands.rb +18 -0
- data/vendor/gen/lib/gen/commands/help.rb +20 -0
- data/vendor/gen/lib/gen/commands/new.rb +21 -0
- data/vendor/gen/lib/gen/entry_point.rb +10 -0
- data/vendor/gen/lib/gen/generator.rb +165 -0
- data/vendor/gen/template/.gitignore +2 -0
- data/vendor/gen/template/Gemfile +10 -0
- data/vendor/gen/template/README.md +1 -0
- data/vendor/gen/template/bin/testunit +23 -0
- data/vendor/gen/template/bin/update-deps +97 -0
- data/vendor/gen/template/dev-gems.yml +3 -0
- data/vendor/gen/template/dev-vendor.yml +4 -0
- data/vendor/gen/template/exe/__app__-gems +17 -0
- data/vendor/gen/template/exe/__app__-vendor +18 -0
- data/vendor/gen/template/lib/__app__.rb +33 -0
- data/vendor/gen/template/lib/__app__/commands.rb +18 -0
- data/vendor/gen/template/lib/__app__/commands/example.rb +19 -0
- data/vendor/gen/template/lib/__app__/commands/help.rb +21 -0
- data/vendor/gen/template/lib/__app__/entry_point.rb +10 -0
- data/vendor/gen/template/test/example_test.rb +17 -0
- data/vendor/gen/template/test/test_helper.rb +22 -0
- metadata +28 -6
- data/Vagrantfile +0 -17
- data/lib/project_types/script/forms/enable.rb +0 -24
- data/lib/project_types/script/forms/push.rb +0 -19
- data/lib/project_types/script/forms/script_form.rb +0 -66
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module CLI
|
|
2
|
+
module UI
|
|
3
|
+
module OS
|
|
4
|
+
# Determines which OS is currently running the UI, to make it easier to
|
|
5
|
+
# adapt its behaviour to the features of the OS.
|
|
6
|
+
def self.current
|
|
7
|
+
@current_os ||= case RUBY_PLATFORM
|
|
8
|
+
when /darwin/
|
|
9
|
+
Mac
|
|
10
|
+
when /linux/
|
|
11
|
+
Linux
|
|
12
|
+
when /mingw32/
|
|
13
|
+
Windows
|
|
14
|
+
else
|
|
15
|
+
raise "Could not determine OS from platform #{RUBY_PLATFORM}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class Mac
|
|
20
|
+
class << self
|
|
21
|
+
def supports_emoji?
|
|
22
|
+
true
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def supports_color_prompt?
|
|
26
|
+
true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def supports_arrow_keys?
|
|
30
|
+
true
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def shift_cursor_on_line_reset?
|
|
34
|
+
false
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
class Linux < Mac
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
class Windows
|
|
43
|
+
class << self
|
|
44
|
+
def supports_emoji?
|
|
45
|
+
false
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def supports_color_prompt?
|
|
49
|
+
false
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def supports_arrow_keys?
|
|
53
|
+
false
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def shift_cursor_on_line_reset?
|
|
57
|
+
true
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -190,7 +190,13 @@ module CLI
|
|
|
190
190
|
end
|
|
191
191
|
|
|
192
192
|
raise(ArgumentError, 'insufficient options') if options.nil? || options.empty?
|
|
193
|
-
|
|
193
|
+
navigate_text = if CLI::UI::OS.current.supports_arrow_keys?
|
|
194
|
+
"Choose with ↑ ↓ ⏎"
|
|
195
|
+
else
|
|
196
|
+
"Navigate up with 'k' and down with 'j', press Enter to select"
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
instructions = (multiple ? "Toggle options. " : "") + navigate_text
|
|
194
200
|
instructions += ", filter with 'f'" if filter_ui
|
|
195
201
|
instructions += ", enter option with 'e'" if select_ui && (options.size > 9)
|
|
196
202
|
puts_question("#{question} {{yellow:(#{instructions})}}")
|
|
@@ -256,7 +262,10 @@ module CLI
|
|
|
256
262
|
# thread to manage output, but the current strategy feels like a
|
|
257
263
|
# better tradeoff.
|
|
258
264
|
prefix = CLI::UI.with_frame_color(:blue) { CLI::UI::Frame.prefix }
|
|
259
|
-
prompt
|
|
265
|
+
# If a prompt is interrupted on Windows it locks the colour of the terminal from that point on, so we should
|
|
266
|
+
# not change the colour here.
|
|
267
|
+
prompt = prefix + CLI::UI.fmt('{{blue:> }}')
|
|
268
|
+
prompt += CLI::UI::Color::YELLOW.code if CLI::UI::OS.current.supports_color_prompt?
|
|
260
269
|
|
|
261
270
|
begin
|
|
262
271
|
line = Readline.readline(prompt, true)
|
|
@@ -10,11 +10,11 @@ module CLI
|
|
|
10
10
|
PERIOD = 0.1 # seconds
|
|
11
11
|
TASK_FAILED = :task_failed
|
|
12
12
|
|
|
13
|
-
RUNES = %w(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏).freeze
|
|
13
|
+
RUNES = CLI::UI::OS.current.supports_emoji? ? %w(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏).freeze : %w(\\ | / - \\ | / -).freeze
|
|
14
14
|
|
|
15
15
|
begin
|
|
16
|
-
colors = [CLI::UI::Color::CYAN.code] *
|
|
17
|
-
|
|
16
|
+
colors = [CLI::UI::Color::CYAN.code] * (RUNES.size / 2).ceil +
|
|
17
|
+
[CLI::UI::Color::MAGENTA.code] * (RUNES.size / 2).to_i
|
|
18
18
|
GLYPHS = colors.zip(RUNES).map(&:join)
|
|
19
19
|
end
|
|
20
20
|
|
|
@@ -98,15 +98,13 @@ module CLI
|
|
|
98
98
|
#
|
|
99
99
|
def render(index, force = true, width: CLI::UI::Terminal.width)
|
|
100
100
|
@m.synchronize do
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
partial_render(index)
|
|
106
|
-
end
|
|
107
|
-
ensure
|
|
108
|
-
@force_full_render = false
|
|
101
|
+
if force || @always_full_render || @force_full_render
|
|
102
|
+
full_render(index, width)
|
|
103
|
+
else
|
|
104
|
+
partial_render(index)
|
|
109
105
|
end
|
|
106
|
+
ensure
|
|
107
|
+
@force_full_render = false
|
|
110
108
|
end
|
|
111
109
|
end
|
|
112
110
|
|
|
@@ -49,6 +49,7 @@ module CLI
|
|
|
49
49
|
|
|
50
50
|
class InvalidWidgetHandle < ArgumentError
|
|
51
51
|
def initialize(handle)
|
|
52
|
+
super
|
|
52
53
|
@handle = handle
|
|
53
54
|
end
|
|
54
55
|
|
|
@@ -61,6 +62,7 @@ module CLI
|
|
|
61
62
|
|
|
62
63
|
class InvalidWidgetArguments < ArgumentError
|
|
63
64
|
def initialize(argstring, pattern)
|
|
65
|
+
super
|
|
64
66
|
@argstring = argstring
|
|
65
67
|
@pattern = pattern
|
|
66
68
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require 'cli/ui'
|
|
2
|
+
require 'cli/kit'
|
|
3
|
+
|
|
4
|
+
CLI::UI::StdoutRouter.enable
|
|
5
|
+
|
|
6
|
+
module Gen
|
|
7
|
+
extend CLI::Kit::Autocall
|
|
8
|
+
|
|
9
|
+
TOOL_NAME = 'cli-kit'
|
|
10
|
+
ROOT = File.expand_path('../../..', __FILE__)
|
|
11
|
+
|
|
12
|
+
TOOL_CONFIG_PATH = File.expand_path(File.join('~', '.config', TOOL_NAME))
|
|
13
|
+
LOG_FILE = File.join(TOOL_CONFIG_PATH, 'logs', 'log.log')
|
|
14
|
+
DEBUG_LOG_FILE = File.join(TOOL_CONFIG_PATH, 'logs', 'debug.log')
|
|
15
|
+
|
|
16
|
+
autoload(:Generator, 'gen/generator')
|
|
17
|
+
|
|
18
|
+
autoload(:EntryPoint, 'gen/entry_point')
|
|
19
|
+
autoload(:Commands, 'gen/commands')
|
|
20
|
+
|
|
21
|
+
autocall(:Config) { CLI::Kit::Config.new(tool_name: TOOL_NAME) }
|
|
22
|
+
autocall(:Command) { CLI::Kit::BaseCommand }
|
|
23
|
+
autocall(:Logger) { CLI::Kit::Logger.new(debug_log_file: DEBUG_LOG_FILE) }
|
|
24
|
+
|
|
25
|
+
autocall(:Executor) { CLI::Kit::Executor.new(log_file: LOG_FILE) }
|
|
26
|
+
autocall(:Resolver) do
|
|
27
|
+
CLI::Kit::Resolver.new(
|
|
28
|
+
tool_name: TOOL_NAME,
|
|
29
|
+
command_registry: Gen::Commands::Registry
|
|
30
|
+
)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
autocall(:ErrorHandler) do
|
|
34
|
+
CLI::Kit::ErrorHandler.new(
|
|
35
|
+
log_file: LOG_FILE,
|
|
36
|
+
exception_reporter: nil
|
|
37
|
+
)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'gen'
|
|
2
|
+
|
|
3
|
+
module Gen
|
|
4
|
+
module Commands
|
|
5
|
+
Registry = CLI::Kit::CommandRegistry.new(
|
|
6
|
+
default: 'help',
|
|
7
|
+
contextual_resolver: nil
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
def self.register(const, cmd, path)
|
|
11
|
+
autoload(const, path)
|
|
12
|
+
Registry.add(->() { const_get(const) }, cmd)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
register :Help, 'help', 'gen/commands/help'
|
|
16
|
+
register :New, 'new', 'gen/commands/new'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'gen'
|
|
2
|
+
|
|
3
|
+
module Gen
|
|
4
|
+
module Commands
|
|
5
|
+
class Help < Gen::Command
|
|
6
|
+
def call(_args, _name)
|
|
7
|
+
puts CLI::UI.fmt("{{bold:Available commands}}")
|
|
8
|
+
puts ""
|
|
9
|
+
|
|
10
|
+
Gen::Commands::Registry.resolved_commands.each do |name, klass|
|
|
11
|
+
puts CLI::UI.fmt("{{command:#{Gen::TOOL_NAME} #{name}}}")
|
|
12
|
+
if klass.respond_to?(:help) && (help = klass.help)
|
|
13
|
+
puts CLI::UI.fmt(help)
|
|
14
|
+
end
|
|
15
|
+
puts ""
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require 'gen'
|
|
2
|
+
|
|
3
|
+
module Gen
|
|
4
|
+
module Commands
|
|
5
|
+
class New < Gen::Command
|
|
6
|
+
def call(args, _name)
|
|
7
|
+
unless args.size == 1
|
|
8
|
+
puts CLI::UI.fmt(self.class.help)
|
|
9
|
+
raise(CLI::Kit::AbortSilent)
|
|
10
|
+
end
|
|
11
|
+
project = args.first
|
|
12
|
+
|
|
13
|
+
Gen::Generator.run(project)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.help
|
|
17
|
+
"Generate a new cli-kit project.\nUsage: {{command:#{Gen::TOOL_NAME} new <name>}}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
require 'gen'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'pathname'
|
|
5
|
+
require 'tmpdir'
|
|
6
|
+
|
|
7
|
+
module Gen
|
|
8
|
+
class Generator
|
|
9
|
+
def self.run(project_name)
|
|
10
|
+
new(project_name).run
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
TEMPLATE_ROOT = File.expand_path('gen/template', Gen::ROOT)
|
|
14
|
+
|
|
15
|
+
VALID_PROJECT_NAME = /\A[a-z][a-z0-9]*\z/
|
|
16
|
+
private_constant :VALID_PROJECT_NAME
|
|
17
|
+
|
|
18
|
+
# false -> delete file
|
|
19
|
+
# string -> rename file before applying template substitutions
|
|
20
|
+
VENDOR_TRANSLATIONS = {
|
|
21
|
+
'Gemfile' => false,
|
|
22
|
+
'exe/__app__-gems' => false,
|
|
23
|
+
'exe/__app__-vendor' => 'exe/__app__',
|
|
24
|
+
'dev-gems.yml' => false,
|
|
25
|
+
'dev-vendor.yml' => 'dev.yml',
|
|
26
|
+
}.freeze
|
|
27
|
+
private_constant :VENDOR_TRANSLATIONS
|
|
28
|
+
|
|
29
|
+
BUNDLER_TRANSLATIONS = {
|
|
30
|
+
'bin/update-deps' => false,
|
|
31
|
+
'exe/__app__-gems' => 'exe/__app__',
|
|
32
|
+
'exe/__app__-vendor' => false,
|
|
33
|
+
'dev-gems.yml' => 'dev.yml',
|
|
34
|
+
'dev-vendor.yml' => false,
|
|
35
|
+
}.freeze
|
|
36
|
+
private_constant :BUNDLER_TRANSLATIONS
|
|
37
|
+
|
|
38
|
+
def initialize(project_name)
|
|
39
|
+
raise(
|
|
40
|
+
CLI::Kit::Abort,
|
|
41
|
+
"project name must match {{bold:#{VALID_PROJECT_NAME}}} (but can be changed later)"
|
|
42
|
+
) unless project_name =~ VALID_PROJECT_NAME
|
|
43
|
+
@project_name = project_name
|
|
44
|
+
@title_case_project_name = @project_name.sub(/^./, &:upcase)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def run
|
|
48
|
+
vendor = ask_vendor?
|
|
49
|
+
create_project_dir
|
|
50
|
+
if vendor
|
|
51
|
+
copy_files(translations: VENDOR_TRANSLATIONS)
|
|
52
|
+
update_deps
|
|
53
|
+
else
|
|
54
|
+
copy_files(translations: BUNDLER_TRANSLATIONS)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
def ask_vendor?
|
|
61
|
+
return 'vendor' if ENV['DEPS'] == 'vendor'
|
|
62
|
+
return 'bundler' if ENV['DEPS'] == 'bundler'
|
|
63
|
+
|
|
64
|
+
vendor = nil
|
|
65
|
+
CLI::UI::Frame.open('Configuration') do
|
|
66
|
+
q = 'How would you like the application to consume {{command:cli-kit}} and {{command:cli-ui}}?'
|
|
67
|
+
vendor = CLI::UI::Prompt.ask(q) do |c|
|
|
68
|
+
c.option('Vendor {{italic:(faster execution, more difficult to update deps)}}') { 'vendor' }
|
|
69
|
+
c.option('Bundler {{italic:(slower execution, easier dep management)}}') { 'bundler' }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
vendor == 'vendor'
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def create_project_dir
|
|
76
|
+
info(create: '')
|
|
77
|
+
FileUtils.mkdir(@project_name)
|
|
78
|
+
rescue Errno::EEXIST
|
|
79
|
+
error("directory already exists: #{@project_name}")
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def copy_files(translations:)
|
|
83
|
+
each_template_file do |source_name|
|
|
84
|
+
target_name = translations.fetch(source_name, source_name)
|
|
85
|
+
next if target_name == false
|
|
86
|
+
target_name = apply_template_variables(target_name)
|
|
87
|
+
|
|
88
|
+
source = File.join(TEMPLATE_ROOT, source_name)
|
|
89
|
+
target = File.join(@project_name, target_name)
|
|
90
|
+
|
|
91
|
+
info(create: target_name)
|
|
92
|
+
|
|
93
|
+
if Dir.exist?(source)
|
|
94
|
+
FileUtils.mkdir(target)
|
|
95
|
+
else
|
|
96
|
+
content = apply_template_variables(File.read(source))
|
|
97
|
+
File.write(target, content)
|
|
98
|
+
end
|
|
99
|
+
File.chmod(File.stat(source).mode, target)
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def update_deps
|
|
104
|
+
Dir.mktmpdir do |tmp|
|
|
105
|
+
clone(tmp, 'cli-ui')
|
|
106
|
+
clone(tmp, 'cli-kit')
|
|
107
|
+
info(run: 'bin/update-deps')
|
|
108
|
+
Dir.chdir(@project_name) do
|
|
109
|
+
system({ 'SOURCE_ROOT' => tmp }, 'bin/update-deps')
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def clone(dir, repo)
|
|
115
|
+
info(clone: repo)
|
|
116
|
+
out, stat = Open3.capture2e('git', '-C', dir, 'clone', "https://github.com/shopify/#{repo}")
|
|
117
|
+
unless stat.success?
|
|
118
|
+
STDERR.puts(out)
|
|
119
|
+
error("git clone failed")
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def each_template_file
|
|
124
|
+
return enum_for(:each_template_file) unless block_given?
|
|
125
|
+
|
|
126
|
+
root = Pathname.new(TEMPLATE_ROOT)
|
|
127
|
+
Dir.glob("#{TEMPLATE_ROOT}/**/*").each do |f|
|
|
128
|
+
el = Pathname.new(f)
|
|
129
|
+
yield(el.relative_path_from(root).to_s)
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def apply_template_variables(s)
|
|
134
|
+
s
|
|
135
|
+
.gsub(/__app__/, @project_name)
|
|
136
|
+
.gsub(/__App__/, @title_case_project_name)
|
|
137
|
+
.gsub(/__cli-kit-version__/, cli_kit_version)
|
|
138
|
+
.gsub(/__cli-ui-version__/, cli_ui_version)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def cli_kit_version
|
|
142
|
+
require 'cli/kit/version'
|
|
143
|
+
CLI::Kit::VERSION.to_s
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def cli_ui_version
|
|
147
|
+
require 'cli/ui/version'
|
|
148
|
+
CLI::UI::VERSION.to_s
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def info(create: nil, clone: nil, run: nil)
|
|
152
|
+
if clone
|
|
153
|
+
puts(CLI::UI.fmt("\t{{bold:{{yellow:clone}}\t#{clone}}}"))
|
|
154
|
+
elsif create
|
|
155
|
+
puts(CLI::UI.fmt("\t{{bold:{{blue:create}}\t#{create}}}"))
|
|
156
|
+
elsif run
|
|
157
|
+
puts(CLI::UI.fmt("\t{{bold:{{green:run}}\t#{run}}}"))
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
def error(msg)
|
|
162
|
+
raise(CLI::Kit::Abort, msg)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
gem 'cli-kit', '~> __cli-kit-version__'
|
|
4
|
+
gem 'cli-ui', '~> __cli-ui-version__'
|
|
5
|
+
|
|
6
|
+
group :test do
|
|
7
|
+
gem 'mocha', '~> 1.5.0', require: false
|
|
8
|
+
gem 'minitest', '>= 5.0.0', require: false
|
|
9
|
+
gem 'minitest-reporters', require: false
|
|
10
|
+
end
|