Skip to content

Commit ee72af1

Browse files
refactor(docgen): Read docgen config from package.json
1 parent 7a8da38 commit ee72af1

File tree

6 files changed

+16
-29
lines changed

6 files changed

+16
-29
lines changed

docgen/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ RUN sed -i'' -e 's/Globals/{{name}}/' node_modules/typedoc-default-themes/bin/de
1010
COPY clone.sh /home/node/work
1111
COPY docgen.sh /home/node/work
1212
COPY prep_docgen.js /home/node/work
13-
COPY findSemverPackage.js /home/node/work
1413

1514
ENTRYPOINT ["/home/node/work/docgen.sh"]

docgen/docgen.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ PROJECT=${WORK}/project
1515
}
1616

1717
pushd $WORK
18-
cp $WORK/project/docgen.json .
19-
cp $WORK/project/typedoc.json .
18+
[[ -e typedoc.json ]] && rm typedoc.json
19+
ln -s $WORK/project/typedoc.json .
2020
README=$(jq -r .readme < typedoc.json)
2121
cp $WORK/project/$README .
2222

2323
./prep_docgen.js
2424
bash ./clone_repos.sh
25-
npx typedoc
25+
cd project
26+
../node_modules/.bin/typedoc --tsconfig tsconfig.docgen.json
2627
rm -rf project/src/includes

docgen/findSemverPackage.js

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

docgen/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"dependencies": {
3-
"lodash": "^4.17.19",
4-
"find-parent-dir": "^0.3.0",
53
"typedoc": "0.17.8",
64
"typescript": "3.9.7",
7-
"typedoc-plugin-ui-router": "3.0.2"
5+
"typedoc-plugin-ui-router": "4.0.0"
86
}
97
}

docgen/prep_docgen.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
#!/usr/bin/env node
22
const fs = require('fs');
33
const childProcess = require('child_process');
4-
const _ = require('lodash');
54

65
const WORKDIR = process.cwd();
76
const PACKAGE_DIR = `${WORKDIR}/project`;
87
const SRC_DIR = `${PACKAGE_DIR}/src`;
9-
const DOCGENCONFIG_PATH = `${PACKAGE_DIR}/docgen.json`;
10-
const TSCONFIG_PATH = `${PACKAGE_DIR}/tsconfig.json`;
118
const PACKAGEJSON_PATH = `${PACKAGE_DIR}/package.json`;
129

1310
if (!fs.existsSync(SRC_DIR)) { throw new Error(`${SRC_DIR} does not exist`) }
14-
if (!fs.existsSync(DOCGENCONFIG_PATH)) { throw new Error(`${DOCGENCONFIG_PATH} does not exist`); }
11+
if (!fs.existsSync(PACKAGEJSON_PATH)) { throw new Error(`${PACKAGEJSON_PATH} does not exist`); }
1512

1613
const PACKAGEJSON = JSON.parse(fs.readFileSync(PACKAGEJSON_PATH));
17-
const DOCGENCONFIG = getDocgenConfig();
18-
const TSCONFIG_COPY = JSON.parse(fs.readFileSync(TSCONFIG_PATH).toString());
14+
const DOCGENCONFIG = getDocgenConfig(PACKAGEJSON);
1915

20-
// Merge tsconfig block from docgen.json into tsconfig.json
21-
_.merge(TSCONFIG_COPY, DOCGENCONFIG.tsconfig);
22-
fs.writeFileSync(`${WORKDIR}/tsconfig.json`, JSON.stringify(TSCONFIG_COPY, null, 2));
23-
24-
function getDocgenConfig() {
25-
const config = JSON.parse(fs.readFileSync(DOCGENCONFIG_PATH));
26-
const requiredKeys = ['navigation', 'tsconfig'];
27-
const missing = requiredKeys.find((key) => !_.has(config, key));
16+
function getDocgenConfig(packageJson) {
17+
const requiredKeys = ['docgen', 'docgen.navigation', 'docgen.publishDir'];
18+
const missing = requiredKeys.find((key) => key.split(".").reduce((acc, k) => acc && acc[k], packageJson) === undefined);
2819
if (missing) {
29-
console.error(`${DOCGENCONFIG_PATH} does not contain configuration key: '${missing}'`);
20+
console.error(`${PACKAGEJSON_PATH} does not contain configuration key: '${missing}'`);
3021
process.exit(1);
3122
}
32-
return config;
23+
return packageJson.docgen;
3324
}
3425

3526
// Fetch all included packages (i.e., core module)

publish_docs.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const _exec = util._exec;
1010
const sh = require('shelljs');
1111
const readlineSync = require('readline-sync');
1212

13-
const CONFIG = JSON.parse(fs.readFileSync('./docgen.json'));
1413
const TYPEDOC_CONFIG = JSON.parse(fs.readFileSync('./typedoc.json'));
15-
const pkg = JSON.parse(fs.readFileSync('./package.json'));
16-
const version = pkg.version;
14+
const PKGJSON = JSON.parse(fs.readFileSync('./package.json'));
15+
const DOCGEN_CONFIG = PKGJSON.docgen || {};
16+
const version = PKGJSON.version;
1717

1818
const GIT_URL = "[email protected]:ui-router/ui-router.github.io.git";
1919
const installTargetDir = path.join(".downstream_cache", "ui-router.gihub.io");
20-
const PAGES_DIR = path.join(installTargetDir, CONFIG.publishDir);
20+
const PAGES_DIR = path.join(installTargetDir, DOCGEN_CONFIG.publishDir);
2121

2222
sh.rm('-rf', installTargetDir);
2323
_exec(`git clone ${GIT_URL} ${installTargetDir}`);

0 commit comments

Comments
 (0)