Skip to content
Open
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
2 changes: 1 addition & 1 deletion examples/csv-importer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"framer-api": "^0.0.1-beta.0",
"framer-api": "^0.0.1-beta.1",
"papaparse": "^5.5.3",
"typescript": "^5.9.3"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/json-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"@hono/node-server": "^1.14.1",
"framer-api": "^0.0.1-beta.0",
"framer-api": "^0.0.1-beta.1",
"hono": "^4.7.10",
"typescript": "^5.9.3"
},
Expand Down
42 changes: 42 additions & 0 deletions examples/publish/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Publish

Publishes and deploys a Framer project. Designed to run as a one-shot script, making it ideal for cron jobs, CI/CD pipelines, and systemd timers.

## Usage

```bash
node --env-file=../../.env index.ts

bun --env-file=../../.env run index.ts

deno --env-file=../../.env run index.ts
```

## Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `EXAMPLE_PROJECT_URL` | Yes | Your Framer project URL |

## Scheduling Examples

### Cron

Publish every 4 hours:

```bash
# Edit crontab
crontab -e

# Add this line (adjust paths as needed)
0 */4 * * * cd /path/to/examples/publish && node --env-file=../../.env index.ts >> /var/log/framer-publish.log 2>&1
```

Common cron schedules:

```bash
0 */4 * * * # Every 4 hours
0 9-18/2 * * 1-5 # Every 2 hours between 9:00 and 18:00, mon-fri
0 9 * * * # Daily at 9:00
0 9 * * 1-5 # Weekdays at 9:00
```
16 changes: 16 additions & 0 deletions examples/publish/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "publish",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"typecheck": "tsc --noEmit"
},
"dependencies": {
"framer-api": "^0.0.1-beta.1",
"typescript": "^5.9.3"
},
"devDependencies": {
"@types/node": "^22.10.2"
}
}
34 changes: 34 additions & 0 deletions examples/publish/publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import assert from "node:assert";
import { connect } from "framer-api";

const projectUrl = process.env["EXAMPLE_PROJECT_URL"];
assert(projectUrl, "EXAMPLE_PROJECT_URL environment variable is required");

using framer = await connect(projectUrl);

// Show changes
const changedPaths = await framer.getChangedPaths();
const entries = Object.entries(changedPaths);
const totalChanges = entries.reduce((sum, [, paths]) => sum + paths.length, 0);

if (totalChanges === 0) {
console.log("⛔️ No changes to publish.");
process.exit(0);
}

console.log(`📄 ${totalChanges} change(s):`);
for (const [type, paths] of entries) {
for (const path of paths) {
console.log(` ${type}: ${path}`);
}
}

// Publish
const { deployment } = await framer.publish();
console.log(`🚀 Published deployment ${deployment.id}`);

const deployedHostnames = await framer.deploy(deployment.id);
console.log(`✅ Deployed to:`);
for (const hostname of deployedHostnames) {
console.log(` https://${hostname.hostname}`);
}
4 changes: 4 additions & 0 deletions examples/publish/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["publish.ts"]
}
24 changes: 19 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.