forked from ionic-team/ionic-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocgen.ts
More file actions
123 lines (112 loc) · 3.07 KB
/
Copy pathdocgen.ts
File metadata and controls
123 lines (112 loc) · 3.07 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env node
import { config as dotenv } from 'dotenv';
dotenv({ silent: true });
import program from 'commander';
import isCI from 'is-ci';
import Listr from 'listr';
import listrVerboseRenderer from 'listr-verbose-renderer';
import frameworkDocs from './framework/generate';
import frameworkDeploy from './framework/deploy';
import cliDocs from './cli/generate';
import cliDeploy from './cli/deploy';
import componentPreview from './component-preview/generate';
import componentPreviewDeploy from './component-preview/deploy';
import nativeDocs from './native/generate';
import nativeDeploy from './native/deploy';
import storageDocs from './storage/generate';
import storageDeploy from './storage/deploy';
import { preCheck, vlog } from './utils';
import { AWS_ACCESS_KEY_ID, setVerbose } from './config';
// the main task of the API documentation generation process
const allTasks = [
{
id: 'framework',
title: 'Framework API Docs',
genFunc: frameworkDocs,
deployFunc: frameworkDeploy
},
{
id: 'cli',
title: 'CLI Docs',
genFunc: cliDocs,
deployFunc: cliDeploy
},
{
id: 'components',
title: 'Component Preview',
genFunc: componentPreview,
deployFunc: componentPreviewDeploy
},
{
id: 'native',
title: 'Native Docs',
genFunc: nativeDocs,
deployFunc: nativeDeploy
},
{
id: 'storage',
title: 'Storage Docs',
genFunc: storageDocs,
deployFunc: storageDeploy
}
].reduce((map, obj) => {
// Listr needs this to be an array but we're making it an object for now to
// make single task runs simpler
map[obj.id] = {
title: obj.title,
task: () => {
return new Listr([
{
title: `Generating ${obj.title}`,
task: (ctx, task) => obj.genFunc(task)
.catch((e) => {
ctx[obj.id] = false;
throw(e);
})
},
{
title: `Deploying ${obj.title}`,
enabled: ctx => obj.deployFunc && AWS_ACCESS_KEY_ID && ctx[obj.id] !== false,
task: (ctx, task) => obj.deployFunc(task)
}
]);
}
};
return map;
}, {});
// Invoke run() only if executed directly i.e. `node ./scripts/e2e`
if (require.main === module) {
program
.version('0.1.0')
.option(
'-s, --section [name]',
'Individual section to generate: framework, cli, components, native, storage'
)
.option(
'-v, --verbose',
'Verbose output'
).parse(process.argv);
const singleSectionRun = program.section && program.section !== 'all';
const listrOpts: any = { exitOnError: false };
if (isCI || program.verbose || singleSectionRun) {
listrOpts.renderer = listrVerboseRenderer;
setVerbose(true);
}
const chosenTasks = singleSectionRun ?
[allTasks[program.section]] : Object.values(allTasks);
const queue = new Listr([
{
title: 'Precheck',
task: () => preCheck()
},
{
title: 'Main Tasks',
task: () => {
return new Listr(chosenTasks, { concurrent: true });
}
}
], listrOpts);
queue.run().catch(err => {
vlog(err);
});
}