fix: incorrect config parsing
This commit is contained in:
		
							
								
								
									
										38
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | |||||||
|  | # rcz | ||||||
|  |  | ||||||
|  | Resultium commit standardization library | ||||||
|  |  | ||||||
|  | ## Installation | ||||||
|  |  | ||||||
|  | 1. Set up @resultium registry in an .npmrc file in your home directory with following content: | ||||||
|  |    ``` | ||||||
|  |    @resultium:registry=https://git.resultium.net/api/packages/technology/npm/ | ||||||
|  |    ``` | ||||||
|  | 2. Install the package using npm | ||||||
|  |    ``` | ||||||
|  |    npm install -g @resultium/rcz | ||||||
|  |    ``` | ||||||
|  |  | ||||||
|  | ## Getting started | ||||||
|  |  | ||||||
|  | 1. Make changes to your git initialized project | ||||||
|  | 2. Run `rcz` in the root directory | ||||||
|  | 3. Answer all the questions | ||||||
|  | 4. Push to remote | ||||||
|  |  | ||||||
|  | ## Configuration | ||||||
|  |  | ||||||
|  | You can create an `.rczrc` file in your root directory and specify available scopes and commit types | ||||||
|  |  | ||||||
|  | ```json | ||||||
|  | { | ||||||
|  |   "scopes": ["forms"], | ||||||
|  |   "types": [ | ||||||
|  |     { | ||||||
|  |       "label": "chore", | ||||||
|  |       "value": "chore", | ||||||
|  |       "hint": "a routine action" | ||||||
|  |     } | ||||||
|  |   ] | ||||||
|  | } | ||||||
|  | ``` | ||||||
							
								
								
									
										14
									
								
								src/index.ts
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								src/index.ts
									
									
									
									
									
								
							| @@ -16,9 +16,11 @@ import simpleGit from "simple-git"; | |||||||
|  |  | ||||||
| const GetConfig = async () => { | const GetConfig = async () => { | ||||||
|   if (fs.existsSync(path.join(process.cwd(), ".rczrc"))) { |   if (fs.existsSync(path.join(process.cwd(), ".rczrc"))) { | ||||||
|     return (await fs.promises.readFile( |     return JSON.parse( | ||||||
|       path.join(process.cwd(), ".rczrc") |       ( | ||||||
|     )) as Config; |         await fs.promises.readFile(path.join(process.cwd(), ".rczrc")) | ||||||
|  |       ).toString() | ||||||
|  |     ) as Config; | ||||||
|   } else { |   } else { | ||||||
|     return null; |     return null; | ||||||
|   } |   } | ||||||
| @@ -46,7 +48,7 @@ const GetConfig = async () => { | |||||||
|  |  | ||||||
|   const type: string | symbol = await select({ |   const type: string | symbol = await select({ | ||||||
|     message: "Choose a commit type", |     message: "Choose a commit type", | ||||||
|     options: [ |     options: config?.types || [ | ||||||
|       { |       { | ||||||
|         label: "feat", |         label: "feat", | ||||||
|         value: "feat", |         value: "feat", | ||||||
| @@ -93,7 +95,7 @@ const GetConfig = async () => { | |||||||
|   const scope: string | symbol = await text({ |   const scope: string | symbol = await text({ | ||||||
|     message: "Input a scope (e.g. router, forms, core) or leave empty", |     message: "Input a scope (e.g. router, forms, core) or leave empty", | ||||||
|     validate: (value) => { |     validate: (value) => { | ||||||
|       if (config?.scopes) { |       if (config?.scopes && value) { | ||||||
|         if (!config?.scopes.includes(value)) |         if (!config?.scopes.includes(value)) | ||||||
|           return "This scope is not allowed by local configuration"; |           return "This scope is not allowed by local configuration"; | ||||||
|       } |       } | ||||||
| @@ -120,7 +122,7 @@ const GetConfig = async () => { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   const body = await text({ |   const body = await text({ | ||||||
|     message: `Briefly describe made changes in imperative tense, recommended length 100, can be left empty`, |     message: `Insert a commit body, recommended length 100, can be left empty`, | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
|   if (isCancel(body)) { |   if (isCancel(body)) { | ||||||
|   | |||||||
| @@ -1,5 +1,5 @@ | |||||||
| export interface Config { | export interface Config { | ||||||
|   commitTypes?: Array<Type>; |   types?: Array<Type>; | ||||||
|   scopes?: Array<string>; |   scopes?: Array<string>; | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user