hjson
This commit is contained in:
		| @@ -19,7 +19,7 @@ const { InteractiveOptions } = require ('./dist/lib/index.js'); | ||||
|     { name: 'num', type: 'number', env: 'TEST_NUM' }, | ||||
|     { name: 'arr', type: 'array', env: 'TEST_ARR' }, | ||||
|     { name: 'fld', type: 'folder', env: 'TEST_FOLDER' } | ||||
|   ], { exit_on_interrupt: true }); | ||||
|   ], { exit_on_interrupt: true, configs: [ 'test.json' ] }); | ||||
|   await reader.parse (); | ||||
|   console.log (reader.serialize (true)); | ||||
| }) (); | ||||
|   | ||||
| @@ -1,5 +1,9 @@ | ||||
| # Changelog | ||||
|  | ||||
| ## 1.7.0 | ||||
|  | ||||
| parsing config files with [hjson](https://github.com/hjson/hjson-js) | ||||
|  | ||||
| ## 1.6.0 | ||||
|  | ||||
| option to change the message displayed on invalid input | ||||
| @@ -19,8 +23,8 @@ new source: config files | ||||
|  | ||||
| ## 1.2.0 | ||||
|  | ||||
| preset option: | ||||
| an array of strings to choose from when using one of the string types | ||||
| preset option: an array of strings to choose from when using one of the string | ||||
| types | ||||
|  | ||||
| ## 1.1.0 | ||||
|  | ||||
|   | ||||
							
								
								
									
										2
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								Jenkinsfile
									
									
									
									
										vendored
									
									
								
							| @@ -5,7 +5,7 @@ pipeline { | ||||
|       VERSION = VersionNumber([ | ||||
|           versionNumberString: | ||||
|               '${BUILDS_ALL_TIME}', | ||||
|           versionPrefix: '1.6.', | ||||
|           versionPrefix: '1.7.', | ||||
|           worstResultForIncrement: 'SUCCESS' | ||||
|       ]) | ||||
|   } | ||||
|   | ||||
							
								
								
									
										11
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								README.md
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | ||||
| # @sapphirecode/console-app | ||||
|  | ||||
| version: 1.6.x | ||||
| version: 1.7.x | ||||
|  | ||||
| read parameters from env, console args or interactively | ||||
|  | ||||
| @@ -30,7 +30,7 @@ const reader = new InteractiveOptions([ | ||||
|     description: 'the switch foo', // description in the help page (optional) | ||||
|     message: 'should foo be true?', // message when asking interactively (optional) | ||||
|     preset: [], // preset choices for string and path types (optional) | ||||
|     error: 'wrong input' // message to display when the user gives invalid input | ||||
|     error: 'wrong input', // message to display when the user gives invalid input | ||||
|   }, | ||||
| ]); | ||||
|  | ||||
| @@ -66,7 +66,10 @@ config files can import other config files with #include. example: | ||||
| } | ||||
| ``` | ||||
|  | ||||
| the option exit_on_interrupt determines whether an error should be thrown or the process should exit when the user presses control + c in an interactive prompt. | ||||
| config files are parsed using [hjson](https://github.com/hjson/hjson-js) | ||||
|  | ||||
| the option exit_on_interrupt determines whether an error should be thrown or the | ||||
| process should exit when the user presses control + c in an interactive prompt. | ||||
|  | ||||
| ```js | ||||
| const reader = new InteractiveOptions([], { | ||||
| @@ -74,7 +77,7 @@ const reader = new InteractiveOptions([], { | ||||
|   env: true, | ||||
|   interactive: true, | ||||
|   configs: ['json files to search for options'], | ||||
|   exit_on_interrupt: true | ||||
|   exit_on_interrupt: true, | ||||
| }); | ||||
| ``` | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
| import { dirname, join } from 'path'; | ||||
| import fs from 'fs-extra'; | ||||
| import { run_regex } from '@sapphirecode/utilities'; | ||||
| import hjson from 'hjson'; | ||||
| import { OptionProcess } from '../Option'; | ||||
| import { OptionSource } from './OptionSource'; | ||||
|  | ||||
| @@ -37,7 +38,7 @@ export class ConfigSource extends OptionSource { | ||||
|       for (const key of Object.keys (data)) | ||||
|         obj[key] = data[key]; | ||||
|     } | ||||
|     const config = JSON.parse (contents.replace (regex, '')); | ||||
|     const config = hjson.parse (contents); | ||||
|     for (const key of Object.keys (config)) | ||||
|       obj[key] = config[key]; | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,7 @@ | ||||
|     "@ava/typescript": "^1.1.1", | ||||
|     "@sapphirecode/eslint-config-ts": "^1.1.4", | ||||
|     "@types/fs-extra": "^9.0.0", | ||||
|     "@types/hjson": "^2.4.1", | ||||
|     "@types/yargs": "^15.0.5", | ||||
|     "ava": "^3.8.2", | ||||
|     "eslint": "^7.0.0", | ||||
| @@ -35,6 +36,7 @@ | ||||
|     "@sapphirecode/utilities": "^1.3.4", | ||||
|     "enquirer": "^2.3.5", | ||||
|     "fs-extra": "^9.0.0", | ||||
|     "hjson": "^3.2.1", | ||||
|     "yargs": "^15.3.1" | ||||
|   } | ||||
| } | ||||
|   | ||||
							
								
								
									
										554
									
								
								yarn-error.log
									
									
									
									
									
								
							
							
						
						
									
										554
									
								
								yarn-error.log
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										10
									
								
								yarn.lock
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								yarn.lock
									
									
									
									
									
								
							| @@ -324,6 +324,11 @@ | ||||
|     "@types/minimatch" "*" | ||||
|     "@types/node" "*" | ||||
|  | ||||
| "@types/hjson@^2.4.1": | ||||
|   version "2.4.1" | ||||
|   resolved "https://registry.yarnpkg.com/@types/hjson/-/hjson-2.4.1.tgz#a6fc8649777b63f979193d2d5c108a71b3d414d9" | ||||
|   integrity sha512-yXq/C73UHM8GQc6RYJnUXUgxudr2Q9227Iawhkp03YCnfJJTc+6LJnnVLx+UR/Dvw6imO5Q3vpGNmR9IRBI0JQ== | ||||
|  | ||||
| "@types/json-schema@^7.0.3": | ||||
|   version "7.0.4" | ||||
|   resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.4.tgz#38fd73ddfd9b55abb1e1b2ed578cb55bd7b7d339" | ||||
| @@ -1646,6 +1651,11 @@ hasha@^5.0.0: | ||||
|     is-stream "^2.0.0" | ||||
|     type-fest "^0.8.0" | ||||
|  | ||||
| hjson@^3.2.1: | ||||
|   version "3.2.1" | ||||
|   resolved "https://registry.yarnpkg.com/hjson/-/hjson-3.2.1.tgz#20de41dc87fc9a10d1557d0230b0e02afb1b09ac" | ||||
|   integrity sha512-OhhrFMeC7dVuA1xvxuXGTv/yTdhTvbe8hz+3LgVNsfi9+vgz0sF/RrkuX8eegpKaMc9cwYwydImBH6iePoJtdQ== | ||||
|  | ||||
| hosted-git-info@^2.1.4: | ||||
|   version "2.8.8" | ||||
|   resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.8.tgz#7539bd4bc1e0e0a895815a2e0262420b12858488" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user