# webstrates-file-system

> Mounts a Webstrate document as a file on disk, propagating changes between the file and document.

Latest version **2.2.1** (published 2019-06-04) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install webstrates-file-system
pnpm add webstrates-file-system
yarn add webstrates-file-system
bun add webstrates-file-system
```

Provides the commands `wfs`, `webstratesfs`.

## Health

**Score 5/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2019-06-04 |
| First published | 2018-05-02 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 29.4 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Kristian Antonsen |
| Maintainers | kbadk |
| Keywords | webstrates, ot, jsonml |

## Links

- npm: https://www.npmjs.com/package/webstrates-file-system
- Repository: https://github.com/Webstrates/Webstrates-file-system
- Homepage: https://github.com/Webstrates/Webstrates-file-system#readme
- Issues: https://github.com/Webstrates/Webstrates-file-system/issues
- npm.io page: https://npm.io/package/webstrates-file-system

## Dependencies (12)

- [chalk](https://npm.io/package/chalk.md) ^2.4.1
- [request](https://npm.io/package/request.md) ^2.88.0
- [sharedb](https://npm.io/package/sharedb.md) ^0.11.37
- [chokidar](https://npm.io/package/chokidar.md) ^3.0.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^6.0.0
- [md5-file](https://npm.io/package/md5-file.md) ^4.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [websocket](https://npm.io/package/websocket.md) ^1.0.26
- [jsonml-tools](https://npm.io/package/jsonml-tools.md) git+http://github.com/Webstrates/jsonml-tools.git#master
- [json0-ot-diff](https://npm.io/package/json0-ot-diff.md) ^1.0.3
- [html-to-jsonml](https://npm.io/package/html-to-jsonml.md) 0.0.6
- [diff-match-patch](https://npm.io/package/diff-match-patch.md) ^1.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.2.1 (latest) — 2019-06-04
- 2.2.0 — 2019-05-24
- 2.1.0 — 2019-05-13
- 2.1.11 — 2019-05-13
- 2.0.11 — 2019-03-18
- 2.0.10 — 2019-03-05
- 2.0.9 — 2018-11-09
- 2.0.8 — 2018-08-20
- 2.0.7 — 2018-08-15
- 2.0.6 — 2018-07-03
- 2.0.5 — 2018-06-11
- 2.0.4 — 2018-06-01
- 2.0.3 — 2018-05-09
- 2.0.2 — 2018-05-03
- 2.0.1 — 2018-05-02
- … 1 more at https://npm.io/package/webstrates-file-system/versions

## README

# Webstrates File System

Webstrates File System allows you to mount a webstrate as a folder on the disk, automatically propagating changes between the folder and its files to the webstrate document on the server.

![WFS demo](demo.gif)

## Installation

**Using NPM (recommended)**

    npm install -g webstrates-file-system

**Using Git**

    git clone git@github.com:Webstrates/file-system.git

## Usage

If installed using NPM, run from anywhere:

    wfs --id=<webstrateId> --host=<host> [<folder>]

(On Windows, `wfs` will conflict with Windows Fax and Scan. Instead, use `webstratesfs`.)

If installed using Git, navigate to the `Webstrates-file-system/` folder and run

    node index.js --id=<webstrateId> --host=<hostname> [<folder>]

When running the command, a folder with name `<webstrateId>` will be created with an `index.html` file, containing the webstrate document's contents. If the optional `<folder>` parameter has been passed, this will be used as the folder name instead.

**Credentials**

By default, the Webstrates server [uses basic auth with username "web" and password "strate"](https://webstrates.github.io/userguide/server-config.html#basic-settings). To use this with webstrate, add it to the host as:

    $ wfs --id=myDocument --host=web:strate@hostname

**HTTP or HTTPS**

WFS assumes the server is using HTTPS. To use HTTP, apply the `--insecure` parameter.

**Assets**

Any file added to the `assets/` folder will be uploaded to the Webstrates server when WFS is running, assuming it isn't already on the server and accessible. "Accessible" here means that it hasn't been overwritten by a newer version on the server. E.g. if version 1 of `cow.png` gets uploaded, and we put version 1 of `cow.png` in the `assets/` folder, it will not get uploaded. If, however, version 2 of `cow.png` has been uploaded after version 1, and version 1 is added to the `assets/` folder, version 1 of `cow.png` will get reuploded.

(Side note: Do not worry too much about wasting space – the Webstrates server deduplicates identical files.)

**Resources in external files**

When adding an `id` attribute to a `<script>` or `<style>` tag ending in either `.js` or `.css` (respectively), the contents of the tag will be moved into a new file in the `resources/` folder with a file name matching the attribute. E.g. adding

    <script id="test.js">console.log('Hello, world!');</script>

to `index.html`, the contents will be removed from the `<script>` tag in `index.html` and instead be put in `resources/test.js`. Any changes made to `test.js` will automatically be synchronized with the Webstrates server (both ways as per usual). To the server, the script will appear in-lined as per usual.

**Ours and theirs**

When connecting to a webstrate document using a folder already containing an `index.html` file, the local version on the disk will be pushed to the server. To use the version on the server instead, use `--theirs`.

**One-shot**

To use WFS only as a deployment tool, the `--oneshot` parameter can be used. This composes the resources and the `index.html`, updates the document on the server and terminates.

NB: Remember to set up your editor to auto-reload the file on changes.

**Downloading assets**

By default, files found in the `assets/` folder are uploaded, but existing assets from the server aren't downloaded. When using `--download-assets`, WFS will download (the newest version of) all assets on the server when connecting and continuously listen for new assets and download them as well to maintain a local copy.

**Using access tokens**

To access a webstrate proteced through the [permissions system](https://webstrates.github.io/userguide/api/permissions.html), users may supply WFS with an [access token](https://webstrates.github.io/userguide/api/access-tokens.html). Generate an access token, then run WFS with `--token=<token>`. Editing a webstrate, as well as uploading and downloading assets will now be possible.

## How?

The brief story: WFS creates a websocket to the Webstrates server, acting exactly as a regular Webstrates client. When the document comes in (or any updates to it), the JsonML document gets converted to HTML (like when accessing a Webstrate document with the [`?raw` parameter](https://webstrates.github.io/userguide/http-api.html#accessing-the-history-of-a-webstrate)) and put it in a file. WFS listens for changes to the file, converts the HTML back to JsonML, calculates an [op diff between the two JsonML structures](https://github.com/kbadk/json0-ot-diff) and submits it to the server.

---
_Source: https://npm.io/package/webstrates-file-system · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
