faastruby 0.4.15 → 0.4.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a06282c038c0af5a31802c852b845e637df02b9fcbcd0b345383ae6ccb5b6e6a
4
- data.tar.gz: c7515040c1c137287364e98aff7f54c6899829048f09b9c1e6a713a80b55a261
3
+ metadata.gz: 6e1be30dd9f54e8b0c0f65e0d7fa3f579675f8fd428801e45770b3f4940ca8b2
4
+ data.tar.gz: 05d2262fd80bb23904c82157d21d51b0fa8640b2bdd0dca411d2b8547c921119
5
5
  SHA512:
6
- metadata.gz: 010c57047b4d4a2e5b16d3a335d4b161ea6ea4227e8a30b85cfb43177b5762c9063f74339a7fe3b906c425833a549a33aa7cfa6ab92fb5a9d3c8002ecf97c565
7
- data.tar.gz: ecfa98457cf79f02359706b95527c9c21192f95accb4e825b06732f29363f325cb48296d820b326e0a4e00971eec96e35947aa4e896652998f85bd147b8b1162
6
+ metadata.gz: 8a7a836d1f7b3e57facbd428d719d309d6649f5f65c5e6f0ed5a98170d99962f5e55055dd76164a78ed9002894b2695e1f066790f0470fdf175c0c2b0d56438e
7
+ data.tar.gz: bcaa943d337a47d2aa328b5af0abe3c3af79917f5a72b5add6b92fdd39a5064510be932c576cfb3c5a4025e64b494a6cdb75ebd5dc06f7ebaffc60b8f28da408
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.16 - Feb 4 2019
4
+ - Add support for function templates
5
+ - Add cli_version to `faastruby.yml`
6
+
7
+ ## 0.4.15 - Feb 2 2019
8
+ - Add support for Crystal 0.27.1 and Ruby 2.6.1
9
+
3
10
  ## 0.4.14 - Feb 1 2019
4
11
  - Ruby functions now use a spec helper from `faastruby` gem.
5
12
  - Crystal functions now use the shard `faastruby-spec-helper` to assist on tests.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faastruby (0.4.14)
4
+ faastruby (0.4.16)
5
5
  colorize (~> 0.8)
6
6
  faastruby-rpc (~> 0.2.1)
7
7
  oj (~> 3.6)
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/faastruby.svg)](https://badge.fury.io/rb/faastruby)
2
2
  [![Build Status](https://travis-ci.org/FaaStRuby/faastruby-cli.svg?branch=master)](https://travis-ci.org/FaaStRuby/faastruby-cli)
3
3
 
4
- [Changelog](https://github.com/FaaStRuby/faastruby-cli/blob/master/CHANGELOG.md)
4
+ * Looking for help? [Ask a question](https://meta.stackoverflow.com/questions/ask?tags=FaaStRuby,Serverless,Ruby,FaaS).
5
+
6
+ * [Changelog](https://github.com/FaaStRuby/faastruby-cli/blob/master/CHANGELOG.md)
5
7
 
6
8
  # faastruby-cli
7
9
 
data/lib/faastruby/cli.rb CHANGED
@@ -5,6 +5,8 @@ require 'zip'
5
5
  require 'colorize'
6
6
  require 'faastruby/cli/commands'
7
7
  require 'faastruby/cli/package'
8
+ require 'faastruby/cli/template'
9
+ require 'erb'
8
10
 
9
11
  module FaaStRuby
10
12
  FAASTRUBY_YAML = 'faastruby.yml'
@@ -23,22 +25,22 @@ module FaaStRuby
23
25
  return
24
26
  end
25
27
  start_server(args) if command == 'server'
26
- check_version
28
+ # check_version
27
29
  check_region
28
30
  error("Unknown command: #{command}") unless FaaStRuby::Command::COMMANDS.has_key?(command)
29
31
  FaaStRuby::Command::COMMANDS[command].new(args).run
30
32
  end
31
33
 
32
- def self.check_version
33
- latest = RestClient.get('https://faastruby.io/gem/minimum.txt').body rescue '0.0.1'
34
- if Gem::Version.new(FaaStRuby::VERSION) < Gem::Version.new(latest)
35
- FaaStRuby.error([
36
- "You are using an old version of the gem. Please run 'gem update faastruby'.".red,
37
- "Installed version: #{FaaStRuby::VERSION}",
38
- "Latest version: #{latest}"
39
- ], color: nil)
40
- end
41
- end
34
+ # def self.check_version
35
+ # latest = RestClient.get('https://faastruby.io/gem/minimum.txt').body rescue '0.0.1'
36
+ # if Gem::Version.new(FaaStRuby::VERSION) < Gem::Version.new(latest)
37
+ # FaaStRuby.error([
38
+ # "You are using an old version of the gem. Please run 'gem update faastruby'.".red,
39
+ # "Installed version: #{FaaStRuby::VERSION}",
40
+ # "Latest version: #{latest}"
41
+ # ], color: nil)
42
+ # end
43
+ # end
42
44
 
43
45
  def self.check_region
44
46
  ENV['FAASTRUBY_REGION'] ||= DEFAULT_REGION
@@ -7,18 +7,25 @@ module FaaStRuby
7
7
  @missing_args = []
8
8
  FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
9
9
  @function_name = @args.shift
10
- @base_dir = "./#{@function_name}"
11
10
  parse_options
12
- @options['template_path'] ||= 'templates/ruby'
13
- @options['template'] ||= 'example'
11
+ @base_dir ||= @function_name
14
12
  @options['runtime_name'] ||= 'ruby'
15
13
  @options['runtime_version'] ||= '2.5.3'
16
- @yaml_content = yaml_for(@options['runtime_name'])
14
+ @options['template'] ||= FaaStRuby::Template.new(type: 'local', source: Template.gem_template_path_for('example', runtime: @options['runtime_name']))
17
15
  end
18
16
 
19
17
  def run
20
- dir_exists? unless @options['force']
21
- copy_template
18
+ @options['template'].install(to: @base_dir, force: @options['force'])
19
+ faastruby_yaml = "#{@base_dir}/faastruby.yml"
20
+ if File.file?(faastruby_yaml)
21
+ @yaml_content = YAML.load(File.read(faastruby_yaml))
22
+ @yaml_content['name'] = @function_name
23
+ @options['runtime_name'], @options['runtime_version'] = @yaml_content['runtime']&.split(':')
24
+ @options['runtime_name'] ||= 'ruby'
25
+ @options['runtime_version'] ||= '2.5.3'
26
+ else
27
+ @yaml_content = yaml_for(@options['runtime_name'])
28
+ end
22
29
  write_yaml
23
30
  post_tasks(@options['runtime_name'])
24
31
  end
@@ -27,9 +34,19 @@ module FaaStRuby
27
34
  "new".light_cyan + " FUNCTION_NAME [--blank] [--force] [--runtime]" +
28
35
  <<-EOS
29
36
 
30
- --blank # Create a blank function
31
- --force # Continue if directory already exists and overwrite files
32
- --runtime # Choose the runtime. Options are: #{SUPPORTED_RUNTIMES.join(', ')}
37
+ --blank
38
+ Create a blank function
39
+ --force
40
+ Continue if directory already exists and overwrite files
41
+ -g
42
+ Initialize a Git repository.
43
+ --runtime
44
+ Choose the runtime. Options are: #{SUPPORTED_RUNTIMES.join(', ')}
45
+ --template TYPE(local|git|github):SOURCE
46
+ Use another function as template. Examples:
47
+ --template local:/path/to/folder
48
+ --template git:git@github.com:user/repo.git
49
+ --template github:user/repo
33
50
  EOS
34
51
  end
35
52
 
@@ -44,28 +61,32 @@ EOS
44
61
  while @args.any?
45
62
  option = @args.shift
46
63
  case option
64
+ when '-g'
65
+ @options['git_init'] = true
66
+ when '--template'
67
+ FaaStRuby::CLI.error("Option '--template' can't be used with '--blank' or '--runtime'.".red) if @options['runtime'] || @options['blank_template']
68
+ template = @args.shift
69
+ type, source = template.split(':')
70
+ @options['template'] = FaaStRuby::Template.new(type: type, source: source)
47
71
  when '--runtime'
72
+ FaaStRuby::CLI.error("Option '--template' can't be used with '--blank' or '--runtime'.".red) if @options['template']
48
73
  @options['runtime'] = @args.shift
49
74
  @options['runtime_name'], @options['runtime_version'] = @options['runtime'].split(':')
50
- @options['template_path'] = "templates/#{@options['runtime_name']}"
75
+ template_name = @options['blank_template'] ? 'example-blank' : 'example'
76
+ @options['template'] = FaaStRuby::Template.new(type: 'local', source: Template.gem_template_path_for('example', runtime: @options['runtime_name']))
51
77
  FaaStRuby::CLI.error(["Unsupported runtime: #{@options['runtime']}".red, "Supported values are #{SUPPORTED_RUNTIMES.join(", ")}"], color: nil) unless SUPPORTED_RUNTIMES.include?(@options['runtime'])
52
78
  when '-f', '--force'
53
79
  @options['force'] = true
54
80
  when '--blank'
55
- @options['template'] = 'example-blank'
81
+ FaaStRuby::CLI.error("Option '--template' can't be used with '--blank' or '--runtime'.".red) if @options['template']
82
+ @options['blank_template'] = true
83
+ @options['template'] = FaaStRuby::Template.new(type: 'local', source: Template.gem_template_path_for('example-blank', runtime: @options['runtime_name'] || 'ruby'))
56
84
  else
57
85
  FaaStRuby::CLI.error(["Unknown argument: #{option}".red, usage], color: nil)
58
86
  end
59
87
  end
60
88
  end
61
89
 
62
- def dir_exists?
63
- return unless File.directory?(@base_dir)
64
- print "The folder '#{@function_name}' already exists. Overwrite files? [y/N] "
65
- response = STDIN.gets.chomp
66
- FaaStRuby::CLI.error("Cancelled", color: nil) unless response == 'y'
67
- end
68
-
69
90
  def missing_args
70
91
  if @args.empty?
71
92
  @missing_args << "Missing argument: FUNCTION_NAME".red
@@ -74,28 +95,6 @@ EOS
74
95
  @missing_args
75
96
  end
76
97
 
77
- def copy_template
78
- source = "#{Gem::Specification.find_by_name("faastruby").gem_dir}/#{@options['template_path']}/#{@options['template']}"
79
- FileUtils.mkdir_p(@base_dir)
80
- FileUtils.cp_r("#{source}/.", "#{@base_dir}/")
81
- case @options['runtime_name']
82
- when 'ruby'
83
- puts "+ d #{@base_dir}".green
84
- puts "+ d #{@base_dir}/spec".green
85
- puts "+ f #{@base_dir}/spec/handler_spec.rb".green
86
- puts "+ f #{@base_dir}/spec/spec_helper.rb".green
87
- puts "+ f #{@base_dir}/Gemfile".green
88
- puts "+ f #{@base_dir}/handler.rb".green
89
- when 'crystal'
90
- puts "+ d #{@base_dir}".green
91
- puts "+ d #{@base_dir}/spec".green
92
- puts "+ f #{@base_dir}/spec/handler_spec.cr".green
93
- puts "+ f #{@base_dir}/spec/spec_helper.cr".green
94
- puts "+ d #{@base_dir}/src".green
95
- puts "+ f #{@base_dir}/src/handler.cr".green
96
- end
97
- end
98
-
99
98
  def yaml_for(runtime_name)
100
99
  case runtime_name
101
100
  when 'crystal'
@@ -106,6 +105,7 @@ EOS
106
105
  test_command = 'rspec'
107
106
  end
108
107
  {
108
+ 'cli_version' => FaaStRuby::VERSION,
109
109
  'name' => @function_name,
110
110
  'runtime' => @options['runtime'] || 'ruby:2.5.3',
111
111
  'test_command' => test_command,
@@ -115,10 +115,12 @@ EOS
115
115
  end
116
116
 
117
117
  def write_yaml
118
- write_file("#{@base_dir}/faastruby.yml", @yaml_content.to_yaml)
118
+ write_file("#{@function_name}/faastruby.yml", @yaml_content.to_yaml)
119
119
  end
120
120
 
121
121
  def post_tasks(runtime_name)
122
+ update_readme
123
+ puts `git init #{@base_dir}` if @options['git_init']
122
124
  case runtime_name
123
125
  when 'ruby'
124
126
  bundle_install
@@ -130,6 +132,13 @@ EOS
130
132
  end
131
133
  end
132
134
 
135
+ def update_readme
136
+ file_path = "#{@base_dir}/README.md"
137
+ return false unless File.file?(file_path)
138
+ readme = File.read(file_path)
139
+ File.write(file_path, ERB.new(readme).result(binding))
140
+ end
141
+
133
142
  def bundle_install
134
143
  spinner = spin("Installing gems...")
135
144
  system("bundle install --gemfile=#{@base_dir}/Gemfile > /dev/null")
@@ -0,0 +1,90 @@
1
+ module FaaStRuby
2
+ class Template
3
+ TYPES = ['local', 'git', 'github']
4
+ def self.gem_template_path_for(name, runtime:)
5
+ "#{Gem::Specification.find_by_name("faastruby").gem_dir}/templates/#{runtime}/#{name}"
6
+ end
7
+
8
+ attr_accessor :type, :source, :target
9
+ def initialize(type:, source:)
10
+ FaaStRuby::CLI.error(["Unknown template type: '#{type}'. Valid types are:", TYPES], color: nil) unless TYPES.include?(type)
11
+ @type = type
12
+ @source = source
13
+ end
14
+
15
+ def install(to:, force: false)
16
+ @target = to
17
+ @force = force
18
+ FaaStRuby::CLI.error("Could not determine the target path for template '#{type}:#{source}'. Please report this bug at https://github.com/FaaStRuby/faastruby-cli/issues", color: nil) unless target
19
+ return install_from_folder(source) if local?
20
+ return install_from_git(source) if git?
21
+ return install_from_github if github?
22
+ end
23
+
24
+ def install_from_github
25
+ repo = "git@github.com:/#{source}.git"
26
+ install_from_git(repo)
27
+ end
28
+
29
+ def install_from_git(repo)
30
+ local_dir = Dir.mktmpdir
31
+ git_pull(repo, local_dir)
32
+ install_from_folder(local_dir)
33
+ ensure
34
+ FileUtils.remove_entry local_dir
35
+ end
36
+
37
+ def git_pull(repo, local_dir)
38
+ FaaStRuby::CLI.error("Could not clone repository #{repo} into #{local_dir}") unless
39
+ system("git clone #{repo} #{local_dir}")
40
+ end
41
+
42
+ def install_from_folder(folder)
43
+ # puts "installing from folder #{folder}"
44
+ if File.directory?(target)
45
+ puts "! d #{target}".yellow
46
+ else
47
+ FileUtils.mkdir_p(target)
48
+ puts "+ d #{target}".green
49
+ end
50
+ Dir.glob("**/*", base: folder).each do |entry|
51
+ full_source_path = "#{folder}/#{entry}"
52
+ full_target_path = "#{target}/#{entry}"
53
+ create_dir(full_target_path) if File.directory?(full_source_path)
54
+ copy_file(source: full_source_path, destination: full_target_path) if File.file?(full_source_path)
55
+ end
56
+
57
+ end
58
+
59
+ def create_dir(dir)
60
+ if File.directory?(dir)
61
+ puts "! d #{dir}".yellow
62
+ else
63
+ FileUtils.mkdir_p(dir)
64
+ puts "+ d #{dir}".green
65
+ end
66
+ end
67
+
68
+ def copy_file(source:, destination:)
69
+ if File.file?(destination) && !@force
70
+ print "File '#{destination}' already exists. Overwrite? [y/N] "
71
+ answer = STDIN.gets.chomp
72
+ return(puts "[skipped] #{destination}") unless ['y', 'Y'].include?(answer)
73
+ end
74
+ FileUtils.cp(source, destination)
75
+ puts "+ f #{destination}".green
76
+ end
77
+
78
+ def local?
79
+ type == 'local'
80
+ end
81
+
82
+ def git?
83
+ type == 'git'
84
+ end
85
+
86
+ def github?
87
+ type == 'github'
88
+ end
89
+ end
90
+ end
@@ -1,3 +1,3 @@
1
1
  module FaaStRuby
2
- VERSION = '0.4.15'
2
+ VERSION = '0.4.16'
3
3
  end
@@ -0,0 +1,22 @@
1
+ # <%= @function_name %>
2
+ One Paragraph of function description goes here.
3
+ ## Getting started
4
+ ### Prerequisites
5
+ * [FaaStRuby](https://faastruby.io) version <%= FaaStRuby::VERSION %> or higher.
6
+ ```
7
+ # To install
8
+ ~$ gem install faastruby
9
+
10
+ # To update
11
+ ~$ gem update faastruby
12
+ ```
13
+ ### How to deploy this function
14
+ ```
15
+ ~$ cd FUNCTION_FOLDER
16
+ ~/FUNCTION_FOLDER$ faastruby deploy-to WORKSPACE_NAME
17
+ ```
18
+ ### How to use this function as a template
19
+ ```
20
+ ~$ faastruby new FUNCTION_NAME --template github:user/repository
21
+ ```
22
+
@@ -0,0 +1,22 @@
1
+ # <%= @function_name %>
2
+ One Paragraph of function description goes here.
3
+ ## Getting started
4
+ ### Prerequisites
5
+ * [FaaStRuby](https://faastruby.io) version <%= FaaStRuby::VERSION %> or higher.
6
+ ```
7
+ # To install
8
+ ~$ gem install faastruby
9
+
10
+ # To update
11
+ ~$ gem update faastruby
12
+ ```
13
+ ### How to deploy this function
14
+ ```
15
+ ~$ cd FUNCTION_FOLDER
16
+ ~/FUNCTION_FOLDER$ faastruby deploy-to WORKSPACE_NAME
17
+ ```
18
+ ### How to use this function as a template
19
+ ```
20
+ ~$ faastruby new FUNCTION_NAME --template github:user/repository
21
+ ```
22
+
@@ -0,0 +1,22 @@
1
+ # <%= @function_name %>
2
+ One Paragraph of function description goes here.
3
+ ## Getting started
4
+ ### Prerequisites
5
+ * [FaaStRuby](https://faastruby.io) version <%= FaaStRuby::VERSION %> or higher.
6
+ ```
7
+ # To install
8
+ ~$ gem install faastruby
9
+
10
+ # To update
11
+ ~$ gem update faastruby
12
+ ```
13
+ ### How to deploy this function
14
+ ```
15
+ ~$ cd FUNCTION_FOLDER
16
+ ~/FUNCTION_FOLDER$ faastruby deploy-to WORKSPACE_NAME
17
+ ```
18
+ ### How to use this function as a template
19
+ ```
20
+ ~$ faastruby new FUNCTION_NAME --template github:user/repository
21
+ ```
22
+
@@ -0,0 +1,22 @@
1
+ # <%= @function_name %>
2
+ One Paragraph of function description goes here.
3
+ ## Getting started
4
+ ### Prerequisites
5
+ * [FaaStRuby](https://faastruby.io) version <%= FaaStRuby::VERSION %> or higher.
6
+ ```
7
+ # To install
8
+ ~$ gem install faastruby
9
+
10
+ # To update
11
+ ~$ gem update faastruby
12
+ ```
13
+ ### How to deploy this function
14
+ ```
15
+ ~$ cd FUNCTION_FOLDER
16
+ ~/FUNCTION_FOLDER$ faastruby deploy-to WORKSPACE_NAME
17
+ ```
18
+ ### How to use this function as a template
19
+ ```
20
+ ~$ faastruby new FUNCTION_NAME --template github:user/repository
21
+ ```
22
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faastruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.15
4
+ version: 0.4.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Arruda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-02 00:00:00.000000000 Z
11
+ date: 2019-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -255,6 +255,7 @@ files:
255
255
  - lib/faastruby/cli/commands/workspace/list.rb
256
256
  - lib/faastruby/cli/credentials.rb
257
257
  - lib/faastruby/cli/package.rb
258
+ - lib/faastruby/cli/template.rb
258
259
  - lib/faastruby/function.rb
259
260
  - lib/faastruby/server.rb
260
261
  - lib/faastruby/server/concurrency_controller.rb
@@ -270,17 +271,21 @@ files:
270
271
  - lib/faastruby/spec_helper.rb
271
272
  - lib/faastruby/version.rb
272
273
  - lib/faastruby/workspace.rb
274
+ - templates/crystal/example-blank/README.md
273
275
  - templates/crystal/example-blank/spec/handler_spec.cr
274
276
  - templates/crystal/example-blank/spec/spec_helper.cr
275
277
  - templates/crystal/example-blank/src/handler.cr
278
+ - templates/crystal/example/README.md
276
279
  - templates/crystal/example/spec/handler_spec.cr
277
280
  - templates/crystal/example/spec/spec_helper.cr
278
281
  - templates/crystal/example/src/handler.cr
279
282
  - templates/ruby/example-blank/Gemfile
283
+ - templates/ruby/example-blank/README.md
280
284
  - templates/ruby/example-blank/handler.rb
281
285
  - templates/ruby/example-blank/spec/handler_spec.rb
282
286
  - templates/ruby/example-blank/spec/spec_helper.rb
283
287
  - templates/ruby/example/Gemfile
288
+ - templates/ruby/example/README.md
284
289
  - templates/ruby/example/handler.rb
285
290
  - templates/ruby/example/spec/handler_spec.rb
286
291
  - templates/ruby/example/spec/spec_helper.rb