-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the crystal lib generator code. #800
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
require "yaml" | ||
|
||
class ShardFileGenerator | ||
getter project_name : String | ||
getter? generate_auth : Bool | ||
getter? browser : Bool | ||
getter? with_sec_tester : Bool | ||
|
||
def initialize( | ||
@project_name : String, | ||
@generate_auth : Bool, | ||
@browser : Bool, | ||
@with_sec_tester : Bool | ||
) | ||
end | ||
|
||
private def project_base_dependencies | ||
{ | ||
lucky: {github: "luckyframework/lucky", version: "~> 1.0.0"}, | ||
avram: {github: "luckyframework/avram", version: "~> 1.0.0"}, | ||
carbon: {github: "luckyframework/carbon", version: "~> 0.3.0"}, | ||
carbon_sendgrid_adapter: {github: "luckyframework/carbon_sendgrid_adapter", version: "~> 0.3.0"}, | ||
lucky_env: {github: "luckyframework/lucky_env", version: "~> 0.1.4"}, | ||
lucky_task: {github: "luckyframework/lucky_task", version: "~> 0.1.1"}, | ||
} | ||
end | ||
|
||
private def project_auth_dependencies | ||
{ | ||
authentic: {github: "luckyframework/authentic", version: "~> 1.0.0"}, | ||
jwt: {github: "crystal-community/jwt", version: "~> 1.6.0"}, | ||
} | ||
end | ||
|
||
private def project_browser_dev_dependencies | ||
{ | ||
lucky_flow: {github: "luckyframework/lucky_flow", version: "~> 0.9.0"}, | ||
} | ||
end | ||
|
||
private def project_additional_dev_dependencies | ||
{ | ||
lucky_sec_tester: {github: "luckyframework/lucky_sec_tester", version: "~> 0.2.0"}, | ||
} | ||
end | ||
|
||
private def add_dependency(yaml, dep_name, details) | ||
yaml.scalar dep_name.to_s | ||
yaml.mapping do | ||
details.each do |key, value| | ||
yaml.scalar key.to_s | ||
yaml.scalar value.to_s | ||
end | ||
end | ||
end | ||
|
||
def render(project_directory : String) | ||
File.open(File.join(project_directory, "shard.yml"), "w") do |f| | ||
YAML.build(f) do |yaml| | ||
yaml.mapping do | ||
yaml.scalar "name" | ||
yaml.scalar project_name | ||
yaml.scalar "version" | ||
yaml.scalar "0.1.0" | ||
yaml.scalar "crystal" | ||
yaml.scalar ">= #{Crystal::VERSION}" | ||
yaml.scalar "targets" | ||
yaml.mapping do | ||
yaml.scalar project_name | ||
yaml.mapping do | ||
yaml.scalar "main" | ||
yaml.scalar File.join("src", "#{project_name}.cr") | ||
end | ||
end | ||
yaml.scalar "dependencies" | ||
yaml.mapping do | ||
project_base_dependencies.each do |dep_name, details| | ||
add_dependency(yaml, dep_name, details) | ||
end | ||
|
||
if generate_auth? | ||
project_auth_dependencies.each do |dep_name, details| | ||
add_dependency(yaml, dep_name, details) | ||
end | ||
end | ||
end | ||
yaml.scalar "development_dependencies" | ||
yaml.mapping do | ||
if browser? | ||
project_browser_dev_dependencies.each do |dep_name, details| | ||
add_dependency(yaml, dep_name, details) | ||
end | ||
end | ||
if with_sec_tester? | ||
project_additional_dev_dependencies.each do |dep_name, details| | ||
add_dependency(yaml, dep_name, details) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how this looks on Windows, by we may need to see if there's some sort of
Crystal::System::FileSeparator
or whatever. I'm assuming on Windows we'd need tochomp('\')
...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you can use
File
methods for dealing withPath
s, because they are just wrappers aroundPath
, I'd recommend to just usePath
directly instead. It makes it more clear what you're doing (e.g. path manipulation), and useFile
for actual filesystem operations (e.g. read/write a file).You don't actually need
#chomp
here:But this is my suggestion (which is the same as
File#join
, just prefer usingPath
):However, my above suggestion would be better suited in a separate PR to change all other places using
File
instead ofPath
(I might add this to my lucky_template work).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I never thought about using
Path
until I started seeing your code. I think that makes more sense. Maybe I'll just merge this PR in as-is, then in another one we can go through it all and really start cleaning stuff up.