alet 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,99 @@
1
+ require 'nokogiri'
2
+
3
+ def gen_lwc(argv, params)
4
+ target_map = {
5
+ 'app' => 'lightning__AppPage',
6
+ 'flow' => 'lightning__FlowScreen',
7
+ 'home' => 'lightning__HomePage',
8
+ 'action' => 'lightning__RecordAction',
9
+ 'record' => 'lightning__RecordPage',
10
+ 'tab' => 'lightning__Tab',
11
+ 'bar' => 'lightning__UtilityBar',
12
+ }
13
+
14
+ return if argv.empty?
15
+
16
+ pastel = Pastel.new
17
+ name = argv.first
18
+ name[0] = name[0].downcase
19
+ base_dir = Dir.pwd
20
+ dx_dir = 'force-app/main/default'
21
+ dir = if FileTest.exist?(%|#{base_dir}/#{dx_dir}|)
22
+ %|#{base_dir}/#{dx_dir}/lwc|
23
+ else
24
+ base_dir
25
+ end
26
+ metafile = %|#{dir}/#{name}/#{name}.js-meta.xml|
27
+ meta_changed = false
28
+
29
+ if FileTest.exist?(%|#{dir}/#{name}|)
30
+ puts pastel.red(t('gen.error.file_duplicated'))
31
+ return
32
+ end
33
+
34
+ sf.lightning.generate_component name, type: :lwc, output_dir: dir, api_version: Alet.config.org.api_version
35
+
36
+ doc = Nokogiri::XML(File.open(metafile), nil, 'UTF-8', Nokogiri::XML::ParseOptions::NOBLANKS)
37
+
38
+ if params[:label]
39
+ node = doc.at_css('LightningComponentBundle')
40
+ label = Nokogiri::XML::Node.new("masterLabel", node)
41
+ label.content = params[:label]
42
+ node.add_child label
43
+ meta_changed = true
44
+ end
45
+
46
+ if params[:description]
47
+ node = doc.at_css('LightningComponentBundle')
48
+ desc = Nokogiri::XML::Node.new("description", node)
49
+ desc.content = params[:description]
50
+ node.add_child desc
51
+ meta_changed = true
52
+ end
53
+
54
+ if params[:exposed]
55
+ node = doc.at_css('isExposed')
56
+ node.content = true
57
+ meta_changed = true
58
+ end
59
+
60
+ if params[:target]
61
+ node = doc.at_css('LightningComponentBundle')
62
+ targets_node = Nokogiri::XML::Node.new("targets", node)
63
+
64
+ targets = params[:target].split(',').map{|t| target_map[t]}
65
+ targets.each do |target|
66
+ target_node = Nokogiri::XML::Node.new("target", targets_node){|n| n.content = target}
67
+ targets_node.add_child target_node
68
+ end
69
+ node.add_child targets_node
70
+
71
+ if targets.include?('lightning__RecordAction') || targets.include?('lightning__RecordPage')
72
+ target_configs = Nokogiri::XML::Node.new('targetConfigs', node)
73
+ action_config = Nokogiri::XML::Node.new('targetConfig', target_configs){|n| n.set_attribute('targets', 'lightning__RecordAction') }
74
+ record_config = Nokogiri::XML::Node.new('targetConfig', target_configs){|n| n.set_attribute('targets', 'lightning__RecordPage') }
75
+
76
+ if targets.include?('lightning__RecordAction')
77
+ action_type = Nokogiri::XML::Node.new('actionType', action_config)
78
+ action_type.content = 'ScreenAction'
79
+ action_config.add_child action_type
80
+ target_configs.add_child action_config
81
+ end
82
+
83
+ if targets.include?('lightning__RecordAction') && params[:object]
84
+ objects = Nokogiri::XML::Node.new('objects', record_config)
85
+ params[:object].split(',').each do |object_name|
86
+ object = Nokogiri::XML::Node.new('object', objects)
87
+ object.content = object_name
88
+ objects.add_child object
89
+ end
90
+ record_config.add_child objects
91
+ target_configs.add_child record_config
92
+ end
93
+ node.add_child target_configs
94
+ end
95
+ meta_changed = true
96
+ end
97
+
98
+ File.open(metafile, 'w') {|f| f.write(doc.to_xml indent: 4)} if meta_changed
99
+ end
@@ -0,0 +1,58 @@
1
+ require 'optparse'
2
+ require 'shellwords'
3
+ require_relative './gen/apex'
4
+ require_relative './gen/lwc'
5
+
6
+ class GenerateResource < IRB::Command::Base
7
+ category "Alet"
8
+ description t('gen.description')
9
+ help_message TTY::Markdown.parse t('gen.help')
10
+
11
+ def execute(arg)
12
+ pastel = Pastel.new
13
+ argv = Shellwords.shellsplit(arg)
14
+ subcommands = {
15
+ 'apex' => OptionParser.new,
16
+ 'lwc' => OptionParser.new,
17
+ }
18
+ subcommands['apex'].on('-t', '--trigger')
19
+ subcommands['apex'].on('-o sobjectName', '--sobject')
20
+ subcommands['apex'].on('-e event1,event2,...', '--event')
21
+
22
+ subcommands['lwc'].on('-l label', '--label')
23
+ subcommands['lwc'].on('-d desc', '--description')
24
+ subcommands['lwc'].on('-e', '--exposed')
25
+ subcommands['lwc'].on('-t target1,target2,...', '--target')
26
+ subcommands['lwc'].on('-o object1,object2,...', '--object')
27
+
28
+ global_parser = OptionParser.new
29
+ global_parser.order!(argv)
30
+
31
+ if argv.empty?
32
+ puts pastel.red(t('gen.error.no_subcommand'))
33
+ return
34
+ end
35
+
36
+ unless subcommands.keys.include?(argv.first)
37
+ puts pastel.red(%|#{t('gen.error.invalid_subcommand')}: #{argv.first}|)
38
+ return
39
+ end
40
+
41
+ params = {}
42
+ subcommand = argv.shift
43
+ subcommands[subcommand].parse!(argv, into: params)
44
+
45
+ #puts subcommand # for debug
46
+ #puts argv # for debug
47
+ #puts params # for debug
48
+
49
+ case subcommand
50
+ when 'apex'
51
+ gen_apex(argv, params)
52
+ when 'lwc'
53
+ gen_lwc(argv, params)
54
+ end
55
+ rescue => e
56
+ puts pastel.red(e.message)
57
+ end
58
+ end
@@ -1,10 +1,32 @@
1
+ require 'optparse'
2
+
1
3
  class GenerateModel < IRB::Command::Base
2
4
  category "Alet"
3
- description t('gen.description')
4
- help_message TTY::Markdown.parse t('gen.help')
5
+ description t('model.description')
6
+ help_message TTY::Markdown.parse t('model.help')
5
7
 
6
8
  def execute(arg)
7
- object_types = arg.split(' ').map{|s| s.tr(' ', '')}
8
- SObjectModel.generate(*object_types)
9
+ pastel = Pastel.new
10
+ argv = arg.split(' ')
11
+ opt = OptionParser.new
12
+ opt.parse!(argv)
13
+
14
+ if argv.count.zero? || argv.first == 'list'
15
+ if SObjectModel.generated_classes.empty?
16
+ puts t('model.list.noclass')
17
+ return
18
+ end
19
+
20
+ puts t('model.list.title')
21
+ table =
22
+ TTY::Table.new(rows: SObjectModel.generated_classes.each_slice(4).map{|row| row.map(&:name).append('','','','')[0..3]})
23
+ puts table.render :basic
24
+ elsif argv.first == 'load'
25
+ SObjectModel.generate(*argv[1..-1])
26
+ end
27
+ rescue SObjectModel::Rest::RequestError => e
28
+ puts pastel.red(e.message)
29
+ rescue SObjectModel::Rest::RecordNotFoundError => e
30
+ puts pastel.red(t('desc.error.notfound'))
9
31
  end
10
32
  end
@@ -0,0 +1,38 @@
1
+ require 'optparse'
2
+
3
+ class Grep < IRB::Command::Base
4
+ category "Alet"
5
+ description t('grep.description')
6
+ help_message TTY::Markdown.parse t('grep.help')
7
+
8
+ def execute(arg)
9
+ argv = arg.split(' ')
10
+ opt = OptionParser.new
11
+ opt.on '-l', '--label'
12
+ opt.on '-n', '--api-name'
13
+
14
+ params = {}
15
+ opt.parse(argv, into: params)
16
+
17
+ regxp = %r{#{argv.first}}
18
+
19
+ sobjects = Alet.describe_global['sobjects'].select do |so|
20
+ if params.has_key?(:label)
21
+ regxp.match(so['label'])
22
+ elsif params.has_key?(:"api-name")
23
+ regxp.match?(so['name'])
24
+ else
25
+ regxp.match?(so['name']) || regxp.match(so['label'])
26
+ end
27
+ end
28
+
29
+ table = TTY::Table.new(
30
+ ["name", "label"],
31
+ sobjects.map{ |so| [so['name'], so['label']] }
32
+ )
33
+ puts table.render :unicode
34
+ rescue SObjectModel::Rest::RequestError => e
35
+ pastel = Pastel.new
36
+ puts pastel.red(e.message)
37
+ end
38
+ end
@@ -0,0 +1,11 @@
1
+ require_relative '../shared_functions'
2
+
3
+ class Org < IRB::Command::Base
4
+ category "Alet"
5
+ description t('org.description')
6
+ help_message TTY::Markdown.parse t('org.help')
7
+
8
+ def execute(arg)
9
+ show_org_settings
10
+ end
11
+ end
@@ -16,6 +16,6 @@ class Query < IRB::Command::Base
16
16
 
17
17
  return if soql.nil?
18
18
 
19
- puts sf.data.query(soql, format: :human, target_org: ::Alet.config.connection.alias)
19
+ puts sf.data.query(soql, format: :human, target_org: ::Alet.config.org.alias)
20
20
  end
21
21
  end
@@ -1,23 +1,5 @@
1
1
  require 'irb/helper_method/base'
2
-
3
- class CurrentConnection < IRB::HelperMethod::Base
4
- description t('connection.description')
5
-
6
- def execute
7
- info = Alet.config.connection
8
- table =
9
- TTY::Table.new(rows: [
10
- [:id, info.id],
11
- [:alias, info.alias],
12
- [:user_name, info.user_name],
13
- [:status, info.status],
14
- [:instance_url, info.instance_url],
15
- [:api_version, info.api_version],
16
- [:access_token, info.access_token]
17
- ])
18
- puts table.render :unicode
19
- end
20
- end
2
+ require_relative './shared_functions'
21
3
 
22
4
  class Apex < IRB::HelperMethod::Base
23
5
  description t('apex.description')
@@ -25,9 +7,9 @@ class Apex < IRB::HelperMethod::Base
25
7
  def execute(apex_code = nil, verbose: false)
26
8
  result =
27
9
  if apex_code
28
- sf.apex.run target_org: Alet.config.conn.alias, file: StringIO.new(apex_code)
10
+ sf.apex.run target_org: Alet.config.org.alias, file: StringIO.new(apex_code)
29
11
  else
30
- sf.apex.run target_org: Alet.config.conn.alias
12
+ sf.apex.run target_org: Alet.config.org.alias
31
13
  end
32
14
 
33
15
  IRB.conf[:INSPECT_MODE] = false
@@ -43,3 +25,4 @@ class Apex < IRB::HelperMethod::Base
43
25
  IRB.conf[:INSPECT_MODE] = true
44
26
  end
45
27
  end
28
+
@@ -0,0 +1,56 @@
1
+ def show_org_settings
2
+ info = sf.org.display target_org: Alet.config.org.alias
3
+
4
+ table =
5
+ TTY::Table.new(rows: [
6
+ [:id, info.id],
7
+ [:alias, info.alias],
8
+ [:user_name, info.user_name],
9
+ [:status, info.status],
10
+ [:instance_url, info.instance_url],
11
+ [:api_version, info.api_version],
12
+ [:access_token, info.access_token]
13
+ ])
14
+ puts table.render :unicode
15
+ rescue => e
16
+ pastel = Pastel.new
17
+ puts pastel.red(e.message.sub("See more help with --help", ''))
18
+ end
19
+
20
+ def show_rest_client_settings
21
+ table =
22
+ TTY::Table.new(rows: [
23
+ [:instance_url, Alet.rest_client.instance_url],
24
+ [:access_token, Alet.rest_client.access_token],
25
+ [:api_version, Alet.rest_client.api_version],
26
+ ])
27
+ puts table.render :unicode
28
+ end
29
+
30
+ def reset_connection
31
+ org = sf.org.display target_org: Alet.config.cli_options[:"target-org"]
32
+
33
+ unless org.connected?
34
+ sf.org.login_web target_org: org.alias, instance_url: org.instance_url
35
+ org = sf.org.display target_org: Alet.config.cli_options[:"target-org"]
36
+ end
37
+
38
+ Alet.config.org = org
39
+
40
+ reset_rest_client
41
+ reset_sobject_model_adapter
42
+ end
43
+
44
+ def reset_rest_client
45
+ rest_client = SObjectModel::Rest::Client.new(
46
+ instance_url: Alet.config.org.instance_url,
47
+ access_token: Alet.config.org.access_token,
48
+ api_version: Alet.config.org.api_version)
49
+
50
+ Alet.rest_client = rest_client
51
+ end
52
+
53
+ def reset_sobject_model_adapter
54
+ adapter = SObjectModel::Adapter::Rest.new(Alet.rest_client)
55
+ SObjectModel.connection = adapter
56
+ end
data/lib/alet/irb.rb CHANGED
@@ -1,14 +1,28 @@
1
1
  require 'sf_cli'
2
2
  require 'sobject_model'
3
- require 'alet/config'
3
+ require 'alet'
4
4
  require 'irb/command/base'
5
5
  require 'tty-markdown'
6
6
  require 'tty-table'
7
7
  require 'pastel'
8
8
  require 'i18n'
9
9
 
10
+ #
11
+ # set locale
12
+ #
10
13
  I18n.locale = IRB.conf[:LC_MESSAGES].lang&.to_sym || :en
11
14
 
15
+ #
16
+ # set prompt
17
+ #
18
+ IRB.conf[:PROMPT][:ALET] = {
19
+ :PROMPT_I => "alet(#{Alet.config.cli_options[:"target-org"]}):%03n:%i> ",
20
+ :PROMPT_S => "alet(#{Alet.config.cli_options[:"target-org"]}):%03n:%i%l ",
21
+ :PROMPT_C => "alet(#{Alet.config.cli_options[:"target-org"]}):%03n:%i* ",
22
+ :RETURN => "=> %s\n"
23
+ }
24
+ IRB.conf[:PROMPT_MODE] = :ALET
25
+
12
26
  #
13
27
  # load commands
14
28
  #
@@ -16,33 +30,38 @@ require_relative 'irb/command/generate_model'
16
30
  require_relative 'irb/command/query'
17
31
  require_relative 'irb/command/sh'
18
32
  require_relative 'irb/command/export'
33
+ require_relative 'irb/command/org'
34
+ require_relative 'irb/command/grep'
35
+ require_relative 'irb/command/describe'
36
+ require_relative 'irb/command/conn'
37
+ require_relative 'irb/command/gen'
38
+ require_relative 'irb/command/deploy'
19
39
 
20
- IRB::Command.register :gen, GenerateModel
21
- IRB::Command.register :query, Query
40
+ IRB::Command.register :conn, Conn
41
+ IRB::Command.register :deploy, Deploy
42
+ IRB::Command.register :desc, Describe
22
43
  IRB::Command.register :export, Export
44
+ IRB::Command.register :gen, GenerateResource
45
+ IRB::Command.register :grep, Grep
46
+ IRB::Command.register :model, GenerateModel
47
+ IRB::Command.register :org, Org
48
+ IRB::Command.register :query, Query
23
49
  IRB::Command.register :sh, Shell
24
50
 
25
51
  #
26
52
  # load helper methods
27
53
  #
28
54
  require_relative 'irb/helper_methods'
29
-
30
- IRB::HelperMethod.register(:conn, CurrentConnection)
31
55
  IRB::HelperMethod.register(:apex, Apex)
32
56
 
33
-
34
57
  #
35
58
  # set connection
36
59
  #
37
- conn = sf.org.display target_org: Alet.config.cli_options[:"target-org"]
38
-
39
- Alet.config.connection = conn
40
-
41
- sf.org.login_web target_org: conn.alias, instance_url: conn.instance_url unless conn.connected?
42
-
43
- SObjectModel.connect(
44
- :rest,
45
- instance_url: conn.instance_url,
46
- access_token: conn.access_token,
47
- api_version: conn.api_version
48
- )
60
+ require_relative 'irb/shared_functions'
61
+ begin
62
+ reset_connection
63
+ rescue => e
64
+ pastel = Pastel.new
65
+ puts pastel.red(e.message.sub("See more help with --help", ''))
66
+ exit(1)
67
+ end
@@ -0,0 +1,44 @@
1
+ require 'sf_cli'
2
+ require 'fileutils'
3
+
4
+ module Alet
5
+ module Project
6
+ def self.generate(project_name, params)
7
+ base_dir = Dir.pwd
8
+ target_org = params[:"target-org"]
9
+ retrieve_source = params[:retrieve]
10
+ editor = params[:"editor-open"]
11
+
12
+ return if project_name.nil?
13
+
14
+ puts sf.project.generate project_name, manifest: true, raw_output: true
15
+
16
+ Dir.chdir project_name
17
+
18
+ puts sf.project.generate_manifest from_org: target_org, output_dir: 'manifest', raw_output: true if target_org
19
+
20
+ sf.project.retrieve_start manifest: 'manifest/package.xml', target_org: target_org, raw_output: true if retrieve_source
21
+ system 'code .' if editor
22
+ ensure
23
+ Dir.chdir base_dir
24
+ end
25
+
26
+ def self.update(project_name, params)
27
+ base_dir = Dir.pwd
28
+ target_org = params[:"target-org"]
29
+ editor = params[:"editor-open"]
30
+
31
+ Dir.chdir project_name
32
+
33
+ manifest = 'manifest/package.xml'
34
+
35
+ FileUtils.rm manifest if FileTest.exist?(manifest)
36
+
37
+ puts sf.project.generate_manifest from_org: target_org, output_dir: 'manifest', raw_output: true
38
+ sf.project.retrieve_start manifest: 'manifest/package.xml', target_org: target_org, raw_output: true
39
+ system 'code .' if editor
40
+ ensure
41
+ Dir.chdir base_dir
42
+ end
43
+ end
44
+ end
data/lib/alet/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Alet
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
data/lib/alet.rb ADDED
@@ -0,0 +1,23 @@
1
+ require_relative 'alet/config'
2
+
3
+ module Alet
4
+ def self.config
5
+ @config ||= Config.new
6
+ end
7
+
8
+ def self.rest_client
9
+ @rest_client
10
+ end
11
+
12
+ def self.rest_client=(client)
13
+ @rest_client = client
14
+ end
15
+
16
+ def self.describe_global
17
+ @describe_global ||= rest_client.describe_global
18
+ end
19
+
20
+ def self.describe(object_type)
21
+ rest_client.describe object_type
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takanobu Maekawa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-04 00:00:00.000000000 Z
11
+ date: 2024-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.2.4
33
+ version: '1.3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.2.4
40
+ version: '1.3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sobjectmodel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.2
47
+ version: 0.1.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.2
54
+ version: 0.1.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tty-markdown
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.14.6
111
+ - !ruby/object:Gem::Dependency
112
+ name: nokogiri
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.16.7
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.16.7
111
125
  description: Salesforce console utility for Ruby users
112
126
  email:
113
127
  executables:
@@ -116,17 +130,27 @@ extensions: []
116
130
  extra_rdoc_files: []
117
131
  files:
118
132
  - bin/alet
133
+ - lib/alet.rb
119
134
  - lib/alet/app.rb
120
135
  - lib/alet/config.rb
121
136
  - lib/alet/config/locales/en.yml
122
137
  - lib/alet/config/locales/ja.yml
123
- - lib/alet/generate/project.rb
124
138
  - lib/alet/irb.rb
139
+ - lib/alet/irb/command/conn.rb
140
+ - lib/alet/irb/command/deploy.rb
141
+ - lib/alet/irb/command/describe.rb
125
142
  - lib/alet/irb/command/export.rb
143
+ - lib/alet/irb/command/gen.rb
144
+ - lib/alet/irb/command/gen/apex.rb
145
+ - lib/alet/irb/command/gen/lwc.rb
126
146
  - lib/alet/irb/command/generate_model.rb
147
+ - lib/alet/irb/command/grep.rb
148
+ - lib/alet/irb/command/org.rb
127
149
  - lib/alet/irb/command/query.rb
128
150
  - lib/alet/irb/command/sh.rb
129
151
  - lib/alet/irb/helper_methods.rb
152
+ - lib/alet/irb/shared_functions.rb
153
+ - lib/alet/project.rb
130
154
  - lib/alet/utils/irb.rb
131
155
  - lib/alet/version.rb
132
156
  homepage: https://github.com/tmkw/alet
@@ -149,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
173
  - !ruby/object:Gem::Version
150
174
  version: '0'
151
175
  requirements:
152
- - 'Salesforce CLI ( >= 2.56.7): https://developer.salesforce.com/tools/salesforcecli'
176
+ - 'Salesforce CLI ( >= 2.64.8): https://developer.salesforce.com/tools/salesforcecli'
153
177
  rubygems_version: 3.5.11
154
178
  signing_key:
155
179
  specification_version: 4
@@ -1,22 +0,0 @@
1
- require 'sf_cli'
2
-
3
- module Alet
4
- module Project
5
- def self.generate(project_name, params)
6
- base_dir = Dir.pwd
7
- target_org = params[:"target-org"]
8
- retrieve_source = params[:retrieve]
9
- editor = params[:"editor-open"]
10
-
11
- sf.project.generate project_name, manifest: true
12
-
13
- Dir.chdir project_name
14
-
15
- sf.project.generate_manifest from_org: target_org, output_dir: 'manifest' if target_org
16
- sf.project.retrieve_start manifest: 'manifest/package.xml', target_org: target_org if retrieve_source
17
- system 'code .' if editor
18
- ensure
19
- Dir.chdir base_dir
20
- end
21
- end
22
- end