Repository: ef4/prember
Branch: master
Commit: f6fda71be499
Files: 62
Total size: 52.7 KB
Directory structure:
gitextract_d48536wg/
├── .editorconfig
├── .ember-cli
├── .eslintignore
├── .eslintrc.js
├── .github/
│ └── workflows/
│ ├── ci.yml
│ ├── plan-release.yml
│ └── publish.yml
├── .gitignore
├── .npmignore
├── .prettierignore
├── .prettierrc.js
├── .release-plan.json
├── .watchmanconfig
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── RELEASE.md
├── addon/
│ └── .gitkeep
├── app/
│ └── .gitkeep
├── config/
│ ├── ember-try.js
│ └── environment.js
├── ember-cli-build.js
├── index.js
├── lib/
│ ├── .eslintrc.js
│ ├── config.js
│ └── prerender.js
├── node-tests/
│ ├── basic-test.js
│ └── url-tester.js
├── package.json
├── testem.js
├── tests/
│ ├── dummy/
│ │ ├── app/
│ │ │ ├── app.js
│ │ │ ├── components/
│ │ │ │ └── .gitkeep
│ │ │ ├── controllers/
│ │ │ │ └── .gitkeep
│ │ │ ├── helpers/
│ │ │ │ └── .gitkeep
│ │ │ ├── index.html
│ │ │ ├── models/
│ │ │ │ └── .gitkeep
│ │ │ ├── router.js
│ │ │ ├── routes/
│ │ │ │ ├── .gitkeep
│ │ │ │ ├── index.js
│ │ │ │ ├── redirects.js
│ │ │ │ └── use-static-asset.js
│ │ │ ├── styles/
│ │ │ │ └── app.css
│ │ │ └── templates/
│ │ │ ├── application.hbs
│ │ │ ├── discovered.hbs
│ │ │ ├── from-sample-data.hbs
│ │ │ ├── head.hbs
│ │ │ ├── index.hbs
│ │ │ └── use-static-asset.hbs
│ │ ├── config/
│ │ │ ├── ember-cli-update.json
│ │ │ ├── environment.js
│ │ │ ├── optional-features.json
│ │ │ └── targets.js
│ │ └── public/
│ │ ├── robots.txt
│ │ ├── sample-data.json
│ │ └── static.json
│ ├── helpers/
│ │ └── .gitkeep
│ ├── index.html
│ ├── integration/
│ │ └── .gitkeep
│ ├── test-helper.js
│ └── unit/
│ └── .gitkeep
└── vendor/
└── .gitkeep
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
[*.hbs]
insert_final_newline = false
[*.{diff,md}]
trim_trailing_whitespace = false
================================================
FILE: .ember-cli
================================================
{
/**
Ember CLI sends analytics information by default. The data is completely
anonymous, but there are times when you might want to disable this behavior.
Setting `disableAnalytics` to true will prevent any data from being sent.
*/
"disableAnalytics": false
}
================================================
FILE: .eslintignore
================================================
# unconventional js
/blueprints/*/files/
/vendor/
# compiled output
/dist/
/tmp/
# dependencies
/bower_components/
/node_modules/
# misc
/coverage/
!.*
.*/
.eslintcache
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
================================================
FILE: .eslintrc.js
================================================
'use strict';
module.exports = {
root: true,
parser: 'babel-eslint',
parserOptions: {
ecmaVersion: 2018,
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true,
},
},
plugins: ['ember'],
extends: [
'eslint:recommended',
'plugin:ember/recommended',
'plugin:prettier/recommended',
],
env: {
browser: true,
},
rules: {},
overrides: [
// node files
{
files: [
'./.eslintrc.js',
'./.prettierrc.js',
'./.template-lintrc.js',
'./ember-cli-build.js',
'./index.js',
'./testem.js',
'./blueprints/*/index.js',
'./config/**/*.js',
'./tests/dummy/config/**/*.js',
'./node-tests/**/*.js',
],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
plugins: ['node'],
extends: ['plugin:node/recommended'],
},
{
// Test files:
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
},
],
};
================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
push:
branches:
- master
- main
pull_request:
jobs:
test:
name: Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: 16
cache: pnpm
- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Lint
run: pnpm lint
- name: Test
run: pnpm test
test-no-lock:
name: Floating Dependencies
runs-on: ubuntu-latest
needs:
- test
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: 16
cache: pnpm
- name: Install dependencies
run: pnpm i --no-lockfile
- name: Test
run: pnpm test
test-try:
name: Additional Tests
runs-on: ubuntu-latest
needs:
- test
strategy:
fail-fast: false
matrix:
scenario:
- ember-lts-3.20
- ember-lts-3.24
- ember-release
- ember-beta
- ember-canary
- embroider-safe
- embroider-optimized
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 8
- name: Setup node.js
uses: actions/setup-node@v4
with:
node-version: 16
cache: pnpm
- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Test
run: pnpm ember try:one ${{ matrix.scenario }}
================================================
FILE: .github/workflows/plan-release.yml
================================================
name: Release Plan Review
on:
push:
branches:
- main
- master
pull_request_target: # This workflow has permissions on the repo, do NOT run code from PRs in this workflow. See https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
types:
- labeled
- unlabeled
concurrency:
group: plan-release # only the latest one of these should ever be running
cancel-in-progress: true
jobs:
check-plan:
name: "Check Release Plan"
runs-on: ubuntu-latest
outputs:
command: ${{ steps.check-release.outputs.command }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 'master'
# This will only cause the `check-plan` job to have a "command" of `release`
# when the .release-plan.json file was changed on the last commit.
- id: check-release
run: if git diff --name-only HEAD HEAD~1 | grep -w -q ".release-plan.json"; then echo "command=release"; fi >> $GITHUB_OUTPUT
prepare_release_notes:
name: Prepare Release Notes
runs-on: ubuntu-latest
timeout-minutes: 5
needs: check-plan
permissions:
contents: write
pull-requests: write
outputs:
explanation: ${{ steps.explanation.outputs.text }}
# only run on push event if plan wasn't updated (don't create a release plan when we're releasing)
# only run on labeled event if the PR has already been merged
if: (github.event_name == 'push' && needs.check-plan.outputs.command != 'release') || (github.event_name == 'pull_request_target' && github.event.pull_request.merged == true)
steps:
- uses: actions/checkout@v4
# We need to download lots of history so that
# github-changelog can discover what's changed since the last release
with:
fetch-depth: 0
ref: 'master'
- uses: actions/setup-node@v4
with:
node-version: 18
- uses: pnpm/action-setup@v3
with:
version: 8
- run: pnpm install --frozen-lockfile
- name: "Generate Explanation and Prep Changelogs"
id: explanation
run: |
set +e
pnpm release-plan prepare 2> >(tee -a release-plan-stderr.txt >&2)
if [ $? -ne 0 ]; then
echo 'text<<EOF' >> $GITHUB_OUTPUT
cat release-plan-stderr.txt >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo 'text<<EOF' >> $GITHUB_OUTPUT
jq .description .release-plan.json -r >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
rm release-plan-stderr.txt
fi
env:
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
- uses: peter-evans/create-pull-request@v6
with:
commit-message: "Prepare Release using 'release-plan'"
labels: "internal"
branch: release-preview
title: Prepare Release
body: |
This PR is a preview of the release that [release-plan](https://github.com/embroider-build/release-plan) has prepared. To release you should just merge this PR 👍
-----------------------------------------
${{ steps.explanation.outputs.text }}
================================================
FILE: .github/workflows/publish.yml
================================================
# For every push to the master branch, this checks if the release-plan was
# updated and if it was it will publish stable npm packages based on the
# release plan
name: Publish Stable
on:
workflow_dispatch:
push:
branches:
- main
- master
concurrency:
group: publish-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
check-plan:
name: "Check Release Plan"
runs-on: ubuntu-latest
outputs:
command: ${{ steps.check-release.outputs.command }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: 'master'
# This will only cause the `check-plan` job to have a result of `success`
# when the .release-plan.json file was changed on the last commit. This
# plus the fact that this action only runs on main will be enough of a guard
- id: check-release
run: if git diff --name-only HEAD HEAD~1 | grep -w -q ".release-plan.json"; then echo "command=release"; fi >> $GITHUB_OUTPUT
publish:
name: "NPM Publish"
runs-on: ubuntu-latest
needs: check-plan
if: needs.check-plan.outputs.command == 'release'
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
# This creates an .npmrc that reads the NODE_AUTH_TOKEN environment variable
registry-url: 'https://registry.npmjs.org'
- uses: pnpm/action-setup@v3
with:
version: 8
- run: pnpm install --frozen-lockfile
- name: npm publish
run: pnpm release-plan publish
env:
GITHUB_AUTH: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
================================================
FILE: .gitignore
================================================
# See https://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist/
/tmp/
# dependencies
/bower_components/
/node_modules/
# misc
/.env*
/.pnp*
/.sass-cache
/.eslintcache
/connect.lock
/coverage/
/libpeerconnection.log
/npm-debug.log*
/testem.log
/yarn-error.log
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
================================================
FILE: .npmignore
================================================
# compiled output
/dist/
/tmp/
# dependencies
/bower_components/
# misc
/.bowerrc
/.editorconfig
/.ember-cli
/.env*
/.eslintcache
/.eslintignore
/.eslintrc.js
/.git/
/.gitignore
/.prettierignore
/.prettierrc.js
/.template-lintrc.js
/.travis.yml
/.watchmanconfig
/bower.json
/config/ember-try.js
/CONTRIBUTING.md
/ember-cli-build.js
/testem.js
/tests/
/node-tests
/yarn-error.log
/yarn.lock
.gitkeep
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
================================================
FILE: .prettierignore
================================================
# unconventional js
/blueprints/*/files/
/vendor/
# compiled output
/dist/
/tmp/
# dependencies
/bower_components/
/node_modules/
# misc
/coverage/
!.*
.eslintcache
# ember-try
/.node_modules.ember-try/
/bower.json.ember-try
/package.json.ember-try
================================================
FILE: .prettierrc.js
================================================
'use strict';
module.exports = {
singleQuote: true,
};
================================================
FILE: .release-plan.json
================================================
{
"solution": {
"prember": {
"impact": "minor",
"oldVersion": "2.0.0",
"newVersion": "2.1.0",
"constraints": [
{
"impact": "minor",
"reason": "Appears in changelog section :rocket: Enhancement"
},
{
"impact": "patch",
"reason": "Appears in changelog section :house: Internal"
}
],
"pkgJSONPath": "./package.json"
}
},
"description": "## Release (2024-07-05)\n\nprember 2.1.0 (minor)\n\n#### :rocket: Enhancement\n* `prember`\n * [#82](https://github.com/ef4/prember/pull/82) recycle the fastboot instance after 1k requests ([@mansona](https://github.com/mansona))\n\n#### :house: Internal\n* `prember`\n * [#84](https://github.com/ef4/prember/pull/84) add release-plan ([@mansona](https://github.com/mansona))\n * [#83](https://github.com/ef4/prember/pull/83) switch to pnpm and fix tests ([@mansona](https://github.com/mansona))\n\n#### Committers: 1\n- Chris Manson ([@mansona](https://github.com/mansona))\n"
}
================================================
FILE: .watchmanconfig
================================================
{
"ignore_dirs": ["tmp", "dist"]
}
================================================
FILE: CHANGELOG.md
================================================
# Changelog
## Release (2024-07-05)
prember 2.1.0 (minor)
#### :rocket: Enhancement
* `prember`
* [#82](https://github.com/ef4/prember/pull/82) recycle the fastboot instance after 1k requests ([@mansona](https://github.com/mansona))
#### :house: Internal
* `prember`
* [#84](https://github.com/ef4/prember/pull/84) add release-plan ([@mansona](https://github.com/mansona))
* [#83](https://github.com/ef4/prember/pull/83) switch to pnpm and fix tests ([@mansona](https://github.com/mansona))
#### Committers: 1
- Chris Manson ([@mansona](https://github.com/mansona))
# 1.1.1 - 2022-08-10
BUGFIX: ensure we always run after ember-auto-import. As of ember-auto-import 2.0, things can break if we run before.
## 1.1.0 - 2021-12-23
ENHANCEMENT: Add embroider support by @simonihmig
## 1.0.5 - 2020-07-01
BUGFIX: Use rootUrl for static files #57 from @mansona
## 1.0.4 - 2020-05-03
ENHANCEMENT: Allow passing urls from prember
## 1.0.3 - 2019-05-29
ENHANCEMENT: Support to ember-engines out of the box
## 1.0.2 - 2019-01-06
BUGFIX: The protocol bugfix in 1.0.1 was not quite right and caused a regresion.
## 1.0.1 - 2018-12-20
BUGFIX: Shutdown express server after build (thanks @astronomersiva)
BUGFIX: Add protocol to fastboot requests for improved compatibility (thanks @xg-wang)
## 1.0.0 - 2018-10-28
BREAKING: We now require ember-cli-fastboot >= 2.0.0, and if you're using broccoli-asset-rev it should be >= 2.7.0. This is to fix the order in which these run relative to prember, so that all asset links will get correct handling.
## 0.4.0 - 2018-04-25
BREAKING: the signature for custom url discovery functions has changed from
async function(distDir, visit) { return [...someURLs] }
to
async function({ distDir, visit }) { return [...someURLs] }
This makes it nicer to compose multiple URL discovery strategies.
================================================
FILE: CONTRIBUTING.md
================================================
# How To Contribute
## Installation
* `git clone <repository-url>`
* `cd prember`
* `yarn install`
## Linting
* `yarn lint`
* `yarn lint:fix`
## Running tests
* `ember test` – Runs the test suite on the current Ember version
* `ember test --server` – Runs the test suite in "watch mode"
* `ember try:each` – Runs the test suite against multiple Ember versions
## Running the dummy application
* `ember serve`
* Visit the dummy application at [http://localhost:4200](http://localhost:4200).
For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/).
================================================
FILE: LICENSE.md
================================================
The MIT License (MIT)
Copyright (c) 2018
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
================================================
FILE: README.md
================================================
# prember = Pre Render Ember
A **progressive static-site generator** for Ember
This Ember addon allows you to pre-render any list of URLs into static HTML files *at build time*. It has no opinions about how you generate the list of URLs.
## Features
- 💯100% Ember
- 🚀 [Blazing](https://runspired.com/2018/06/03/ember-in-2018-part-2/) optimized for speed.
- 🚚 Data Agnostic. Supply your site with data from anywhere, however you want!
- 💥 Instant navigation and page views
- ☔️ Progressively Enhanced and mobile-ready
- 🎯 SEO Friendly.
- 🥇 Ember-centric developer experience.
- 😌 Painless project setup & migration.
- 📦 Embroider support
## Quick Start
Add these packages to your app:
```sh
ember install ember-cli-fastboot
ember install prember
```
And configure some URLs that you would like to prerender:
```
// In ember-cli-build.js
let app = new EmberApp(defaults, {
prember: {
urls: [
'/',
'/about',
'/contact'
]
}
});
```
When you do `ember build --environment=production`, your built app will include fastboot-rendered HTML in the following files:
```
/index.html
/about/index.html
/contact/index.html
```
## Explanation
When you build a normal ember app (`ember build --environment=production`) you get a structure something like this:
```
dist/
├── assets
│ ├── my-app-0d31988c08747007cb982909a0b2c9db.css
│ ├── my-app-bdaaa766a1077911a7dae138cbd9e39d.js
│ ├── vendor-553c722f80bed2ea90c42b2c6a54238a.js
│ └── vendor-9eda64f0de2569c64ba0d33f08940fbf.css
├── index.html
└── robots.txt
```
To serve this app to users, you just need to configure a webserver to use `index.html` in response to *all* URLs that don't otherwise map to files (because the Ember app will boot and take care of the routing).
If you add [ember-cli-fastboot](https://github.com/ember-fastboot/ember-cli-fastboot) to your app, it augments your build with a few things that are needed to run the app within node via [fastboot](https://github.com/ember-fastboot/fastboot):
```
dist/
├── assets
│ ├── assetMap.json
│ ├── my-app-0d31988c08747007cb982909a0b2c9db.css
│ ├── my-app-a72732b0d2468246920fa5401610caf4.js
│ ├── my-app-fastboot-af717865dadf95003aaf6903aefcd125.js
│ ├── vendor-553c722f80bed2ea90c42b2c6a54238a.js
│ └── vendor-9eda64f0de2569c64ba0d33f08940fbf.css
├── index.html
├── package.json
└── robots.txt
```
You can still serve the resulting app in the normal way, but to get the benefits of server-side rendering you would probably serve it from a fastboot server that knows how to combine the JS files and the `index.html` file and generate unique output per URL. The downside of this is that your fastboot server is now in the critical path, which increases your ops complexity and is necessarily slower than serving static files.
`prember` starts with an app that's already capable of running in fastboot and augments it further. You configure it with a source of URLs to prerender, and it uses Fastboot to visit each one *during the build process*, saving the resulting HTML files:
```
dist/
├── _empty.html <--------- A copy of the original index.html
├── about
│ └── index.html <--------- Pre-rendered content
├── assets
│ ├── assetMap.json
│ ├── my-app-0d31988c08747007cb982909a0b2c9db.css
│ ├── my-app-a72732b0d2468246920fa5401610caf4.js
│ ├── my-app-fastboot-af717865dadf95003aaf6903aefcd125.js
│ ├── vendor-553c722f80bed2ea90c42b2c6a54238a.js
│ └── vendor-9eda64f0de2569c64ba0d33f08940fbf.css
├── contact
│ └── index.html <--------- Pre-rendered content
├── index.html <--------- Rewritten with pre-rendered content
├── package.json
└── robots.txt
```
The resulting application can be served entirely statically, like a normal Ember app. But it has the fast-first-paint and SEO benefits of a Fastboot-rendered application for all of the URLs that you pre-rendered.
## Configuring Your Webserver
Your webserver needs to do two things correctly for this to work:
1. It should use a file like `about/index.html` to respond to URLs like `/about`. This is a pretty normal default behavior.
2. It should use `_empty.html` to respond to unknown URLs (404s). In a normal Ember app, you would configure `index.html` here instead, but we may have already overwritten `index.html` with content that only belongs on the homepage, not on every route. This is why `prember` gives you a separate `_empty.html` file with no prerendered content.
## Options
You pass options to `prember` by setting them in `ember-cli-build.js`:
```
// In ember-cli-build.js
let app = new EmberApp(defaults, {
prember: {
urls: [
'/',
'/about',
'/contact'
]
}
});
```
The supported options are:
- `urls`: this can be an array or a promise-returning function that resolves to an array. How you generate the list of URLs is up to you, there are many valid strategies. See next section about using a custom url discovery function.
- `enabled`: defaults to `environment === 'production'` so that `prember` only runs during production builds.
- `indexFile`: defaults to `"index.html"`. This is the name we will give to each of the files we create during pre-rendering.
- `emptyFile`: defaults to `"_empty.html"`. This is where we will put a copy of your empty `index.html` as it was before any pre-rendering.
- `requestsPerFastboot`: defaults to `1000`. This tells prember how many requests to pass to a single fastboot instance before creating a new one. This can be useful for memory management.
## Using a custom URL discovery function
If you pass a function as the `urls` option, prember will invoke it like:
```js
let listOfUrls = await yourUrlFunction({ distDir, visit });
```
`distDir` is the directory containing your built application. This allows your function to inspect the build output to discover URLs.
`visit` is an asynchronous function that takes a URL string and resolves to a response from a running fastboot server. This lets your function crawl the running application to discover URLs.
For an example of both these strategies in action, see `./node-tests/url-tester.js` in this repo's test suite.
## Using prember in development
In addition to the `enabled` option, you can temporarily turn `prember` on by setting the environment variable `PREMBER=true`, like:
```sh
PREMBER=true ember serve
```
**However**, by default ember-cli doesn't understand that it should use a file like `about/index.html` to respond to a URL like `/about`. So you should do:
```sh
ember install prember-middleware
```
It's harmless to keep prember-middleware permanently installed in your app, it has no impact on your production application.
When running in development, you will see console output from ember-cli that distinguishes whether a given page was handled by prember vs handled on-the-fly by fastboot:
```
prember: serving prerendered static HTML for /about <--- served by prember
2017-10-27T05:25:02.161Z 200 OK /some-other-page <--- served by fastboot
```
## Using prember from an addon
Addon authors may declare urls *for* prember during compilation. To do so, you will want to:
- Add `prember-plugin` to your addon's package.json `keywords` array;
- Consider also using package.json's `ember-addon` object to configure your addon to run `before: 'prember'`
- Define a `urlsForPrember(distDir, visit)` function in your addon's main file;
- This function shares an interface with the "custom URL discovery" function, as defined above; and
- Advise your addon's users to install & configure `prember` in the host application.
Addon authors may also get access to urls *from* prember. To do so, you will want to:
- Add `prember-plugin` to your addon's package.json `keywords` array;
- Consider also using package.json's `ember-addon` object to configure your addon to run `before: 'prember'`
- Define a `urlsFromPrember(urls)` function in your addon's main file;
- This function will receive the array of urls prember knows about as the only argument; and
- Advise your addon's users to install & configure `prember` in the host application.
## Using prember with Embroider
You can use prember in an Embroider-based build, however you must apply some changes to your `ember-cli-build.js` for it to work.
Embroider does not support the `postprocessTree` (type `all`) hook that this addon uses to *implicitly* hook into the build pipeline.
But it exposes a `prerender` function to do so *explicitly*.
In a [typical Embroider setup](https://github.com/embroider-build/embroider), your `ember-cli-build.js` will look like this:
```js
const { Webpack } = require('@embroider/webpack');
return require('@embroider/compat').compatBuild(app, Webpack);
```
For prember to add its prerendered HTML pages on top of what Embroider already emitted, wrap the compiled output with the `prerender` function like this:
```diff
const { Webpack } = require('@embroider/webpack');
- return require('@embroider/compat').compatBuild(app, Webpack);
+ const compiledApp = require('@embroider/compat').compatBuild(app, Webpack);
+
+ return require('prember').prerender(app, compiledApp);
```
# Deployment
You shouldn't need to do much special -- just make sure the html files get copied along with all your other files.
If you're using `ember-cli-deploy-s3`, you just need to customize the `filePattern` setting so it includes `.html` files. For example:
```js
ENV.s3 = {
bucket: 'cardstack.com',
region: 'us-east-1',
filePattern: '**/*.{js,css,png,gif,ico,jpg,map,xml,txt,svg,swf,eot,ttf,woff,woff2,otf,html}'
allowOverwrite: true
};
```
# Compared to other addons
There are other ways to pre-render content:
- [ember-prerender](https://github.com/zipfworks/ember-prerender) depends on having a real browser to do prerendering, which is heavy and complex. It's old and unmaintained.
- [ember-cli-prerender](https://github.com/Motokaptia/ember-cli-prerender) uses Fastboot like we do, but it is not integrated with the build pipeline (so it's harder to make it Just Work™ with things like [ember-cli-deploy](http://ember-cli-deploy.com/)) and it has stronger opinions about what URLs it will discover, including blueprint-driven sitemap configuration.
- [ember-cli-staticboot](https://github.com/robwebdev/ember-cli-staticboot) is quite similar to this addon, and I didn't realize it existed before I started making this one. I do think `prember` does a better job of integrating the static build output with the existing ember app in a way that requires the minimal webserver configuration.
Contributing
------------------------------------------------------------------------------
See the [Contributing](CONTRIBUTING.md) guide for details.
License
------------------------------------------------------------------------------
This project is licensed under the [MIT License](LICENSE.md).
================================================
FILE: RELEASE.md
================================================
# Release Process
Releases in this repo are mostly automated using [release-plan](https://github.com/embroider-build/release-plan/). Once you label all your PRs correctly (see below) you will have an automatically generated PR that updates your CHANGELOG.md file and a `.release-plan.json` that is used to prepare the release once the PR is merged.
## Preparation
Since the majority of the actual release process is automated, the remaining tasks before releasing are:
- correctly labeling **all** pull requests that have been merged since the last release
- updating pull request titles so they make sense to our users
Some great information on why this is important can be found at [keepachangelog.com](https://keepachangelog.com/en/1.1.0/), but the overall
guiding principle here is that changelogs are for humans, not machines.
When reviewing merged PR's the labels to be used are:
* breaking - Used when the PR is considered a breaking change.
* enhancement - Used when the PR adds a new feature or enhancement.
* bug - Used when the PR fixes a bug included in a previous release.
* documentation - Used when the PR adds or updates documentation.
* internal - Internal changes or things that don't fit in any other category.
**Note:** `release-plan` requires that **all** PRs are labeled. If a PR doesn't fit in a category it's fine to label it as `internal`
## Release
Once the prep work is completed, the actual release is straight forward: you just need to merge the open [Plan Release](https://github.com/ef4/prember/pulls?q=is%3Apr+is%3Aopen+%22Prepare+Release%22+in%3Atitle) PR
================================================
FILE: addon/.gitkeep
================================================
================================================
FILE: app/.gitkeep
================================================
================================================
FILE: config/ember-try.js
================================================
'use strict';
const getChannelURL = require('ember-source-channel-url');
const { embroiderSafe, embroiderOptimized } = require('@embroider/test-setup');
module.exports = async function () {
return {
usePnpm: true,
command: 'pnpm test',
scenarios: [
{
name: 'ember-lts-3.20',
npm: {
devDependencies: {
'ember-source': '~3.20.5',
},
},
},
{
name: 'ember-lts-3.24',
npm: {
devDependencies: {
'ember-source': '~3.24.3',
},
},
},
{
name: 'ember-release',
npm: {
devDependencies: {
'ember-source': await getChannelURL('release'),
},
},
},
{
name: 'ember-beta',
npm: {
devDependencies: {
'ember-source': await getChannelURL('beta'),
},
},
},
{
name: 'ember-canary',
npm: {
devDependencies: {
'ember-source': await getChannelURL('canary'),
},
},
},
{
name: 'ember-default-with-jquery',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'jquery-integration': true,
}),
},
npm: {
devDependencies: {
'@ember/jquery': '^1.1.0',
},
},
},
{
name: 'ember-classic',
env: {
EMBER_OPTIONAL_FEATURES: JSON.stringify({
'application-template-wrapper': true,
'default-async-observers': false,
'template-only-glimmer-components': false,
}),
},
npm: {
devDependencies: {
'ember-source': '~3.28.0',
},
ember: {
edition: 'classic',
},
},
},
embroiderSafe(),
embroiderOptimized(),
],
};
};
================================================
FILE: config/environment.js
================================================
'use strict';
module.exports = function (/* environment, appConfig */) {
return {};
};
================================================
FILE: ember-cli-build.js
================================================
'use strict';
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
const urls = require('./node-tests/url-tester');
module.exports = function (defaults) {
let app = new EmberAddon(defaults, {
// This is the configuration for Prember's dummy app that we use
// to test prember. You would do something similar to this in your
// own app's ember-cli-build.js to configure prember, see the
// README.
prember: {
enabled: true,
urls,
},
});
const { maybeEmbroider } = require('@embroider/test-setup');
const appTree = maybeEmbroider(app, {
skipBabel: [
{
package: 'qunit',
},
],
});
if ('@embroider/core' in app.dependencies()) {
return require('./index').prerender(app, appTree);
} else {
return appTree;
}
};
================================================
FILE: index.js
================================================
'use strict';
const premberConfig = require('./lib/config');
const path = require('path');
const fs = require('fs');
module.exports = {
name: require('./package').name,
premberConfig,
included(app) {
this.fastbootOptions = fastbootOptionsFor(app.env, app.project);
},
postprocessTree(type, tree) {
if (type !== 'all') {
return tree;
}
return this._prerenderTree(tree);
},
/**
* This function is *not* called by ember-cli directly, but supposed to be imported by an app to wrap the app's
* tree, to add the prerendered HTML files. This workaround is currently needed for Embroider-based builds that
* don't support the `postprocessTree('all', tree)` hook used here.
*/
prerender(app, tree) {
let premberAddon = app.project.addons.find(
({ name }) => name === 'prember'
);
if (!premberAddon) {
throw new Error(
"Could not find initialized prember addon. It must be part of your app's dependencies!"
);
}
return premberAddon._prerenderTree(tree);
},
_prerenderTree(tree) {
let config = this.premberConfig();
if (!config.enabled) {
return tree;
}
config.fastbootOptions = this.fastbootOptions;
let Prerender = require('./lib/prerender');
let BroccoliDebug = require('broccoli-debug');
let Merge = require('broccoli-merge-trees');
let debug = BroccoliDebug.buildDebugCallback(`prember`);
let ui = this.project.ui;
let plugins = loadPremberPlugins(this);
return debug(
new Merge(
[
tree,
new Prerender(
debug(tree, 'input'),
config,
ui,
plugins,
this._rootURL
),
],
{
overwrite: true,
}
),
'output'
);
},
config: function (env, baseConfig) {
this._rootURL = baseConfig.rootURL;
},
};
function loadPremberPlugins(context) {
let addons = context.project.addons || [];
return addons
.filter((addon) => addon.pkg.keywords.includes('prember-plugin'))
.filter((addon) => {
return (
typeof addon.urlsForPrember === 'function' ||
typeof addon.urlsFromPrember === 'function'
);
})
.map((addon) => {
const premberPlugin = {};
if (addon.urlsForPrember) {
premberPlugin.urlsForPrember = addon.urlsForPrember.bind(addon);
}
if (addon.urlsFromPrember) {
premberPlugin.urlsFromPrember = addon.urlsFromPrember.bind(addon);
}
return premberPlugin;
});
}
function fastbootOptionsFor(environment, project) {
const configPath = path.join(
path.dirname(project.configPath()),
'fastboot.js'
);
if (fs.existsSync(configPath)) {
return require(configPath)(environment);
}
return {};
}
================================================
FILE: lib/.eslintrc.js
================================================
module.exports = {
env: {
node: true,
browser: false,
},
};
================================================
FILE: lib/config.js
================================================
function findHost(context) {
var current = context;
var app;
// Keep iterating upward until we don't have a grandparent.
// Has to do this grandparent check because at some point we hit the project.
do {
app = current.app || app;
} while (
current.parent &&
current.parent.parent &&
(current = current.parent)
);
return app;
}
function loadConfig(context) {
let app = findHost(context);
let config = app.options.prember || {};
if (config.enabled == null) {
config.enabled = app.env === 'production';
}
if (process.env.PREMBER) {
config.enabled = true;
}
return config;
}
module.exports = function () {
if (!this._premberConfig) {
this._premberConfig = loadConfig(this);
}
return this._premberConfig;
};
================================================
FILE: lib/prerender.js
================================================
const Plugin = require('broccoli-plugin');
const FastBoot = require('fastboot');
const { writeFile, readFile } = require('fs/promises');
const { mkdirp } = require('mkdirp');
const path = require('path');
const chalk = require('chalk');
const express = require('express');
const { URL } = require('url');
const protocol = 'http';
const port = 7784;
// We need to have some origin for the purpose of serving redirects
// and static assets
class Prerender extends Plugin {
constructor(
builtAppTree,
{ urls, indexFile, emptyFile, fastbootOptions, requestsPerFastboot },
ui,
plugins,
rootURL
) {
super([builtAppTree], { name: 'prember', needsCache: false });
this.urls = urls || [];
this.indexFile = indexFile || 'index.html';
this.emptyFile = emptyFile || '_empty.html';
this.ui = ui;
this.plugins = plugins;
this.rootURL = rootURL;
this.protocol = protocol;
this.port = port;
this.host = `localhost:${port}`;
this.fastbootOptions = fastbootOptions || {};
this.requestsPerFastboot = requestsPerFastboot || 1000;
this.app = undefined;
this.visitCounter = 0;
}
async listUrls(protocol, host) {
let visit = async (url) => {
return this._visit(protocol, host, url);
};
if (typeof this.urls === 'function') {
this.urls = await this.urls({ distDir: this.inputPaths[0], visit });
}
for (let plugin of this.plugins) {
if (plugin.urlsForPrember) {
this.urls = this.urls.concat(
await plugin.urlsForPrember(this.inputPaths[0], visit)
);
}
}
for (let plugin of this.plugins) {
if (plugin.urlsFromPrember) {
await plugin.urlsFromPrember(this.urls);
}
}
return this.urls;
}
async build() {
let pkg;
try {
pkg = require(path.join(this.inputPaths[0], 'package.json'));
} catch (err) {
throw new Error(
`Unable to load package.json from within your built application. Did you forget to add ember-cli-fastboot to your app? ${err}`
);
}
/* Move the original "empty" index.html HTML file to an
out-of-the-way place, and rewrite the fastboot manifest to
point at it. This ensures that:
(1) even if you have prerendered the contents of your homepage,
causing the empty "index.html" to get replaced with actual
content, we still keep a copy of the original empty
index.html file that can be used to serve URLs that don't
have a prerendered version. You wouldn't want a flash of
your homepage content to appear on every non-prerendered
route.
(2) if you choose to run the prerendered app inside a fastboot
server for some reason (this happens in development by
default), fastboot will still work correctly because it can
find the empty index.html file.
*/
let fastbootManifestSchema = pkg.fastboot.schemaVersion;
let htmlFilename =
fastbootManifestSchema < 5
? pkg.fastboot.manifest.htmlFile
: pkg.fastboot.htmlEntrypoint;
let htmlFile = await readFile(
path.join(this.inputPaths[0], htmlFilename),
'utf8'
);
await writeFile(path.join(this.outputPath, this.emptyFile), htmlFile);
pkg = JSON.parse(JSON.stringify(pkg));
if (fastbootManifestSchema < 5) {
pkg.fastboot.manifest.htmlFile = this.emptyFile;
} else {
pkg.fastboot.htmlEntrypoint = this.emptyFile;
}
await writeFile(
path.join(this.outputPath, 'package.json'),
JSON.stringify(pkg)
);
let expressServer = express()
.use(this.rootURL, express.static(this.inputPaths[0]))
.listen(this.port);
let hadFailures = false;
for (let url of await this.listUrls(this.protocol, this.host)) {
try {
hadFailures =
!(await this._prerender(this.protocol, this.host, url)) ||
hadFailures;
} catch (err) {
hadFailures = true;
this.ui.writeLine(
`pre-render ${url} ${chalk.red('failed with exception')}: ${err}`
);
}
}
expressServer.close();
if (hadFailures) {
throw new Error('Some pre-rendered URLs had failures');
}
}
async _visit(protocol, host, url) {
// keep track of calls to visit so we know when we can recycle the fastboot instance
this.visitCounter++;
if (!this.app || this.visitCounter > this.requestsPerFastboot) {
this.visitCounter = 0;
this.app = new FastBoot(
Object.assign({}, this.fastbootOptions, {
distPath: this.inputPaths[0],
})
);
}
let opts = {
request: {
url,
protocol,
headers: {
host,
'x-broccoli': {
outputPath: this.inputPaths[0],
},
},
},
};
return await this.app.visit(url, opts);
}
async _prerender(protocol, host, url) {
let page = await this._visit(protocol, host, url);
if (page.statusCode === 200) {
let html = await page.html();
await this._writeFile(url, html);
this.ui.writeLine(`pre-render ${url} ${chalk.green('200 OK')}`);
return true;
} else if (page.statusCode >= 300 && page.statusCode < 400) {
let location = page.headers.headers.location[0];
let redirectTo = new URL(location, `http://${host}${this.rootURL}`)
.pathname;
let html = `<meta http-equiv="refresh" content="0;url=${redirectTo}"><link rel="canonical" href="${redirectTo}" />`;
await this._writeFile(url, html);
this.ui.writeLine(
`pre-render ${url} ${chalk.yellow(page.statusCode)} ${location}`
);
return true;
} else {
this.ui.writeLine(`pre-render ${url} ${chalk.red(page.statusCode)}`);
}
}
async _writeFile(url, html) {
let filename = path.join(
this.outputPath,
url.replace(this.rootURL, '/'),
this.indexFile
);
await mkdirp(path.dirname(filename));
await writeFile(filename, html);
}
}
module.exports = Prerender;
================================================
FILE: node-tests/basic-test.js
================================================
const { execFileSync } = require('child_process');
const { module: Qmodule, test } = require('qunit');
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
const fs = require('fs');
function findDocument(filename) {
let dom = new JSDOM(fs.readFileSync(`dist/${filename}`));
return dom.window.document;
}
Qmodule('Prember', function (hooks) {
hooks.before(async function () {
if (!process.env.REUSE_FASTBOOT_BUILD) {
execFileSync('pnpm', ['ember', 'build']);
}
process.env.REUSE_FASTBOOT_BUILD = true;
});
test('it renders /', function (assert) {
let doc = findDocument('index.html');
assert.equal(
doc.querySelector('[data-test-id="index-content"]').textContent,
'This is some content'
);
});
test('it works with ember-cli-head', function (assert) {
let doc = findDocument('index.html');
assert.equal(
doc.querySelector('meta[property="og:description"]').content,
'OG Description from Index Route'
);
});
test('it works with ember-page-title', function (assert) {
let doc = findDocument('index.html');
assert.equal(
doc.querySelector('title').textContent,
'Document Title from page-title'
);
});
test('the URL discovery function can crawl the running app', function (assert) {
// this test is relying on configuration in our ember-cli-build.js
let doc = findDocument('discovered/index.html');
assert.equal(doc.querySelector('h1').textContent, 'Discovered');
});
test('the URL discovery function can inspect the app build output', function (assert) {
// this test is relying on configuration in our ember-cli-build.js
let doc = findDocument('from-sample-data/index.html');
assert.equal(doc.querySelector('h1').textContent, 'From Sample Data');
});
test('fastboot-rendered routes have access to static assets', function (assert) {
// this test is relying on configuration in our ember-cli-build.js
let doc = findDocument('use-static-asset/index.html');
assert.equal(
doc.querySelector('.message').textContent,
'This is from static json'
);
});
test('redirects via meta http-eqiv refresh', function (assert) {
// this test is relying on configuration in our ember-cli-build.js
let doc = findDocument('redirects/index.html');
assert.equal(
doc.querySelector('meta[http-equiv=refresh]').getAttribute('content'),
'0;url=/from-sample-data'
);
});
test('redirects have rel canonical', function (assert) {
// this test is relying on configuration in our ember-cli-build.js
let doc = findDocument('redirects/index.html');
assert.equal(
doc.querySelector('link[rel=canonical]').getAttribute('href'),
'/from-sample-data'
);
});
});
================================================
FILE: node-tests/url-tester.js
================================================
const jsdom = require('jsdom');
const { JSDOM } = jsdom;
module.exports = async function ({ distDir, visit }) {
let urls = ['/', '/redirects', '/use-static-asset'];
// Here we exercise the ability to make requests against the
// fastboot app in order to discover more urls
let page = await visit('/');
if (page.statusCode === 200) {
let html = await page.html();
let dom = new JSDOM(html);
for (let aTag of [...dom.window.document.querySelectorAll('a')]) {
if (aTag.href) {
urls.push(aTag.href);
}
}
}
// Here we exercise the ability to inspect the build output of the
// app to discover more urls
let sampleData = require(distDir + '/sample-data.json');
for (let entry of sampleData) {
urls.push(entry.url);
}
return urls;
};
================================================
FILE: package.json
================================================
{
"name": "prember",
"version": "2.1.0",
"description": "Prerender Ember apps using Fastboot at build time.",
"keywords": [
"ember-addon",
"fastboot",
"prerender"
],
"repository": "https://github.com/ef4/prember",
"license": "MIT",
"author": "Edward Faulkner <edward@eaf4.com>",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build --environment=production",
"lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
"lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"start": "ember serve",
"test": "qunit node-tests/*-test.js"
},
"dependencies": {
"broccoli-debug": "^0.6.3",
"broccoli-merge-trees": "^4.2.0",
"broccoli-plugin": "^4.0.7",
"chalk": "^4.0.0",
"ember-cli-babel": "^7.26.11",
"express": "^4.18.2",
"fastboot": "^4.1.1",
"mkdirp": "^3.0.1"
},
"devDependencies": {
"@ember/optional-features": "^2.0.0",
"@ember/string": "^3.0.1",
"@ember/test-helpers": "^2.4.2",
"@embroider/test-setup": "^0.43.5",
"@glimmer/component": "^1.0.4",
"@glimmer/tracking": "^1.0.4",
"babel-eslint": "^10.1.0",
"broccoli-asset-rev": "^3.0.0",
"ember-auto-import": "^2.2.3",
"ember-cli": "~3.28.3",
"ember-cli-dependency-checker": "^3.2.0",
"ember-cli-fastboot": "^4.1.1",
"ember-cli-head": "^2.0.0",
"ember-cli-htmlbars": "^5.7.1",
"ember-cli-inject-live-reload": "^2.1.0",
"ember-cli-sri": "^2.1.1",
"ember-cli-terser": "^4.0.2",
"ember-disable-prototype-extensions": "^1.1.3",
"ember-fetch": "^8.1.1",
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^1.0.0",
"ember-page-title": "^7.0.0",
"ember-qunit": "^5.1.4",
"ember-resolver": "^8.0.3",
"ember-source": "~3.28.0",
"ember-source-channel-url": "^3.0.0",
"ember-try": "^3.0.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-ember": "^10.5.4",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-qunit": "^6.2.0",
"jsdom": "^11.5.1",
"loader.js": "^4.7.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"qunit": "^2.16.0",
"qunit-dom": "^1.6.0",
"release-plan": "^0.9.0",
"webpack": "^5.59.0"
},
"engines": {
"node": "12.* || 14.* || >= 16"
},
"ember": {
"edition": "octane"
},
"ember-addon": {
"configPath": "tests/dummy/config",
"after": [
"ember-cli-fastboot",
"ember-engines",
"ember-auto-import"
],
"before": [
"broccoli-asset-rev"
]
}
}
================================================
FILE: testem.js
================================================
'use strict';
module.exports = {
test_page: 'tests/index.html?hidepassed',
disable_watching: true,
launch_in_ci: ['Chrome'],
launch_in_dev: ['Chrome'],
browser_start_timeout: 120,
browser_args: {
Chrome: {
ci: [
// --no-sandbox is needed when running Chrome inside a container
process.env.CI ? '--no-sandbox' : null,
'--headless',
'--disable-dev-shm-usage',
'--disable-software-rasterizer',
'--mute-audio',
'--remote-debugging-port=0',
'--window-size=1440,900',
].filter(Boolean),
},
},
};
================================================
FILE: tests/dummy/app/app.js
================================================
import Application from '@ember/application';
import Resolver from 'ember-resolver';
import loadInitializers from 'ember-load-initializers';
import config from 'dummy/config/environment';
export default class App extends Application {
modulePrefix = config.modulePrefix;
podModulePrefix = config.podModulePrefix;
Resolver = Resolver;
}
loadInitializers(App, config.modulePrefix);
================================================
FILE: tests/dummy/app/components/.gitkeep
================================================
================================================
FILE: tests/dummy/app/controllers/.gitkeep
================================================
================================================
FILE: tests/dummy/app/helpers/.gitkeep
================================================
================================================
FILE: tests/dummy/app/index.html
================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for "head"}}
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link integrity="" rel="stylesheet" href="{{rootURL}}assets/dummy.css">
{{content-for "head-footer"}}
</head>
<body>
{{content-for "body"}}
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/dummy.js"></script>
{{content-for "body-footer"}}
</body>
</html>
================================================
FILE: tests/dummy/app/models/.gitkeep
================================================
================================================
FILE: tests/dummy/app/router.js
================================================
import EmberRouter from '@ember/routing/router';
import config from 'dummy/config/environment';
import { inject } from '@ember/service';
export default class Router extends EmberRouter {
location = config.locationType;
rootURL = config.rootURL;
// This implements is the standard instructions from ember-cli-document-title
// for making it play nicely with ember-cli-head
@inject()
headData;
setTitle(title) {
this.headData.set('title', title);
}
}
Router.map(function () {
this.route('discovered');
this.route('from-sample-data');
this.route('use-static-asset');
this.route('redirects');
});
================================================
FILE: tests/dummy/app/routes/.gitkeep
================================================
================================================
FILE: tests/dummy/app/routes/index.js
================================================
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class IndexRoute extends Route {
@service
headData;
afterModel() {
this.headData.description = 'OG Description from Index Route';
}
}
================================================
FILE: tests/dummy/app/routes/redirects.js
================================================
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
export default class RedirectsRoute extends Route {
@service router;
beforeModel() {
return this.router.transitionTo('from-sample-data');
}
}
================================================
FILE: tests/dummy/app/routes/use-static-asset.js
================================================
import Route from '@ember/routing/route';
import fetch from 'fetch';
import { inject as service } from '@ember/service';
export default class UseStaticAssetRoute extends Route {
@service
fastboot;
async model() {
let url;
if (this.fastboot.isFastBoot) {
url = `http://${this.fastboot.request.host}/static.json`;
} else {
url = '/static.json';
}
let response = await fetch(url);
let json = await response.json();
return json;
}
}
================================================
FILE: tests/dummy/app/styles/app.css
================================================
================================================
FILE: tests/dummy/app/templates/application.hbs
================================================
{{head-layout}}
<h2 id="title">Welcome to Ember</h2>
{{outlet}}
================================================
FILE: tests/dummy/app/templates/discovered.hbs
================================================
<h1>Discovered</h1>
================================================
FILE: tests/dummy/app/templates/from-sample-data.hbs
================================================
<h1>From Sample Data</h1>
================================================
FILE: tests/dummy/app/templates/head.hbs
================================================
<title>{{this.model.title}}</title>
<meta property="og:description" content={{this.model.description}} />
================================================
FILE: tests/dummy/app/templates/index.hbs
================================================
{{page-title "Document Title from page-title"}}
<div data-test-id="index-content">This is some content</div>
<a href="/discovered">discovered</a>
================================================
FILE: tests/dummy/app/templates/use-static-asset.hbs
================================================
<div class="message">{{this.model.message}}</div>
================================================
FILE: tests/dummy/config/ember-cli-update.json
================================================
{
"schemaVersion": "1.0.0",
"packages": [
{
"name": "ember-cli",
"version": "3.28.3",
"blueprints": [
{
"name": "addon",
"outputRepo": "https://github.com/ember-cli/ember-addon-output",
"codemodsSource": "ember-addon-codemods-manifest@1",
"isBaseBlueprint": true,
"options": [
"--yarn",
"--no-welcome"
]
}
]
}
]
}
================================================
FILE: tests/dummy/config/environment.js
================================================
'use strict';
module.exports = function (environment) {
let ENV = {
modulePrefix: 'dummy',
environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
// Here you can enable experimental features on an ember canary build
// e.g. EMBER_NATIVE_DECORATOR_SUPPORT: true
},
EXTEND_PROTOTYPES: {
// Prevent Ember Data from overriding Date.parse.
Date: false,
},
},
APP: {
// Here you can pass flags/options to your application instance
// when it is created
},
fastboot: {
hostWhitelist: [/^localhost:\d+$/],
},
};
if (environment === 'development') {
// ENV.APP.LOG_RESOLVER = true;
// ENV.APP.LOG_ACTIVE_GENERATION = true;
// ENV.APP.LOG_TRANSITIONS = true;
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
// ENV.APP.LOG_VIEW_LOOKUPS = true;
}
if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
ENV.APP.autoboot = false;
}
if (environment === 'production') {
// here you can enable a production-specific feature
}
return ENV;
};
================================================
FILE: tests/dummy/config/optional-features.json
================================================
{
"application-template-wrapper": false,
"default-async-observers": true,
"jquery-integration": false,
"template-only-glimmer-components": true
}
================================================
FILE: tests/dummy/config/targets.js
================================================
'use strict';
const browsers = [
'last 1 Chrome versions',
'last 1 Firefox versions',
'last 1 Safari versions',
];
// Ember's browser support policy is changing, and IE11 support will end in
// v4.0 onwards.
//
// See https://deprecations.emberjs.com/v3.x#toc_3-0-browser-support-policy
//
// If you need IE11 support on a version of Ember that still offers support
// for it, uncomment the code block below.
//
// const isCI = Boolean(process.env.CI);
// const isProduction = process.env.EMBER_ENV === 'production';
//
// if (isCI || isProduction) {
// browsers.push('ie 11');
// }
module.exports = {
browsers,
node: true,
};
================================================
FILE: tests/dummy/public/robots.txt
================================================
# http://www.robotstxt.org
User-agent: *
Disallow:
================================================
FILE: tests/dummy/public/sample-data.json
================================================
[
{
"url": "/from-sample-data"
}
]
================================================
FILE: tests/dummy/public/static.json
================================================
{
"message": "This is from static json"
}
================================================
FILE: tests/helpers/.gitkeep
================================================
================================================
FILE: tests/index.html
================================================
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Dummy Tests</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{content-for "head"}}
{{content-for "test-head"}}
<link rel="stylesheet" href="{{rootURL}}assets/vendor.css">
<link rel="stylesheet" href="{{rootURL}}assets/dummy.css">
<link rel="stylesheet" href="{{rootURL}}assets/test-support.css">
{{content-for "head-footer"}}
{{content-for "test-head-footer"}}
</head>
<body>
{{content-for "body"}}
{{content-for "test-body"}}
<div id="qunit"></div>
<div id="qunit-fixture">
<div id="ember-testing-container">
<div id="ember-testing"></div>
</div>
</div>
<script src="/testem.js" integrity="" data-embroider-ignore></script>
<script src="{{rootURL}}assets/vendor.js"></script>
<script src="{{rootURL}}assets/test-support.js"></script>
<script src="{{rootURL}}assets/dummy.js"></script>
<script src="{{rootURL}}assets/tests.js"></script>
{{content-for "body-footer"}}
{{content-for "test-body-footer"}}
</body>
</html>
================================================
FILE: tests/integration/.gitkeep
================================================
================================================
FILE: tests/test-helper.js
================================================
import Application from 'dummy/app';
import config from 'dummy/config/environment';
import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';
setApplication(Application.create(config.APP));
setup(QUnit.assert);
start();
================================================
FILE: tests/unit/.gitkeep
================================================
================================================
FILE: vendor/.gitkeep
================================================
gitextract_d48536wg/
├── .editorconfig
├── .ember-cli
├── .eslintignore
├── .eslintrc.js
├── .github/
│ └── workflows/
│ ├── ci.yml
│ ├── plan-release.yml
│ └── publish.yml
├── .gitignore
├── .npmignore
├── .prettierignore
├── .prettierrc.js
├── .release-plan.json
├── .watchmanconfig
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE.md
├── README.md
├── RELEASE.md
├── addon/
│ └── .gitkeep
├── app/
│ └── .gitkeep
├── config/
│ ├── ember-try.js
│ └── environment.js
├── ember-cli-build.js
├── index.js
├── lib/
│ ├── .eslintrc.js
│ ├── config.js
│ └── prerender.js
├── node-tests/
│ ├── basic-test.js
│ └── url-tester.js
├── package.json
├── testem.js
├── tests/
│ ├── dummy/
│ │ ├── app/
│ │ │ ├── app.js
│ │ │ ├── components/
│ │ │ │ └── .gitkeep
│ │ │ ├── controllers/
│ │ │ │ └── .gitkeep
│ │ │ ├── helpers/
│ │ │ │ └── .gitkeep
│ │ │ ├── index.html
│ │ │ ├── models/
│ │ │ │ └── .gitkeep
│ │ │ ├── router.js
│ │ │ ├── routes/
│ │ │ │ ├── .gitkeep
│ │ │ │ ├── index.js
│ │ │ │ ├── redirects.js
│ │ │ │ └── use-static-asset.js
│ │ │ ├── styles/
│ │ │ │ └── app.css
│ │ │ └── templates/
│ │ │ ├── application.hbs
│ │ │ ├── discovered.hbs
│ │ │ ├── from-sample-data.hbs
│ │ │ ├── head.hbs
│ │ │ ├── index.hbs
│ │ │ └── use-static-asset.hbs
│ │ ├── config/
│ │ │ ├── ember-cli-update.json
│ │ │ ├── environment.js
│ │ │ ├── optional-features.json
│ │ │ └── targets.js
│ │ └── public/
│ │ ├── robots.txt
│ │ ├── sample-data.json
│ │ └── static.json
│ ├── helpers/
│ │ └── .gitkeep
│ ├── index.html
│ ├── integration/
│ │ └── .gitkeep
│ ├── test-helper.js
│ └── unit/
│ └── .gitkeep
└── vendor/
└── .gitkeep
SYMBOL INDEX (25 symbols across 9 files)
FILE: index.js
method included (line 11) | included(app) {
method postprocessTree (line 15) | postprocessTree(type, tree) {
method prerender (line 28) | prerender(app, tree) {
method _prerenderTree (line 42) | _prerenderTree(tree) {
function loadPremberPlugins (line 82) | function loadPremberPlugins(context) {
function fastbootOptionsFor (line 108) | function fastbootOptionsFor(environment, project) {
FILE: lib/config.js
function findHost (line 1) | function findHost(context) {
function loadConfig (line 18) | function loadConfig(context) {
FILE: lib/prerender.js
class Prerender (line 15) | class Prerender extends Plugin {
method constructor (line 16) | constructor(
method listUrls (line 39) | async listUrls(protocol, host) {
method build (line 65) | async build() {
method _visit (line 141) | async _visit(protocol, host, url) {
method _prerender (line 169) | async _prerender(protocol, host, url) {
method _writeFile (line 191) | async _writeFile(url, html) {
FILE: node-tests/basic-test.js
function findDocument (line 7) | function findDocument(filename) {
FILE: tests/dummy/app/app.js
class App (line 6) | class App extends Application {
FILE: tests/dummy/app/router.js
class Router (line 5) | class Router extends EmberRouter {
method setTitle (line 14) | setTitle(title) {
FILE: tests/dummy/app/routes/index.js
class IndexRoute (line 4) | class IndexRoute extends Route {
method afterModel (line 8) | afterModel() {
FILE: tests/dummy/app/routes/redirects.js
class RedirectsRoute (line 4) | class RedirectsRoute extends Route {
method beforeModel (line 6) | beforeModel() {
FILE: tests/dummy/app/routes/use-static-asset.js
class UseStaticAssetRoute (line 5) | class UseStaticAssetRoute extends Route {
method model (line 9) | async model() {
Condensed preview — 62 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (60K chars).
[
{
"path": ".editorconfig",
"chars": 367,
"preview": "# EditorConfig helps developers define and maintain consistent\n# coding styles between different editors and IDEs\n# edit"
},
{
"path": ".ember-cli",
"chars": 280,
"preview": "{\n /**\n Ember CLI sends analytics information by default. The data is completely\n anonymous, but there are times "
},
{
"path": ".eslintignore",
"chars": 257,
"preview": "# unconventional js\n/blueprints/*/files/\n/vendor/\n\n# compiled output\n/dist/\n/tmp/\n\n# dependencies\n/bower_components/\n/no"
},
{
"path": ".eslintrc.js",
"chars": 1078,
"preview": "'use strict';\n\nmodule.exports = {\n root: true,\n parser: 'babel-eslint',\n parserOptions: {\n ecmaVersion: 2018,\n "
},
{
"path": ".github/workflows/ci.yml",
"chars": 1811,
"preview": "name: CI\n\non:\n push:\n branches:\n - master\n - main\n pull_request:\n\njobs:\n test:\n name: Tests\n runs-"
},
{
"path": ".github/workflows/plan-release.yml",
"chars": 3273,
"preview": "name: Release Plan Review\non:\n push:\n branches:\n - main\n - master\n pull_request_target: # This workflow h"
},
{
"path": ".github/workflows/publish.yml",
"chars": 1793,
"preview": "# For every push to the master branch, this checks if the release-plan was\n# updated and if it was it will publish stabl"
},
{
"path": ".gitignore",
"chars": 383,
"preview": "# See https://help.github.com/ignore-files/ for more about ignoring files.\n\n# compiled output\n/dist/\n/tmp/\n\n# dependenci"
},
{
"path": ".npmignore",
"chars": 486,
"preview": "# compiled output\n/dist/\n/tmp/\n\n# dependencies\n/bower_components/\n\n# misc\n/.bowerrc\n/.editorconfig\n/.ember-cli\n/.env*\n/."
},
{
"path": ".prettierignore",
"chars": 253,
"preview": "# unconventional js\n/blueprints/*/files/\n/vendor/\n\n# compiled output\n/dist/\n/tmp/\n\n# dependencies\n/bower_components/\n/no"
},
{
"path": ".prettierrc.js",
"chars": 58,
"preview": "'use strict';\n\nmodule.exports = {\n singleQuote: true,\n};\n"
},
{
"path": ".release-plan.json",
"chars": 1039,
"preview": "{\n \"solution\": {\n \"prember\": {\n \"impact\": \"minor\",\n \"oldVersion\": \"2.0.0\",\n \"newVersion\": \"2.1.0\",\n "
},
{
"path": ".watchmanconfig",
"chars": 37,
"preview": "{\n \"ignore_dirs\": [\"tmp\", \"dist\"]\n}\n"
},
{
"path": "CHANGELOG.md",
"chars": 1856,
"preview": "# Changelog\n\n## Release (2024-07-05)\n\nprember 2.1.0 (minor)\n\n#### :rocket: Enhancement\n* `prember`\n * [#82](https://git"
},
{
"path": "CONTRIBUTING.md",
"chars": 596,
"preview": "# How To Contribute\n\n## Installation\n\n* `git clone <repository-url>`\n* `cd prember`\n* `yarn install`\n\n## Linting\n\n* `yar"
},
{
"path": "LICENSE.md",
"chars": 1066,
"preview": "The MIT License (MIT)\n\nCopyright (c) 2018\n\nPermission is hereby granted, free of charge, to any person obtaining a copy "
},
{
"path": "README.md",
"chars": 10929,
"preview": "# prember = Pre Render Ember\n\nA **progressive static-site generator** for Ember\n\n\nThis Ember addon allows you to pre-ren"
},
{
"path": "RELEASE.md",
"chars": 1602,
"preview": "# Release Process\n\nReleases in this repo are mostly automated using [release-plan](https://github.com/embroider-build/re"
},
{
"path": "addon/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "app/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "config/ember-try.js",
"chars": 1924,
"preview": "'use strict';\n\nconst getChannelURL = require('ember-source-channel-url');\nconst { embroiderSafe, embroiderOptimized } = "
},
{
"path": "config/environment.js",
"chars": 90,
"preview": "'use strict';\n\nmodule.exports = function (/* environment, appConfig */) {\n return {};\n};\n"
},
{
"path": "ember-cli-build.js",
"chars": 811,
"preview": "'use strict';\n\nconst EmberAddon = require('ember-cli/lib/broccoli/ember-addon');\nconst urls = require('./node-tests/url-"
},
{
"path": "index.js",
"chars": 2815,
"preview": "'use strict';\n\nconst premberConfig = require('./lib/config');\nconst path = require('path');\nconst fs = require('fs');\n\nm"
},
{
"path": "lib/.eslintrc.js",
"chars": 72,
"preview": "module.exports = {\n env: {\n node: true,\n browser: false,\n },\n};\n"
},
{
"path": "lib/config.js",
"chars": 771,
"preview": "function findHost(context) {\n var current = context;\n var app;\n\n // Keep iterating upward until we don't have a grand"
},
{
"path": "lib/prerender.js",
"chars": 6079,
"preview": "const Plugin = require('broccoli-plugin');\nconst FastBoot = require('fastboot');\nconst { writeFile, readFile } = require"
},
{
"path": "node-tests/basic-test.js",
"chars": 2772,
"preview": "const { execFileSync } = require('child_process');\nconst { module: Qmodule, test } = require('qunit');\nconst jsdom = req"
},
{
"path": "node-tests/url-tester.js",
"chars": 795,
"preview": "const jsdom = require('jsdom');\nconst { JSDOM } = jsdom;\n\nmodule.exports = async function ({ distDir, visit }) {\n let u"
},
{
"path": "package.json",
"chars": 2774,
"preview": "{\n \"name\": \"prember\",\n \"version\": \"2.1.0\",\n \"description\": \"Prerender Ember apps using Fastboot at build time.\",\n \"k"
},
{
"path": "testem.js",
"chars": 589,
"preview": "'use strict';\n\nmodule.exports = {\n test_page: 'tests/index.html?hidepassed',\n disable_watching: true,\n launch_in_ci: "
},
{
"path": "tests/dummy/app/app.js",
"chars": 388,
"preview": "import Application from '@ember/application';\nimport Resolver from 'ember-resolver';\nimport loadInitializers from 'ember"
},
{
"path": "tests/dummy/app/components/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/dummy/app/controllers/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/dummy/app/helpers/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/dummy/app/index.html",
"chars": 659,
"preview": "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n "
},
{
"path": "tests/dummy/app/models/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/dummy/app/router.js",
"chars": 625,
"preview": "import EmberRouter from '@ember/routing/router';\nimport config from 'dummy/config/environment';\nimport { inject } from '"
},
{
"path": "tests/dummy/app/routes/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/dummy/app/routes/index.js",
"chars": 257,
"preview": "import Route from '@ember/routing/route';\nimport { inject as service } from '@ember/service';\n\nexport default class Inde"
},
{
"path": "tests/dummy/app/routes/redirects.js",
"chars": 247,
"preview": "import Route from '@ember/routing/route';\nimport { inject as service } from '@ember/service';\n\nexport default class Redi"
},
{
"path": "tests/dummy/app/routes/use-static-asset.js",
"chars": 479,
"preview": "import Route from '@ember/routing/route';\nimport fetch from 'fetch';\nimport { inject as service } from '@ember/service';"
},
{
"path": "tests/dummy/app/styles/app.css",
"chars": 0,
"preview": ""
},
{
"path": "tests/dummy/app/templates/application.hbs",
"chars": 65,
"preview": "{{head-layout}}\n\n<h2 id=\"title\">Welcome to Ember</h2>\n\n{{outlet}}"
},
{
"path": "tests/dummy/app/templates/discovered.hbs",
"chars": 19,
"preview": "<h1>Discovered</h1>"
},
{
"path": "tests/dummy/app/templates/from-sample-data.hbs",
"chars": 25,
"preview": "<h1>From Sample Data</h1>"
},
{
"path": "tests/dummy/app/templates/head.hbs",
"chars": 105,
"preview": "<title>{{this.model.title}}</title>\n<meta property=\"og:description\" content={{this.model.description}} />"
},
{
"path": "tests/dummy/app/templates/index.hbs",
"chars": 147,
"preview": "{{page-title \"Document Title from page-title\"}}\n\n<div data-test-id=\"index-content\">This is some content</div>\n<a href=\"/"
},
{
"path": "tests/dummy/app/templates/use-static-asset.hbs",
"chars": 49,
"preview": "<div class=\"message\">{{this.model.message}}</div>"
},
{
"path": "tests/dummy/config/ember-cli-update.json",
"chars": 452,
"preview": "{\n \"schemaVersion\": \"1.0.0\",\n \"packages\": [\n {\n \"name\": \"ember-cli\",\n \"version\": \"3.28.3\",\n \"bluepri"
},
{
"path": "tests/dummy/config/environment.js",
"chars": 1308,
"preview": "'use strict';\n\nmodule.exports = function (environment) {\n let ENV = {\n modulePrefix: 'dummy',\n environment,\n r"
},
{
"path": "tests/dummy/config/optional-features.json",
"chars": 154,
"preview": "{\n \"application-template-wrapper\": false,\n \"default-async-observers\": true,\n \"jquery-integration\": false,\n \"template"
},
{
"path": "tests/dummy/config/targets.js",
"chars": 642,
"preview": "'use strict';\n\nconst browsers = [\n 'last 1 Chrome versions',\n 'last 1 Firefox versions',\n 'last 1 Safari versions',\n]"
},
{
"path": "tests/dummy/public/robots.txt",
"chars": 51,
"preview": "# http://www.robotstxt.org\nUser-agent: *\nDisallow:\n"
},
{
"path": "tests/dummy/public/sample-data.json",
"chars": 43,
"preview": "[\n {\n \"url\": \"/from-sample-data\"\n }\n]\n"
},
{
"path": "tests/dummy/public/static.json",
"chars": 44,
"preview": "{\n \"message\": \"This is from static json\"\n}\n"
},
{
"path": "tests/helpers/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/index.html",
"chars": 1228,
"preview": "<!DOCTYPE html>\n<html>\n <head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n "
},
{
"path": "tests/integration/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "tests/test-helper.js",
"chars": 323,
"preview": "import Application from 'dummy/app';\nimport config from 'dummy/config/environment';\nimport * as QUnit from 'qunit';\nimpo"
},
{
"path": "tests/unit/.gitkeep",
"chars": 0,
"preview": ""
},
{
"path": "vendor/.gitkeep",
"chars": 0,
"preview": ""
}
]
About this extraction
This page contains the full source code of the ef4/prember GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 62 files (52.7 KB), approximately 15.6k tokens, and a symbol index with 25 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.