appifier 0.2.0 → 0.3.0

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: 64a7a60db8dd229246c475055d13afb7bdfd5132ecc6ef459363e556d2e35fee
4
- data.tar.gz: c0644082483f20413e04199e3be7a22d03b3555454014763d8fc08b09bf69049
3
+ metadata.gz: bc6decc46de1031b29f5752b5a8e9e19ff34503910f853a796c13becde17f516
4
+ data.tar.gz: 7cf6cff0288638c120c74f815087ea5e668a1299b1cde1407f0e42b46286057a
5
5
  SHA512:
6
- metadata.gz: 4a84ad6c49d32cc7a5ab26ceac69e9727ca324696274223ca86653255a0c10deb72043d5f01d1f1313fd8599857a7b5fdb2cc87507ab2c6209cda20c8ec5082e
7
- data.tar.gz: 56ad5218965225bcb9ad2caa95e241f9cdbe0063dbfd2631599ef915562a66463a3815a293987e72766735cbfaccaa9bba44febce253b514df8294caa6f766cb
6
+ metadata.gz: 1383dc7d00f324f6831066639eb4ae19577571ba6c3cf0eaa712fae13d41997ffa56ae10b90d74a9249c8fe8a18f29f1bc24b103f9a2bdaccb28934dc594ccd0
7
+ data.tar.gz: adb3a368020d53a60a880baba3f688b65e8b608224c1227e26acd9850d76753c85ddd64e77abe59635eed4f075369884eecadf29275ce8717866de29da36bb5d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -7,6 +7,7 @@ module Appifier
7
7
 
8
8
  extend Carioca::Injector
9
9
  inject service: :output
10
+ inject service: :finisher
10
11
 
11
12
  attr_accessor :dataset
12
13
  attr_reader :template
@@ -19,22 +20,25 @@ module Appifier
19
20
 
20
21
 
21
22
  def collect
22
-
23
- appifilename = "#{File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)}/#{template}/Appifile"
24
- appifile = Appifier::Components::Appifile::new path: appifilename
25
- prompt = TTY::Prompt.new
26
- @dataset = {}
27
- appifile.dataset_rules.each do |name, rule|
28
- default = (rule[:default])? rule[:default] : ""
29
- @dataset[name] = prompt.ask("Give #{rule[:description]} : ", default: default) do |q|
30
- q.required true
31
- q.validate Regexp.new(rule[:format]) if rule[:format]
32
- end
23
+ begin
24
+ appifilename = "#{File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)}/#{template}/Appifile"
25
+ appifile = Appifier::Components::Appifile::new path: appifilename
26
+ prompt = TTY::Prompt.new
27
+ @dataset = {}
28
+ appifile.dataset_rules.each do |name, rule|
29
+ default = (rule[:default])? rule[:default] : ""
30
+ @dataset[name] = prompt.ask("Give #{rule[:description]} : ", default: default) do |q|
31
+ q.required true
32
+ q.validate Regexp.new(rule[:format]) if rule[:format]
33
+ end
34
+ end
35
+ write_dataset template: @template, data: @dataset
36
+ @collected = true
37
+ output.info "Dataset recorded for #{@template}"
38
+ rescue TTY::Reader::InputInterrupt
39
+ output.warn "Interactive collect interrupted"
40
+ finisher.terminate exit_case: :interrupt
33
41
  end
34
- write_dataset template: @template, data: @dataset
35
- @collected = true
36
- output.info "Dataset recorded for #{@template}"
37
-
38
42
  end
39
43
 
40
44
  def collected?
@@ -9,8 +9,9 @@ module Appifier
9
9
  inject service: :output
10
10
 
11
11
 
12
- def initialize(src_root:, target_root:, dataset: )
13
- @src_root = src_root
12
+ def initialize(template_root:, target_root:, dataset: )
13
+ @template_root = template_root
14
+ @src_root = "#{template_root}/skeleton"
14
15
  @target_root = target_root
15
16
  @target_folders = []
16
17
  @target_files = []
@@ -19,7 +20,7 @@ module Appifier
19
20
  @src_paths.delete_if { |file| file =~ %r{/\.$} }
20
21
  @src_folders = @src_paths.select { |item| File.directory? item }
21
22
  @src_files = @src_paths.select { |item| File.file? item }
22
- raise 'Application template not found' unless File.exist?(src_root)
23
+ raise 'Application template not found' unless File.exist?(@template_root)
23
24
  end
24
25
 
25
26
  def generate(dry_run: false, force: false)
@@ -31,6 +32,7 @@ module Appifier
31
32
  generate_folders dry_run: dry_run
32
33
  output.info 'Generate files'
33
34
  generate_files dry_run: dry_run
35
+ copy_appifile dry_run: dry_run
34
36
  end
35
37
 
36
38
  def calculate
@@ -53,6 +55,15 @@ module Appifier
53
55
  end
54
56
  end
55
57
 
58
+
59
+ def copy_appifile(dry_run:)
60
+ output.info "Copy Appifile in #{@target_root} :"
61
+ action = dry_run ? :skipped : :ok
62
+ FileUtils.cp "#{@template_root}/Appifile", @target_root unless dry_run
63
+ output.send action, "Install Appifile"
64
+ end
65
+
66
+
56
67
  def generate_files(dry_run:)
57
68
  output.info "Target files to create in #{@target_root} :"
58
69
  @src_files.each_with_index do |path, index|
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+ module Appifier
3
+ module CLI
4
+ module Subcommands
5
+ class Datasets < ::Thor
6
+
7
+ def initialize(*args)
8
+ super
9
+ @output = Carioca::Registry.get.get_service name: :output
10
+ @finisher = Carioca::Registry.get.get_service name: :finisher
11
+ end
12
+
13
+ # Thor method : list availables datasets in user bundle
14
+ desc 'ls', 'list defined datasets in user bundle'
15
+ def ls
16
+ begin
17
+ Appifier::Components::Dataset::list
18
+ @finisher.terminate exit_case: :quiet_exit
19
+ rescue RuntimeError => e
20
+ @output.error e.message
21
+ @finisher.terminate exit_case: :error_exit
22
+ end
23
+ end
24
+
25
+ # Thor method : show a specific dataset in user bundle
26
+ desc 'show DATASET', 'show a specific dataset in user bundle'
27
+ def show(dataset)
28
+ begin
29
+ Appifier::Components::Dataset::show dataset
30
+ @finisher.terminate exit_case: :quiet_exit
31
+ rescue RuntimeError => e
32
+ @output.error e.message
33
+ @finisher.terminate exit_case: :error_exit
34
+ end
35
+ end
36
+
37
+ # Thor method : remove a dataset from user bundle
38
+ desc 'rm DATASET', 'Remove dataset from user bundle'
39
+ def rm(dataset)
40
+ begin
41
+ Appifier::Components::Dataset::rm(dataset)
42
+ @finisher.terminate exit_case: :quiet_exit
43
+ rescue RuntimeError => e
44
+ @output.error e.message
45
+ @finisher.terminate exit_case: :error_exit
46
+ end
47
+ end
48
+
49
+
50
+ # Thor method : Prune orphans datasets in user bundle
51
+ desc 'prune', 'Prune orphans datasets in user bundle'
52
+ long_desc <<-LONGDESC
53
+ Prune orphans datasets in user bundle\n
54
+ with --force, force pruning of dataset [DANGER]
55
+ LONGDESC
56
+ option :force, type: :boolean, aliases: '-F'
57
+ def prune
58
+ begin
59
+ ok = (options[:force]) ? true : TTY::Prompt.new.yes?("Do you want to prune datasets?")
60
+ if ok
61
+ Appifier::Components::Dataset::prune
62
+ @finisher.terminate exit_case: :quiet_exit
63
+ else
64
+ puts "Pruning cancelled"
65
+ @finisher.terminate exit_case: :quiet_exit
66
+ end
67
+ rescue TTY::Reader::InputInterrupt
68
+ @output.warn "Command interrupted"
69
+ @finisher.terminate exit_case: :interrupt
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -14,16 +14,20 @@ module Appifier
14
14
  # Thor method : list availables templates in user bundle
15
15
  desc 'ls', 'list templates availables in user bundle'
16
16
  def ls
17
- Appifier::Components::Template::list
18
- @finisher.terminate exit_case: :quiet_exit
17
+ begin
18
+ Appifier::Components::Template::list
19
+ @finisher.terminate exit_case: :quiet_exit
20
+ rescue RuntimeError => e
21
+ @output.error e.message
22
+ @finisher.terminate exit_case: :error_exit
23
+ end
19
24
  end
20
25
 
21
26
  # Thor method : remove a template from user bundle
22
- desc 'rm', 'rm templates from user bundle'
27
+ desc 'rm TEMPLATE', 'Remove templates from user bundle'
23
28
  def rm(template)
24
29
  begin
25
30
  Appifier::Components::Template::rm(template)
26
- @output.info "Template #{template} removed"
27
31
  @finisher.terminate exit_case: :quiet_exit
28
32
  rescue RuntimeError => e
29
33
  @output.error e.message
@@ -32,7 +36,7 @@ module Appifier
32
36
  end
33
37
 
34
38
  # Thor method : show information for a specific template in user bundle
35
- desc 'show', 'show information for a specific template in user bundle'
39
+ desc 'show TEMPLATE', 'show information for a specific template in user bundle'
36
40
  def show(template)
37
41
  begin
38
42
  Appifier::Components::Template::show(template)
@@ -50,7 +54,7 @@ module Appifier
50
54
  end
51
55
 
52
56
  # Thor method : display directory tree view for a specific template in user bundle
53
- desc 'treeview', 'display directory tree view for a specific template in user bundle'
57
+ desc 'treeview TEMPLATE', 'display directory tree view for a specific template in user bundle'
54
58
  def treeview(template)
55
59
  begin
56
60
  Appifier::Components::Template::treeview(template)
@@ -62,7 +66,7 @@ module Appifier
62
66
  end
63
67
 
64
68
  # Thor method : lint a specific template in user bundle
65
- desc 'lint', 'Lint a specific template in user bundle'
69
+ desc 'lint TEMPLATE', 'Lint a specific template in user bundle'
66
70
  def lint(template)
67
71
  begin
68
72
  Appifier::Components::Template::lint(template)
data/lib/appifier/cli.rb CHANGED
@@ -21,6 +21,9 @@ module Appifier
21
21
  true
22
22
  end
23
23
 
24
+ desc 'datasets SUBCOMMAND ...ARGS', 'Managing apps datasets'
25
+ subcommand 'datasets', Subcommands::Datasets
26
+
24
27
  desc 'templates SUBCOMMAND ...ARGS', 'Managing apps templates'
25
28
  subcommand 'templates', Subcommands::Templates
26
29
 
@@ -39,27 +42,34 @@ module Appifier
39
42
  option :force, type: :boolean, aliases: '-F'
40
43
  def generate(template, target = '.')
41
44
  root = "#{File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)}/#{template}"
42
- source = "#{root}/skeleton"
43
-
45
+ unless File::exist? root
46
+ @output.error "Template not found #{template}"
47
+ @finisher.terminate exit_case: :error_exit
48
+ end
44
49
  if File::exist? File::expand_path("#{DEFAULT_DATASETS_PATH}/#{template}.yml") then
45
50
  dataset = open_dataset(template: template)
46
51
  @output.info "Dataset file found for #{template}"
47
52
  else
48
- @output.warn "Dataset file not found for #{template}"
49
- if TTY::Prompt.new.yes?("Do you want to collect dataset interactively ?")
50
- @output.info "Beginning interactive Dataset input for #{template}"
51
- collector = Appifier::Actors::Collector.new template: template
52
- collector.collect
53
- dataset = open_dataset(template: template)
54
- else
55
- puts "=> Exiting run 'appifier collect #{template}' for collecting data"
56
- puts " (use -S for collecting from STDIN or -f <FILE>) "
57
- @finisher.terminate exit_case: :quiet_exit
53
+ begin
54
+ @output.warn "Dataset file not found for #{template}"
55
+ if TTY::Prompt.new.yes?("Do you want to collect dataset interactively ?")
56
+ @output.info "Beginning interactive Dataset input for #{template}"
57
+ collector = Appifier::Actors::Collector.new template: template
58
+ collector.collect
59
+ dataset = open_dataset(template: template)
60
+ else
61
+ puts "=> Exiting run 'appifier collect #{template}' for collecting data"
62
+ puts " (use -S for collecting from STDIN or -f <FILE>) "
63
+ @finisher.terminate exit_case: :quiet_exit
64
+ end
65
+ rescue TTY::Reader::InputInterrupt
66
+ @output.warn "Command interrupted"
67
+ @finisher.terminate exit_case: :interrupt
58
68
  end
59
69
  end
60
70
 
61
71
  begin
62
- generator = Appifier::Actors::Generator.new src_root: source, target_root: File.expand_path(target), dataset: dataset
72
+ generator = Appifier::Actors::Generator.new template_root: root, target_root: File.expand_path(target), dataset: dataset
63
73
  generator.generate dry_run: options[:simulate], force: options[:force]
64
74
  @finisher.terminate exit_case: :quiet_exit
65
75
  rescue RuntimeError => e
@@ -0,0 +1,60 @@
1
+ module Appifier
2
+ module Components
3
+ class Dataset
4
+
5
+ extend Carioca::Injector
6
+ inject service: :output
7
+
8
+
9
+ def self.list
10
+ output.info "List of available Datasets for user : #{current_user} :"
11
+ templates_path = File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)
12
+ datasets_path = File.expand_path(Appifier::DEFAULT_DATASETS_PATH)
13
+ templates = Dir.glob("#{templates_path}/*").map { |item| item.delete_prefix("#{templates_path}/") }
14
+ Dir.glob("#{datasets_path}/*").map { |item| item.delete_prefix("#{datasets_path}/") }.each do |file|
15
+ dataset = File::basename(file,'.yml')
16
+ res = dataset; res << " [TEMPLATE MISSING]" unless templates.include? dataset
17
+ output.item res
18
+ end
19
+ end
20
+
21
+
22
+ def self.prune
23
+ output.info "Pruning Datasets for user : #{current_user} :"
24
+ templates_path = File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)
25
+ datasets_path = File.expand_path(Appifier::DEFAULT_DATASETS_PATH)
26
+ templates = Dir.glob("#{templates_path}/*").map { |item| item.delete_prefix("#{templates_path}/") }
27
+ Dir.glob("#{datasets_path}/*").each do |file|
28
+ dataset = File::basename(file,'.yml')
29
+ unless templates.include? dataset
30
+ FileUtils::rm file
31
+ output.item "Pruned : #{dataset}"
32
+ end
33
+ end
34
+ end
35
+
36
+
37
+ def self.show(dataset)
38
+ raise "Not yet Implemented"
39
+ end
40
+
41
+ def self.rm(dataset)
42
+ output.info "Removing dataset #{dataset} for user : #{current_user}"
43
+ dataset_path = File.expand_path(Appifier::DEFAULT_DATASETS_PATH)
44
+ begin
45
+ if File::exist? "#{dataset_path}/#{dataset}.yml"
46
+ FileUtils.rm_rf "#{dataset_path}/#{dataset}.yml"
47
+ output.ok "Dataset #{dataset} deleted of bundle for user #{current_user}"
48
+ else
49
+ raise "Dataset #{dataset} not found in bundle for user #{current_user}"
50
+ end
51
+ rescue Errno::ENOENT
52
+ raise "Dataset #{dataset} not found in bundle for user #{current_user}"
53
+ end
54
+ end
55
+
56
+
57
+
58
+ end
59
+ end
60
+ end
@@ -52,7 +52,7 @@ module Appifier
52
52
  end
53
53
 
54
54
  def self.list
55
- output.info "List of avaible templates for user : #{current_user} :"
55
+ output.info "List of available templates for user : #{current_user} :"
56
56
  template_path = File.expand_path(Appifier::DEFAULT_TEMPLATES_PATH)
57
57
  Dir.glob("#{template_path}/*").map { |item| item.delete_prefix("#{template_path}/") }.each do |template|
58
58
  output.item "#{template}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Camille Paquet
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-10-28 00:00:00.000000000 Z
12
+ date: 2022-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: code_statistics
@@ -279,8 +279,10 @@ files:
279
279
  - lib/appifier/actors/retriever.rb
280
280
  - lib/appifier/cli.rb
281
281
  - lib/appifier/cli/configuration.rb
282
+ - lib/appifier/cli/datasets.rb
282
283
  - lib/appifier/cli/templates.rb
283
284
  - lib/appifier/components/Appifile.rb
285
+ - lib/appifier/components/dataset.rb
284
286
  - lib/appifier/components/init.rb
285
287
  - lib/appifier/components/template.rb
286
288
  - lib/appifier/helpers/archives.rb