我正在为一些内部项目构建一个简单的基于 thor
的生成器,但似乎无法从正确的目录运行 bundle install
。
当我运行新的 [APP_NAME] 函数时,它应该创建目录和文件,然后运行 bundle install
来安装应用程序所需的 gem。 p>
生成器函数的来源:
def create
puts "Creating application #{name}"
directory 'application', "#{name}"
Dir.chdir("#{Dir.pwd}/#{name}") do
puts `bundle install`
end
end
运行调用此创建方法的命令的控制台输出:
$ bundle exec bin/my_gem new test_app
Creating application test_app
create test_app
create test_app/Gemfile
create test_app/Guardfile
create test_app/README.md
create test_app/app/controllers
create test_app/app/helpers
create test_app/app/models
create test_app/app/views
Using thor (0.14.6)
Using my_gem (0.0.1)
Using bundler (1.1.3)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
如您所见,它正在运行 bundle install
但它在我当前的目录中运行 (thor
, bundler
, my_gem
),相对于 test_app
目录(guard
、guard-coffeescript
、guard-less
,以及其他)。
运行其他命令,如 ls
或 pwd
给出预期的结果:
Gemfile
Guardfile
README.md
app
和
/Users/davidlumley/Development/Gems/my_gem/test_app
不确定这是否有任何区别,但我使用 RVM 来管理我的 ruby 。
最佳答案
听起来您的应用已经在使用 bundler ,并且您遇到了 bundler 内部 bundler 问题。试试这个:
Bundler.with_clean_env do
puts `bundle install`
end
我猜你的外部打包器将 BUNDLE_GEMFILE
环境变量设置为你应用的 Gemfile,然后你的内部打包器最终继承了它。
关于ruby - bundle 安装从错误的目录运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10185552/