Skip to content

Commit e805276

Browse files
Use a js file for local docs generation
1 parent 431a14a commit e805276

File tree

5 files changed

+104
-51
lines changed

5 files changed

+104
-51
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The script pulls yuidoc build output from all Ember versions from Amazon S3, con
3232

3333
## To Generate docs for a specific project and/or version for development
3434

35-
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`.
35+
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`.
3636
You need an additional flag `AWS_SHOULD_PUBLISH=true` for publishing the docs.
3737

3838
## To override a specific version of a doc with a different yuidoc from your machine (For core contributors)
@@ -56,8 +56,7 @@ app with documentation pulled from a local copy of ember.js.
5656
- [ember-jsonapi-docs](https://github.com/ember-learn/ember-jsonapi-docs)
5757
- [ember-api-docs](https://github.com/ember-learn/ember-api-docs)
5858
1. Set up the project according to the instructions above in `Running the app`.
59-
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`.
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
59+
1. From the `ember-jsonapi-docs` directory, run `yarn gen --project ember --version 2.18.0`. This command runs the Ember documentation build, generates jsonapi output, copies it to the `ember-api-docs` directory & runs this app. To build ember data documentation, run `yarn gen --project ember-data --version 2.18.0`.
6160
- 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.\_
6261
1. Run `yarn server` in this app to serve the content locally.
63-
1. Run the API app with the newly generated local data by running `API_HOST=http://localhost:5050 ember s` in the `ember-api-docs` directory.
62+
1. Run the API app with the newly generated local data by running `yarn server` in this app & then run `yarn start:local` in the `ember-api-docs` directory.

generate-local.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
import chalk from 'chalk'
2+
import commandExists from 'command-exists'
3+
import execa from 'execa'
4+
import { copyFileSync, existsSync, mkdirpSync, removeSync } from 'fs-extra'
5+
import minimist from 'minimist'
6+
import path from 'path'
7+
8+
const argv = minimist(process.argv.slice(2))
9+
10+
const { project, version } = argv
11+
12+
const exit = function exit() {
13+
console.log(...arguments)
14+
process.exit(1)
15+
}
16+
17+
const runCmd = async (cmd, path) => {
18+
console.log(chalk.underline(`Running '${chalk.green(cmd)}'`))
19+
const executedCmd = await execa.shell(cmd, { cwd: path })
20+
21+
if (executedCmd.failed) {
22+
console.error(executedCmd.stderr)
23+
process.exit(1)
24+
}
25+
26+
console.log(executedCmd.stdout + '\n')
27+
}
28+
;(async () => {
29+
if (!project || !version) {
30+
exit(
31+
chalk.red('Both project and version args are required.\n'),
32+
chalk.yellow(' e.g., yarn gen --project ember --version 3.10.1')
33+
)
34+
}
35+
36+
if (!['ember', 'ember-data'].includes(project)) {
37+
exit(chalk.red(`Project has to be either 'ember' or 'ember-data'. (was given ${project})\n`))
38+
}
39+
40+
try {
41+
await commandExists('yarn')
42+
} catch (e) {
43+
exit(chalk.red('We need yarn installed globally for this script to work'))
44+
}
45+
46+
let emberProjectPath = path.join(__dirname, '../', 'ember.js')
47+
let emberDataProjectPath = path.join(__dirname, '../', 'data')
48+
49+
let checkIfProjectDirExists = dirPath => {
50+
if (!existsSync(dirPath)) {
51+
exit(chalk.yellow(`Please checkout the ${project} project at ${dirPath}`))
52+
}
53+
}
54+
55+
let buildDocs = async projDirPath => {
56+
checkIfProjectDirExists(projDirPath)
57+
await runCmd('yarn', projDirPath)
58+
59+
console.log('\n\n')
60+
61+
await runCmd(project === 'ember' ? 'yarn docs' : 'yarn build:production', projDirPath)
62+
63+
const projYuiDocFile = `tmp/s3-docs/v${version}/${project}-docs.json`
64+
removeSync(projYuiDocFile)
65+
removeSync(`tmp/json-docs/${project}/${version}`)
66+
67+
mkdirpSync(`tmp/s3-docs/v${version}`)
68+
69+
const yuiDocFile = path.join(
70+
projDirPath,
71+
project === 'ember' ? 'docs/data.json' : 'packages/-ember-data/dist/docs/data.json'
72+
)
73+
copyFileSync(yuiDocFile, projYuiDocFile)
74+
}
75+
76+
let dirMap = {
77+
ember: emberProjectPath,
78+
'ember-data': emberDataProjectPath,
79+
}
80+
81+
await buildDocs(dirMap[project])
82+
83+
await execa('yarn', [
84+
'start',
85+
'--project',
86+
project,
87+
'--version',
88+
version,
89+
'--ignorePreviouslyIndexedDoc',
90+
]).stdout.pipe(process.stdout)
91+
})()

generate-local.sh

Lines changed: 0 additions & 47 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@
1919
"test": "test"
2020
},
2121
"scripts": {
22+
"gen": "node -r esm generate-local.js",
2223
"greet": "echo 'hi'",
2324
"server": "http-server -p 5050 --cors tmp",
2425
"start": "node index.js",
2526
"test": "eslint lib/**/*.js index.js test/**.js && mocha -r esm test"
2627
},
2728
"dependencies": {
2829
"cheerio": "^1.0.0-rc.2",
30+
"command-exists": "^1.2.8",
2931
"compare-versions": "^3.4.0",
3032
"download": "^7.1.0",
3133
"ember-rfc176-data": "^0.3.9",
3234
"esm": "^3.2.25",
35+
"execa": "^1.0.0",
3336
"fs-extra": "^7.0.0",
3437
"glob": "^7.1.3",
3538
"graceful-fs": "^4.1.11",

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ async@^1.5.2:
108108
aws-sdk@~2.0.31, aws-sdk@~2.276.1:
109109
version "2.276.1"
110110
resolved "https://registry.yarnpkg.com/aws-sdk/-/aws-sdk-2.276.1.tgz#4f5cd52f4d1a13a412c8a8d75b276c556ad13947"
111+
integrity sha512-pxIJmDwE+JWeHyc8WAa9mTpAh/X+RQF7DHLMM4amf7Dhj6EvoucbWByKS6+rZF4MfYIA+a4E1J0GELEz/m+uJA==
111112
dependencies:
112113
buffer "4.9.1"
113114
events "1.1.1"
@@ -333,6 +334,11 @@ [email protected]:
333334
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
334335
integrity sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=
335336

337+
command-exists@^1.2.8:
338+
version "1.2.8"
339+
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.8.tgz#715acefdd1223b9c9b37110a149c6392c2852291"
340+
integrity sha512-PM54PkseWbiiD/mMsbvW351/u+dafwTJ0ye2qB60G1aGQP9j3xK2gmMDc+R34L3nDtx4qMCitXT75mkbkGJDLw==
341+
336342
337343
version "2.15.1"
338344
resolved "https://registry.yarnpkg.com/commander/-/commander-2.15.1.tgz#df46e867d0fc2aec66a34662b406a9ccafff5b0f"
@@ -2479,6 +2485,7 @@ util-deprecate@~1.0.1:
24792485
24802486
version "3.1.0"
24812487
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"
2488+
integrity sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==
24822489

24832490
validate-npm-package-license@^3.0.1:
24842491
version "3.0.4"

0 commit comments

Comments
 (0)