fs-codesandboxer

Create CodeSandbox from file system

Usage no npm install needed!

<script type="module">
  import fsCodesandboxer from 'https://cdn.skypack.dev/fs-codesandboxer';
</script>

README

fs-codesandboxer

npm

Create CodeSandbox from file system.

Usage

npx fs-codesandboxer <source-directory-path>

Options

  • --ignore-paths, -i: Paths to be ignored when uploading. Can be provided multiple times. Note that providing this option will override the default settings.
  • --skip-uploading-binary-files: Skip uploading binary files, note that providing this option could results in unexpected behavior.

Caveats

Binary files are being uploaded to file.io to let CodeSandbox to download them. The uploaded links would get expired once requested, or after 14 days (by default). The generated sandboxes are expected to be used/accessed at least once in the range of the expiration time. If for whatever reason you don't want to upload them to file.io, provide the --skip-uploading-binary-files option when using this module.

Example

$ fs-codesandboxer ./examples/react
CodeSandbox ID	: 2qxth (copied to clipboard)
Editor URL  	: https://codesandbox.io/s/2qxth
Preview URL 	: https://2qxth.csb.app

API

It can also be used programmatically.

yarn add fs-codesandboxer
const fsCodeSandboxer = require('fs-codesandboxer');

const sandboxID = await fsCodeSandboxer(
  path.resolve(process.cwd(), './examples/react'),
  {
    ignorePaths: [],
    skipUploadingBinaryFiles: false,
  }
);

console.log(sandboxID); // "2qxth"

Comparison to the official CodeSandbox CLI

The official CodeSandbox CLI also has the same functionality as fs-codesandboxer, but it requires you to sign in to deploy sandboxes. fs-codesandboxer uses the public API and file.io to allow you to programmatically deploy sandboxes without authentication.