puml-for-markdown 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +7 -4
  2. package/bin/index.js +79 -71
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  ## Simple CLI Usage
4
4
  Just run `puml-for-markdown` in any directory where you have markdown files and it will render links to PlantUML files
5
- in markdown comments. [PlantUML](https://plantuml.com) files allow you to create diagrams that are defined using a
6
- simple and intuitive language. By default the entire directory is recursively searched, automatically ignoring anything
7
- in the gitignore file.
5
+ in markdown comments. The best part about this is that it requires no build files, you don't even need to store
6
+ puml images in your repo. Also the embedded diagrams can link to other diagrams. [PlantUML](https://plantuml.com) files
7
+ allow you to create diagrams that are defined using a simple and intuitive language. By default the entire directory
8
+ is recursively searched, automatically ignoring anything in the gitignore file.
8
9
 
9
10
  ## Examples
10
11
  The following examples are of a project I worked on, **yellow components will link you to another diagram**. Obviously the
@@ -79,7 +80,9 @@ don't need to delete the rendered image or link.
79
80
 
80
81
  ### Advanced Usage
81
82
  Here are some other features supported
82
- - You can specify the CLI to output the diagram images as png and/or svg see `--output-images` and `--image-formats`
83
+ - You can specify the CLI to output the diagram images as png and/or svg see `--output-images` and `--image-formats`.
84
+ For an example of outputted images, checkout [dist_puml/puml](./dist_puml/puml). These images were created by the
85
+ [pre-commit hook](./.husky/pre-commit).
83
86
  - You can specify the PUML server used to render the diagrams see `--puml-server-url`
84
87
 
85
88
  ### All CLI Options
package/bin/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const path = require('path')
4
+ const fs = require('fs')
4
5
 
5
6
  const {Command, Option} = require('commander')
6
7
 
@@ -12,75 +13,82 @@ const run = require(path.resolve(__dirname, '../index.js'))
12
13
  // =============
13
14
 
14
15
  new Command()
15
- .description('An application to add interactive PUML diagrams to your github markdown files. If running with default arguments, run in project root directory.')
16
- .option(
17
- '-s, --puml-server-url <url>',
18
- 'This is the base URL used to render diagrams. Defaults to the public plantuml server.',
19
- 'https://www.plantuml.com/plantuml',
20
- )
21
- .addOption(new Option(
22
- '-x, --root-directory <path>',
23
- 'The path to your project'
24
- ).default(process.cwd(), 'CWD')
25
- )
26
- .option(
27
- '-r, --hot-reload',
28
- 'Rerun markdown generator every `interval` seconds, determined by interval option',
29
- )
30
- .option(
31
- '-v, --interval-seconds <number>',
32
- 'If --hot-reload is set, how often should it reload',
33
- 2,
34
- )
35
- .addOption(new Option(
36
- '-p, --puml-directory <path>',
37
- 'Path to directory containing puml files which are referenced in markdown files',
38
- ).default(false, 'rootDirectory')
39
- )
40
- .addOption(new Option(
41
- '-m, --markdown-directory <path>',
42
- 'Path to directory containing markdown files referencing puml files',
43
- ).default(false, 'rootDirectory')
44
- )
45
- .option(
46
- '-g, --ignore-gitignore',
47
- "Don't use .gitignore to skip PUML and MD",
48
- )
49
- .addOption(new Option(
50
- '-i, --gitignore-path <path>',
51
- 'Use this as path to .gitignore file.'
52
- ).default(false, 'rootDirectory/.gitignore')
53
- )
54
- .option(
55
- '-d, --output-images',
56
- 'If set, will output images of diagrams to the dist directory',
57
- )
58
- .addOption(new Option(
59
- '-b, --dist-directory <path>',
60
- 'If --output-images is set, path to output diagram images'
61
- ).default(false, 'rootDirectory/dist_puml')
62
- )
63
- .addOption(new Option(
64
- '-f, --image-formats <format>',
65
- 'If --output-images is set, sets the output image format',
66
- ).choices(['png', 'svg', 'both']).default('png')
67
- )
68
- .option(
69
- '-t, --turn-off-link-shortening',
70
- "Use the full puml server link instead of the tiny url, if your diagrams are too big this won't work",
71
- )
72
- .action(opts => {
73
- opts.distDirectory = opts.distDirectory || path.resolve(opts.rootDirectory, 'dist_puml')
74
- opts.gitignorePath = opts.gitignorePath || path.resolve(opts.rootDirectory, '.gitignore')
75
- opts.markdownDirectory = opts.markdownDirectory || opts.rootDirectory
76
- opts.pumlDirectory = opts.pumlDirectory || opts.rootDirectory
77
- opts.shouldShortenLinks = !opts.turnOffLinkShortening
78
- opts.respectGitignore = !opts.ignoreGitignore
79
- opts.imageFormats = opts.imageFormats === 'both' ? ['png', 'svg'] : [opts.imageFormats]
16
+ .description('An application to add interactive PUML diagrams to your github markdown files. If running with default arguments, run in project root directory.')
17
+ .option(
18
+ '-s, --puml-server-url <url>',
19
+ 'This is the base URL used to render diagrams. Defaults to the public plantuml server.',
20
+ 'https://www.plantuml.com/plantuml',
21
+ )
22
+ .addOption(new Option(
23
+ '-x, --root-directory <path>',
24
+ 'The path to your project'
25
+ ).default(process.cwd(), 'CWD')
26
+ )
27
+ .option(
28
+ '-r, --hot-reload',
29
+ 'Rerun markdown generator every `interval` seconds, determined by interval option',
30
+ )
31
+ .option(
32
+ '-v, --interval-seconds <number>',
33
+ 'If --hot-reload is set, how often should it reload',
34
+ 2,
35
+ )
36
+ .addOption(new Option(
37
+ '-p, --puml-directory <path>',
38
+ 'Path to directory containing puml files which are referenced in markdown files',
39
+ ).default(false, 'rootDirectory')
40
+ )
41
+ .addOption(new Option(
42
+ '-m, --markdown-directory <path>',
43
+ 'Path to directory containing markdown files referencing puml files',
44
+ ).default(false, 'rootDirectory')
45
+ )
46
+ .option(
47
+ '-g, --ignore-gitignore',
48
+ "Don't use .gitignore to skip PUML and MD. Will automatically be true if no gitignore is found",
49
+ )
50
+ .addOption(new Option(
51
+ '-i, --gitignore-path <path>',
52
+ 'Use this as path to .gitignore file.'
53
+ ).default(false, 'rootDirectory/.gitignore')
54
+ )
55
+ .option(
56
+ '-d, --output-images',
57
+ 'If set, will output images of diagrams to the dist directory',
58
+ )
59
+ .addOption(new Option(
60
+ '-b, --dist-directory <path>',
61
+ 'If --output-images is set, path to output diagram images'
62
+ ).default(false, 'rootDirectory/dist_puml')
63
+ )
64
+ .addOption(new Option(
65
+ '-f, --image-formats <format>',
66
+ 'If --output-images is set, sets the output image format',
67
+ ).choices(['png', 'svg', 'both']).default('png')
68
+ )
69
+ .option(
70
+ '-t, --turn-off-link-shortening',
71
+ "Use the full puml server link instead of the tiny url, if your diagrams are too big this won't work",
72
+ )
73
+ .action(opts => {
74
+ const useDefaultGitignorePath = !opts.gitignorePath
80
75
 
81
- return run(opts).catch((e) => {
82
- console.error('FATAL EXCEPTION')
83
- console.error(e)
84
- })
85
- })
86
- .parse(process.argv)
76
+ opts.distDirectory = opts.distDirectory || path.resolve(opts.rootDirectory, 'dist_puml')
77
+ opts.gitignorePath = opts.gitignorePath || path.resolve(opts.rootDirectory, '.gitignore')
78
+ opts.markdownDirectory = opts.markdownDirectory || opts.rootDirectory
79
+ opts.pumlDirectory = opts.pumlDirectory || opts.rootDirectory
80
+ opts.shouldShortenLinks = !opts.turnOffLinkShortening
81
+ opts.respectGitignore = !opts.ignoreGitignore
82
+ opts.imageFormats = opts.imageFormats === 'both' ? ['png', 'svg'] : [opts.imageFormats]
83
+
84
+ // If a gitignore path wasn't specified, don't try and parse it
85
+ if (useDefaultGitignorePath && !fs.existsSync(opts.gitignorePath)) {
86
+ opts.respectGitignore = false
87
+ }
88
+
89
+ return run(opts).catch((e) => {
90
+ console.error('FATAL EXCEPTION')
91
+ console.error(e)
92
+ })
93
+ })
94
+ .parse(process.argv)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "puml-for-markdown",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "An application to add interactive PUML diagrams to your github markdown files. If running with default arguments, run in project root directory.",
5
5
  "main": "index.js",
6
6
  "scripts": {