-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheed-cli.js
More file actions
executable file
·259 lines (236 loc) · 6.12 KB
/
heed-cli.js
File metadata and controls
executable file
·259 lines (236 loc) · 6.12 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/usr/bin/env node
import { readFile } from 'fs/promises';
import path from 'path';
import process from 'process';
import { fileURLToPath } from 'url';
import { Command, Option } from 'commander';
import {
runCommand,
addPlugin,
addSection,
addSlide,
linkPlugin,
newPresentation,
pack,
removePlugin,
showIndex,
showRoot,
installPlugins,
} from './lib/command/index.js';
const program = new Command();
const heedRoot = path.dirname(fileURLToPath(import.meta.url));
const pkg = JSON.parse(await readFile(path.join(heedRoot, 'package.json')));
program.hook('preAction', (_thisCommand, actionCommand) => {
const opts = actionCommand.opts();
opts.heedRoot = heedRoot;
});
program
.name('heed-cli')
.description('Command-line tool for managing Heed presentations')
.version(pkg.version);
/**
* "add"-command and subcommands
*
*/
const addCommand = program.command('add');
addCommand
.command('section [sectionId] [path]')
.description('Add a section to the presentation')
.option('-i, --index', 'Add/insert at index in the target context')
.option('--json', 'Outut result as JSON')
.action(async (sectionId, contextPath = '.', options) => {
await runCommand({
cmd: addSection,
cmdArgs: [
{ __type: 'root-required', value: contextPath },
{ __type: 'presentation-file' },
{
__type: 'string',
__name: 'Section ID',
__required: true,
value: sectionId,
},
{ __type: 'content-dir', value: contextPath },
],
cmdOpts: options,
});
});
addCommand
.command('slide [slideId] [path]')
.description('Add a slide to the presentation.')
.option('--json', 'Output result as JSON')
.action(async (slideId, contextPath = '.', options) => {
await runCommand({
cmd: addSlide,
cmdArgs: [
{ __type: 'root-required', value: contextPath },
{ __type: 'presentation-file' },
{
__type: 'string',
__name: 'Slide ID',
__required: true,
value: slideId,
},
{ __type: 'context-dir', value: contextPath },
],
cmdOpts: options,
});
});
addCommand
.command('plugin [pluginName] [source]')
.description('Add a plugin to the presentation')
.option('--json', 'Output result as JSON')
.action(async (pluginName, source, options) => {
await runCommand({
cmd: addPlugin,
cmdArgs: [
{ __type: 'root-required', value: '.' },
{
__type: 'string',
__name: 'Plugin name',
__required: true,
value: pluginName,
},
source,
],
cmdOpts: options,
});
});
/**
* "install"-command and subcommands
*
*/
const installCommand = program.command('install');
installCommand
.command('plugins')
.option('--json', 'Output result as JSON')
.action(async (options) => {
await runCommand({
cmd: installPlugins,
cmdArgs: [{ __type: 'root-required', value: '.' }],
cmdOpts: options,
});
});
/**
* "link"-command and subcommands
*
*/
const linkCommand = program.command('link');
linkCommand
.command('plugin [pluginName] [source]')
.description('Add a plugin by symlink from a local folder')
.option('--json', 'Output result as JSON')
.action(async (pluginName, source, options) => {
await runCommand({
cmd: linkPlugin,
cmdArgs: [
{ __type: 'root-required', value: '.' },
{
__type: 'string',
__name: 'Plugin name',
__required: true,
value: pluginName,
},
source,
],
cmdOpts: options,
});
});
/**
* "new" command
*
*/
program
.command('new [presentationName] [presentationPath]')
.description('Create a new presentation in the current or provided folder.')
.option('--json', 'Output index as JSON.')
.action(async (presentationName, presentationPath = '.', options) => {
await runCommand({
cmd: newPresentation,
cmdArgs: [
{
__type: 'string',
__name: 'Presentation name',
__required: true,
value: presentationName,
},
presentationPath,
],
cmdOpts: options,
});
});
/**
* "pack" command
*
*/
program
.command('pack [presentationPath]')
.description('Pack/compress the presentation into a distributable archive.')
.option('--json', 'Output result as JSON.')
.addOption(
new Option('-t, --type [type]')
.choices(['zip', 'tar', 'tgz'])
.default('tgz'),
)
.action(async (presentationPath = '.', options) => {
await runCommand({
cmd: pack,
cmdArgs: [{ __type: 'root-required', value: presentationPath }, options],
});
});
/**
* "remove"-command and subcommands
*
*/
const removeCommand = program.command('remove');
removeCommand
.command('plugin [pluginName]')
.description('Remove/uninstall a plugin from this presentation.')
.option('--json', 'Output result as JSON.')
.action(async (pluginName, options) => {
await runCommand({
cmd: removePlugin,
cmdArgs: [
{ __type: 'root-required', value: '.' },
{
__type: 'string',
__name: 'Plugin name',
__required: true,
value: pluginName,
},
],
cmdOpts: options,
});
});
/**
* "show" command and subcommands
*
*/
const showCommand = program.command('show');
showCommand
.command('index [presentationPath]')
.description('Display a table of slides defined in presentation.json')
.option('--json', 'Output index as JSON.')
.action(async (presentationPath = '.', options) => {
await runCommand({
cmd: showIndex,
cmdArgs: [
{ __type: 'root-required', value: presentationPath },
{ __type: 'presentation-file' },
],
cmdOpts: options,
});
});
showCommand
.command('root [dir]')
.description('Display the root directory path of the presentation.')
.option('--json', 'Output paths as JSON.')
.action(async (dir = '.', options) => {
await runCommand({
cmd: showRoot,
cmdArgs: [dir],
cmdOpts: options,
});
});
/** Parse arguments and run command */
program.parse(process.argv);