Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 40 additions & 30 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,87 @@
###########################################################################
# just configuration
###########################################################################
set shell := ["bash", "-c"]
set dotenv-load := true

set shell := ["bash", "-c"]
set dotenv-load := true

###########################################################################
# library configuration
###########################################################################
NPM_MODULE := `cat package.json | jq -r .name`
tsc := "./node_modules/typescript/bin/tsc"
vite := "NODE_OPTIONS='--max_old_space_size=16384' ./node_modules/vite/bin/vite.js"

NPM_MODULE := `cat package.json | jq -r .name`
tsc := "./node_modules/typescript/bin/tsc"
vite := "NODE_OPTIONS='--max_old_space_size=16384' ./node_modules/vite/bin/vite.js"

# minimal formatting, bold is very useful
bold := '\033[1m'
normal := '\033[0m'
green := "\\e[32m"
yellow := "\\e[33m"
blue := "\\e[34m"
magenta := "\\e[35m"
grey := "\\e[90m"

bold := '\033[1m'
normal := '\033[0m'
green := "\\e[32m"
yellow := "\\e[33m"
blue := "\\e[34m"
magenta := "\\e[35m"
grey := "\\e[90m"

_help:
@just --list --unsorted --list-heading $'Commands:\n'

# Build the production npm distributions in dist/metaframe and dist/metapage
build: _build

_build: _ensure_node_modules _build_npm

_build_npm:
#!/usr/bin/env bash
set -euo pipefail
# Compiles the entire codebase to typescript files in ./dist. Packaged into the npm module '{{NPM_MODULE}}'
# Compiles the entire codebase to typescript files in ./dist. Packaged into the npm module '{{ NPM_MODULE }}'
# How to test installation of the build?
{{tsc}} --noEmit
{{ tsc }} --noEmit
echo "✅ typescript check"
{{vite}} build
{{ vite }} build
echo "✅ vite build"

# watch for file changes, then build ALL into ./dist
watch: _ensure_node_modules
#!/usr/bin/env bash
set -euo pipefail
echo "👀 watching and building into ./dist..."
{{tsc}} --noEmit
{{ tsc }} --noEmit
echo "✅ typescript check"
{{vite}} --watch build
{{ vite }} --watch build

@_tsc +args="":
{{tsc}} {{args}}
{{ tsc }} {{ args }}

# Run tests
@test +args="": (_tsc "--build")
npx vitest {{args}}
test +args="": _ensure_node_modules (_tsc "--build")
npx vitest {{ args }}

# Develop:
# 1. just dev
# 2. modify metapage/metaframe code
# 3. refresh browser window

# recompile metapage/metaframe src on change, and open a browser at the test page for the local metapage test
dev: _ensure_node_modules watch

# typescript check
# typescript check
@check: (_tsc "--build")
echo -e "✅ {{green}}TypeScript{{normal}} check passed"
echo -e "✅ {{ green }}TypeScript{{ normal }} check passed"

# npm link the package in dist for local development. In the other project: 'npm link @metapages/metapage'
@link:
if [ ! -d dist ]; then just build; fi
cd dist && npm link
echo -e "👉 in the other project: npm link {{NPM_MODULE}}"
echo -e "👉 in the other project: npm link {{ NPM_MODULE }}"

# unlink the package in dist from local development. You probably don't ever need to do this
@unlink:
cd dist && npm unlink

# List all published versions
@list:
npm view {{NPM_MODULE}} versions --json
npm view {{ NPM_MODULE }} versions --json

# Bump version (patch|minor|major|<version>), commit, tag, and push to trigger publish
version bump="patch":
Expand All @@ -88,7 +95,7 @@ version bump="patch":
exit 1
fi
# Bump version in package.json
npm version {{bump}} --no-git-tag-version
npm version {{ bump }} --no-git-tag-version
VERSION=`cat package.json | jq -r '.version'`
# Commit and tag
git add package.json
Expand All @@ -111,15 +118,18 @@ publish: _ensure_node_modules
set -euo pipefail
VERSION=`cat package.json | jq -r '.version'`
# Check if the package exists, if not this is the first publish
if ! npm view {{NPM_MODULE}} version &> /dev/null; then
echo "📦 First time publishing {{NPM_MODULE}}"
if ! npm view {{ NPM_MODULE }} version &> /dev/null; then
echo "📦 First time publishing {{ NPM_MODULE }}"
else
INDEX=`npm view {{NPM_MODULE}} versions --json | jq "index( \"$VERSION\" )"`
INDEX=`npm view {{ NPM_MODULE }} versions --json | jq "index( \"$VERSION\" )"`
if [ "$INDEX" != "null" ]; then
echo -e '🌳 Version exists, not publishing'
exit 0
fi
fi
echo "Running tests before publish..."
just test --run
echo "✅ Tests passed"
just build
rm -rf dist/test
echo "PUBLISHING npm version $VERSION"
Expand All @@ -130,11 +140,11 @@ publish: _ensure_node_modules
# Unpublish version https://docs.npmjs.com/cli/v7/commands/npm-unpublish
unpublish version:
@echo "❗ If this fails: you cannot use .npmrc or NPM_TOKEN, you must 'npm login' 🤷‍♀️"
npm unpublish {{NPM_MODULE}}@{{version}}
npm unpublish {{ NPM_MODULE }}@{{ version }}

# https://docs.npmjs.com/cli/v7/commands/npm-deprecate
module_deprecate version +message:
npm deprecate {{NPM_MODULE}}@{{version}} "{{message}}"
npm deprecate {{ NPM_MODULE }}@{{ version }} "{{ message }}"

# delete all generated assets/files
clean:
Expand Down
4 changes: 2 additions & 2 deletions src/test/serialize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ describe("Primary Serialize/Deserialize API", () => {

// Large data should be uploaded (URL dataref)
expect(typeof serialized.largeData).toBe("string");
expect(serialized.largeData).toContain("text/x-uri");
expect(serialized.largeData as unknown as string).toContain("text/x-uri");
// URL is encoded in the dataref
expect(decodeURIComponent(serialized.largeData)).toContain("https://storage.example.com");
expect(decodeURIComponent(serialized.largeData as unknown as string)).toContain("https://storage.example.com");

// Small data should be inline
expect(typeof serialized.smallData).toBe("string");
Expand Down
Loading