Linux Code Push環境搭建

所需環境:

數據庫,nodejs,git

下載 code-push-server 倉庫

git clone https://github.com/lisong/code-push-server.git

cd code-push-server && npm install

# 啓動後登陸默認賬號,獲取access key
account: admin
password: 123456

修改默認配置,需要改動db模塊配置數據庫,local模塊配置bundle下載配置

vi config/config.js
# 初始化數據庫
./bin/db init --dbhost localhost --dbuser root --dbpassword 數據庫密碼
# 啓動Code Push服務
./bin/www

客戶端

# 全局安裝微軟提供的code-push-cli工具
npm install code-push-cli@latest -g


# 常用code-push命令
# 註冊賬號: 
code-push register

# 登陸: 
code-push login

# 查看當前登陸賬號: 
code-push whoami

# 註銷: 
code-push logout

# 添加項目: 
code-push app add app名稱

# 刪除項目: 
code-push app remove app名稱

# 列出賬號下的所有項目: 
code-push app list

# 顯示登陸的token: 
code-push access-key ls

# 部署一個環境: 
code-push deployment add appName deploymentName

# 刪除部署: 
code-push deployment rm appName

# 列出應用的部署: 
code-push deployment ls appName

# 查詢部署環境的key: 
code-push deployment ls appName -k

# 例
code-push login http://localhost:3000
code-push app add CodePushDemoIos ios react-native
code-push app add CodePushDemoAndroid android react-native
# 其中Production對應的是生產的Deployment Key,Staging是開發時使用。
code-push deployment ls CodePushDemoAndroid -k

React Native配置Code Push

# 項目中導入CodePush代碼
npm install --save react-native-code-push
# 關聯項目
react-native link react-native-code-push
new CodePush("xxxxxxxxxxxxx", MainApplication.this, BuildConfig.DEBUG,"http://你的IP:端口/")

componentDidMount() {
    CodePush.sync({
        //啓動模式三種:ON_NEXT_RESUME、ON_NEXT_RESTART、IMMEDIATE
        installMode: CodePush.InstallMode.ON_NEXT_RESTART,
        // 蘋果公司和中國區安卓的熱更新,是不允許彈窗提示的,所以不能設置爲true
        updateDialog: false  
    });
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章