Skip to content

Commit 05e7ad1

Browse files
feature/issue-#55 #56 - closed
1 parent 7a2a3fe commit 05e7ad1

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/bin/index.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@ import fs from 'fs'
33
import path from 'path'
44
import { ModuleArgv } from '../modules'
55
const moduleArgv = new ModuleArgv()
6-
const args = moduleArgv.getNotFormatted()
6+
const arg = moduleArgv.getNotFormatted()[0]
77
const paths = fs.readdirSync(path.join(__dirname, '..', 'scripts'))
8-
const scripts = [...paths.map((script) => `--${script.split('.script')[0]}`)]
9-
const arg = args.filter((arg) => scripts.includes(arg))[0]
10-
if (typeof arg !== 'string') throw new Error('No script')
11-
require(`../scripts/${arg.replace('--', '')}.script`)
8+
9+
function createTeamNamesFromFile(str: string) {
10+
const [filename] = str.split('.')
11+
const firstLetters = filename
12+
.split('-')
13+
.map((word) => word[0])
14+
.join('')
15+
const hyphenated = `--${filename}`
16+
const short = `-${firstLetters}`
17+
return { [hyphenated]: str, [short]: str }
18+
}
19+
20+
const arrayCommands = paths.map((path) => ({
21+
...createTeamNamesFromFile(path),
22+
}))
23+
24+
const commands = arrayCommands.reduce((flat, command) => {
25+
return { ...flat, ...command }
26+
}, {})
27+
28+
const command = commands[arg]
29+
30+
if (typeof command === 'undefined') throw new Error('No script')
31+
require(`../scripts/${commands[arg]}`)

src/modules/config/config.module.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ ${objectToString(enumSnippetName)}
107107
`
108108
Documentation
109109
110-
npx create-snippet --help will show hints
111-
npx create-snippet --init initializes the project
112-
npx create-snippet --generate generates a new snippet
113-
npx create-snippet --clear-cache clear cache
110+
npx create-snippet --help or -h will show hints
111+
npx create-snippet --init or -i initializes the project
112+
npx create-snippet --generate or -g generates a new snippet
113+
npx create-snippet --clear-cache or -cc clear cache
114114
115115
New snippet
116116

0 commit comments

Comments
 (0)