better_auth 0.1.1 → 0.2.0

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.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +106 -16
  4. data/lib/better_auth/adapters/base.rb +49 -0
  5. data/lib/better_auth/adapters/internal_adapter.rb +439 -0
  6. data/lib/better_auth/adapters/memory.rb +232 -0
  7. data/lib/better_auth/adapters/mongodb.rb +369 -0
  8. data/lib/better_auth/adapters/mssql.rb +42 -0
  9. data/lib/better_auth/adapters/mysql.rb +33 -0
  10. data/lib/better_auth/adapters/postgres.rb +17 -0
  11. data/lib/better_auth/adapters/sql.rb +425 -0
  12. data/lib/better_auth/adapters/sqlite.rb +20 -0
  13. data/lib/better_auth/api.rb +226 -0
  14. data/lib/better_auth/api_error.rb +53 -0
  15. data/lib/better_auth/auth.rb +42 -0
  16. data/lib/better_auth/configuration.rb +399 -0
  17. data/lib/better_auth/context.rb +210 -0
  18. data/lib/better_auth/cookies.rb +278 -0
  19. data/lib/better_auth/core.rb +37 -1
  20. data/lib/better_auth/crypto/jwe.rb +76 -0
  21. data/lib/better_auth/crypto.rb +191 -0
  22. data/lib/better_auth/database_hooks.rb +114 -0
  23. data/lib/better_auth/endpoint.rb +326 -0
  24. data/lib/better_auth/error.rb +52 -0
  25. data/lib/better_auth/middleware/origin_check.rb +128 -0
  26. data/lib/better_auth/password.rb +120 -0
  27. data/lib/better_auth/plugin.rb +129 -0
  28. data/lib/better_auth/plugin_context.rb +16 -0
  29. data/lib/better_auth/plugin_registry.rb +67 -0
  30. data/lib/better_auth/plugins/access.rb +87 -0
  31. data/lib/better_auth/plugins/additional_fields.rb +29 -0
  32. data/lib/better_auth/plugins/admin/schema.rb +28 -0
  33. data/lib/better_auth/plugins/admin.rb +518 -0
  34. data/lib/better_auth/plugins/anonymous.rb +198 -0
  35. data/lib/better_auth/plugins/api_key.rb +16 -0
  36. data/lib/better_auth/plugins/bearer.rb +128 -0
  37. data/lib/better_auth/plugins/captcha.rb +159 -0
  38. data/lib/better_auth/plugins/custom_session.rb +84 -0
  39. data/lib/better_auth/plugins/device_authorization.rb +302 -0
  40. data/lib/better_auth/plugins/email_otp.rb +536 -0
  41. data/lib/better_auth/plugins/expo.rb +88 -0
  42. data/lib/better_auth/plugins/generic_oauth.rb +780 -0
  43. data/lib/better_auth/plugins/have_i_been_pwned.rb +94 -0
  44. data/lib/better_auth/plugins/jwt.rb +482 -0
  45. data/lib/better_auth/plugins/last_login_method.rb +92 -0
  46. data/lib/better_auth/plugins/magic_link.rb +181 -0
  47. data/lib/better_auth/plugins/mcp.rb +342 -0
  48. data/lib/better_auth/plugins/multi_session.rb +173 -0
  49. data/lib/better_auth/plugins/oauth_protocol.rb +348 -0
  50. data/lib/better_auth/plugins/oauth_provider.rb +16 -0
  51. data/lib/better_auth/plugins/oauth_proxy.rb +257 -0
  52. data/lib/better_auth/plugins/oidc_provider.rb +597 -0
  53. data/lib/better_auth/plugins/one_tap.rb +154 -0
  54. data/lib/better_auth/plugins/one_time_token.rb +106 -0
  55. data/lib/better_auth/plugins/open_api.rb +489 -0
  56. data/lib/better_auth/plugins/organization/schema.rb +106 -0
  57. data/lib/better_auth/plugins/organization.rb +990 -0
  58. data/lib/better_auth/plugins/passkey.rb +16 -0
  59. data/lib/better_auth/plugins/phone_number.rb +321 -0
  60. data/lib/better_auth/plugins/scim.rb +16 -0
  61. data/lib/better_auth/plugins/siwe.rb +242 -0
  62. data/lib/better_auth/plugins/sso.rb +16 -0
  63. data/lib/better_auth/plugins/stripe.rb +16 -0
  64. data/lib/better_auth/plugins/two_factor.rb +514 -0
  65. data/lib/better_auth/plugins/username.rb +278 -0
  66. data/lib/better_auth/plugins.rb +46 -0
  67. data/lib/better_auth/rate_limiter.rb +215 -0
  68. data/lib/better_auth/request_ip.rb +70 -0
  69. data/lib/better_auth/router.rb +365 -0
  70. data/lib/better_auth/routes/account.rb +211 -0
  71. data/lib/better_auth/routes/email_verification.rb +108 -0
  72. data/lib/better_auth/routes/error.rb +102 -0
  73. data/lib/better_auth/routes/ok.rb +15 -0
  74. data/lib/better_auth/routes/password.rb +164 -0
  75. data/lib/better_auth/routes/session.rb +137 -0
  76. data/lib/better_auth/routes/sign_in.rb +90 -0
  77. data/lib/better_auth/routes/sign_out.rb +15 -0
  78. data/lib/better_auth/routes/sign_up.rb +145 -0
  79. data/lib/better_auth/routes/social.rb +188 -0
  80. data/lib/better_auth/routes/user.rb +193 -0
  81. data/lib/better_auth/schema/sql.rb +191 -0
  82. data/lib/better_auth/schema.rb +275 -0
  83. data/lib/better_auth/session.rb +122 -0
  84. data/lib/better_auth/session_store.rb +91 -0
  85. data/lib/better_auth/social_providers/apple.rb +55 -0
  86. data/lib/better_auth/social_providers/base.rb +67 -0
  87. data/lib/better_auth/social_providers/discord.rb +59 -0
  88. data/lib/better_auth/social_providers/github.rb +59 -0
  89. data/lib/better_auth/social_providers/gitlab.rb +54 -0
  90. data/lib/better_auth/social_providers/google.rb +65 -0
  91. data/lib/better_auth/social_providers/microsoft_entra_id.rb +65 -0
  92. data/lib/better_auth/social_providers.rb +9 -0
  93. data/lib/better_auth/version.rb +1 -1
  94. data/lib/better_auth.rb +87 -2
  95. metadata +218 -21
  96. data/.ruby-version +0 -1
  97. data/.standard.yml +0 -12
  98. data/.vscode/settings.json +0 -22
  99. data/AGENTS.md +0 -50
  100. data/CLAUDE.md +0 -1
  101. data/CODE_OF_CONDUCT.md +0 -173
  102. data/CONTRIBUTING.md +0 -187
  103. data/Gemfile +0 -12
  104. data/Makefile +0 -207
  105. data/Rakefile +0 -25
  106. data/SECURITY.md +0 -28
  107. data/docker-compose.yml +0 -63
@@ -1,22 +0,0 @@
1
- {
2
- "rubyLsp.enabled": true,
3
- "rubyLsp.formatter": "standard",
4
- "rubyLsp.linters": ["standard"],
5
- "editor.formatOnSave": true,
6
- "editor.insertSpaces": true,
7
- "editor.tabSize": 2,
8
- "files.insertFinalNewline": true,
9
- "files.trimTrailingWhitespace": true,
10
- "[ruby]": {
11
- "editor.defaultFormatter": "Shopify.ruby-lsp",
12
- "editor.formatOnSave": true,
13
- "editor.rulers": [120]
14
- },
15
- "search.exclude": {
16
- "**/.bundle": true,
17
- "**/vendor": true,
18
- "**/coverage": true,
19
- "**/doc": true,
20
- "**/*.gem": true
21
- }
22
- }
data/AGENTS.md DELETED
@@ -1,50 +0,0 @@
1
- # AGENTS.md - Better Auth Core Package
2
-
3
- **⚠️ CRITICAL: Always read this file when editing files in packages/better_auth/**
4
-
5
- ## What is this package?
6
-
7
- This is the **core gem** of Better Auth Ruby - a Ruby port of the TypeScript [better-auth](https://github.com/better-auth/better-auth) library. It contains framework-agnostic authentication logic built on Rack.
8
-
9
- ## Upstream Reference
10
-
11
- **Always check `upstream/` before implementing or modifying features.**
12
-
13
- The TypeScript implementation in `upstream/packages/better-auth/` is the source of truth. Your workflow should be:
14
-
15
- 1. **Find the feature** in `upstream/packages/better-auth/src/`
16
- 2. **Understand how it works** in TypeScript
17
- 3. **Translate to Ruby** following Ruby/Rails best practices
18
- 4. **Adapt idiomatically** - don't do a literal translation, make it feel native to Ruby
19
-
20
- Key upstream directories:
21
- - `upstream/packages/better-auth/src/` - Core auth logic
22
- - `upstream/packages/better-auth/src/plugins/` - Plugin implementations
23
-
24
- ## Development Commands
25
-
26
- ```bash
27
- bundle install # Install dependencies
28
- bundle exec rake test # Run tests (Minitest)
29
- bundle exec standardrb # Run linter
30
- bundle exec standardrb --fix # Fix linting issues
31
- ```
32
-
33
- ## Directory Structure
34
-
35
- * `lib/better_auth.rb` - Main entry point
36
- * `lib/better_auth/core/` - Core authentication logic
37
- * `test/` - Tests (Minitest)
38
-
39
- ## Code Style
40
-
41
- * StandardRB for linting
42
- * `frozen_string_literal: true` in all files
43
- * snake_case for files/methods, CamelCase for classes
44
-
45
- ## After Everything is Done
46
-
47
- **Unless the user asked for it, DO NOT COMMIT**
48
-
49
- * Make sure `bundle exec standardrb` passes
50
- * Make sure `bundle exec rake test` passes
data/CLAUDE.md DELETED
@@ -1 +0,0 @@
1
- AGENTS.md
data/CODE_OF_CONDUCT.md DELETED
@@ -1,173 +0,0 @@
1
- # Contributor Covenant 3.0
2
-
3
- ## Our Pledge
4
-
5
- We pledge to make our community welcoming, safe, and equitable for all.
6
-
7
- We are committed to fostering an environment that respects and promotes the
8
- dignity, rights, and contributions of all individuals, regardless of
9
- characteristics including race, ethnicity, caste, color, age, physical
10
- characteristics, neurodiversity, disability, sex or gender, gender identity or
11
- expression, sexual orientation, language, philosophy or religion, national or
12
- social origin, socio-economic position, level of education, or other status.
13
- The same privileges of participation are extended to everyone who participates
14
- in good faith and in accordance with this Covenant.
15
-
16
- ## Encouraged Behaviors
17
-
18
- While acknowledging differences in social norms, we all strive to meet our
19
- community's expectations for positive behavior.
20
- We also understand that our words and actions may be interpreted differently
21
- than we intend based on culture, background, or native language.
22
-
23
- With these considerations in mind, we agree to behave mindfully toward each
24
- other and act in ways that center our shared values, including:
25
-
26
- 1. Respecting the **purpose of our community**, our activities, and our ways of
27
- gathering.
28
- 2. Engaging **kindly and honestly** with others.
29
- 3. Respecting **different viewpoints** and experiences.
30
- 4. **Taking responsibility** for our actions and contributions.
31
- 5. Gracefully giving and accepting **constructive feedback**.
32
- 6. Committing to **repairing harm** when it occurs.
33
- 7. Behaving in other ways that promote and sustain the **well-being of our
34
- community**.
35
-
36
- ## Restricted Behaviors
37
-
38
- We agree to restrict the following behaviors in our community.
39
- Instances, threats, and promotion of these behaviors are violations of this Code
40
- of Conduct.
41
-
42
- 1. **Harassment.** Violating explicitly expressed boundaries or engaging in
43
- unnecessary personal attention after any clear request to stop.
44
- 2. **Character attacks.** Making insulting, demeaning, or pejorative comments
45
- directed at a community member or group of people.
46
- 3. **Stereotyping or discrimination.** Characterizing anyone's personality or
47
- behavior on the basis of immutable identities or traits.
48
- 4. **Sexualization.** Behaving in a way that would generally be considered
49
- inappropriately intimate in the context or purpose of the community.
50
- 5. **Violating confidentiality**. Sharing or acting on someone's personal or
51
- private information without their permission.
52
- 6. **Endangerment.** Causing, encouraging, or threatening violence or other harm
53
- toward any person or group.
54
- 7. Behaving in other ways that **threaten the well-being** of our community.
55
-
56
- ### Other Restrictions
57
-
58
- 1. **Misleading identity.** Impersonating someone else for any reason, or
59
- pretending to be someone else to evade enforcement actions.
60
- 2. **Failing to credit sources.** Not properly crediting the sources of content
61
- you contribute.
62
- 3. **Promotional materials**. Sharing marketing or other commercial content in a
63
- way that is outside the norms of the community.
64
- 4. **Irresponsible communication.** Failing to responsibly present content which
65
- includes, links or describes any other restricted behaviors.
66
-
67
- ## Reporting an Issue
68
-
69
- Tensions can occur between community members even when they are trying their
70
- best to collaborate.
71
-
72
- Not every conflict represents a code of conduct violation, and this Code of
73
- Conduct reinforces encouraged behaviors and norms that can help avoid conflicts
74
- and minimize harm.
75
-
76
- When an incident does occur, it is important to report it promptly.
77
- To report a possible violation, **email [community@better-auth.com](mailto:community@better-auth.com)**
78
-
79
- Community Moderators take reports of violations seriously and will make every
80
- effort to respond in a timely manner.
81
-
82
- They will investigate all reports of code of conduct violations, reviewing
83
- messages, logs, and recordings, or interviewing witnesses and other
84
- participants.
85
-
86
- Community Moderators will keep investigation and enforcement actions as
87
- transparent as possible while prioritizing safety and confidentiality.
88
-
89
- In order to honor these values, enforcement actions are carried out in private
90
- with the involved parties, but communicating to the whole community may be part
91
- of a mutually agreed upon resolution.
92
-
93
- ## Addressing and Repairing Harm
94
-
95
- If an investigation by the Community Moderators finds that this Code of Conduct
96
- has been violated, the following enforcement ladder may be used to determine how
97
- best to repair harm, based on the incident's impact on the individuals involved
98
- and the community as a whole.
99
- Depending on the severity of a violation, lower rungs on the ladder may be
100
- skipped.
101
-
102
- 1. Warning
103
- 1. Event: A violation involving a single incident or series of incidents.
104
- 2. Consequence: A private, written warning from the Community Moderators.
105
- 3. Repair: Examples of repair include a private written apology,
106
- acknowledgement of responsibility, and seeking clarification on
107
- expectations.
108
- 2. Temporarily Limited Activities
109
- 1. Event: A repeated incidence of a violation that previously resulted in a
110
- warning, or the first incidence of a more serious violation.
111
- 2. Consequence: A private, written warning with a time-limited cooldown
112
- period designed to underscore the seriousness of the situation and give
113
- the community members involved time to process the incident.
114
- The cooldown period may be limited to particular communication channels or
115
- interactions with particular community members.
116
- 3. Repair: Examples of repair may include making an apology, using the
117
- cooldown period to reflect on actions and impact, and being thoughtful
118
- about re-entering community spaces after the period is over.
119
- 3. Temporary Suspension
120
- 1. Event: A pattern of repeated violation which the Community Moderators have
121
- tried to address with warnings, or a single serious violation.
122
- 2. Consequence: A private written warning with conditions for return from
123
- suspension.
124
- In general, temporary suspensions give the person being suspended time to
125
- reflect upon their behavior and possible corrective actions.
126
- 3. Repair: Examples of repair include respecting the spirit of the
127
- suspension, meeting the specified conditions for return, and being
128
- thoughtful about how to reintegrate with the community when the suspension
129
- is lifted.
130
- 4. Permanent Ban
131
- 1. Event: A pattern of repeated code of conduct violations that other steps
132
- on the ladder have failed to resolve, or a violation so serious that the
133
- Community Moderators determine there is no way to keep the community safe
134
- with this person as a member.
135
- 2. Consequence: Access to all community spaces, tools, and communication
136
- channels is removed.
137
- In general, permanent bans should be rarely used, should have strong
138
- reasoning behind them, and should only be resorted to if working through
139
- other remedies has failed to change the behavior.
140
- 3. Repair: There is no possible repair in cases of this severity.
141
-
142
- This enforcement ladder is intended as a guideline.
143
- It does not limit the ability of Community Managers to use their discretion and
144
- judgment, in keeping with the best interests of our community.
145
-
146
- ## Scope
147
-
148
- This Code of Conduct applies within all community spaces, and also applies when
149
- an individual is officially representing the community in public or other
150
- spaces.
151
- Examples of representing our community include using an official email address,
152
- posting via an official social media account, or acting as an appointed
153
- representative at an online or offline event.
154
-
155
- ## Attribution
156
-
157
- This Code of Conduct is adapted from the Contributor Covenant, version 3.0,
158
- permanently available at
159
- [https://www.contributor-covenant.org/version/3/0/](https://www.contributor-covenant.org/version/3/0/).
160
-
161
- Contributor Covenant is stewarded by the Organization for Ethical Source and
162
- licensed under CC BY-SA 4.0.
163
- To view a copy of this license, visit
164
- [https://creativecommons.org/licenses/by-sa/4.0/](https://creativecommons.org/licenses/by-sa/4.0/)
165
-
166
- For answers to common questions about Contributor Covenant, see the FAQ at
167
- [https://www.contributor-covenant.org/faq](https://www.contributor-covenant.org/faq).
168
- Translations are provided at
169
- [https://www.contributor-covenant.org/translations](https://www.contributor-covenant.org/translations).
170
- Additional enforcement and community guideline resources can be found at
171
- [https://www.contributor-covenant.org/resources](https://www.contributor-covenant.org/resources).
172
- The enforcement ladder was inspired by the work of
173
- [Mozilla's code of conduct team](https://github.com/mozilla/inclusion).
data/CONTRIBUTING.md DELETED
@@ -1,187 +0,0 @@
1
- # Contributing to Better Auth Ruby
2
-
3
- Thank you for your interest in contributing to Better Auth Ruby!
4
- This guide will help you get started with the contribution process.
5
-
6
- ## Code of Conduct
7
-
8
- This project and everyone participating in it is governed by our
9
- [Code of Conduct](/CODE_OF_CONDUCT.md).
10
- By participating, you are expected to uphold this code.
11
-
12
- ## Project Structure
13
-
14
- ```
15
- lib/
16
- better_auth.rb # Main entry point
17
- better_auth/
18
- version.rb # Version constant
19
- core.rb # Core module loader
20
- core/ # Core authentication logic
21
- rails.rb # Rails adapter entry
22
- rails/ # Rails-specific code
23
-
24
- test/ # Core library tests (Minitest)
25
- spec/ # Rails adapter tests (RSpec)
26
- ```
27
-
28
- ## Development Guidelines
29
-
30
- When contributing to Better Auth Ruby:
31
-
32
- * Keep changes focused. Large PRs are harder to review.
33
- * Follow Ruby conventions and idioms
34
- * Ensure all code passes StandardRB linting
35
- * Write tests for new features
36
- * Maintain backward compatibility when possible
37
-
38
- ## Getting Started
39
-
40
- 1. Fork the repository to your GitHub account
41
-
42
- 2. Clone your fork locally:
43
-
44
- ```bash
45
- git clone https://github.com/your-username/better-auth-ruby.git
46
- cd better-auth-ruby
47
- ```
48
-
49
- 3. Install Ruby (3.2+ required, 3.3 recommended)
50
-
51
- We recommend using a Ruby version manager like rbenv, rvm, or asdf.
52
-
53
- 4. Install dependencies:
54
-
55
- ```bash
56
- bundle install
57
- ```
58
-
59
- 5. Run tests to ensure everything is working:
60
-
61
- ```bash
62
- bundle exec rake ci
63
- ```
64
-
65
- ## Development Workflow
66
-
67
- 1. Create a new branch for your changes:
68
-
69
- ```bash
70
- git checkout -b type/description
71
- # Example: git checkout -b feat/oauth-provider
72
- ```
73
-
74
- Branch type prefixes:
75
-
76
- * `feat/` - New features
77
- * `fix/` - Bug fixes
78
- * `docs/` - Documentation changes
79
- * `refactor/` - Code refactoring
80
- * `test/` - Test-related changes
81
- * `chore/` - Build process or tooling changes
82
-
83
- 2. Make your changes following the code style guidelines
84
-
85
- 3. Run the linter:
86
-
87
- ```bash
88
- bundle exec standardrb --fix
89
- ```
90
-
91
- 4. Add tests for your changes
92
-
93
- 5. Run the test suite:
94
-
95
- ```bash
96
- # Run all tests
97
- bundle exec rake ci
98
-
99
- # Run only core tests
100
- bundle exec rake test
101
-
102
- # Run only Rails adapter tests
103
- bundle exec rspec
104
- ```
105
-
106
- 6. Commit your changes with a descriptive message:
107
-
108
- ```text
109
- feat(rails): add current_user helper method
110
-
111
- fix(core): resolve token validation issue
112
- ```
113
-
114
- 7. Push your branch to your fork
115
-
116
- 8. Open a pull request against the **main** branch
117
-
118
- ## Code Style
119
-
120
- We use [StandardRB](https://github.com/standardrb/standard) for code formatting and linting.
121
- Before committing, please ensure your code passes:
122
-
123
- ```bash
124
- # Check code style
125
- bundle exec standardrb
126
-
127
- # Auto-fix issues
128
- bundle exec standardrb --fix
129
- ```
130
-
131
- ### Ruby Style Guidelines
132
-
133
- * Use 2 spaces for indentation
134
- * Use `snake_case` for methods, variables, and file names
135
- * Use `CamelCase` for classes and modules
136
- * Use `SCREAMING_SNAKE_CASE` for constants
137
- * Add `frozen_string_literal: true` pragma to all Ruby files
138
- * Prefer single quotes for strings without interpolation
139
- * Avoid unnecessary Ruby features (unless they improve readability)
140
-
141
- ## Testing Guidelines
142
-
143
- ### Core Library (Minitest)
144
-
145
- Located in `test/` directory:
146
-
147
- ```ruby
148
- # test/better_auth/some_feature_test.rb
149
- require_relative "test_helper"
150
-
151
- class SomeFeatureTest < Minitest::Test
152
- def test_something
153
- assert_equal expected, actual
154
- end
155
- end
156
- ```
157
-
158
- ### Rails Adapter (RSpec)
159
-
160
- Located in `spec/` directory:
161
-
162
- ```ruby
163
- # spec/better_auth/rails/some_feature_spec.rb
164
- require "spec_helper"
165
-
166
- RSpec.describe BetterAuth::Rails::SomeFeature do
167
- it "does something" do
168
- expect(subject).to eq expected
169
- end
170
- end
171
- ```
172
-
173
- ## Pull Request Process
174
-
175
- 1. Create a draft pull request early to facilitate discussion
176
- 2. Reference any related issues in your PR description
177
- 3. Ensure all tests pass and the build is successful
178
- 4. Update documentation as needed
179
- 5. Keep your PR focused on a single feature or bug fix
180
- 6. Be responsive to code review feedback
181
-
182
- ## Security Issues
183
-
184
- For security-related issues, please email [security@better-auth.com](mailto:security@better-auth.com).
185
- Include a detailed description of the vulnerability and steps to reproduce it.
186
- All reports will be reviewed and addressed promptly.
187
- For more information, see our [security documentation](/SECURITY.md).
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- ruby file: ".ruby-version"
4
-
5
- gemspec
6
-
7
- group :development, :test do
8
- gem "standardrb", "~> 1.0"
9
- gem "minitest", "~> 5.25"
10
- gem "rake", "~> 13.2"
11
- gem "simplecov", "~> 0.22", require: false
12
- end
data/Makefile DELETED
@@ -1,207 +0,0 @@
1
- # Better Auth Ruby - Makefile
2
- # Este archivo te ayuda a ejecutar comandos comunes de desarrollo
3
- # Cada comando tiene comentarios explicativos para aprender
4
-
5
- # Variables de color para hacer la salida más legible
6
- BLUE := \033[36m
7
- GREEN := \033[32m
8
- YELLOW := \033[33m
9
- NC := \033[0m # No Color
10
-
11
- # =============================================
12
- # COMANDOS PRINCIPALES DE DESARROLLO
13
- # =============================================
14
-
15
- # Instala todas las dependencias del proyecto
16
- # Equivale a: bundle install
17
- .PHONY: install
18
- install:
19
- @echo "$(BLUE)📦 Instalando dependencias...$(NC)"
20
- bundle install
21
- @echo "$(GREEN)✓ Dependencias instaladas$(NC)"
22
-
23
- # Configuración inicial del proyecto (primer clone)
24
- # Ejecuta bin/setup que hace bundle install
25
- .PHONY: setup
26
- setup:
27
- @echo "$(BLUE)🔧 Configurando proyecto...$(NC)"
28
- bin/setup
29
- @echo "$(GREEN)✓ Proyecto configurado$(NC)"
30
-
31
- # =============================================
32
- # COMANDOS DE CALIDAD DE CÓDIGO
33
- # =============================================
34
-
35
- # Revisa que el código cumpla con el estilo StandardRB
36
- # Muestra errores pero NO los corrige automáticamente
37
- .PHONY: lint
38
- lint:
39
- @echo "$(BLUE)🔍 Revisando estilo de código...$(NC)"
40
- bundle exec standardrb
41
- @echo "$(GREEN)✓ Código cumple con el estilo$(NC)"
42
-
43
- # Revisa Y AUTOCORRIGE problemas de estilo con StandardRB
44
- # Úsalo cuando quieras formatear todo automáticamente
45
- .PHONY: lint-fix
46
- lint-fix:
47
- @echo "$(BLUE)🔧 Corrigiendo estilo de código automáticamente...$(NC)"
48
- bundle exec standardrb --fix
49
- @echo "$(GREEN)✓ Código corregido$(NC)"
50
-
51
- # =============================================
52
- # COMANDOS DE TESTING
53
- # =============================================
54
-
55
- # Ejecuta TODOS los tests (core + rails adapter)
56
- # Es lo mismo que: bundle exec rake ci
57
- .PHONY: test
58
- test:
59
- @echo "$(BLUE)🧪 Ejecutando todos los tests...$(NC)"
60
- bundle exec rake test
61
- @echo "$(GREEN)✓ Tests completados$(NC)"
62
-
63
- # Ejecuta solo los tests del core (Minitest)
64
- # Son los tests en el directorio test/
65
- .PHONY: test-core
66
- test-core:
67
- @echo "$(BLUE)🧪 Ejecutando tests del core...$(NC)"
68
- bundle exec rake test:core
69
- @echo "$(GREEN)✓ Tests del core completados$(NC)"
70
-
71
- # Ejecuta solo los tests del adapter Rails (RSpec)
72
- # Son los tests en el directorio spec/
73
- .PHONY: test-rails
74
- test-rails:
75
- @echo "$(BLUE)🧪 Ejecutando tests del adapter Rails...$(NC)"
76
- bundle exec rspec
77
- @echo "$(GREEN)✓ Tests de Rails completados$(NC)"
78
-
79
- # Ejecuta tests con cobertura de código
80
- # Genera reporte en coverage/index.html
81
- .PHONY: test-coverage
82
- test-coverage:
83
- @echo "$(BLUE)📊 Ejecutando tests con cobertura...$(NC)"
84
- COVERAGE=true bundle exec rake test
85
- @echo "$(GREEN)✓ Reporte de cobertura en coverage/index.html$(NC)"
86
-
87
- # =============================================
88
- # COMANDOS DE INTEGRACIÓN CONTINUA (CI)
89
- # =============================================
90
-
91
- # Ejecuta TODO el pipeline de CI localmente
92
- # 1. Lint (StandardRB)
93
- # 2. Tests (Minitest + RSpec)
94
- # Esto es lo que corre GitHub Actions en cada PR
95
- .PHONY: ci
96
- ci:
97
- @echo "$(BLUE)🔧 Ejecutando CI completo...$(NC)"
98
- bundle exec rake ci
99
- @echo "$(GREEN)✓ CI completado exitosamente$(NC)"
100
-
101
- # =============================================
102
- # COMANDOS DE DESARROLLO INTERACTIVO
103
- # =============================================
104
-
105
- # Abre una consola interactiva (IRB) con la gema cargada
106
- # Útil para probar código manualmente
107
- .PHONY: console
108
- console:
109
- @echo "$(BLUE)💻 Abriendo consola interactiva...$(NC)"
110
- bin/console
111
-
112
- # =============================================
113
- # COMANDOS DE PUBLICACIÓN (RELEASE)
114
- # =============================================
115
-
116
- # PASO 1: Actualiza la versión en version.rb
117
- # Debes hacerlo manualmente antes de release
118
-
119
- # PASO 2: Crea un git tag con la versión
120
- # Ejemplo: make tag VERSION=0.1.0
121
- .PHONY: tag
122
- tag:
123
- ifndef VERSION
124
- $(error VERSION no está definido. Usa: make tag VERSION=0.1.0)
125
- endif
126
- @echo "$(YELLOW)🏷️ Creando tag v$(VERSION)...$(NC)"
127
- git add -A
128
- git commit -m "chore: release v$(VERSION)"
129
- git tag -a v$(VERSION) -m "Release v$(VERSION)"
130
- @echo "$(GREEN)✓ Tag creado. Ahora haz: git push origin main --tags$(NC)"
131
-
132
- # PASO 3 (MANUAL): Publica la gema a RubyGems manualmente
133
- # Solo úsalo si NO estás usando GitHub Actions
134
- .PHONY: release-manual
135
- release-manual:
136
- @echo "$(YELLOW)📦 Construyendo gema...$(NC)"
137
- gem build better_auth.gemspec
138
- @echo "$(YELLOW)🚀 Publicando a RubyGems...$(NC)"
139
- gem push better_auth-*.gem
140
- @echo "$(GREEN)✓ Gema publicada$(NC)"
141
-
142
- # =============================================
143
- # COMANDOS DE BASES DE DATOS (TESTING)
144
- # =============================================
145
-
146
- # Inicia los contenedores de Docker para testing
147
- # (PostgreSQL, MySQL, Redis)
148
- .PHONY: db-up
149
- db-up:
150
- @echo "$(BLUE)🐳 Iniciando bases de datos...$(NC)"
151
- docker-compose up -d
152
- @echo "$(GREEN)✓ Bases de datos listas$(NC)"
153
-
154
- # Detiene los contenedores de Docker
155
- .PHONY: db-down
156
- db-down:
157
- @echo "$(BLUE)🐳 Deteniendo bases de datos...$(NC)"
158
- docker-compose down
159
- @echo "$(GREEN)✓ Bases de datos detenidas$(NC)"
160
-
161
- # =============================================
162
- # COMANDOS DE LIMPIEZA
163
- # =============================================
164
-
165
- # Limpia archivos temporales y la gema compilada
166
- .PHONY: clean
167
- clean:
168
- @echo "$(BLUE)🧹 Limpiando archivos temporales...$(NC)"
169
- rm -rf *.gem coverage/ .bundle/
170
- @echo "$(GREEN)✓ Limpieza completada$(NC)"
171
-
172
- # =============================================
173
- # AYUDA
174
- # =============================================
175
-
176
- # Muestra todos los comandos disponibles con descripción
177
- .PHONY: help
178
- help:
179
- @echo "$(GREEN)Better Auth Ruby - Comandos disponibles:$(NC)"
180
- @echo ""
181
- @echo "$(YELLOW)Instalación:$(NC)"
182
- @echo " make install - Instala dependencias (bundle install)"
183
- @echo " make setup - Configuración inicial del proyecto"
184
- @echo ""
185
- @echo "$(YELLOW)Desarrollo:$(NC)"
186
- @echo " make console - Abre consola interactiva (IRB)"
187
- @echo " make lint - Revisa estilo de código"
188
- @echo " make lint-fix - Corrige estilo automáticamente"
189
- @echo ""
190
- @echo "$(YELLOW)Testing:$(NC)"
191
- @echo " make test - Ejecuta todos los tests"
192
- @echo " make test-core - Solo tests del core (Minitest)"
193
- @echo " make test-rails - Solo tests Rails (RSpec)"
194
- @echo " make test-coverage - Tests con reporte de cobertura"
195
- @echo " make ci - Ejecuta CI completo (lint + test)"
196
- @echo ""
197
- @echo "$(YELLOW)Bases de datos (Docker):$(NC)"
198
- @echo " make db-up - Inicia PostgreSQL, MySQL, Redis"
199
- @echo " make db-down - Detiene contenedores"
200
- @echo ""
201
- @echo "$(YELLOW)Release:$(NC)"
202
- @echo " make tag VERSION=x.x.x - Crea git tag para release"
203
- @echo " make release-manual - Publica manualmente (NO usar con CI)"
204
- @echo ""
205
- @echo "$(YELLOW)Utilidades:$(NC)"
206
- @echo " make clean - Limpia archivos temporales"
207
- @echo " make help - Muestra esta ayuda"
data/Rakefile DELETED
@@ -1,25 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rake/testtask"
5
-
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/*_test.rb"]
10
- end
11
-
12
- desc "Run StandardRB linter"
13
- task :lint do
14
- sh "bundle exec standardrb"
15
- end
16
-
17
- desc "Auto-fix StandardRB issues"
18
- task "lint:fix" do
19
- sh "bundle exec standardrb --fix"
20
- end
21
-
22
- desc "Run full CI check (lint + test)"
23
- task ci: [:lint, :test]
24
-
25
- task default: :ci