2016年6月14日 星期二

【JavaScript】bower 自動化部署 (github安裝)

- bower官方說明:
ignore [array]: An array of paths not needed in production that you want Bower to ignore when installing your package.
- 實作後:
bower.json定義的ignore的屬性,只能排除自己的package,不包含相依的套件
利用bower.json定義需要安裝的相依套件,取出需要的檔案放至自己的目錄結構,當然還要過濾掉不要的檔案。
    分成兩個部分,來完成這個目標:
  1. 在github上建一個bower.json,安裝bower套件後,再利用postinstall複製到預想的目錄結構
  2. 從bower install 自建的github專案,在此專案的bower.json中的ignore就有作用,可刪除不要的檔案與目錄,只留下預想的目錄結構
下面實作lab

Bower custom github install

bower install <github>

ignore [array]: An array of paths not needed in production that you want Bower to ignore when installing your package.」

Description: Because ignore attribute only apply project file, not it’s dependencies project.
copy the latest version to custom structure directory using postinstall at git project
then bower install from git && ignore unwanted file

Collect Bower

Bower Init

generate bower.json

Command:
bower init

Example:
#]bower init
bower existing The existing bower.json file will be used and filled in
? name components
? description test bower install
? main file static/components/angular/angular.js
? keywords bower static file install
? authors yourName yourName@yourDomain
? license MIT
? homepage
? set currently installed components as dependencies? No
? add commonly ignored files to ignore list? Yes
? would you like to mark this package as private which prevents it from being accidentally published to the registry? No
{
  name: 'components',
  authors: [
    'yourName <yourName@yourDomain>'
  ],
  description: 'test bower install',
  main: 'static/components/angular/angular.js',
  license: 'MIT',
  homepage: '',
  directory: 'static/components/',
  ignore: [
    'LICENSE.md',
    'package.json',
    'test',
    'tests',
    '**/.*',
    'node_modules',
    'bower_components'
  ],
  dependencies: {
    angular: 'angular2#^1.5.6'
  },                                                                                                                                                                                                                                         
  keywords: [                                                                                                                                                                                                                                
    'bower',                                                                                                                                                                                                                                 
    'static',                                                                                                                                                                                                                                
    'file',                                                                                                                                                                                                                                  
    'install'                                                                                                                                                                                                                                
  ]                                                                                                                                                                                                                                          
}

Bower Dependencies

diff dependencies && devDependencies

install && save to production’s dependencies at bower.json Command:
bower install bootstrap --save
install && save to production’s devDependencies at bower.json Command:
bower install bootstrap --save-dev

Script Postinstall

postinstall script

STEP1:
create .bowerrc file
Code:
{
  "scripts": {
      "postinstall": "./.bower-postinstall.sh"
  }
}
STEP2:
create postinstall scripts
copy dependencies file to your custom directory ['css', 'js', 'fonts']
Code:
for dir in js fonts css; do
    if [ ! -d $dir ]; then
        mkdir $dir
    fi
done
#minimal=".min"
minimal=""

cp -af bower_components/angular/angular${minimal}.js js/angular${minimal}.js
cp -af bower_components/bootstrap/dist/js/bootstrap${minimal}.js js/bootstrap${minimal}.js
cp -af bower_components/bootstrap/dist/fonts/* fonts/
cp -af bower_components/bootstrap/dist/css/bootstrap-theme${minimal}.css css/bootstrap-theme${minimal}.css
cp -af bower_components/bootstrap/dist/css/bootstrap${minimal}.css css/bootstrap${minimal}.css
cp -af bower_components/jquery/dist/jquery${minimal}.js js/jquery${minimal}.js
cp -af bower_components/angular-google-maps/dist/angular-google-maps${minimal}.js js/angular-google-maps${minimal}.js
cp -af bower_components/lodash/dist/lodash${minimal}.js js/lodash${minimal}.js
cp -af bower_components/angular-simple-logger/dist/angular-simple-logger${minimal}.js js/angular-simple-logger${minimal}.js
STEP3:
run bower install
Command:
bower install

Bower Install

bower install from custom bower repository

Bowerrc

install directory && postinstall setup

STEP1:
create .bowerrc file
Code:
{
  "directory": "static",
  "scripts": {
      "postinstall": "./.bower-postinstall.sh"
  }
}
STEP2:
create postinstall scripts
Code:
rm -rf static/components/.bower.json
rm -rf static/components/bower.json

Bower Ignore

ignore unwanted file

Description:
Edit bower.json
Code:
{
  ...
  "ignore": [
    "**/.*",
    ".*",
    "README.md",
    "bower_components"
  ],
  ...
}

Bower Custom Git Install

install from custom repository

Description:
bower will install to your path <directory>/<bower-project-name>
<dirctory> default is bower_components, it can be override by .bowerrc file
Command:
bower install git@<githubFQDN>:yourName/bower-lab.git

Bower File Result

finally file structure

Result:
#] ls static/components/
total 0
drwxr-xr-x 1 yourAccount yourGroup  20 Jun 13 13:45 .
drwxr-xr-x 1 yourAccount yourGroup  54 Jun 13 13:45 ..
drwxr-xr-x 1 yourAccount yourGroup  64 Jun 13 13:45 css
drwxr-xr-x 1 yourAccount yourGroup 326 Jun 13 13:45 fonts
drwxr-xr-x 1 yourAccount yourGroup 172 Jun 13 13:45 js

2016年6月1日 星期三

【Android】Sqlite 建資料表失敗


  • 問題:
  • Caused by: android.database.sqlite.SQLiteException: near "group": syntax error (code 1): , while compiling: DROP TABLE IF EXISTS group
  • 解決:
  • 參考:sqlite保留字
    The SQL standard specifies a huge number of keywords which may not be used as the names of tables, indices, columns, databases, user-defined functions, collations, virtual table modules, or any other named object.
在Android使用Sqlite做Content Provider,group table跟本沒建起來,所以在升級的時候也找不到table。因為用到的sqlite保留字,原來保留字不僅欄位不行,table名稱不行,自訂的function不行…反正就遇到就知道了 XD

【Travel】東京-富士山行_[5天4夜]_廉航晚去早回攻略 PartⅢ


星期日富士山行程是重點行程,巴士是準點發車,為了不出差錯。前一天先去決濟, 順便定位一下新宿南口的位置,去 4F 的 9 號櫃檯抽號碼牌結帳。隔天很慶幸有先買單,當日六點多起來, 7 點準點在飯店 1F提供的早餐處用餐,搭一站地鐵再走到新宿南口 8 點 5 分到,還有 10 分鐘可以上廁所,剛上車還有空位,還以為沒坐滿, 原來有些乘客是在不同站上車,幾站後就是全部滿坐,而且這是劃位坐,千萬不要去現場才買,最好一個月前先預約,以免買不到票。
到河口湖後,可以租車搭巴士騎腳踏車
  1. 如果想快速遊五湖可以租車
  2. 如果想在幾個點玩可以搭巴士
  3. 想固定兩三個點玩久一點就騎腳踏車
三選一,我是選擇騎踏實地的腳踏車,在河口湖駅對向巷子進入,左手邊就有一家,當天租是一台1500日幣,還有附locker可以鎖車,這樣停在路邊也比較安心。
整個行程非常的eazy,騎腳踏車走三個點,非常的輕鬆愉快

搭纜車到天上山公園 -> ほうとう不動 河口湖北本店 -> 音樂之森美術館

  • 先在河口湖駅內找一下天上山公園的纜車割引卷,原本720日幣,就可以650日幣購入
  • 中午我們就到ほうとう不動,點了名物ほうとう,一份1080日幣,很有飽足感
  • 下午就到「音樂之森美術館」,待一下午,順便買了音樂盒,這裡還有整點的水舞,整體來說還不錯,不過就是門票貴了些(1500日幣/人)

晚上的回程巴士,竟然遇到了塞車,多花了一個多小時才到新宿,不知道是不是星期日特有的 XD