You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					23 lines
				
				518 B
			
		
		
			
		
	
	
					23 lines
				
				518 B
			| 
											3 years ago
										 | const fs = require('fs'); | ||
|  | const path = require('path'); | ||
|  | 
 | ||
|  | const md = fs.readFileSync(path.join(__dirname, '../src/utils/errors.md'), 'utf8'); | ||
|  | 
 | ||
|  | const errorMap = md | ||
|  |   .split(/^#/gm) | ||
|  |   .slice(1) | ||
|  |   .reduce((errors, str) => { | ||
|  |     const [, code, message] = str.split(/^.*?(\d+)\s*\n/); | ||
|  | 
 | ||
|  |     // eslint-disable-next-line no-param-reassign
 | ||
|  |     errors[code] = message; | ||
|  | 
 | ||
|  |     return errors; | ||
|  |   }, {}); | ||
|  | 
 | ||
|  | fs.writeFileSync( | ||
|  |   path.join(__dirname, '../src/utils/errors.js'), | ||
|  |   `export default ${JSON.stringify(errorMap)};`, | ||
|  |   'utf8' | ||
|  | ); |