Skip to content

Commit 2692c5d

Browse files
Merge branch 'release/1.6.0'
2 parents eb480a5 + ed4f95f commit 2692c5d

File tree

6 files changed

+47
-9
lines changed

6 files changed

+47
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"automating-code-creation",
1010
"code-generation"
1111
],
12-
"version": "1.5.0",
12+
"version": "1.6.0",
1313
"license": "ISC",
1414
"bin": {
1515
"create-snippet": "./dist/bin/index.js"

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/cache/cache.module.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import chalk from 'chalk'
12
import fs from 'fs'
23
import path from 'path'
4+
import { enumSymbol } from '../../enums'
35

46
export class ModuleCache {
57
private cacheDir: string
@@ -45,4 +47,16 @@ export class ModuleCache {
4547
const fileName = `${key}.json`
4648
return path.join(this.cacheDir, fileName)
4749
}
50+
51+
public clear(): void {
52+
fs.readdirSync(this.cacheDir).forEach((file) => {
53+
fs.unlinkSync(path.join(this.cacheDir, file))
54+
})
55+
// eslint-disable-next-line no-console
56+
console.log(
57+
`${chalk.green(enumSymbol.check)} ${chalk.gray(
58+
`Cache cleared successfully!`
59+
)}`
60+
)
61+
}
4862
}

src/modules/config/config.module.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +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
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
113114
114115
New snippet
115116

src/modules/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export * from './argv'
2+
export * from './cache'
23
export * from './config'
34
export * from './path'
45
export * from './snippet'

src/scripts/clear-cache.script.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import { ModuleCache } from '../modules'
2+
new ModuleCache().clear()

0 commit comments

Comments
 (0)