mac下安装pomelo

壹、| 安装必要项

一、安装Xcode及相关工具

1、安装Xcode

2、安装相应版本的command line tools

下载command line tools需要一个苹果账号,如果没有的话注册一个就OK。


Tip:桌面状态command + shift + g (即打开前往文件夹窗口),输入/Library/Developer/CommandLineTools回车, 如果存在该文件夹说明安装成功。


二、安装Node.js

1、官方下载点这里

2、安装后文件夹Node被放在/usr/local/bin/node,文件夹npm被放在/usr/local/bin/npm。正常情况下$PATH(环境变量的PATH中)中应该有路径/usr/local/bin

三、安装pomelo

1、打开终端,切换到root权限

$ sudo -i

回车后需要输入本机用户密码(就是电脑登陆密码)。

2、安装pomelo项目

先转到需要安装的目录,例如:

$ cd /Users/apple/Documents/WorkSpace

安装

$ npm install pomelo -g

》 可能出现的错误

1、错误提示:

xcrun: error: active developer path
("/Volumes/Xcode/Xcode.app/Contents/Developer") does not exist, use
xcode-select to change 

2、解决方案:

$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer 

参考源:在mac pro 上使用 gcc 命令


貳、| pomelo HelloWorld项目

一、创建项目

在当前目录下新建一个HelloWorld项目

$ pomelo init ./HelloWorld

二、安装必要的两个npm依赖库express和crc

每次新建项目都需要安装依赖库。

1、切换到HelloWorld所在目录

$ cd /private/var/root/HelloWorld

2、安装依赖库文件

$ sh npm-install.sh

可以用上面的这个文件npm-install安装,也可以自己下载这两个依赖库。上面这种方式下载速度可能有点慢,可以自己设置。自己设置的方法还未尝试,读者可自行摸索。

三、启动game-server服务器

1、进入game-server目录

$ cd game-server

2、启动game-server

$ pomelo start

》 可能出现的错误

1、错误提示

    throw err;
          ^

Error: Cannot find module 'pomelo'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/apple/Documents/WorkSpace/Cocos2d-x/Projects/HelloWorld/game-server/app.js:1:76)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10) 

2、解决方法
/usr/local/lib/node_modules/路径下新建文件夹pomelo 在相应位置创建pomelo文件夹。如果没有添加依赖库也会出现此类错误。


四、启动web-server服务器:

终端进行新建窗口后输入

$ sudo -i
$ cd /private/var/root/HelloWorld/web-server
$ node app 

启动后会给出一个ip地址,例如:http://127.0.0.1:3001/index.html这个地址可以更改具体更改方法详见 官方:使用 WebStorm IDE 调试 Pomelo 应用程序

在浏览器中输入上述 ip,点击Test Game Server后弹出如下对话框说明HelloWorld连接成功

<iframe id="iframe_0.9295181375928223" style="margin: 0px; padding: 0px; border-style: none; width: 630px; height: 555px;" src="data:text/html;charset=utf8,%3Cstyle%3Ebody%7Bmargin:0;padding:0%7D%3C/style%3E%3Cimg%20id=%22img%22%20src=%22https://github.com/NetEase/pomelo/wiki/images/helloworld_test_snapshot.png?_=3979347%22%20style=%22border:none;max-width:669px%22%3E%3Cscript%3Ewindow.onload%20=%20function%20()%20%7Bvar%20img%20=%20document.getElementById('img');%20window.parent.postMessage(%7BiframeId:'iframe_0.9295181375928223',width:img.width,height:img.height%7D,%20'http://www.cnblogs.com');%7D%3C/script%3E" frameborder="0" scrolling="no"></iframe>

五、关闭game-server服务器

1、进入game-server所在目录。

2、使用pomelo stop命令关闭。

叁、| 参考资料

一、官方:安装pomelo

二、官方:pomelo wiki(中文版)

猜你喜欢

转载自1197757723.iteye.com/blog/2356448