1.0.2 • Published 6 months ago

microcms-schema-gen v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

microCMS Schema Gen

Getting Started

Install

npm i -D microcms-schema-gen

Usage

import * as fs from 'fs';
import * as path from 'path';
import { schema, field } from 'microcms-schema-gen';

const json = schema.api({
  title: field.text({
    name: '記事のタイトル',
    description: '100文字以内で記事のタイトルを入力してください。',
    required: true,
    length: { min: 1, max: 100 },
  }),
});

// Export schema.json
fs.writeFileSync(
  path.join(__dirname, 'schema.json'),
  JSON.stringify(json, null, 2),
);

Export to schema.json:

{
  "apiFields": [
    {
      "fieldId": "title",
      "idValue": "cbi3d4ngqt",
      "kind": "text",
      "name": "記事のタイトル",
      "description": "100文字以内で記事のタイトルを入力してください。",
      "required": true,
      "textSizeLimitValidation": {
        "textSize": {
          "min": 1,
          "max": 100
        }
      }
    }
  ],
  "customFields": []
}

API

schema

schema.api()

Parameters

NameTypeDescription
fieldsobjectフィールド

schema.custom()

Parameters

NameTypeDescription
namestring表示名
fieldIdstringフィールドID
fieldsobjectフィールド

field

method namedescription
text自由入力の1行テキストです。タイトル等に適しています。
textArea自由入力の複数行テキストです。プレーンテキストによる入力となります。
richEditorV2自由入力の複数行テキストです。リッチエディタによる編集が可能です。APIからHTMLが取得できます。
media画像用のフィールドです。APIからは画像URLが返却されます。
mediaList複数の画像用のフィールドです。APIからは画像URLの配列が返却されます。
dateDate型のフィールドです。カレンダーから日時を選択することができます。
booleanBoolean型のフィールドです。スイッチでオン/オフを切り替えることができます。
select定義したリストの中から値を選択するフィールドです。設定により複数選択も可能です。
fileファイル用のフィールドです。APIからはファイルURLが返却されます。
numberNumber型のフィールドです。入力時は数値型のキーボードが開きます。
relation他コンテンツのレスポンスを含むことができます。参照先がリスト型の場合は選択式となります。
relationList他コンテンツを複数参照することができます。レスポンスは配列形式となります。
iframe拡張フィールドを用いて、外部データの読み込みを行うことができます
repeater作成済みのカスタムフィールドを複数選択し、繰り返し入力が可能です
customカスタムフィールドです。設定済みのカスタムフィールドを用いて入力ができます。

field.text()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
isUnique?boolean重複を許可しない
length?object文字数を制限する
length.minnumber最小文字数
length.maxnumber最大文字数
regexp?RegExp特定のパターンのみ入力を許可する。

field.textArea()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
length?object文字数を制限する
length.minnumber最小文字数
length.maxnumber最大文字数
regexp?RegExp特定のパターンのみ入力を許可する。

field.richEditorV2()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
richEditorV2Options?('undo' | 'redo' | 'clean' | 'customClass' | 'link' | 'image' | 'oembedly' | 'listOrdered' | 'listBullet' | 'horizontalRule' | 'bold' | 'headerOne' | 'headerTwo' | 'italic' | 'blockquote' | 'codeBlock' | 'underline' | 'strike' | 'table' | 'code' | 'textAlign' | 'headerThree' | 'headerFour' | 'headerFive' | 'paragraph')[]ツールバーの編集
customClassList{ name: string; value: string; }[]カスタムclass

field.media()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
size?object画像サイズを制限する
size.widthnumber横幅
size.heightnumber縦幅

field.mediaList()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
size?object画像サイズを制限する
size.widthnumber横幅
size.heightnumber縦幅
layout?('HORIZONTAL_SCROLL' | 'GRID_2' | 'GRID_3' | 'GRID_4')レイアウト

field.date()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
dateFormat?boolean日付のみを選択するか

field.boolean()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?string必須項目
initialValue?boolean初期値

field.select()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
selectItemsstring[]選択肢
selectInitialValue?string[]初期値
multiple?boolean複数選択を許可するか

field.file()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目

field.number()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
range?object数値の範囲
range.minnumber最小値
range.maxnumber最大値

field.relation()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目

field.relationList()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
limit?object最大数
limit.maxnumber最大数
limit.minnumber最小数

field.iframe()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
iframeUrlstring拡張フィールド URL

field.repeater()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
fieldsMicroCMSApiSchemaCustomFieldType[]選択肢
limit?object最大数
limit.maxnumber最大数
limit.minnumber最小数

field.custom()

Parameters

NameTypeDescription
displayNamestring表示名
description?string説明文
required?boolean必須項目
fieldMicroCMSApiSchemaCustomFieldTypeカスタムフィールド
1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago