lib/generators/dockerfile_generator.rb in dockerfile-rails-1.0.6 vs lib/generators/dockerfile_generator.rb in dockerfile-rails-1.0.7
- old
+ new
@@ -102,11 +102,13 @@
Bundler.with_original_env { install_gems }
template 'Dockerfile.erb', 'Dockerfile'
template 'dockerignore.erb', '.dockerignore'
- template 'node-version.erb', '.node-version' if using_node?
+ if using_node? and node_version =~ /\A\d+\.\d+\.\d+\z/
+ template 'node-version.erb', '.node-version'
+ end
template 'docker-entrypoint.erb', 'bin/docker-entrypoint'
chmod "bin/docker-entrypoint", 0755 & ~File.umask, verbose: false
template 'docker-compose.yml.erb', 'docker-compose.yml' if options.compose
@@ -384,13 +386,20 @@
'sqlite3'
end
end
def node_version
- if File.exist? '.node_version'
- IO.read('.node_version')[/\d+\.\d+\.\d+/]
+ if File.exist? '.node-version'
+ IO.read('.node-version')[/\d+\.\d+\.\d+/]
else
- `node --version`[/\d+\.\d+\.\d+/]
+ version = nil
+
+ if File.exist? 'package.json'
+ version = JSON.parse(IO.read('package.json')).dig("engines", "node")
+ version = nil unless version =~ /\A(\d+\.)+(\d+|x)\z/
+ end
+
+ version || `node --version`[/\d+\.\d+\.\d+/]
end
rescue
"lts"
end