Skip to content

Commit

Permalink
load PouchDB via ES6 module
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHicks committed May 14, 2020
1 parent 08a41be commit 42d262d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions script/es6ify.sh
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -euo pipefail

FILE="${1:-}"
EXPORT="${2:-}"
if test -z "${FILE}" || test -z "${EXPORT}"; then
echo "usage: ${0:-} file thingToExport"
fi

sed '1 i\var exports = {};\nvar module = {};' "$FILE" | sed "\$ a\export const ${EXPORT} = module.exports;"
6 changes: 5 additions & 1 deletion script/ninja.sh
Expand Up @@ -9,6 +9,9 @@ elmFlags=--debug
rule elm
command = ./script/elm-make-module.sh \$in \$out \$elmFlags
rule es6ify
command = ./script/es6ify.sh \$in \$export > \$out
rule copy
command = cp \$in \$out
Expand All @@ -17,5 +20,6 @@ build dist/script/custom-elements-builtin-bootstrap.js: copy src/custom-elements
build dist/script/custom-elements-builtin.js: copy vendor/custom-elements-builtin.js
build dist/script/elm.js: elm src/Main.elm | elm.json $(echo "$ELM_FILES" | tr '\n' ' ')
build dist/script/index.js: copy src/index.js
build dist/script/pouchdb.js: copy vendor/pouchdb-7.1.1.js
build dist/script/pouchdb.js: es6ify vendor/pouchdb-7.1.1.js
export = PouchDB
EOF
1 change: 0 additions & 1 deletion src/index.html
Expand Up @@ -5,7 +5,6 @@
</head>
<body>
<script src="/script/custom-elements-builtin-bootstrap.js"></script>
<script src="/script/pouchdb.js"></script>
<script type=module src="/script/index.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -31,6 +31,7 @@ customElements.define("node-input", NodeInput, { extends: "textarea" });

// Go!
import * as Elm from "./elm.js";
import { PouchDB } from "./pouchdb.js";

var db = new PouchDB("notes");
// TODO: set up syncing
Expand Down

0 comments on commit 42d262d

Please sign in to comment.