2015-05-07 52 views
1

編輯:請參見下面更新部分,在這裏我根據給出的解決方案建議配置家園,爲Windows用戶工作

我使用的無業遊民與我的win7機器上的宅基地修改了代碼。我想安裝一些gulp軟件包,例如gulp-uncss,它不起作用,因爲我在下面添加了錯誤。

一些研究,並在#npm IRC頻道討論我暗示了這個問題以後這裏:

https://github.com/npm/npm/wiki/Troubleshooting#running-a-vagrant-box-on-windows-fails-due-to-path-length-issues

根據此項,Windows用戶使用的流浪漢時,因爲共享仍然有問題主機和來賓機之間的文件夾的最大字符數限制爲260個字符,這一直是Windows開發的主要問題。

一個解決方案似乎是改變流浪者檔案和規定。

這裏是最初的錯誤:

[email protected]:~/Code/Wordpress/wp-content/themes/expimo$ gulp uncss 
[10:51:07~/Code/Wordpress/wp-content/themes/expimo/gulpfile.js 
[10:51:07] Starting 'uncss'... 

/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/bluebird/js/main/async.js:43 
     fn = function() { throw arg; }; 
           ^
TypeError: Bad argument 
    at TypeError (native) 
    at ChildProcess.spawn (child_process.js:1136:26) 
    at /home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/lib/spawn.js:82:38 
    at init (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePro 
    at new Promise (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:27:53) 
    at Function.promise (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/when.js:97:10) 
    at startPhantom (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/lib/spawn.js:58:25) 
    at tryCatchReject (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:845:30) 
    at runContinuation1 (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:804:4) 
    at Fulfilled.when (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:592:4) 
    at Pending.run (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:483:13) 
    at Scheduler._drain (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/Scheduler.js:62:19) 
    at Scheduler.drain (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/Scheduler.js:27:9) 
    at process._tickCallback (node.js:355:11) 

正如我剛纔從入門的理解,就是我要修改我的Vagrantfile,甚至添加一些規定?

這是我當前的默認Vagrantfile通過宅基地補充說:

require 'json' 
require 'yaml' 

VAGRANTFILE_API_VERSION = "2" 

homesteadYamlPath = File.expand_path("~/.homestead/Homestead.yaml") 
afterScriptPath = File.expand_path("~/.homestead/after.sh") 
aliasesPath = File.expand_path("~/.homestead/aliases") 

require_relative 'scripts/homestead.rb' 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    if File.exists? aliasesPath then 
     config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases" 
    end 

    Homestead.configure(config, YAML::load(File.read(homesteadYamlPath))) 

    if File.exists? afterScriptPath then 
     config.vm.provision "shell", path: afterScriptPath 
    end 
end 

而且很顯然,我必須在這裏插入規定的修改: https://github.com/renobit/vagrant-node-env/commit/bdf15f2f301e2b1660b839875e34f172ea8be227

這個Vagrantfile內部,使得宅基地正常工作的窗口。

由於我剛開始使用流浪漢,我的知識非常有限,因此我希望能夠就此話題獲得任何幫助。先謝謝你。

UPDATE

UPDATE大衛邁爾斯建議:

我修改Vagrantfile根據下面無濟於事大衛邁爾斯建議:

require 'json' 
require 'yaml' 

VAGRANTFILE_API_VERSION = "2" 
confDir = $confDir ||= File.expand_path("~/.homestead") 

homesteadYamlPath = confDir + "/Homestead.yaml" 
afterScriptPath = confDir + "/after.sh" 
aliasesPath = confDir + "/aliases" 

require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb') 

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 
    if File.exists? aliasesPath then 
     config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases" 
    end 


     # this should be inserted right before the "Homestead.configure()" line 
     config.vm.provider "virtualbox" do |v, override| 
      if Vagrant::Util::Platform.windows? 
       override.vm.synced_folder "./Code", "/home/vagrant/Code", disabled: true 

       v.customize ["sharedfolder", "add", :id, "--name", "Code", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/Code").gsub("/","\\"))] 

       override.vm.provision :shell, inline: "mkdir -p /home/vagrant/Code" 
       override.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` Code /home/vagrant/Code", run: "always" 
      else 
       override.vm.synced_folder "./Code", "/home/vagrant/Code" 
      end 

      v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Code", "1"] 
     end 
     # this should be inserted right before the "Homestead.configure()" line 



    Homestead.configure(config, YAML::load(File.read(homesteadYamlPath))) 

    if File.exists? afterScriptPath then 
     config.vm.provision "shell", path: afterScriptPath 
    end 
end 

而且我也註釋掉您在我的Homestead.yaml文件中指出的三行:

--- 
ip: "192.168.10.10" 
memory: 2048 
cpus: 1 
provider: virtualbox 

authorize: ~/.ssh/id_rsa.pub 

keys: 
    - ~/.ssh/id_rsa 

# folders: 
# - map: ~/Code 
#  to: /home/vagrant/Code 

sites: 
    - map: expimo.app 
     to: /home/vagrant/Code/Wordpress 
    - map: laravel.app 
     to: /home/vagrant/Code/laravel/public 

databases: 
    - homestead 

variables: 
    - key: APP_ENV 
     value: local 

不幸的是當時我得到的錯誤信息:

沒有輸入文件中指定,因爲它似乎這些URI並不指向正確的文件夾。

如果我然後在我的homestead.yaml文件中再次取消註釋這三行,並保留修改的Vagrantfile,當我嘗試通過「npm install gulp-uncss-」安裝gulp-uncss時,保存-dev的」。

接下來應該做什麼?

回答

2

我是實施您提到的修復程序的人。 :)

我個人還沒有遇到與Homestead這個問題,但我想我知道你需要做什麼。首先,你需要註釋掉Homestead.yaml文件這些行:

folders 
- map: ~/Code 
    to: /home/vagrant/Code 

接下來,你需要這個配置添加到您的Vagrantfile

# this should be inserted right before the "Homestead.configure()" line 
config.vm.provider "virtualbox" do |v, override| 
    if Vagrant::Util::Platform.windows? 
     override.vm.synced_folder "./Code", "/home/vagrant/Code", disabled: true 

     v.customize ["sharedfolder", "add", :id, "--name", "Code", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/Code").gsub("/","\\"))] 

     override.vm.provision :shell, inline: "mkdir -p /home/vagrant/Code" 
     override.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` Code /home/vagrant/Code", run: "always" 
    else 
     override.vm.synced_folder "./Code", "/home/vagrant/Code" 
    end 

    v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Code", "1"] 
end 
# this should be inserted right before the "Homestead.configure()" line 

注意在前面程序的意見;您需要確保在Homestead配置運行之前插入它。

注意:此腳本假定您正在共享一個名爲「代碼」的目錄,該目錄位於與此Vagrantfile相同的目錄中。

+0

嗨大衛,謝謝你的努力。 Unfortunatley的解決方案似乎並不那麼簡單,因爲它仍然不起作用。我更新了上面的條目以反映您的建議。 – LoveAndHappiness

+0

你介意告訴我共享目錄在你的機器上的位置嗎? –

+0

它只是在C:/用戶/格奧爾格/代碼 證明:http://imgur.com/IYLqPEp,lGE9f4Z,d7ak6vQ – LoveAndHappiness

2

我在Windows上爲Homestead提供了一個完整的指導/演練,它解決了所有這些問題(以及其他問題,如緩存winnfsd /等問題)以及Laravel 5 & Lumen的解決方案。我將保持這個Gist最新(並不斷提高它的可讀性)。您可以在這裏找到,要點是:https://gist.github.com/prograhammer/9493ee04f30dd74e121b

在這一要義,我不得不幾步添加到大衛邁爾斯解決方案:

更新C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.2\plugins\providers\virtualbox\driver\version_4_3.rb線附近某處495-510,與'\\\\?\\' + folder[:hostpath].gsub(/[\/\\]/,'\\')]

更換線 folder[:hostpath]

更新C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.2\lib\vagrant\util\platform.rb和註釋掉這一節的重要組成部分:

# This expands the path and ensures proper casing of each part 
# of the path. 

def fs_real_path(path, **opts) 

    #path = Pathname.new(File.expand_path(path)) 
    # 
    # if path.exist? && !fs_case_sensitive? 
    # # Build up all the parts of the path 
    # original = [] 
    # while !path.root? 
    # original.unshift(path.basename.to_s) 
    # path = path.parent 
    # end 
    # 
    # # Traverse each part and join it into the resulting path 
    # original.each do |single| 
    # Dir.entries(path).each do |entry| 
    #  if entry.downcase == single.encode('filesystem').downcase 
    #  path = path.join(entry) 
    #  end 
    # end 
    # end 
    #end 
    # 
    # if windows? 
    # # Fix the drive letter to be uppercase. 
    # path = path.to_s 
    # if path[1] == ":" 
    # path[0] = path[0].upcase 
    # end 
    # 
    # path = Pathname.new(path) 
    #end 

    path 
end 

現在無業遊民了。