-
Notifications
You must be signed in to change notification settings - Fork 5
Introducing publish example #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0ac68b
Introducing publish example
elmarburke a127fee
Update framer-api version to 0.0.1-beta.1 in package-lock.json and ex…
elmarburke 1b91722
Update publish example README to use publish.ts
elmarburke 4261df2
Handle no custom domains on deploy
elmarburke 2cec677
Bump framer-api to 0.1.1
elmarburke a90eeb3
Fix CI env setup step failing when .env.example is missing
elmarburke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 publish.ts | ||
|
|
||
| bun --env-file=../../.env run publish.ts | ||
|
|
||
| deno --env-file=../../.env run publish.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 publish.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 | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| 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}`); | ||
|
|
||
| // Deploy to custom domains | ||
| const deployed = await framer.deploy(deployment.id); | ||
|
|
||
| if (deployed.length > 0) { | ||
| console.log(`✅ Deployed to ${deployed.length} custom domain(s):`); | ||
| for (const hostname of deployed) { | ||
| console.log(` https://${hostname.hostname}`); | ||
| } | ||
| } else { | ||
| console.log("No custom domains to deploy — default hostname is already live."); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "extends": "../../tsconfig.base.json", | ||
| "include": ["publish.ts"] | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be bumped to
0.1There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this to all packages