|
1 | | -import * as _fs from "fs"; |
2 | | -const fs = _fs.promises; |
3 | | -import { extname } from "path"; |
4 | | -const __dirname = import.meta.dirname; |
| 1 | +import * as _fs from 'fs' |
| 2 | +import { extname } from 'path' |
| 3 | +import { parseArgs } from 'util' |
| 4 | +import * as yaml from 'yaml' |
5 | 5 |
|
6 | | -import { parseArgs } from "util"; |
7 | | -import pkg from "../package.json" assert { type: "json" }; |
| 6 | +const fs = _fs.promises |
8 | 7 |
|
9 | | -import * as yaml from "yaml"; |
| 8 | +const __dirname = import.meta.dirname |
10 | 9 |
|
11 | 10 | // content to appear above the commands outline |
12 | 11 | const prepend = `--- |
@@ -35,119 +34,120 @@ You can access this documentation on a per-command basis by appending the \`--he |
35 | 34 | <Aside type="note"> |
36 | 35 | This reference does not apply to the \`daytona\` command when run inside of a Workspace. |
37 | 36 | </Aside> |
38 | | -`; |
| 37 | +` |
39 | 38 |
|
40 | 39 | // content to appear below the commands outline |
41 | | -const append = ``; |
| 40 | +const append = `` |
42 | 41 |
|
43 | 42 | const notes = { |
44 | | - "daytona autocomplete": `\n<Aside type="note"> |
| 43 | + 'daytona autocomplete': `\n<Aside type="note"> |
45 | 44 | If using bash shell environment, make sure you have bash-completion installed in order to get full autocompletion functionality. |
46 | 45 | Linux Installation: \`\`\`sudo apt-get install bash-completion\`\`\` |
47 | 46 | macOS Installation: \`\`\`brew install bash-completion\`\`\` |
48 | | -</Aside>`}; |
| 47 | +</Aside>`, |
| 48 | +} |
49 | 49 |
|
50 | 50 | async function fetchRawDocs(ref) { |
51 | | - const url = "https://api.github.com/repos/daytonaio/daytona/contents/hack/docs"; |
52 | | - const request = await fetch(`${url}?ref=${ref}`); |
53 | | - const response = await request.json(); |
| 51 | + const url = |
| 52 | + 'https://api.github.com/repos/daytonaio/daytona/contents/hack/docs' |
| 53 | + const request = await fetch(`${url}?ref=${ref}`) |
| 54 | + const response = await request.json() |
54 | 55 |
|
55 | | - const files = []; |
| 56 | + const files = [] |
56 | 57 |
|
57 | | - for (const file of response) { |
58 | | - const { download_url } = file; |
| 58 | + for (const file of response) { |
| 59 | + const { download_url } = file |
59 | 60 |
|
60 | | - if (!download_url) continue; |
| 61 | + if (!download_url) continue |
61 | 62 |
|
62 | | - const contentsReq = await fetch(download_url); |
63 | | - let contents = await contentsReq.text(); |
| 63 | + const contentsReq = await fetch(download_url) |
| 64 | + let contents = await contentsReq.text() |
64 | 65 |
|
65 | | - contents = yaml.parse(contents); |
| 66 | + contents = yaml.parse(contents) |
66 | 67 |
|
67 | | - files.push(contents); |
68 | | - } |
| 68 | + files.push(contents) |
| 69 | + } |
69 | 70 |
|
70 | | - return files; |
| 71 | + return files |
71 | 72 | } |
72 | 73 |
|
73 | 74 | function flagToRow(flag) { |
74 | | - let { name, shorthand, usage } = flag; |
| 75 | + let { name, shorthand, usage } = flag |
75 | 76 |
|
76 | | - name = `\`--${name}\``; |
77 | | - shorthand = shorthand ? `\`-${shorthand}\`` : ""; |
78 | | - usage = usage ? usage : ""; |
| 77 | + name = `\`--${name}\`` |
| 78 | + shorthand = shorthand ? `\`-${shorthand}\`` : '' |
| 79 | + usage = usage ? usage : '' |
79 | 80 |
|
80 | | - return `| ${name} | ${shorthand} | ${usage} |\n`; |
| 81 | + return `| ${name} | ${shorthand} | ${usage} |\n` |
81 | 82 | } |
82 | 83 |
|
83 | 84 | function yamlToMarkdown(files) { |
84 | | - return files.map((rawDoc) => { |
85 | | - let output = ""; |
86 | | - output += `## ${rawDoc.name}\n`; |
87 | | - output += `${rawDoc.synopsis}\n\n`; |
88 | | - |
89 | | - if (!rawDoc.usage) { |
90 | | - rawDoc.usage = `${rawDoc.name} [flags]`; |
91 | | - } |
92 | | - |
93 | | - output += "```shell\n"; |
94 | | - output += `${rawDoc.usage}\n`; |
95 | | - output += "```\n\n"; |
96 | | - |
97 | | - |
98 | | - output += "__Flags__\n"; |
99 | | - output += "| Long | Short | Description |\n"; |
100 | | - output += "| :--- | :---- | :---------- |\n"; |
101 | | - |
102 | | - if (rawDoc.options) { |
103 | | - for (const flag of rawDoc.options) { |
104 | | - let row = flagToRow(flag); |
105 | | - output += row; |
106 | | - } |
107 | | - } |
108 | | - |
109 | | - if (rawDoc.inherited_options) { |
110 | | - for (const flag of rawDoc.inherited_options) { |
111 | | - let row = flagToRow(flag); |
112 | | - output += row; |
113 | | - } |
114 | | - } |
115 | | - |
116 | | - if (notes[rawDoc.name]) { |
117 | | - output += notes[rawDoc.name]; |
118 | | - } |
119 | | - |
120 | | - output += "\n"; |
121 | | - |
122 | | - return output; |
123 | | - }); |
| 85 | + return files.map(rawDoc => { |
| 86 | + let output = '' |
| 87 | + output += `## ${rawDoc.name}\n` |
| 88 | + output += `${rawDoc.synopsis}\n\n` |
| 89 | + |
| 90 | + if (!rawDoc.usage) { |
| 91 | + rawDoc.usage = `${rawDoc.name} [flags]` |
| 92 | + } |
| 93 | + |
| 94 | + output += '```shell\n' |
| 95 | + output += `${rawDoc.usage}\n` |
| 96 | + output += '```\n\n' |
| 97 | + |
| 98 | + output += '__Flags__\n' |
| 99 | + output += '| Long | Short | Description |\n' |
| 100 | + output += '| :--- | :---- | :---------- |\n' |
| 101 | + |
| 102 | + if (rawDoc.options) { |
| 103 | + for (const flag of rawDoc.options) { |
| 104 | + let row = flagToRow(flag) |
| 105 | + output += row |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + if (rawDoc.inherited_options) { |
| 110 | + for (const flag of rawDoc.inherited_options) { |
| 111 | + let row = flagToRow(flag) |
| 112 | + output += row |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + if (notes[rawDoc.name]) { |
| 117 | + output += notes[rawDoc.name] |
| 118 | + } |
| 119 | + |
| 120 | + output += '\n' |
| 121 | + |
| 122 | + return output |
| 123 | + }) |
124 | 124 | } |
125 | 125 |
|
126 | 126 | async function process(args) { |
127 | | - const { output, ref } = args.values; |
128 | | - console.log(`grabbing docs for ${ref}...`); |
| 127 | + const { output, ref } = args.values |
| 128 | + console.log(`grabbing docs for ${ref}...`) |
129 | 129 |
|
130 | | - // grab the files from GitHub |
131 | | - let files = await fetchRawDocs(ref); |
132 | | - let transformed = yamlToMarkdown(files); |
| 130 | + // grab the files from GitHub |
| 131 | + let files = await fetchRawDocs(ref) |
| 132 | + let transformed = yamlToMarkdown(files) |
133 | 133 |
|
134 | | - const singleMarkdown = transformed.join("\n"); |
135 | | - console.log(`writing to '${output}'...`); |
136 | | - await fs.writeFile(output, `${prepend}\n${singleMarkdown}\n${append}`); |
137 | | - console.log("done"); |
| 134 | + const singleMarkdown = transformed.join('\n') |
| 135 | + console.log(`writing to '${output}'...`) |
| 136 | + await fs.writeFile(output, `${prepend}\n${singleMarkdown}\n${append}`) |
| 137 | + console.log('done') |
138 | 138 | } |
139 | 139 |
|
140 | 140 | const commandOpts = { |
141 | | - ref: { |
142 | | - type: "string", |
143 | | - default: `v${pkg.version}` |
144 | | - }, |
145 | | - output: { |
146 | | - type: "string", |
147 | | - short: "o", |
148 | | - default: `${__dirname}/../src/content/docs/tools/cli.mdx` |
149 | | - } |
| 141 | + ref: { |
| 142 | + type: 'string', |
| 143 | + default: `v0.47.0`, |
| 144 | + }, |
| 145 | + output: { |
| 146 | + type: 'string', |
| 147 | + short: 'o', |
| 148 | + default: `${__dirname}/../src/content/docs/tools/cli.mdx`, |
| 149 | + }, |
150 | 150 | } |
151 | 151 |
|
152 | | -const args = parseArgs({ options: commandOpts }); |
153 | | -process(args); |
| 152 | +const args = parseArgs({ options: commandOpts }) |
| 153 | +process(args) |
0 commit comments