Giter Site home page Giter Site logo

fusion-site-sdk's Introduction

Fusion Site SDK

安装

npm install @alifd/fusion-site-sdk -S

自带 .d.ts文件 支持 Typescript.

API

获取Token

见帮助文档: https://fusion.design/help.html#/dev-create-site

client类

初始化

import Client from '@alifd/fusion-site-sdk';
// 或
const Client = require('@alifd/fusion-site-sdk').default;

// 使用token 初始化token
const client = new Client('your token'); 

// 为了方便开发调试 可以让client链接到不同环境
const client = new Client({
    token: 'your token',
    env: 'prod',  // 全部支持的环境见: https://github.com/alibaba-fusion/fusion-site-sdk/blob/master/src/type.ts
});

环境

默认是外网prod, 内网请使用aliprod, 不同环境token不通用。

重置token

如果token过期 可以通过client实例的方法刷新token.

const client = new Client('your token');

client.setToken('new token'); 

查看环境、Token

const client = new Client('your token');
// 只读 不要修改
client.token; // 'your token'
client.env; // env

user方法群

const user = client.user;

校验token是否有效

async () => {
    const isValid = await user.checkToken();
    // true 代表有效  false 代表 无效或者网络不通
}

获取用户名下的站点

async () => {
    const sites = await user.getSites();
    // sites Array<Site> 具体字段见 https://github.com/alibaba-fusion/fusion-site-sdk/blob/master/src/type.ts 的 IFusionSite
}

site方法群

const {site} = client;

siteId

获取siteId需要先调用获取site的接口

添加物料

async () => {
    // blocks + components + scaffolds  总数不要超过20,数量太多需要切分 多次调用 
    const res = await site.addMaterials(siteId, {
        blocks: ['npm包名@精确版本号', '@alifd/[email protected]'],
        components: ['npm包名@精确版本号', '@alifd/[email protected]'],
        scaffolds: ['npm包名@精确版本号', '@alifd/[email protected]'],
    });
    console.log(res); //成功 {success: true}  失败 {success: false, message: 'xxxxx'}
}

添加区块、模板、组件

以下几个方法是对site.addMaterials方法的封装,方便调用

async () => {
    // 添加区块, 返回值同 site.addMaterials
    const res = site.addBlocks(siteId, ['@alifd/[email protected]']);
    // 添加组件, 返回值同 site.addMaterials
    const res = site.addComponents(siteId, ['@alifd/[email protected]']);
    // 添加模板, 返回值同 site.addMaterials
    const res = site.addScaffolds(siteId, ['@alifd/[email protected]']);
}

fusion-site-sdk's People

Contributors

tao1991123 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.