Skip to content

Commit a83d556

Browse files
committed
Deploy 'latest' into the root of gh-pages
1 parent 44e3e3f commit a83d556

File tree

4 files changed

+32
-36
lines changed

4 files changed

+32
-36
lines changed

lib/deploy/plugin.js

+20-16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path');
55
const execa = require('execa');
66
const quickTemp = require('quick-temp');
77
const hostedGitInfo = require('hosted-git-info');
8+
const walkSync = require('walk-sync');
89

910
const VERSION_PREFIX = 'v';
1011

@@ -48,7 +49,7 @@ module.exports = class AddonDocsDeployPlugin {
4849

4950
return this._copyExistingFiles(context, relativeBuildDestination)
5051
.then(() => this._copyBuildOutput(context, stagingDirectory, relativeBuildDestination))
51-
.then(() => this._verifyRootFiles(stagingDirectory))
52+
.then(() => this._verifyRedirectFile(stagingDirectory))
5253
.then(() => this._updateVersionsManifest(stagingDirectory))
5354
.then(() => this._maybeUpdateLatest(context, stagingDirectory, fullBuildDestination))
5455
.then(() => context.distDir = stagingDirectory);
@@ -58,18 +59,13 @@ module.exports = class AddonDocsDeployPlugin {
5859
quickTemp.remove(this, 'deployStagingDirectory');
5960
}
6061

61-
_getVersionPath(version = this.userConfig.getVersionPath()) {
62-
return `${VERSION_PREFIX}/${version}`;
62+
_getVersionPath() {
63+
return `${VERSION_PREFIX}/${this.userConfig.getVersionPath()}`;
6364
}
6465

65-
_verifyRootFiles(stagingDirectory) {
66+
_verifyRedirectFile(stagingDirectory) {
6667
let vendorDir = `${__dirname}/../../vendor/ember-cli-addon-docs`;
67-
68-
if (!fs.existsSync(`${stagingDirectory}/index.html`)) {
69-
fs.copySync(`${vendorDir}/index.html`, `${stagingDirectory}/index.html`);
70-
}
71-
72-
let segmentCount = this._getRootURL().split('/').length + 2;
68+
let segmentCount = this._getRootURL().split('/').length;
7369
let redirectContents = fs.readFileSync(`${vendorDir}/404.html`, 'utf-8');
7470
redirectContents = redirectContents.replace(/\bADDON_DOCS_SEGMENT_COUNT\b/g, segmentCount);
7571
fs.writeFileSync(`${stagingDirectory}/404.html`, redirectContents);
@@ -117,12 +113,20 @@ module.exports = class AddonDocsDeployPlugin {
117113
_maybeUpdateLatest(context, stagingDirectory) {
118114
if (!this.userConfig.shouldUpdateLatest()) { return; }
119115

120-
let latestDir = this._getVersionPath('latest');
121-
let fullPath = path.join(stagingDirectory, latestDir);
122116
let deployVersion = this._latestDeployVersion();
123-
return fs.remove(fullPath)
124-
.then(() => fs.copy(context.distDir, fullPath))
125-
.then(() => this._updateIndexContents(context, stagingDirectory, latestDir, deployVersion));
117+
let manifestPath = `${stagingDirectory}/root-deploy-files.json`;
118+
let deletions = [];
119+
120+
if (fs.existsSync(manifestPath)) {
121+
for (let file of fs.readJSONSync(manifestPath)) {
122+
deletions.push(fs.remove(`${stagingDirectory}/${file}`));
123+
}
124+
}
125+
126+
return Promise.all(deletions)
127+
.then(() => fs.writeJSON(manifestPath, walkSync(context.distDir, { directories: false })))
128+
.then(() => fs.copy(context.distDir, stagingDirectory))
129+
.then(() => this._updateIndexContents(context, stagingDirectory, '', deployVersion));
126130
}
127131

128132
_updateIndexContents(context, stagingDirectory, appRoot, deployVersion) {
@@ -145,7 +149,7 @@ module.exports = class AddonDocsDeployPlugin {
145149
}
146150

147151
_latestDeployVersion() {
148-
let path = this._getVersionPath('latest');
152+
let path = '';
149153
let name = 'latest';
150154
let sha = this.userConfig.repoInfo.sha;
151155
let tag = this.userConfig.repoInfo.tag;

tests/dummy/app/pods/docs/deploying/template.md

+6-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Now take a look at the `gh-pages` branch either locally or on GitHub. You should
2020

2121
```sh
2222
├── 404.html
23-
├── index.html
2423
├── v
2524
│ └── [current-branch]
2625
│   ├── assets
@@ -30,12 +29,11 @@ Now take a look at the `gh-pages` branch either locally or on GitHub. You should
3029
```
3130

3231
Let's break down what each of those items is doing.
33-
- `index.html` simply redirects from the root of your gh-pages site to `/v/latest` (more details on that [below](#tag-deploys))
3432
- `404.html` contains [some smart redirect logic](https://github.com/rafrex/spa-github-pages) to keep you from having to use `locationType: 'hash'` in your dummy app
3533
- `versions.json` contains a manifest of the available versions of your documentation
3634
- `v/[current-branch]` contains all the files from your built docs app
3735

38-
If you were to make a change to your dummy app and run `ember deploy production` again right now, the entry for `[current-branch]` in `version.json` and the entire contents of the `v/[current-branch]` directory would be replaced with the updated version of your site. Next we'll talk about how to manage keeping published documentation around for multiple versions of your addon.
36+
If you were to make a change to your dummy app and run `ember deploy production` again right now, the entry for `[current-branch]` in `versions.json` and the entire contents of the `v/[current-branch]` directory would be replaced with the updated version of your site. Next we'll talk about how to manage keeping published documentation around for multiple versions of your addon.
3937

4038
## Versioning your content
4139

@@ -45,15 +43,15 @@ Whenever you deploy your documentation site with Addon Docs, it places the compi
4543

4644
When you run `ember deploy` at a commit that has a git tag associated with it, the app will wind up in a directory named after that tag. For example, if you've just published version 1.2.3 of your addon (creating tag `v1.2.3` in your git repository), your deployed site will be available at <u>https://**[user]**.github.io/**[repo]**/v/1.2.3</u>.
4745

48-
By default, deploying from a tagged commit also places a copy of your app under a special directory called `/v/latest`. As mentioned above, the `index.html` that Addon Docs sets up at the root redirects to `/v/latest`, so <u>https://**[user]**.github.io/**[repo]**</u> will always bring developers to the documentation for the most recent stable release of your addon.
46+
By default, deploying from a tagged commit also places a copy of your app at the root of your `gh-pages` branch, so <u>https://**[user]**.github.io/**[repo]**</u> will always bring developers to the documentation for the most recent stable release of your addon.
4947

50-
Note that this only applies to non-prerelease tags, so `v1.2.3` would update `/v/latest`, but `v2.0.0-beta.1` would not. Check out the documentation for [node-semver](https://github.com/npm/node-semver) for the exact details on what constitutes a prerelease version.
48+
Note that this only applies to non-prerelease tags, so `v1.2.3` would update the root app, but `v2.0.0-beta.1` would not. Check out the documentation for [node-semver](https://github.com/npm/node-semver) for the exact details on what constitutes a prerelease version.
5149

5250
### Branch deploys
5351

54-
When you deploy from a commit at the head of a branch that _doesn't_ have a tag associated with it, the compiled app will land in a folder named after that branch, as in our "getting started" example above. Unlike tag deploys, branch deploys will never automatically update `/v/latest`.
52+
When you deploy from a commit at the head of a branch that _doesn't_ have a tag associated with it, the compiled app will land in a folder named after that branch, as in our "getting started" example above. Unlike tag deploys, branch deploys will never automatically update the root app.
5553

56-
The main use case for branch deploys is tracking development work since your last stable release. If you run `ember deploy` after successful builds on `master`, you'll always have documentation available for the bleeding edge of your addon's features. Since branch deploys don't update `/v/latest`, though, developers looking at your docs will still hit your most recent stable tag by default, so there won't be any confusion about things that have drifted since the last release.
54+
The main use case for branch deploys is tracking development work since your last stable release. If you run `ember deploy` after successful builds on `master`, you'll always have documentation available for the bleeding edge of your addon's features. Since branch deploys don't update the root, though, developers looking at your docs will still hit your most recent stable tag by default, so there won't be any confusion about things that have drifted since the last release.
5755

5856
## Automating deploys
5957

@@ -134,7 +132,7 @@ This method returns a name for a given version of your documentation. By default
134132

135133
### `shouldUpdateLatest()`
136134

137-
This method determines whether the `/v/latest` directory will also be updated with the current deploy. By default, this will return true for builds from a tagged commit where the tag is a [semver non-prerelease version](https://github.com/npm/node-semver), and false otherwise. You can explicitly set the `ADDON_DOCS_UPDATE_LATEST` environment variable to `true` or `false` to override this behavior.
135+
This method determines whether the root copy of your docs app will also be updated with the current deploy. By default, this will return true for builds from a tagged commit where the tag is a [semver non-prerelease version](https://github.com/npm/node-semver), and false otherwise. You can explicitly set the `ADDON_DOCS_UPDATE_LATEST` environment variable to `true` or `false` to override this behavior.
138136

139137
### `getRootURL()`
140138

vendor/ember-cli-addon-docs/404.html

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
var l = window.location;
2727
var segments = l.pathname.split('/');
2828

29+
// If we're looking at a versioned deploy, there are effectively
30+
// two more static segments in the count.
31+
if (segments[segmentCount + 1] === 'v') {
32+
segmentCount += 2;
33+
}
34+
2935
// Avoid an infinite loop if we try to direct to a location that doesn't exist
3036
if (!/^\?p=\/.*&q=.*/.test(l.search)) {
3137
l.replace(

vendor/ember-cli-addon-docs/index.html

-12
This file was deleted.

0 commit comments

Comments
 (0)