ContentfulCLIのインストールでContentful Guideをスタートする

2021.03.05

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、yagiです。

先日、 以下の記事

CircleCI × Contentful × S3で作るJamstackなブログ環境。

を参照して、ContentfulとGatsbyアプリを連携させ、簡単なブログをローカルに立ち上げました。

本日はContentfulのGuideを始めるにあたり、ContentfulCLIをインストールしたので、今回インストールした手順を記載しようと思います。

なお、ContentfulのGuideはメールで送られてきます。

「Get started with Contentful」を押下して、Guideのサイトにアクセスします。

ContentfulCLIのインストール

以下よりインストールを行いました。

Installing the Contentful CLI

Homebrew を利用してインストールしました。npm、yarnでも可能です。

% brew install contentful-cli
Updating Homebrew...
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
  
  ・・・・
  
 ==> Summary
?  /usr/local/Cellar/node/15.11.0: 3,298 files, 56.5MB
==> Installing contentful-cli
==> Pouring contentful-cli-1.5.35.catalina.bottle.tar.gz
?  /usr/local/Cellar/contentful-cli/1.5.35: 17,563 files, 78.7MB
==> Caveats
==> icu4c
icu4c is keg-only, which means it was not symlinked into /usr/local,
because macOS provides libicucore.dylib (but nothing else).

If you need to have icu4c first in your PATH, run:
  echo 'export PATH="/usr/local/opt/icu4c/bin:$PATH"' >> ~/.zshrc
  echo 'export PATH="/usr/local/opt/icu4c/sbin:$PATH"' >> ~/.zshrc

For compilers to find icu4c you may need to set:
  export LDFLAGS="-L/usr/local/opt/icu4c/lib"
  export CPPFLAGS="-I/usr/local/opt/icu4c/include"

これでインストール完了です。

ContentfulCLIによる認証

Authentication with the Contentful CLI を参照し、認証(アクセストークンコード)情報を入力してログインをします。

% contentful login

A browser window will open where you will log in (or sign up if you don’t have an account), authorize this CLI tool and paste your CMA token here:

? Open a browser window now?

ブラウザで開くかを聞いてくるので、yでブラウザを開きます。

ブラウザ側で以下の画面が表示されるので、「Authorize」 をクリックします。

すると、アクセストークンコードが表示されます。

「Copy to clipboard」でコピーします。

それを先ほどの 

? Paste your token here: [input is hidden]

 行にペーストします。

以下のように出力されればOKです。

Great! Your CMA token is now stored on your system. (Located at /Users/yukoyagi/.contentfulrc.json)
You can always run contentful logout to remove it.

ContentfulCLIのconfigリストの表示

Configuration of the Contentful CLI

以下のコマンドでconfigリストを表示、確認できます。(なお、リストに項目を適宜追加、削除できます。)

% contentful config list 

┌───────────────────────────────────────────────────────────────────────────────────┐
│ ⚙  managementToken: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   │
│ ⚙  activeEnvironmentId: master                                                    │
│ ⚙  host: api.contentful.com                                                       │
└───────────────────────────────────────────────────────────────────────────────────┘

これで完了です。

以下のコマンドで、ガイドをスタートします。

% contentful guide


   ____            _             _    __       _    ____       _     _      
  / ___|___  _ __ | |_ ___ _ __ | |_ / _|_   _| |  / ___|_   _(_) __| | ___ 
 | |   / _ \| '_ \| __/ _ \ '_ \| __| |_| | | | | | |  _| | | | |/ _` |/ _ \
 | |__| (_) | | | | ||  __/ | | | |_|  _| |_| | | | |_| | |_| | | (_| |  __/
  \____\___/|_| |_|\__\___|_| |_|\__|_|  \__,_|_|  \____|\__,_|_|\__,_|\___|

結論

Contentfulついて、ContentfulCLIのインストール方法について記載しました。

以下にContentfulの開発者向けラーニングビデオがあります。(ContentfulCLIとログインの流れについても一通り説明があります)

Bits and Bytes