kvendrik / node-codesandbox

πŸ‘¨β€πŸ’» Upload code to CodeSandbox

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-codesandbox

NPM Version License: MIT

Upload code to CodeSandbox using Node.

Usage

  1. yarn add node-codesandbox
  2. Check out the example:
import {Uploader, getApiTokenFromUser, logSandboxUrl} from 'node-codesandbox';

(async () => {
  const token = await getApiTokenFromUser();
  const uploader = new Uploader(token);
  const {sandboxUrl} = await uploader.upload(`path/to/folder`, {
    include: ['playground', 'src'], // When defined, the uploader will only upload these files (supports glob patterns)
    exclude: ['**/.DS_Store'], // Files to exclude (supports glob patterns)
    files: {
      'README.md': '# Hello!', // Extra files to include
    },
  });
  logSandboxUrl(sandboxUrl);
})();

How is this different from the CodeSandbox CLI?

This is basically the CodeSandbox CLI plus the ability to modify what files are being uploaded in a config object.

This package can be seen as a proof of concept because if this proves to be something thats useful to people it should likely just be part of the CLI itself. I created it as a seperate package because I needed a quick and easy way to to do this and due to the simplicity of the CodeSandbox API and the way the CLI is currently structured it was faster to do this in a seperate package. And as a bonus it also helped me better understand how the CodeSandbox API works.

About

πŸ‘¨β€πŸ’» Upload code to CodeSandbox


Languages

Language:TypeScript 99.4%Language:CSS 0.6%