Skip to content

Commit 58afc88

Browse files
feat(docs): Add generate_docs script to generate typedoc documentation
1 parent b13b0a4 commit 58afc88

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

generate_docs.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env node
2+
3+
const publishYalcPackage = require('./publish_yalc_package');
4+
const util = require('./util');
5+
util.packageDir();
6+
7+
const fs = require('fs');
8+
const path = require('path');
9+
const _exec = util._exec;
10+
11+
const pkg = JSON.parse(fs.readFileSync('./package.json'));
12+
const CONFIG = JSON.parse(fs.readFileSync('./typedoc.json'));
13+
14+
const has = require('lodash').has;
15+
16+
const requiredKeys = ['typedoc', 'typedoc.generateOptions', 'files'];
17+
const missing = requiredKeys.find(key => !has(CONFIG, key));
18+
if (missing) {
19+
console.error(`typedoc.json does not contain configuration key: "${missing}"`);
20+
process.exit(1);
21+
}
22+
23+
const includes = CONFIG.typedoc.include || [];
24+
includes.forEach(include => {
25+
const { package, repo } = include;
26+
const flags = { noBuild: true, noPublish: true, noInstall: true };
27+
const versionline = _exec(`yarn list --pattern ${package}`).stdout.split(/[\r\n]+/).find(line => line.includes(package));
28+
const version = /.*\@([^@]*)/.exec(versionline)[1];
29+
30+
if (version) {
31+
flags.branch = version;
32+
}
33+
34+
publishYalcPackage(path.join('.downstream_cache', package), repo, flags);
35+
});
36+
37+
const typedocOptions = CONFIG.typedoc.generateOptions || {};
38+
const cmdLineOpts = Object.keys(typedocOptions)
39+
.map(key => `--${key} ${typedocOptions[key]}`)
40+
.join(" ");
41+
42+
const files = CONFIG.files.concat(includes.map(x => path.join('.downstream_cache', x.package, x.entry))).join(" ");
43+
44+
util.packageDir();
45+
_exec(`./node_modules/.bin/typedoc ${cmdLineOpts} ${files}`);
46+

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@
1919
"bin": {
2020
"artifact_tagging": "./artifact_tagging.js",
2121
"ensure_clean_master": "./ensure_clean_master.js",
22+
"generate_docs": "./generate_docs.js",
2223
"modify_sourcemap_paths": "./modify_sourcemap_paths.js",
24+
"publish_docs": "./publish_docs.js",
25+
"publish_yalc_package": "./publish_yalc_package.js",
2326
"release": "./release.js",
2427
"show_changelog": "./show_changelog.js",
2528
"test_downstream_projects": "./test_downstream_projects.js",
26-
"publish_yalc_package": "./publish_yalc_package.js",
2729
"util": "./util.js"
2830
},
2931
"dependencies": {
3032
"conventional-changelog": "^1.1.4",
3133
"conventional-changelog-ui-router-core": "^1.4.2",
3234
"find-parent-dir": "^0.3.0",
3335
"git-semver-tags": "^1.2.1",
36+
"lodash": "^4.17.5",
3437
"npm-run-all": "^4.1.1",
3538
"open": "^0.0.5",
3639
"readline-sync": "^1.4.7",

publish_yalc_package.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const ORIG_DIR = process.cwd();
1717

1818
function publishYalcPackage(installTargetDir, installSource, flags) {
1919
flags = flags || {};
20+
const branch = flags.branch || 'origin/master';
21+
2022
if (!installTargetDir || !installSource) {
2123
throw new Error('Usage: publish_yalc_package [INSTALL_DIR] [GITHUB_URL|LOCAL_DIR]');
2224
}
@@ -29,7 +31,7 @@ function publishYalcPackage(installTargetDir, installSource, flags) {
2931
// Create directory and clone git repo
3032
if (!fs.existsSync(path.join(installTargetDir, '.git'))) {
3133
if (isRemoteSource) {
32-
util._exec(`git clone --depth 3 ${installSource} ${installTargetDir}`);
34+
util._exec(`git clone ${installSource} ${installTargetDir}`);
3335
} else {
3436
shelljs.rm('-rf', installTargetDir);
3537
shelljs.cp('-r', installSourceDir, installTargetDir);
@@ -43,7 +45,7 @@ function publishYalcPackage(installTargetDir, installSource, flags) {
4345
if (isRemoteSource) {
4446
process.chdir(installTargetDir);
4547
util._exec('git fetch origin');
46-
util._exec('git reset --hard origin/master');
48+
util._exec(`git reset --hard ${branch}`);
4749
util._exec('git clean --force -d');
4850
} else {
4951
// Create a tmp dir with a copy of the current package contents
@@ -70,7 +72,9 @@ function publishYalcPackage(installTargetDir, installSource, flags) {
7072
}
7173

7274
// Update dependencies
73-
util._exec('yarn install --check-files');
75+
if (!flags.noInstall) {
76+
util._exec('yarn install --check-files');
77+
}
7478

7579
const TEMP = tmp.dirSync();
7680
const TEMP_DIR = TEMP.name;

yarn.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,10 @@ lodash@^4.0.0, lodash@^4.2.1:
704704
version "4.17.4"
705705
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
706706

707+
lodash@^4.17.5:
708+
version "4.17.5"
709+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.5.tgz#99a92d65c0272debe8c96b6057bc8fbfa3bed511"
710+
707711
longest@^1.0.1:
708712
version "1.0.1"
709713
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"

0 commit comments

Comments
 (0)