2017年7月7日 星期五

一些常用的 npm 指令

npm 要常更新
$npm i -g npm 

初始化 node project , 建立 package.json
$ npm init

初始化 node project , 有沒有 y 的差別在於,沒有 y 時,npm 會以互動方式詢問要建在 package.json 的項目內容,諸如 package name, description 等等。有 y 時 npm 就會使用預設值,一次建立完成。
$ npm init -y [ --yes ]

範例如下:
D:\tmp\testnpm2>npm init -y
Wrote to D:\tmp\testnpm2\package.json:
{
  "name": "testnpm2",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


安裝目前目錄下 package.json 下 dependencies 列的套件
$npm install  
全域安裝
套件                                      
$ npm install <package name> -g

移除全域套件
$ npm install <package name> -g

安裝最新版本的 Package
$ npm install <package name>@latest

列出全域套件

$ npm ls -g

更新全域套

$ npm update -g

安裝套件,套件僅列在 devDependencies ,同 --save-dev

npm install <package name> -D   

2017年7月5日 星期三

Firebase CLI 使用

Firebase CLI 主要是用來管理 及部署  firebase 專案,目前常用到的就是初始化專案及佈署 Cloud functions, Hosting SPA ......

首先要安裝 Firebase CLI (當然要先安裝 Node.Js 環境 ) 如下:
$ npm install -g firebase-tools (記得用安裝命令來更新到最新版本) 

再來是登入 Firebase 
$ firebase login  ( 會跳出一個登入畫面 )



還會跳出一個登入成功的頁面



初始化 firebase,要先建立專案目錄,移到該目錄下再執行 INIT。
$ firebase init
選擇要建立的設定檔,有 realtime database rule,cloud functions , Hosting


D:\WorkSpace\firebase\recipe-book-4ng>firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  D:\WorkSpace\firebase\recipe-book-4ng

? Are you ready to proceed? Yes
? Which Firebase CLI features do you want to setup for this folder? Press Space to select features, then Enter to confirm you
r choices. Database: Deploy Firebase Realtime Database Rules, Functions: Configure and deploy Cloud Functions, Hosting: Confi
gure and deploy Firebase Hosting sites

=== Project Setup ( 目前的目錄是要建給哪個 project 用的 )

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

? Select a default Firebase project for this directory: recipe-book-4ng (recipe-book-4ng)

=== Database Setup ( realtime database 的 rule 設定 , 看 firebase console database )

Firebase Realtime Database Rules allow you to define how your data should be
structured and when your data can be read from and written to.

? What file should be used for Database Rules? database.rules.json
+  Database Rules for recipe-book-4ng have been downloaded to database.rules.json.
Future modifications to database.rules.json will update Database Rules when you run
firebase deploy.

=== Functions Setup ( Cloud functions 的功能,執行在 Node.js 環境 )

A functions directory will be created in your project with a Node.js
package pre-configured. Functions can be deployed with firebase deploy.

+  Wrote functions/package.json
+  Wrote functions/index.js
? Do you want to install dependencies with npm now? Yes
npm notice created a lockfile as package-lock.json. You should commit this file.
added 90 packages in 17.299s

=== Hosting Setup (設定 static html page , 使用 Angular 2 建立的 SPA )

Your public directory is the folder (relative to your project directory) that
will contain Hosting assets to be uploaded with firebase deploy. If you
have a build process for your assets, use your build's output directory.

? What do you want to use as your public directory? public
? Configure as a single-page app (rewrite all urls to /index.html)? Yes
+  Wrote public/index.html

i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

+  Firebase initialization complete!



2017年7月3日 星期一

Extend Disk of VirtualBox

剛開始建立 VirtualBox 虛擬機器,只留作業系統的實體空間,以便以後做各種測試環境的來源,可是後來遇到要安裝軟體時,安裝程式會檢查可空間夠不夠用,這時只好乖乖的把存放裝置變大:

1. 先確認虛擬硬碟的位置 ( 虛擬機器 > 設定值)

2.確認大小


3.卸除虛擬硬碟


4. 使用Vboxmanage.exe 命令工具修改檔案大小
( Vboxmanage modifymedium  <fileName>  --resize  <size>


5.然後再把硬碟加回去,開啟虛擬機器,再從系統管理員的硬碟管理工具將未配置的部分,使用延伸磁區加進來


一些常用的 npm 指令

npm 要常更新 $npm i -g npm  初始化 node project , 建立 package.json $ npm init 初始化 node project , 有沒有 y 的差別在於,沒有 y 時,npm 會以互動方式詢問要建在 package.js...