kopia lustrzana https://github.com/shoelace-style/shoelace
				
				
				
			refactor metadata fetching
							rodzic
							
								
									12b0365ce0
								
							
						
					
					
						commit
						5e7fcdd105
					
				|  | @ -248,7 +248,14 @@ | ||||||
|     metadata.modules.map(module => { |     metadata.modules.map(module => { | ||||||
|       module.exports.find(ex => { |       module.exports.find(ex => { | ||||||
|         if (ex.kind === 'custom-element-definition') { |         if (ex.kind === 'custom-element-definition') { | ||||||
|           allComponents.push(getComponent(metadata, ex.name)); |           const tagName = ex.name; | ||||||
|  |           const className = ex.declaration.name; | ||||||
|  |           const component = Object.assign( | ||||||
|  |             { className, tagName }, | ||||||
|  |             module?.declarations.find(dec => dec.name === 'default') | ||||||
|  |           ); | ||||||
|  | 
 | ||||||
|  |           allComponents.push(component); | ||||||
|         } |         } | ||||||
|       }); |       }); | ||||||
|     }); |     }); | ||||||
|  | @ -256,18 +263,8 @@ | ||||||
|     return allComponents; |     return allComponents; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function getComponent(metadata, tag) { |   function getComponent(metadata, tagName) { | ||||||
|     const module = metadata.modules.find(module => { |     return getAllComponents(metadata).find(component => (component.tagName = tagName)); | ||||||
|       return module.exports.find(ex => { |  | ||||||
|         return ex.kind === 'custom-element-definition' && ex.name === tag; |  | ||||||
|       }); |  | ||||||
|     }); |  | ||||||
|     const component = module?.declarations.find(dec => dec.name === 'default'); |  | ||||||
|     const definition = module.exports.filter(ex => ex.kind === 'custom-element-definition' && ex.name === tag)[0]; |  | ||||||
|     const tagName = definition?.name; |  | ||||||
|     const className = definition?.declaration?.name; |  | ||||||
| 
 |  | ||||||
|     return Object.assign({ className, tagName }, component); |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   function getMetadata() { |   function getMetadata() { | ||||||
|  |  | ||||||
|  | @ -11,25 +11,18 @@ const metadata = JSON.parse(fs.readFileSync('./dist/custom-elements.json', 'utf8 | ||||||
| 
 | 
 | ||||||
| function getAllComponents() { | function getAllComponents() { | ||||||
|   const allComponents = []; |   const allComponents = []; | ||||||
|   const getComponent = tagName => { |  | ||||||
|     const module = metadata.modules.find(module => { |  | ||||||
|       return module.exports.find(ex => { |  | ||||||
|         return ex.kind === 'custom-element-definition' && ex.name === tagName; |  | ||||||
|       }); |  | ||||||
|     }); |  | ||||||
| 
 |  | ||||||
|     const component = module?.declarations.find(dec => dec.name === 'default'); |  | ||||||
|     const tag = module.exports.filter(ex => ex.kind === 'custom-element-definition' && ex.name === tagName)[0]?.name; |  | ||||||
| 
 |  | ||||||
|     return Object.assign({ tag }, component); |  | ||||||
|   }; |  | ||||||
| 
 | 
 | ||||||
|   metadata.modules.map(module => { |   metadata.modules.map(module => { | ||||||
|     module.exports.find(ex => { |     module.exports.find(ex => { | ||||||
|       if (ex.kind === 'custom-element-definition') { |       if (ex.kind === 'custom-element-definition') { | ||||||
|         if (typeof ex.name === 'string') { |         const tagName = ex.name; | ||||||
|           allComponents.push(getComponent(ex.name)); |         const className = ex.declaration.name; | ||||||
|         } |         const component = Object.assign( | ||||||
|  |           { className, tagName }, | ||||||
|  |           module?.declarations.find(dec => dec.name === 'default') | ||||||
|  |         ); | ||||||
|  | 
 | ||||||
|  |         allComponents.push(component); | ||||||
|       } |       } | ||||||
|     }); |     }); | ||||||
|   }); |   }); | ||||||
|  | @ -83,4 +76,4 @@ components.map(component => { | ||||||
| 
 | 
 | ||||||
| fs.writeFileSync('./dist/vscode.html-custom-data.json', JSON.stringify(vscode, null, 2), 'utf8'); | fs.writeFileSync('./dist/vscode.html-custom-data.json', JSON.stringify(vscode, null, 2), 'utf8'); | ||||||
| 
 | 
 | ||||||
| console.log(chalk.cyan(`Successfully generated IntelliSense data for VS Code 🔮\n`)); | console.log(chalk.cyan(`Successfully generated custom data for VS Code 🔮\n`)); | ||||||
|  |  | ||||||
		Ładowanie…
	
		Reference in New Issue
	
	 Cory LaViska
						Cory LaViska