sanctuary 0.1.14 → 0.1.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebd4dedc86020c21aa1e94ff4856305c34080b24239e71849aa157c778ea7515
4
- data.tar.gz: 77c28af164582321c36127f8a44bbac0e371b5863ecb88e29a9cc91314758ec2
3
+ metadata.gz: 207a4dd579dba8393270db2247fe7689f85ca41ec88f0b99f53aabf7eee8a664
4
+ data.tar.gz: ff15206cec8ae0db6b379ad7cbf8b859a2759dff6dc124a5d50a6833135cf3ec
5
5
  SHA512:
6
- metadata.gz: 39486a94f0c048b673a4578ff9e7c9de3ff5d8be941c6fbebcc1e3392c95c989ab2863739d0d9d4a2d8ed0c7f3bfdf1be1c6901bee1c7c1c16ec304a9cb2f61f
7
- data.tar.gz: 66a35aa84926c496675e2b8c874aab87e3c1625891b93707eef4a4cd2a03cc2d88e816f4f49a4c987e78a1a81506108233218bf760e87ce2397e9cbdbdaad7b3
6
+ metadata.gz: e837770e1df1a78cf77e50010eb04a5280b50cd416ce0f0af7bab7f96309ee0407ab499208ee00ab1d68996d90d3308ae8fb64e5b19712ec8666c2039d224da2
7
+ data.tar.gz: f54b4faad73f8b92e6a63ac1e8fb7d447e2bcf34e0257732447e0b82f927dec6cdbbc38aaa715dee6658c67dda8daec80b38dc1c4c5bd645f229f381ee1666d5
@@ -1,6 +1,7 @@
1
1
  require "tty-prompt"
2
2
  require_relative "generator"
3
3
  require_relative "reader"
4
+ require_relative "recipe_generator"
4
5
 
5
6
  module Sanctuary
6
7
  class CLI
@@ -10,14 +11,19 @@ module Sanctuary
10
11
  results.each do |result|
11
12
  Generator.start([result[1..-1], '', ''])
12
13
  end
13
- elsif ARGV.include?("-r")
14
+ elsif ARGV.include?("--recipe")
14
15
  result = present_recipe_choices
15
- Generator.start([result[1..-1], '', 'true'])
16
+ Generator.start([result[1..-1], '', 'recipe'])
17
+ elsif ARGV.include?("--script")
18
+ result = present_script_choices
19
+ Generator.start([result[1..-1], ARGV.last, 'script'])
20
+ elsif ARGV.include?("--save-recipe")
21
+ RecipeGenerator.generate_recipe
16
22
  else
17
23
  result = present_choices
18
24
  if ARGV.include?("-p")
19
25
  Generator.start([result[1..-1], ARGV.last, ''])
20
- else
26
+ elsif ARGV.include?("--file")
21
27
  Generator.start([result[1..-1], '', ''])
22
28
  end
23
29
  end
@@ -45,6 +51,16 @@ module Sanctuary
45
51
  return path + "/" + prompt_choice
46
52
  end
47
53
 
54
+ def self.present_script_choices(path = "")
55
+ choices = Reader.read_scripts(path)[2..-1].sort
56
+ prompt = TTY::Prompt.new
57
+ prompt_choice = prompt.enum_select("Select a template?", choices)
58
+ if Reader.directory?(path.empty? ? prompt_choice : path + "/" + prompt_choice)
59
+ return present_recipe_choices(path + "/" + prompt_choice)
60
+ end
61
+ return path + "/" + prompt_choice
62
+ end
63
+
48
64
  def self.multi_select(path = "")
49
65
  choices = Reader.read_templates(path)[2..-1].sort
50
66
  prompt = TTY::Prompt.new
@@ -6,19 +6,28 @@ module Sanctuary
6
6
  include Thor::Actions
7
7
  argument :template
8
8
  argument :name
9
- argument :recipe
9
+ argument :type
10
10
 
11
11
  def self.source_root
12
12
  Sanctuary::HOME_DIR
13
13
  end
14
14
 
15
15
  def create_lib_file
16
- unless recipe.empty?
16
+ if type == 'recipe'
17
17
  File.open(Sanctuary::HOME_DIR.gsub("templates", "recipes/") + template) do |file|
18
18
  file.each do |line|
19
19
  copy_file "#{line.gsub("||", "/").chomp}", "#{line.split("||")[1..-1].join("/").chomp}"
20
20
  end
21
21
  end
22
+ if Dir.entries(".").include?('sanctuary-post-recipe-copy-hook.sh')
23
+ system "sh ./sanctuary-post-recipe-copy-hook.sh"
24
+ end
25
+ elsif type == 'script'
26
+ if name.nil?
27
+ system "sh #{Sanctuary::HOME_DIR.gsub("templates", "scripts/")}#{template}"
28
+ else
29
+ system "sh #{Sanctuary::HOME_DIR.gsub("templates", "scripts/")}#{template} #{name}"
30
+ end
22
31
  else
23
32
  if name.empty?
24
33
  # only copy the file and not the directory the file resides in
@@ -1,3 +1,5 @@
1
+ require("pathname")
2
+
1
3
  module Sanctuary
2
4
  HOME_DIR = Dir.home + "/.sanctuary/templates"
3
5
  class Reader
@@ -9,8 +11,12 @@ module Sanctuary
9
11
  Dir.open(HOME_DIR.gsub("templates", "recipes") + "/#{path}").to_a
10
12
  end
11
13
 
14
+ def self.read_scripts(path = "")
15
+ Dir.open(HOME_DIR.gsub("templates", "scripts") + "/#{path}").to_a
16
+ end
17
+
12
18
  def self.directory?(path = "")
13
- ::Pathname.new(HOME_DIR + "/#{path}").directory?
19
+ Pathname.new(HOME_DIR + "/#{path}").directory?
14
20
  end
15
21
  end
16
22
  end
@@ -0,0 +1,20 @@
1
+ require_relative("reader")
2
+
3
+ module Sanctuary
4
+ class RecipeGenerator
5
+ def self.generate_recipe
6
+ current_dir_path = Dir.pwd
7
+ raise "Recipe Already Exists" if Dir.exists?(Sanctuary::HOME_DIR + "/starters/#{current_dir_path.split("/").last}_starter")
8
+
9
+ FileUtils.copy_entry(current_dir_path, Sanctuary::HOME_DIR + "/starters/#{current_dir_path.split("/").last}_starter")
10
+ current_files = Dir.entries(".")[2..Dir.entries(".").length]
11
+ File.open(Sanctuary::HOME_DIR.gsub("templates", "recipes") + "/" + current_dir_path.split("/").last + "_recipe", "w") do |file|
12
+ Dir.glob("**/*").each do |entry|
13
+ unless File.directory?(entry)
14
+ file.write("starters/#{current_dir_path.split("/").last}_starter||" + entry + "\n")
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Sanctuary
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.19"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sanctuary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin-Kawai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-prompt
@@ -118,6 +118,7 @@ files:
118
118
  - lib/sanctuary/cli.rb
119
119
  - lib/sanctuary/generator.rb
120
120
  - lib/sanctuary/reader.rb
121
+ - lib/sanctuary/recipe_generator.rb
121
122
  - lib/sanctuary/version.rb
122
123
  - sanctuary.gemspec
123
124
  homepage: https://github.com/Kevin-Kawai/sanctuary