-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1.07 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
'use strict';
const fs = require('fs').promises;
const { existsSync } = require('fs');
const path = require('path');
const core = require('@actions/core');
const { exec } = require('@actions/exec');
const entry = core.getInput('entry');
(async () => {
const packageJson = await getPackageJson();
const entryFile = entry || packageJson.module || packageJson.main;
if (!entryFile) {
return core.setFailed(
`Missing "entry" input or package.json's "module" or "main" field`,
);
}
if (!existsSync('node_modules')) {
core.warning('node_modules is not present. Running `npm install`...');
await exec('npm', ['install']);
}
await exec('node', [
path.join(__dirname, 'node_modules/documentation/bin/documentation.js'),
'build',
entryFile,
'--github',
'--output',
'docs',
'--format',
'html',
'--sort-order',
'alpha',
]);
await fs.writeFile('docs/.nojekyll', '');
})().catch((error) => {
core.setFailed(error);
});
async function getPackageJson() {
return JSON.parse(await fs.readFile('package.json', 'utf-8'));
}