@stackbit/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.0.23 • Public • Published

Stackbit SDK

Stackbit SDK contains set of utilities to work with stackbit.yaml file.

Add to your project

npm install @stackbit/sdk

Generate stackbit.yaml

Create a FileBrowser with FileSystemFileBrowserAdapter or GitHubFileBrowserAdapter:

  • Analyzing a local project:

    import { FileSystemFileBrowserAdapter, FileBrowser } from '@stackbit/sdk';
    
    const fileBrowserAdapter = new FileSystemFileBrowserAdapter({ dirPath: inputDir });
    const fileBrowser = new FileBrowser({ fileBrowserAdapter });
  • Analyzing a remote GitHub project:

    import { GitHubFileBrowserAdapter, FileBrowser } from '@stackbit/sdk';
    
    const fileBrowserAdapter = new GitHubFileBrowserAdapter({
        owner: 'stackbit',
        repo: 'theme',
        branch: 'master',
        auth: GITHUB_PERSONAL_ACCESS_TOKEN
    });
    const fileBrowser = new FileBrowser({ fileBrowserAdapter });

Then, pass the fileBrowser to the analyzeSite() method, get the result and save the config as stackbit.yaml:

import { writeConfig, analyzeSite } from '@stackbit/sdk';

const analyzeResult = await analyzeSite({ fileBrowser });
await writeConfig({ dirPath: inputDir, config: analyzeResult.config });

Validate stackbit.yaml

Load and validate stackbit.yaml. Any errors will be returned within the errors array.

import { loadConfig } from '@stackbit/sdk';

const configResult = await loadConfig({ dirPath: inputDir });

configResult.errors.forEach((error) => {
    console.log(error.message);
});

If configResult.config is not null, pass it to load and validate web-site's content. Any errors will be returned within the errors array, and loaded content within the contentItems:

import { loadContent } from '@stackbit/sdk';

if (configResult.config) {
    return;
}

const contentResult = await loadContent({ dirPath: inputDir, config: configResult.config });

contentResult.contentItems.forEach((contentItem) => {
    console.log(contentItem.__metadata.filePath);
});

contentResult.errors.forEach((error) => {
    console.log(error.message);
});

Versions

Current Tags

Version History

Package Sidebar

Install

npm i @stackbit/sdk

Weekly Downloads

11,201

Version

1.0.23

License

MIT

Unpacked Size

1.08 MB

Total Files

153

Last publish

Collaborators

  • bwwhite
  • bob_netlify
  • noahcrowley-netlify
  • greglobinski
  • seancdavis
  • merlyn_at_netlify
  • cmparsons
  • suzanneaitchison
  • ryanbonial
  • stackbitjoe
  • arseny.gurevich
  • smnh
  • tomasb
  • rodikh
  • berdav
  • stackbit-admin
  • vitaliyr
  • denar90
  • youvalv