-
Notifications
You must be signed in to change notification settings - Fork 80
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·99 lines (90 loc) · 3.34 KB
/
Copy pathindex.js
File metadata and controls
executable file
·99 lines (90 loc) · 3.34 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
#!/usr/bin/env node
const path = require('path')
const fs = require('fs')
const {Command, Option} = require('commander')
const run = require(path.resolve(__dirname, '../index.js'))
// =============
// = CLI Setup =
// =============
new Command()
.description('An application to add interactive PUML diagrams to your github markdown files. If running with default arguments, run in project root directory.')
.option(
'-s, --puml-server-url <url>',
'This is the base URL used to render diagrams. Defaults to the public plantuml server.',
'https://www.plantuml.com/plantuml',
)
.addOption(new Option(
'-x, --root-directory <path>',
'The path to your project'
).default(process.cwd(), 'CWD')
)
.option(
'-r, --hot-reload',
'Rerun markdown generator every `interval` seconds, determined by interval option',
)
.option(
'-v, --interval-seconds <number>',
'If --hot-reload is set, how often should it reload',
2,
)
.addOption(new Option(
'-p, --puml-directory <path>',
'Path to directory containing puml files which are referenced in markdown files',
).default(false, 'rootDirectory')
)
.addOption(new Option(
'-m, --markdown-directory <path>',
'Path to directory containing markdown files referencing puml files',
).default(false, 'rootDirectory')
)
.option(
'-g, --ignore-gitignore',
"Don't use .gitignore to skip PUML and MD. Will automatically be true if no gitignore is found",
)
.addOption(new Option(
'-i, --gitignore-path <path>',
'Use this as path to .gitignore file.'
).default(false, 'rootDirectory/.gitignore')
)
.option(
'-d, --output-images',
'If set, will output images of diagrams to the dist directory',
)
.addOption(new Option(
'-b, --dist-directory <path>',
'If --output-images is set, path to output diagram images'
).default(false, 'rootDirectory/dist_puml')
)
.addOption(new Option(
'-f, --image-formats <format>',
'If --output-images is set, sets the output image format',
).choices(['png', 'svg', 'both']).default('png')
)
.option(
'-t, --turn-off-link-shortening',
"Use the full puml server link instead of the tiny url, if your diagrams are too big this won't work",
)
.addOption(new Option(
'-l, --polr-url <url>',
"Use polr shortener instead tinyurl - optionally specify polr api key in POLR_APIKEY env var",
)
)
.action(opts => {
const useDefaultGitignorePath = !opts.gitignorePath
opts.distDirectory = opts.distDirectory || path.resolve(opts.rootDirectory, 'dist_puml')
opts.gitignorePath = opts.gitignorePath || path.resolve(opts.rootDirectory, '.gitignore')
opts.markdownDirectory = opts.markdownDirectory || opts.rootDirectory
opts.pumlDirectory = opts.pumlDirectory || opts.rootDirectory
opts.shouldShortenLinks = !opts.turnOffLinkShortening
opts.respectGitignore = !opts.ignoreGitignore
opts.imageFormats = opts.imageFormats === 'both' ? ['png', 'svg'] : [opts.imageFormats]
// If a gitignore path wasn't specified, don't try and parse it
if (useDefaultGitignorePath && !fs.existsSync(opts.gitignorePath)) {
opts.respectGitignore = false
}
return run(opts).catch((e) => {
console.error('FATAL EXCEPTION')
console.error(e)
})
})
.parse(process.argv)