Skip to content

Commit 1acbe11

Browse files
committed
📝 Add cli documentation
1 parent c480e2a commit 1acbe11

6 files changed

Lines changed: 26 additions & 2 deletions

File tree

lib/cloudrun/CloudRunStarter.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/cloudrun/CloudRunStarter.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cloudrun/CloudRunStarter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ export class CloudRunStarter implements Starter {
162162

163163
tb.mkdir(tb.stringToPath(`${tb.destination}/src/view/cli`))
164164
tb.copyAsset('src/view/cli/cli.ts')
165+
tb.copyAsset('src/view/cli/README.md')
165166
tb.mkdir(tb.stringToPath(`${tb.destination}/src/view/cli/openapi`))
166167
tb.copyAsset('src/view/cli/openapi/generate.ts')
167168
tb.npm.iDev('yargs')

starter/cloudrun-graphql/.eslintrc.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
extends: 'plugin:@graphql-eslint/schema-recommended',
2525
parserOptions: {
2626
graphQLConfig: {
27-
schema: './src/app/api/graphql/schema/*.graphql',
27+
schema: './src/view/graphql/schema/*.graphql',
2828
},
2929
},
3030
rules: {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# CLI
2+
3+
Cli tool to operate scripts that can use internal services or to add development toolkit with the same interface and usage. Currently cli tool is operated using tsx tool.
4+
5+
## 👷 Development
6+
7+
The CLI tool is build around `yargs` library. Each command needs its own `ts` file in current folder or in subfolder. The entrypoint `Cli.ts` scans the sub folders for `ts` files and intrerprets them as a command under the module called same as the folder.
8+
9+
For example, current [openapi folder](./openapi) creates a new module `openapi` and assigns a new command called `generate` based on contents in [generate.ts](./openapi/generate.ts) file.
10+
11+
Each command should export only functions and variables according to `CommandDefinition` in [cli.ts file](./cli.ts).
12+
13+
Take a look at the [generate.ts](./openapi/generate.ts) for example how to implement own command.
14+
15+
## ⚠️ Usage in production scripts
16+
17+
If the cli tool is used to run production scripts (CRON), make sure all dependencies are also listed in production list and build the code instead of using `tsx` (e.g. `yargs`).

starter/cloudrun/src/view/cli/cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ import { readdir, stat } from 'fs/promises'
44
import { join, extname } from 'path'
55

66
interface CommandDefinition {
7+
// Description of the command used for help
78
description: string
9+
// Defines positional description of the command (e.g. '<filepath>' will mean it takes one positional required argument)
810
positional?: string
11+
// Function that will be called when the command is executed
912
run: (argv: any) => Promise<void> | void
13+
// Function that will be called to add options to the command
1014
options?: (yargs: Argv) => Argv
15+
// Any other properties that will be added to the command
1116
[key: string]: any
1217
}
1318

0 commit comments

Comments
 (0)