JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q55561F
  • License ISC

A module for consuming bit components out of a remote scope

Package Exports

  • bit-scope-client
  • bit-scope-client/bit-id
  • bit-scope-client/bit-json
  • bit-scope-client/component-resolver

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (bit-scope-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

bit-scope-client

This pacakge is working with the bit project, as a client for the scopes created by bit. You can use it to fetch bit components out of remote scopes and put them in the components directory.

API

fetchComponents (componentIds: string[]): Promise<Response[]>

gets an array of component ids and returns an array of responses with component and dependencies objects as payload.

const { fetchComponents } = require('bit-scope-client');

const componentIds = ['bit.utils/array/flat-map', 'bit.promise/global/promisify', 'bit.utils/array/diff'];

fetchComponents(componentIds)
.then((componentDependenciesArr) => {
  componentDependenciesArr.forEach((response) => {
    console.log(response.payload)
    // { component: Component, dependencies: Component[] }
    console.log(response.headers)
    // { version: "0.5.0" }
  });
});

The return value is a promise with an Array of objects contains the main Component and its dependencies.

writeComponents (responses: Response[], customDir: ?string): Promise<{ component: Component, dependencies: Component[] }

Takes responses and model them on the file system in components directory, returns a components array.

The second argument is a custom directory (other then components direcotory on the current working directory)

importComponents (componentIds: string[]): Promise<{ component: Component, dependencies: Component[] }>

performs fetch and then write.

Component is an object with the following structure

{
    "component": {
        "scope": "component scope",
        "name": "component name",
        "box": "component namespace",
        "impl": {
            "file": "file contents",
            "name": "impl.js"
        },
        "specs": {
            "file": "file contents",
            "name": "spec.js"
        },
        "dist": {
            "file": "file contents",
            "name": "dist.js"
        },
        "compiler": "component-id/none",
        "tester": "component-id/none",
        "log": {
            "message": "exmaple message",
            "date": "1487178184111",
            "username": "example username",
            "email": "exmaple@email.com"
        },
        "dependencies": ["an array of component ids"],
        "docs": [
            {
                "name": "function name",
                "description": "example description",
                "args": [
                    {
                        "description": "example description",
                        "type": "arg type",
                        "name": "arg name"
                    }
                ],
                "returns": {
                    "description": "example description",
                    "type": "return type"
                },
                "access": "public/private",
                "examples": [
                    {
                        "raw": "raw examples",
                        "code": "identified exampels"
                    }
                ],
                "static": true
            }
        ],
        "ci": { "ci object if the ci run": "example"},
        "specsResults": {
            "tests": [
                {
                    "title": "test description",
                    "pass": true,
                    "err": null,
                    "duration": 2
                }
            ],
            "stats": {
                "start": "2017-02-15T17:03:04.095Z",
                "end": "2017-02-15T17:03:04.104Z",
                "duration": 9
            },
            "pass": true
        },
        "flattenedDependencies": [],
        "packageDependencies": {},
        "version": "1"
    },
    "dependencies": []
}

an example Component object

{
    "component": {
        "scope": "bit.utils",
        "name": "flat-map",
        "box": "array",
        "impl": {
            "file": "/** @flow */\n\n/**\n * Builds a new collection by applying a function to all elements of \n * this array and using the elements of the resulting collections.\n * @name flatMap\n * @param {[*]} array\n * @param {Function} cb\n * @returns {[*]}\n * @example\n * ```js\n *  flatMap([[1, 2, 3], [4, 5, 6]], val => val) // => [1, 2, 3, 4, 5, 6]\n * ```\n */\nmodule.exports = function flatMap(array: any[], cb: (val: any, key: number) => any[]) {\n  return Array.prototype.concat.apply([], array.map(cb));\n};\n",
            "name": "impl.js"
        },
        "specs": {
            "file": "import { expect } from 'chai';\n\nconst flatMap = require(__impl__);\n\ndescribe('#flatMap()', () => {\n  it('should flatten the multi-dimensional array to a single-dimensional one ', () => {\n    const array = [[1, 2, 3], [4, 5, 6]];\n    expect(flatMap(array, val => val)).to.deep.equal([1, 2, 3, 4, 5, 6]);\n  });\n\n  it('should flatten to a single-dimensional array without odd numbers', () => {\n    const array = [[1, 2, 3], [4, 5, 6]];\n    expect(flatMap(array, nums => nums.filter(n => n % 2 === 0)))\n      .to.deep.equal([2, 4, 6]);\n  });\n\n  it('should throw a type error in case the first argument is not an array', () => {\n    expect(() => {\n      flatMap();\n    }).to.throw();\n  });\n\n  it('should throw a type error in case the second argument is not a function', () => {\n    expect(() => {\n      flatMap([]);\n    }).to.throw();\n  });\n});\n",
            "name": "spec.js"
        },
        "dist": {
            "file": "\"use strict\";\n\n/**\n * Builds a new collection by applying a function to all elements of \n * this array and using the elements of the resulting collections.\n * @name flatMap\n * @param {[*]} array\n * @param {Function} cb\n * @returns {[*]}\n * @example\n * ```js\n *  flatMap([[1, 2, 3], [4, 5, 6]], val => val) // => [1, 2, 3, 4, 5, 6]\n * ```\n */\nmodule.exports = function flatMap(array, cb) {\n  return Array.prototype.concat.apply([], array.map(cb));\n};",
            "name": "dist.js"
        },
        "compiler": "bit.envs/compilers/flow::latest",
        "tester": "bit.envs/testers/mocha-chai::latest",
        "log": {
            "message": "initial commit",
            "date": "1487178184111",
            "username": "USERNAME",
            "email": "USERNAME@gmail.com"
        },
        "dependencies": [],
        "docs": [
            {
                "name": "flatMap",
                "description": "Builds a new collection by applying a function to all elements of \nthis array and using the elements of the resulting collections.",
                "args": [
                    {
                        "description": null,
                        "type": "[*]",
                        "name": "array"
                    },
                    {
                        "description": null,
                        "type": "Function",
                        "name": "cb"
                    }
                ],
                "returns": {
                    "description": null,
                    "type": "[*]"
                },
                "access": "public",
                "examples": [
                    {
                        "raw": "```js\n flatMap([[1, 2, 3], [4, 5, 6]], val => val) // => [1, 2, 3, 4, 5, 6]\n```",
                        "code": "```js\nflatMap([[1, 2, 3], [4, 5, 6]], val => val) // => [1, 2, 3, 4, 5, 6]\n```"
                    }
                ],
                "static": false
            }
        ],
        "ci": {},
        "specsResults": {
            "tests": [
                {
                    "title": "#flatMap() should flatten the multi-dimensional array to a single-dimensional one ",
                    "pass": true,
                    "err": null,
                    "duration": 2
                },
                {
                    "title": "#flatMap() should flatten to a single-dimensional array without odd numbers",
                    "pass": true,
                    "err": null,
                    "duration": 0
                },
                {
                    "title": "#flatMap() should throw a type error in case the first argument is not an array",
                    "pass": true,
                    "err": null,
                    "duration": 2
                },
                {
                    "title": "#flatMap() should throw a type error in case the second argument is not a function",
                    "pass": true,
                    "err": null,
                    "duration": 0
                }
            ],
            "stats": {
                "start": "2017-02-15T17:03:04.095Z",
                "end": "2017-02-15T17:03:04.104Z",
                "duration": 9
            },
            "pass": true
        },
        "flattenedDependencies": [],
        "packageDependencies": {},
        "version": "1"
    },
    "dependencies": []
}