Skip to content

Commit 587909e

Browse files
Merge branch 'release/1.3.8'
2 parents 4415062 + 44691e2 commit 587909e

File tree

11 files changed

+423
-44
lines changed

11 files changed

+423
-44
lines changed

.github/workflows/publish.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- uses: actions/setup-node@v3
15+
with:
16+
node-version: '16.x'
17+
registry-url: 'https://registry.npmjs.org'
18+
- run: npm ci
19+
- run: npm run pre-test
20+
- run: npm run build
21+
- run: npm publish
22+
env:
23+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_CREATE_SNIPPET }}

.github/workflows/github-actions.yml renamed to .github/workflows/testing.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
name: GitHub Actions
2-
run-name: ${{ github.actor }} is testing out GitHub Actions 🚀
1+
name: Testing
32
on: [push]
43
jobs:
54
init:

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.3.7",
12+
"version": "1.3.8",
1313
"bin": {
1414
"create-snippet": "./dist/bin/index.js"
1515
},

src/enums/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './prefix-name.enum'
22
export * from './snippet-name.enum'
3+
export * from './snippet-variable.enum'
34
export * from './suffix-name.enum'

src/enums/snippet-variable.enum.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { TypeCase } from '../types'
2+
3+
export const enumSnippetVariable: TypeCase = {
4+
camelCase: 'snippetVariable',
5+
pascalCase: 'SnippetVariable',
6+
lowerSnakeCase: 'snippet_variable',
7+
upperSnakeCase: 'SNIPPET_VARIABLE',
8+
lowerKebabCase: 'snippet-variable',
9+
upperKebabCase: 'SNIPPET-VARIABLE',
10+
}

src/modules/snippet/snippet.module.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import nodePath from 'path'
44
import { prompt } from 'prompts'
55
import recursiveReadDir from 'recursive-readdir'
66
import { CONSTANTS } from '../../constants'
7-
import { enumPrefixName, enumSnippetName, enumSuffixName } from '../../enums'
7+
import { enumPrefixName, enumSnippetName, enumSnippetVariable, enumSuffixName } from '../../enums'
88
import type { TypeCase, TypeStringConversionMethod } from '../../types'
99
import { ModuleConfig } from '../config'
1010
import { ModulePath } from '../path'
@@ -69,14 +69,6 @@ export class ModuleSnippet {
6969
name: 'prefix',
7070
message: 'Pick a prefix (specify a string in the kebab-case format)',
7171
},
72-
73-
{
74-
type: async (_: any, values: TypeOptionsSnippetGeneration) => {
75-
return (await this.check(values.snippetName)).isSuffix ? 'text' : null
76-
},
77-
name: 'suffix',
78-
message: 'Pick a suffix (specify a string in the kebab-case format)',
79-
},
8072
]
8173

8274
const questions = await data()
@@ -145,6 +137,29 @@ export class ModuleSnippet {
145137
return { isPrefix, isSuffix }
146138
}
147139

140+
public async getSnippetVariables(pathToSnippet: string): Promise<string[]> {
141+
function createRegExp(): RegExp[] {
142+
return Object.values(enumSnippetVariable).map((item) => new RegExp(`${item}\\d+`, 'g'))
143+
}
144+
145+
const myPaths = await recursiveReadDir(nodePath.join(...[this.rootDirConfig, pathToSnippet]))
146+
147+
let snippetVariables: string[] = []
148+
149+
myPaths.forEach((item) => {
150+
const data = JSON.stringify(fs.readFileSync(item, 'utf-8'))
151+
152+
snippetVariables = [
153+
...(createRegExp()
154+
.map((item) => data.match(item))
155+
.flat(Infinity)
156+
.filter((item) => typeof item === 'string') as []),
157+
]
158+
})
159+
160+
return snippetVariables
161+
}
162+
148163
public async generate() {
149164
if (!fs.existsSync(nodePath.join(...[this.rootDirConfig]))) throw new Error('npx create-snippet --init')
150165

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,85 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`module/string snapshot: HELLO_WORLD 1`] = `"HELLO_WORLD"`;
3+
exports[`module/string snapshot 1`] = `"snippetName"`;
44

5-
exports[`module/string snapshot: HELLO-WORLD 1`] = `"HELLO-WORLD"`;
5+
exports[`module/string snapshot 2`] = `"snippet-name"`;
66

7-
exports[`module/string snapshot: HelloWorld 1`] = `"HelloWorld"`;
7+
exports[`module/string snapshot 3`] = `"snippet_name"`;
88

9-
exports[`module/string snapshot: hello_world 1`] = `"hello_world"`;
9+
exports[`module/string snapshot 4`] = `"SnippetName"`;
1010

11-
exports[`module/string snapshot: hello-world 1`] = `"hello-world"`;
11+
exports[`module/string snapshot 5`] = `"SNIPPET-NAME"`;
1212

13-
exports[`module/string snapshot: helloWorld 1`] = `"helloWorld"`;
13+
exports[`module/string snapshot 6`] = `"SNIPPET_NAME"`;
14+
15+
exports[`module/string snapshot 7`] = `true`;
16+
17+
exports[`module/string snapshot 8`] = `false`;
18+
19+
exports[`module/string snapshot 9`] = `false`;
20+
21+
exports[`module/string snapshot 10`] = `false`;
22+
23+
exports[`module/string snapshot 11`] = `false`;
24+
25+
exports[`module/string snapshot 12`] = `false`;
26+
27+
exports[`module/string snapshot 13`] = `false`;
28+
29+
exports[`module/string snapshot 14`] = `true`;
30+
31+
exports[`module/string snapshot 15`] = `false`;
32+
33+
exports[`module/string snapshot 16`] = `false`;
34+
35+
exports[`module/string snapshot 17`] = `false`;
36+
37+
exports[`module/string snapshot 18`] = `false`;
38+
39+
exports[`module/string snapshot 19`] = `false`;
40+
41+
exports[`module/string snapshot 20`] = `false`;
42+
43+
exports[`module/string snapshot 21`] = `true`;
44+
45+
exports[`module/string snapshot 22`] = `false`;
46+
47+
exports[`module/string snapshot 23`] = `false`;
48+
49+
exports[`module/string snapshot 24`] = `false`;
50+
51+
exports[`module/string snapshot 25`] = `false`;
52+
53+
exports[`module/string snapshot 26`] = `false`;
54+
55+
exports[`module/string snapshot 27`] = `false`;
56+
57+
exports[`module/string snapshot 28`] = `true`;
58+
59+
exports[`module/string snapshot 29`] = `false`;
60+
61+
exports[`module/string snapshot 30`] = `false`;
62+
63+
exports[`module/string snapshot 31`] = `false`;
64+
65+
exports[`module/string snapshot 32`] = `false`;
66+
67+
exports[`module/string snapshot 33`] = `false`;
68+
69+
exports[`module/string snapshot 34`] = `false`;
70+
71+
exports[`module/string snapshot 35`] = `true`;
72+
73+
exports[`module/string snapshot 36`] = `false`;
74+
75+
exports[`module/string snapshot 37`] = `false`;
76+
77+
exports[`module/string snapshot 38`] = `false`;
78+
79+
exports[`module/string snapshot 39`] = `false`;
80+
81+
exports[`module/string snapshot 40`] = `false`;
82+
83+
exports[`module/string snapshot 41`] = `false`;
84+
85+
exports[`module/string snapshot 42`] = `true`;

0 commit comments

Comments
 (0)