Skip to content

Commit 4e2fa74

Browse files
Add ability to override existing docs with yuidoc from local
1 parent 75f2b4f commit 4e2fa74

File tree

6 files changed

+75
-49
lines changed

6 files changed

+75
-49
lines changed

README.md

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Ember JSON API Docs [![Build Status](https://travis-ci.org/ember-learn/ember-jsonapi-docs.svg?branch=master)](https://travis-ci.org/ember-learn/ember-jsonapi-docs)
22

3-
If are looking for the app behind https://emberjs.com/api/, visit
3+
If are looking for the app behind https://emberjs.com/api/, visit
44
[ember-api-docs](https://github.com/ember-learn/ember-api-docs) instead. This ember-jsonapi-docs
55
repository is internal tooling that is not required to run the ember-api-docs app locally.
66

@@ -11,42 +11,52 @@ The script pulls yuidoc build output from all Ember versions from Amazon S3, con
1111

1212
## Running the app
1313

14-
1. Fork/Clone [ember-jsonapi-docs](https://github.com/ember-learn/ember-jsonapi-docs)
15-
1. Run `yarn` or `npm install` (Needs node 6+)
16-
1. Set up AWS access
14+
1. Fork/Clone [ember-jsonapi-docs](https://github.com/ember-learn/ember-jsonapi-docs)
15+
1. Run `yarn` or `npm install` (Needs node 6+)
16+
1. Set up AWS access
17+
1718
```shell
1819
export AWS_ACCESS_KEY=xxxxxx
1920
export AWS_SECRET_KEY=xxxxx
2021
```
22+
2123
The app accesses builds.emberjs.com (an Amazon S3 bucket) in read-only mode, which is public. This requires any valid AWS credentials.
2224

2325
You can get your credentials by logging into your [AWS console](https://console.aws.amazon.com) and navigating to "_My Security Credentials_" under your profile name. You can generate a new pair under the "_Access Keys (Access Key ID and Secret Access Key)_" section.
24-
1. To test your changes in the app run,
25-
```node index.js```
26-
Once complete, if no errors you should see a docs.tar file inside the `tmp` folder. The app tries to process all
27-
ember & ember-data versions since 1.0 which takes high memory & time to complete. If you intend it, then run `node --max_old_space_size=8192 index.js`.
28-
You are setting your node max heap space to 8GB, so make sure you have that much space available on your machine.
2926

27+
1. To test your changes in the app run,
28+
`node index.js`
29+
Once complete, if no errors you should see a docs.tar file inside the `tmp` folder. The app tries to process all
30+
ember & ember-data versions since 1.0 which takes high memory & time to complete. If you intend it, then run `node --max_old_space_size=8192 index.js`.
31+
You are setting your node max heap space to 8GB, so make sure you have that much space available on your machine.
3032

3133
## To Generate docs for a specific project and/or version for development
3234

3335
You can do this by passing `--project ember/ember-data --version 2.11.1` as an argument to the index script. e.g., `yarn start -- --project ember --version 2.11.0`.
34-
Setting `export SKIP_S3_SYNC=yes` will stop the generator from syncing s3 content. You need an additional flag `AWS_SHOULD_PUBLISH=true` for publishing the docs.
36+
You need an additional flag `AWS_SHOULD_PUBLISH=true` for publishing the docs.
37+
38+
## To override a specific version of a doc with a different yuidoc from your machine (For core contributors)
39+
40+
- Read this section first!
41+
- We assume you have the keys to the kingdom before you start doing this (AWS keys to publish to api-docs.emberjs.com & all necessary env variables that need to be set) 😄
42+
- In its present form this should be used only when there aren't new docs out there that are yet to be processed. As in if ember 3.3 is released but isn't indexed yet you should wait for this app to finish processing it via the cron job we have on heroku before you can proceed to modify any of the existing docs from your machine.
43+
- First run `yarn start` so that you have all the docs from s3 on your local. This is important so that we don't loose other versions of docs that are already out there when the index files are generated
44+
- Then go to `./tmp/s3-docs/<the_version_you_want_to_replace>` and override the file there with the yuidoc file that you want to be processed. Ensure that the file name is same as the one that's already there.
45+
- Then run `yarn start --project=ember-data --version=3.2.0 --ignorePreviouslyIndexedDoc`. Make sure you enter the entire version(including patch version).
3546

3647
## Generating API Documentation and Testing API Docs Locally
3748

3849
These steps are only necessary if you are trying to run the ember-api-docs
3950
app with documentation pulled from a local copy of ember.js.
4051

41-
1. Clone the following 4 repositories into a single parent directory. Install dependencies for each app as described in their respective `README` files.
42-
- [ember.js](https://github.com/emberjs/ember.js)
43-
- [data (ember data)](https://github.com/emberjs/data)
44-
- [ember-jsonapi-docs](https://github.com/ember-learn/ember-jsonapi-docs)
45-
- [ember-api-docs](https://github.com/ember-learn/ember-api-docs)
46-
1. Set up the project according to the instructions above in `Running the app`.
47-
1. From the `ember-jsonapi-docs` directory, run `./generate-local.sh yui ember 2.18.0`. This command runs the Ember documentation build, generates jsonapi output, and copies it to the `ember-api-docs` directory. To build ember data documentation, run `./generate-local.sh yui ember-data 2.17.2`.
48-
- _If you encounter an error like `ember-2.18.0 has already been indexed in json-docs`, then use a new unique version number like `2.18.1`, or whatever is appropriate.
49-
- If your `rev-index/ember-X.X.X.json` file fails to generate, make sure you have all dependencies installed for the ember.js repo
50-
- If you are debugging failed builds, periodically clear out the contents of the `tmp` directory, and run the script again. Past failed runs can cause subsequent runs to fail in unexpected ways._
51-
1. Run the API app with the newly generated local data by running `API_HOST=http://localhost:4200 ember s` in the `ember-api-docs` directory.
52-
52+
1. Clone the following 4 repositories into a single parent directory. Install dependencies for each app as described in their respective `README` files.
53+
- [ember.js](https://github.com/emberjs/ember.js)
54+
- [data (ember data)](https://github.com/emberjs/data)
55+
- [ember-jsonapi-docs](https://github.com/ember-learn/ember-jsonapi-docs)
56+
- [ember-api-docs](https://github.com/ember-learn/ember-api-docs)
57+
1. Set up the project according to the instructions above in `Running the app`.
58+
1. From the `ember-jsonapi-docs` directory, run `./generate-local.sh yui ember 2.18.0`. This command runs the Ember documentation build, generates jsonapi output, and copies it to the `ember-api-docs` directory. To build ember data documentation, run `./generate-local.sh yui ember-data 2.17.2`.
59+
- \_If you encounter an error like `ember-2.18.0 has already been indexed in json-docs`, then use a new unique version number like `2.18.1`, or whatever is appropriate.
60+
- If your `rev-index/ember-X.X.X.json` file fails to generate, make sure you have all dependencies installed for the ember.js repo
61+
- If you are debugging failed builds, periodically clear out the contents of the `tmp` directory, and run the script again. Past failed runs can cause subsequent runs to fail in unexpected ways.\_
62+
1. Run the API app with the newly generated local data by running `API_HOST=http://localhost:4200 ember s` in the `ember-api-docs` directory.

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
11
// eslint-disable-next-line
22
require = require('esm')(module /*, options*/)
3+
const argv = require('minimist')(process.argv.slice(2))
4+
5+
let possibleProjects = ['ember', 'ember-data']
6+
let projects =
7+
argv.project && possibleProjects.includes(argv.project) ? [argv.project] : possibleProjects
8+
let specificDocsVersion = argv.version ? argv.version : ''
9+
10+
let ignorePreviouslyIndexedDoc =
11+
projects.length !== 0 && specificDocsVersion !== '' && argv.ignorePreviouslyIndexedDoc
12+
313
const { apiDocsProcessor } = require('./main.js')
4-
apiDocsProcessor()
14+
apiDocsProcessor(projects, specificDocsVersion, ignorePreviouslyIndexedDoc)

lib/fetch-yui-docs.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ function getObjects() {
3838
})
3939
}
4040

41-
function downloadFile({ Key }) {
41+
const getSrcFilePath = Key => {
4242
let name = path.basename(Key)
4343
let dir = path.basename(path.dirname(Key))
44+
return path.join('tmp', 's3-docs', dir, name)
45+
}
4446

45-
let finalFile = path.join('tmp', 's3-docs', dir, name)
47+
function downloadFile({ Key }) {
48+
let finalFile = getSrcFilePath(Key)
4649

4750
return mkdirp(path.dirname(finalFile)).then(() => {
4851
return new RSVP.Promise((resolve, reject) => {
@@ -77,7 +80,7 @@ function filterReleaseDocs({ Key }) {
7780
return versionRegex.test(tag) && /-docs\.json/.test(key)
7881
}
7982

80-
export default function fetchYuiDocs(projects, specificDocsVersion) {
83+
export default function fetchYuiDocs(projects, specificDocsVersion, ignorePreviouslyIndexedDoc) {
8184
return getObjects().then(docs => {
8285
let projectFiles = projects.map(p => `${p}-docs.json`)
8386

@@ -89,7 +92,16 @@ export default function fetchYuiDocs(projects, specificDocsVersion) {
8992
)
9093

9194
if (!isEmpty(trim(specificDocsVersion))) {
92-
return RSVP.map(filteredDocs, downloadFile)
95+
if (ignorePreviouslyIndexedDoc) {
96+
return RSVP.map(filteredDocs, ({ Key }) => {
97+
console.log(
98+
`Skipping download of ${Key} so that you can use your local file. We hope you know what you're doing 😅`
99+
)
100+
return getSrcFilePath(Key)
101+
})
102+
} else {
103+
return RSVP.map(filteredDocs, downloadFile)
104+
}
93105
}
94106

95107
let projectDocs = groupBy(filteredDocs, ({ Key }) => Key.split('/')[2].replace('.json', ''))

lib/read-docs.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import path from 'path'
44
import RSVP from 'rsvp'
55
import { dasherize } from 'inflected'
66

7-
export default function readDocs(projects, specificVersion = '') {
7+
export default function readDocs(
8+
projects,
9+
specificVersion = '',
10+
ignorePreviouslyIndexedDoc = false
11+
) {
812
console.log('Reading project files')
913

1014
let docs = {}
@@ -22,7 +26,7 @@ export default function readDocs(projects, specificVersion = '') {
2226
}
2327

2428
folders = folders.filter(f => {
25-
if (!prevIndexedVersions.includes(f)) {
29+
if (!prevIndexedVersions.includes(f) || ignorePreviouslyIndexedDoc) {
2630
return f
2731
} else {
2832
let version = f.replace('tmp/s3-docs/v', '').replace(`/${projectName}-docs.json`, '')

lib/s3-sync.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import humanSize from 'human-size'
88
// To increase s3's download & upload dir perf
99
http.globalAgent.maxSockets = https.globalAgent.maxSockets = 30
1010

11-
const { AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_SHOULD_PUBLISH, SKIP_S3_SYNC } = process.env
11+
const { AWS_ACCESS_KEY, AWS_SECRET_KEY, AWS_SHOULD_PUBLISH } = process.env
1212

1313
const client = S3.createClient({
1414
s3Options: {
@@ -75,17 +75,13 @@ const syncDir = (operation, options) => {
7575
}
7676

7777
export function downloadExistingDocsToLocal() {
78-
if (!SKIP_S3_SYNC) {
79-
let revDocsDirDownloadOptions = revDocsDirUploadOptions
80-
delete revDocsDirDownloadOptions.s3Params.GrantRead
78+
let revDocsDirDownloadOptions = revDocsDirUploadOptions
79+
delete revDocsDirDownloadOptions.s3Params.GrantRead
8180

82-
return waitForAllPromises([
83-
syncDir('download', jsonDocsDirDownloadOptions),
84-
syncDir('download', revDocsDirDownloadOptions),
85-
])
86-
}
87-
console.log('Skipping download of pre-cached docs')
88-
return Promise.resolve()
81+
return waitForAllPromises([
82+
syncDir('download', jsonDocsDirDownloadOptions),
83+
syncDir('download', revDocsDirDownloadOptions),
84+
])
8985
}
9086

9187
export function uploadToS3() {

main.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import RSVP from 'rsvp'
22
import fs from 'fs-extra'
3-
const argv = require('minimist')(process.argv.slice(2))
43

54
import markup from './lib/markup'
65
import readDocs from './lib/read-docs'
@@ -13,23 +12,18 @@ import saveDoc from './lib/save-document'
1312
import revProjVersionFiles from './lib/rev-docs'
1413
import { downloadExistingDocsToLocal, uploadToS3 } from './lib/s3-sync'
1514

16-
export function apiDocsProcessor() {
15+
export function apiDocsProcessor(projects, specificDocsVersion, ignorePreviouslyIndexedDoc) {
1716
RSVP.on('error', reason => {
1817
console.log(reason)
1918
process.exit(1)
2019
})
2120

22-
let possibleProjects = ['ember', 'ember-data']
23-
let projects =
24-
argv.project && possibleProjects.includes(argv.project) ? [argv.project] : possibleProjects
25-
let specificDocsVersion = argv.version ? argv.version : ''
26-
2721
let docsVersionMsg = specificDocsVersion !== '' ? `. For version ${specificDocsVersion}` : ''
2822
console.log(`Downloading docs for ${projects.join(' & ')}${docsVersionMsg}`)
2923

3024
downloadExistingDocsToLocal()
31-
.then(() => fetchYuiDocs(projects, specificDocsVersion))
32-
.then(() => readDocs(projects, specificDocsVersion))
25+
.then(() => fetchYuiDocs(projects, specificDocsVersion, ignorePreviouslyIndexedDoc))
26+
.then(() => readDocs(projects, specificDocsVersion, ignorePreviouslyIndexedDoc))
3327
.then(docs => {
3428
return RSVP.map(projects, projectName => {
3529
return RSVP.map(docs[projectName], doc => {

0 commit comments

Comments
 (0)