Skip to content

Commit 44e3e3f

Browse files
committed
Move deploys under a version namespace
1 parent df76015 commit 44e3e3f

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

lib/config.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module.exports = class AddonDocsConfig {
2222
}
2323

2424
if (this.repoInfo.tag) {
25-
return this.repoInfo.tag;
25+
// Turn v1.0.0 -> 1.0.0 since we're prefixing with /v/
26+
return this.repoInfo.tag.replace(/^v(\d)/i, '$1');
2627
}
2728

2829
return this.repoInfo.branch || process.env.TRAVIS_BRANCH;
@@ -33,7 +34,7 @@ module.exports = class AddonDocsConfig {
3334
return process.env.ADDON_DOCS_VERSION_NAME;
3435
}
3536

36-
return this.getVersionPath();
37+
return this.repoInfo.tag || this.repoInfo.branch || process.env.TRAVIS_BRANCH;
3738
}
3839

3940
shouldUpdateLatest() {

lib/deploy/plugin.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const execa = require('execa');
66
const quickTemp = require('quick-temp');
77
const hostedGitInfo = require('hosted-git-info');
88

9+
const VERSION_PREFIX = 'v';
10+
911
module.exports = class AddonDocsDeployPlugin {
1012
constructor(userConfig) {
1113
this.name = 'addon-docs';
@@ -42,6 +44,8 @@ module.exports = class AddonDocsDeployPlugin {
4244
let stagingDirectory = context.addonDocs.stagingDirectory;
4345
let fullBuildDestination = path.join(stagingDirectory, relativeBuildDestination);
4446

47+
fs.ensureDirSync(fullBuildDestination);
48+
4549
return this._copyExistingFiles(context, relativeBuildDestination)
4650
.then(() => this._copyBuildOutput(context, stagingDirectory, relativeBuildDestination))
4751
.then(() => this._verifyRootFiles(stagingDirectory))
@@ -54,8 +58,8 @@ module.exports = class AddonDocsDeployPlugin {
5458
quickTemp.remove(this, 'deployStagingDirectory');
5559
}
5660

57-
_getVersionPath(version) {
58-
return version || this.userConfig.getVersionPath();
61+
_getVersionPath(version = this.userConfig.getVersionPath()) {
62+
return `${VERSION_PREFIX}/${version}`;
5963
}
6064

6165
_verifyRootFiles(stagingDirectory) {
@@ -65,7 +69,7 @@ module.exports = class AddonDocsDeployPlugin {
6569
fs.copySync(`${vendorDir}/index.html`, `${stagingDirectory}/index.html`);
6670
}
6771

68-
let segmentCount = this._getRootURL().split('/').length + 1;
72+
let segmentCount = this._getRootURL().split('/').length + 2;
6973
let redirectContents = fs.readFileSync(`${vendorDir}/404.html`, 'utf-8');
7074
redirectContents = redirectContents.replace(/\bADDON_DOCS_SEGMENT_COUNT\b/g, segmentCount);
7175
fs.writeFileSync(`${stagingDirectory}/404.html`, redirectContents);

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

+19-18
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,39 @@ Now take a look at the `gh-pages` branch either locally or on GitHub. You should
2121
```sh
2222
├── 404.html
2323
├── index.html
24-
├── [current-branch]
25-
│   ├── assets
26-
│   ├── index.html
27-
│   └── ...
24+
├── v
25+
│ └── [current-branch]
26+
│   ├── assets
27+
│    ├── index.html
28+
│   └── ...
2829
└── versions.json
2930
```
3031

3132
Let's break down what each of those items is doing.
32-
- `index.html` simply redirects from the root of your gh-pages site to `/latest` (more details on that [below](#tag-deploys))
33+
- `index.html` simply redirects from the root of your gh-pages site to `/v/latest` (more details on that [below](#tag-deploys))
3334
- `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
3435
- `versions.json` contains a manifest of the available versions of your documentation
35-
- `[current-branch]` contains all the files from your built docs app
36+
- `v/[current-branch]` contains all the files from your built docs app
3637

37-
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 `[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.
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.
3839

3940
## Versioning your content
4041

4142
Whenever you deploy your documentation site with Addon Docs, it places the compiled application in a subdirectory based on the current state of your git repository. All of this behavior [is customizable](#customizing-deploys), but we expect the out-of-the-box configuration should be a good place to get started.
4243

4344
### Tag deploys
4445

45-
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]**/v1.2.3</u>.
46+
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>.
4647

47-
By default, deploying from a tagged commit also places a copy of your app under a special directory called `/latest`. As mentioned above, the `index.html` that Addon Docs sets up at the root redirects to `/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.
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.
4849

49-
Note that this only applies to non-prerelease tags, so `v1.2.3` would update `/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.
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.
5051

5152
### Branch deploys
5253

53-
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 `/latest`.
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`.
5455

55-
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 `/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.
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.
5657

5758
## Automating deploys
5859

@@ -121,19 +122,19 @@ You can override methods on this class to customize deploy behavior.
121122

122123
### `getVersionPath()`
123124

124-
This method determines the location that a given version of your documentation will be written to on your deploy branch.
125+
This method determines the location that a given version of your documentation will be written to within the `v` directory on your deploy branch.
125126

126-
By default, this method will use the current tag name (if any), or fall back to the current branch name as described above. Note that you can override this behavior by setting an `ADDON_DOCS_VERSION_PATH` environment variable.
127+
By default, this method will use the current tag name (if any) stripped of its leading `v`, or fall back to the current branch name as described above. Note that you can override this behavior by setting an `ADDON_DOCS_VERSION_PATH` environment variable.
127128

128129
If this method returns a falsey value, the deploy will be aborted.
129130

130131
### `getVersionName()`
131132

132-
This method returns a name for a given version of your documentation. By default it just returns the same thing as `getVersionPath()`, but if, for instance, you wanted to set up named releases, you might override this method. You can also explicitly specify the version name by setting an `ADDON_DOCS_VERSION_NAME` environment variable.
133+
This method returns a name for a given version of your documentation. By default it returns the current tag if any, or the current branch name otherwise. If, for instance, you wanted to set up named releases, you might override this method. You can also explicitly specify the version name by setting an `ADDON_DOCS_VERSION_NAME` environment variable.
133134

134135
### `shouldUpdateLatest()`
135136

136-
This method determines whether the `/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.
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.
137138

138139
### `getRootURL()`
139140

@@ -149,15 +150,15 @@ Deploying a version of your documentation does two things: it copies the `dist`
149150

150151
First, you can run `git checkout gh-pages` to switch to your deploy branch. You may see a message indicating that that branch has already been checked out somewhere else by `git worktree`—if that's the case, you can just `cd` to that directory instead.
151152

152-
Next, remove the item from `versions.json` for the version you want to get rid of, and delete the corresponding directory. For example, if you ran a deploy on a branch called `deploy-test` and wanted to remove the results of that after you finished testing it out, you could `git rm deploy-test` to remove the deployed app, and then find the `deploy-test` key in `versions.json` and remove it:
153+
Next, remove the item from `versions.json` for the version you want to get rid of, and delete the corresponding directory. For example, if you ran a deploy on a branch called `deploy-test` and wanted to remove the results of that after you finished testing it out, you could `git rm v/deploy-test` to remove the deployed app, and then find the `deploy-test` key in `versions.json` and remove it:
153154

154155
```js
155156
{
156157
// ...
157158
"deploy-test": {
158159
"sha": "caad536c48dd3562629a4f7a467c976f0ec6bb2b",
159160
"tag": null,
160-
"path": "deploy-test",
161+
"path": "v/deploy-test",
161162
"name": "deploy-test"
162163
},
163164
// ...

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8">
55
<title>Latest Docs Redirect</title>
66
<script type="text/javascript">
7-
window.location.href = './latest';
7+
window.location.href = './v/latest';
88
</script>
99
</head>
1010
<body>

0 commit comments

Comments
 (0)