Skip to content

Commit

Permalink
Use shards version in crystal init tool
Browse files Browse the repository at this point in the history
`shards version` is a new shards command which finds a `shard.yml` in the
directory tree above the path given and returns the version specified in it. We
can use it here to automatically generate the version constant for libraries
directly from shard.yml, meaning it will never be out of sync.

The `VERSION` constant is also moved into the main library file, instead of
being placed in a separate `version.cr`. The old `version.cr` convention
persisted from ruby due to the need for gemspec files to require only the
version constant from the library.
  • Loading branch information
RX14 committed Dec 26, 2017
1 parent 3a5fde0 commit 5ad8bdc
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
13 changes: 3 additions & 10 deletions spec/compiler/crystal/tools/init_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,11 @@ dependencies:
end

describe_file "example/src/example.cr" do |example|
example.should eq(%{require "./example/*"
# TODO: Write documentation for `Example`
example.should eq(%{# TODO: Write documentation for `Example`
module Example
# TODO: Put your code here
end
})
end
VERSION = {{ `shards version \#{__DIR__}`.chomp.stringify }}
describe_file "example/src/example/version.cr" do |version|
version.should eq(%{module Example
VERSION = "0.1.0"
# TODO: Put your code here
end
})
end
Expand Down
1 change: 0 additions & 1 deletion src/compiler/crystal/tools/init.cr
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ module Crystal
template ShardView, "shard.yml.ecr", "shard.yml"

template SrcExampleView, "example.cr.ecr", "src/#{config.name}.cr"
template SrcVersionView, "version.cr.ecr", "src/#{config.name}/version.cr"

template SpecHelperView, "spec_helper.cr.ecr", "spec/spec_helper.cr"
template SpecExampleView, "example_spec.cr.ecr", "spec/#{config.name}_spec.cr"
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/tools/init/template/example.cr.ecr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "./<%= config.name %>/*"

# TODO: Write documentation for `<%= module_name %>`
module <%= module_name %>
VERSION = {{ `shards version #{__DIR__}`.chomp.stringify }}

# TODO: Put your code here
end
3 changes: 0 additions & 3 deletions src/compiler/crystal/tools/init/template/version.cr.ecr

This file was deleted.

0 comments on commit 5ad8bdc

Please sign in to comment.