sanity-template
TypeScript icon, indicating that this package has built-in type declarations

2.4.3 • Public • Published

sanity-template

Sanity template developer tools, documentation and specification.

npm install sanity-template --save-dev

npm version

Specification

WARNING: Not ready for public consumption

Documentation

sanity-template is an npm module which exposes both a CLI and a Node.js API.

CLI

# Build template files from `template/` to `build/`
npx sanity-template build --template-values values.json

# The same, but in watch mode
npx sanity-template watch --template-values values.json

# Check if the template is valid
npx sanity-template check

This will copy files from the template directory into the build (which should be gitignored). The files in the build directory will have template variables replaced (<#<varName>#>).

Node.js API

build

The build method returns a Promise instance:

const {build} = require("sanity-template");

build({
  basedir: "path/to/basedir",
  templateValuesPath: "template-values.json"
})
  .then(() => console.log("successfully built"))
  .catch(err => console.error(err));

lockfiles

This will generate lockfiles in all your template's deployment directory. Generating package-lock.json files will reduce build time.

watch

The watch method returns an RxJS Observable instance:

const {watch} = require("sanity-template");

watch({
  basedir: "path/to/basedir",
  templateValuesPath: "template-values.json"
}).subscribe({
  next: ({ type, file }) => console.log(`${type}: ${file}`),
  error: err => console.error(err)
});

check

The check method returns a Promise instance (however you need to check result value for status):

const {check} = require("sanity-template");

check({
  basedir: "path/to/basedir"
})
  .then(({errors, isSuccess}) => {
    if (isSuccess) {
      console.log("the template is valid")
    } else {
      console.error(errors)
    }
  })

Migrate from v1 to v2

migrate

The migrate method is a helper function to convert a template from v1 to v2. When run in the CLI, it will modify the sanity-template.json file to match the syntax required for v2.

npx sanity-template migrate

License

MIT © Sanity.io

Readme

Keywords

none

Package Sidebar

Install

npm i sanity-template

Weekly Downloads

106

Version

2.4.3

License

MIT

Unpacked Size

165 kB

Total Files

116

Last publish

Collaborators

  • tambet
  • jtpetty
  • drewsanity
  • refiito
  • sergeisarviro
  • ash
  • indrek.karner
  • cngonzalez-sanity
  • rdunk
  • rneatherway-sanity
  • ricokahler
  • pedro-sanity
  • jonabc
  • kenjonespizza
  • pauloborgesf
  • binoy14
  • simen.svale
  • svirs
  • josh_sanity_io
  • joneidejohnsen
  • nina.andal
  • rankers
  • snorreeb
  • mattcraig
  • vincentquigley
  • stipsan
  • michael-sanity
  • rubioz
  • tonina
  • ritasdias
  • simeonsanity
  • kmelve
  • bjoerge
  • rexxars
  • skogsmaskin
  • robinpyon
  • mariuslundgard
  • sanity-io
  • evenw
  • radhe_sanity
  • rbotten
  • judofyr
  • obliadp
  • dcilke
  • fredcarlsen
  • hermanw
  • sgulseth
  • atombender