Copy static assets functionality
This commit is contained in:
		
							parent
							
								
									9068c422b3
								
							
						
					
					
						commit
						2222b82378
					
				
					 3 changed files with 37 additions and 0 deletions
				
			
		
							
								
								
									
										2
									
								
								index.js
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								index.js
									
										
									
									
									
								
							|  | @ -1,4 +1,6 @@ | |||
| const { generateStaticPages } = require('./src/generateHTMLPages'); | ||||
| const copyStaticAssets = require('./src/copyStaticAssets'); | ||||
| 
 | ||||
| generateStaticPages().then(() => console.log('✓ Generated html pages')); | ||||
| copyStaticAssets().then(() => console.log('✓ Copied static assets')); | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										0
									
								
								src/assets/stylesheet.css
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								src/assets/stylesheet.css
									
										
									
									
									
										Normal file
									
								
							
							
								
								
									
										35
									
								
								src/copyStaticAssets.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								src/copyStaticAssets.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,35 @@ | |||
| const { readdir, copyFile } = require('fs-extra'); | ||||
| const { extname, join } = require('path'); | ||||
| 
 | ||||
| const paths = { | ||||
|   srcAssets: './src/assets', | ||||
|   distAssets: './dist/assets', | ||||
| } | ||||
| 
 | ||||
| const _discoverAssets = async () => { | ||||
|   try { | ||||
|     return await readdir(paths.srcAssets); | ||||
|   } catch (error) { | ||||
|     console.error('Unable to find assets to copy', error); | ||||
|     return []; | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| const _copyAssets = async assets => { | ||||
|   try { | ||||
|     assets.forEach(asset => { | ||||
|       let srcFile = join(paths.srcAssets, asset); | ||||
|       let distFile = join(paths.distAssets, asset); | ||||
|       return copyFile(srcFile, distFile); | ||||
|     }); | ||||
|   } catch (error) { | ||||
|     console.error('Unable to copy assets', error); | ||||
|     return; | ||||
|   } | ||||
| }; | ||||
| 
 | ||||
| module.exports = async () => { | ||||
|   let assets = await _discoverAssets(); | ||||
|   _copyAssets(assets); | ||||
| }; | ||||
| 
 | ||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Joe Wroten
						Joe Wroten