foobara-typescript-remote-command-generator 1.5.0 → 1.5.2

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: 3665400333aa868dea13a4812bfc7cfbaf13e1475d3823eac5824566b4e4bb2b
4
- data.tar.gz: 764d0161640c99f2b5bfbe8f92f985455509c4a211e15703eb0bbfe1d38b043e
3
+ metadata.gz: 8f9ab7173395e0395aa68ec70af02241d434cfad4feca91d1930ca5749d3152f
4
+ data.tar.gz: 6d68586d307d903105f34d9b66561d4b6fd43d7cff64dc924f05ae2a18ac5a9d
5
5
  SHA512:
6
- metadata.gz: aa6643f0ff7c9661cc37f9294b50fbe28d52de56b8c2a34e4b549f085d026e76c3f38a84b42ee9004e1d911b7c7f302961999a819e3e796905330fa046f247e1
7
- data.tar.gz: 70ec01c2a3664fcd68a973baa7b2ae5c9e5a519b0aac8067aade428307911bf035e388f84b249f4ac66486f5dc8867c2f1bb34f935e3ff8a04eed88fe815fcbf
6
+ metadata.gz: 1c2e9edbaf0b1e3bfe520b1e2909d26d007861a666f84847f3e952a5ac3c5d478fb4cf2a4057d4651c4ffe28c4a932ebdb5fce9ae92722c541b794aed810a8c0
7
+ data.tar.gz: 621c4e4dc3509853fa2c874c016e344373ebe2049442b72dc4bb7a925fd68ba39742b97cb00b6a343aaec2a6570b713269aa029d4becd6d2ca01672181c00264
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [1.5.2] - 2026-11-19
2
+
3
+ - Run eslint, prettier, and/or oxlint if their config files are present
4
+
5
+ ## [1.5.1] - 2026-08-22
6
+
7
+ - Allow setting the env expression to either import.meta.env or process.env with --env-expression
8
+
1
9
  ## [1.5.0] - 2026-08-06
2
10
 
3
11
  - Only generate RequiresAuthCommand when its imports will exist
@@ -1,6 +1,8 @@
1
1
  require "net/http"
2
2
  require "uri"
3
3
 
4
+ require_relative "remote_generator"
5
+
4
6
  module Foobara
5
7
  module RemoteGenerator
6
8
  class GenerateTypescript < Foobara::Generators::Generate
@@ -16,10 +18,11 @@ module Foobara
16
18
  default: false,
17
19
  description: "Never generate Foobara::Auth's RequiresAuthCommand, even if the " \
18
20
  "manifest contains that domain. For apps that import it from elsewhere."
21
+ env_expression :env_expression, default: "import.meta.env"
19
22
  end
20
23
 
21
24
  def execute
22
- RemoteGenerator.no_foobara_auth(no_foobara_auth) do
25
+ apply_remote_generator_config do
23
26
  load_manifest_if_needed
24
27
 
25
28
  include_non_templated_files
@@ -36,6 +39,16 @@ module Foobara
36
39
  paths_to_source_code
37
40
  end
38
41
 
42
+ def apply_remote_generator_config
43
+ RemoteGenerator.no_foobara_auth(no_foobara_auth) do
44
+ RemoteGenerator.auto_dirty_queries(auto_dirty_queries) do
45
+ RemoteGenerator.with_env_expression(env_expression) do
46
+ yield
47
+ end
48
+ end
49
+ end
50
+ end
51
+
39
52
  def validate
40
53
  if raw_manifest.nil? && manifest_url.nil?
41
54
  # simplecov:disable
@@ -83,12 +96,6 @@ module Foobara
83
96
  end
84
97
  end
85
98
 
86
- def generate_element
87
- RemoteGenerator.auto_dirty_queries(auto_dirty_queries) do
88
- super
89
- end
90
- end
91
-
92
99
  def add_root_manifest_to_set_of_elements_to_generate
93
100
  elements_to_generate << manifest
94
101
  end
@@ -454,6 +454,8 @@ module Foobara
454
454
  def auto_dirty_queries?
455
455
  RemoteGenerator.auto_dirty_queries?
456
456
  end
457
+
458
+ def env_expression = RemoteGenerator.env_expression
457
459
  end
458
460
  end
459
461
  end
@@ -2,6 +2,8 @@ module Foobara
2
2
  module RemoteGenerator
3
3
  foobara_domain!
4
4
 
5
+ foobara_register_type(:env_expression, :string, one_of: ["import.meta.env", "process.env"])
6
+
5
7
  class << self
6
8
  def auto_dirty_queries(auto_dirty_queries)
7
9
  if auto_dirty_queries == @auto_dirty_queries
@@ -35,6 +37,19 @@ module Foobara
35
37
  def no_foobara_auth?
36
38
  @no_foobara_auth
37
39
  end
40
+
41
+ def with_env_expression(env_expression)
42
+ old = @env_expression
43
+
44
+ begin
45
+ @env_expression = env_expression
46
+ yield
47
+ ensure
48
+ @env_expression = old
49
+ end
50
+ end
51
+
52
+ attr_reader :env_expression
38
53
  end
39
54
  end
40
55
  end
@@ -1,3 +1,4 @@
1
+ require "pathname"
1
2
  require_relative "generate_typescript"
2
3
 
3
4
  module Foobara
@@ -19,6 +20,7 @@ module Foobara
19
20
  default: false,
20
21
  description: "Never generate Foobara::Auth's RequiresAuthCommand, even if the " \
21
22
  "manifest contains that domain. For apps that import it from elsewhere."
23
+ env_expression :env_expression, default: "import.meta.env"
22
24
  end
23
25
 
24
26
  possible_error :missing_manifest
@@ -56,34 +58,56 @@ module Foobara
56
58
 
57
59
  inputs[:auto_dirty_queries] = auto_dirty_queries
58
60
  inputs[:no_foobara_auth] = no_foobara_auth
61
+ inputs[:env_expression] = env_expression
59
62
 
60
63
  self.paths_to_source_code = run_subcommand!(GenerateTypescript, inputs)
61
64
  end
62
65
 
63
66
  def run_post_generation_tasks
64
67
  Dir.chdir(project_directory || output_directory) do
65
- eslint_fix
68
+ eslint_fix if eslint_config_present?
69
+ oxlint_fix if oxlint_config_present?
70
+ prettier_write if prettier_config_present?
66
71
  end
67
72
  end
68
73
 
74
+ def output_directory_relative_to_project
75
+ return @output_directory_relative_to_project if defined?(@output_directory_relative_to_project)
76
+
77
+ project_path = Pathname.new(File.expand_path(project_directory || output_directory))
78
+ pathname = Pathname.new(File.expand_path(output_directory))
79
+
80
+ @output_directory_relative_to_project = pathname.relative_path_from(project_path).to_s
81
+ end
82
+
83
+ def eslint_config_present? = any_files_present?("eslint.config.*", ".eslintrc", ".eslintrc.*")
84
+ def oxlint_config_present? = any_files_present?(".oxlintrc.json", "oxlint.config.*")
85
+ def prettier_config_present? = any_files_present?("prettier.config.*", ".prettierrc", ".prettierrc.*")
86
+ def any_files_present?(*globs) = !Dir.glob(globs).empty?
87
+
69
88
  def eslint_fix
70
- cmd = "npx eslint 'src/**/*.{js,jsx,ts,tsx}' --fix"
71
-
72
- Open3.popen3(cmd) do |_stdin, stdout, stderr, wait_thr|
73
- exit_status = wait_thr.value
74
-
75
- unless exit_status.success?
76
- # simplecov:disable
77
- out = stdout.read
78
- err = stderr.read
79
-
80
- if fail_if_does_not_pass_linter?
81
- add_runtime_error :failed_to_lint, stdout: out, stderr: err
82
- else
83
- warn "WARNING: could not #{cmd}\n#{out}\n#{err}"
84
- end
85
- # simplecov:enable
89
+ run_lint_cmd("npx eslint '#{output_directory_relative_to_project}/**/*.{js,jsx,ts,tsx}' --fix")
90
+ end
91
+
92
+ def oxlint_fix
93
+ run_lint_cmd("npx oxlint --fix '#{output_directory_relative_to_project}'")
94
+ end
95
+
96
+ def prettier_write
97
+ run_lint_cmd("npx prettier --write '#{output_directory_relative_to_project}/**/*.{js,jsx,ts,tsx}'")
98
+ end
99
+
100
+ def run_lint_cmd(cmd)
101
+ out, err, exit_status = Open3.capture3(cmd)
102
+
103
+ unless exit_status.success?
104
+ # simplecov:disable
105
+ if fail_if_does_not_pass_linter?
106
+ add_runtime_error :failed_to_lint, stdout: out, stderr: err
107
+ else
108
+ warn "WARNING: could not #{cmd}\n#{out}\n#{err}"
86
109
  end
110
+ # simplecov:enable
87
111
  end
88
112
  end
89
113
 
@@ -1,4 +1,4 @@
1
- let _urlBase = import.meta.env.REACT_APP_FOOBARA_GLOBAL_URL_BASE
1
+ let _urlBase = <%= env_expression %>.REACT_APP_FOOBARA_GLOBAL_URL_BASE
2
2
 
3
3
  const config = {
4
4
  get urlBase(): string {
@@ -1,4 +1,4 @@
1
- let _urlBase = import.meta.env.REACT_APP_FOOBARA_GLOBAL_URL_BASE
1
+ let _urlBase = <%= env_expression %>.REACT_APP_FOOBARA_GLOBAL_URL_BASE
2
2
 
3
3
  const config = {
4
4
  get urlBase(): string {
@@ -15,7 +15,7 @@ export default abstract class RemoteCommand<Inputs, Result, CommandError extends
15
15
  let base = this._urlBase
16
16
 
17
17
  if (base == null) {
18
- base = import.meta.env.REACT_APP_FOOBARA_GLOBAL_URL_BASE
18
+ base = <%= env_expression %>.REACT_APP_FOOBARA_GLOBAL_URL_BASE
19
19
  }
20
20
 
21
21
  if (base == null) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara-typescript-remote-command-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -33,6 +33,9 @@ dependencies:
33
33
  name: foobara-files-generator
34
34
  requirement: !ruby/object:Gem::Requirement
35
35
  requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.2.3
36
39
  - - "<"
37
40
  - !ruby/object:Gem::Version
38
41
  version: 2.0.0
@@ -40,6 +43,9 @@ dependencies:
40
43
  prerelease: false
41
44
  version_requirements: !ruby/object:Gem::Requirement
42
45
  requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 0.2.3
43
49
  - - "<"
44
50
  - !ruby/object:Gem::Version
45
51
  version: 2.0.0
@@ -162,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
168
  - !ruby/object:Gem::Version
163
169
  version: '0'
164
170
  requirements: []
165
- rubygems_version: 4.0.16
171
+ rubygems_version: 4.0.20
166
172
  specification_version: 4
167
173
  summary: Generates remote commands for Typescript from a foobara manifest
168
174
  test_files: []