[Scripts > Strip] Rewrite
This commit is contained in:
		
							parent
							
								
									c69bfdf0e1
								
							
						
					
					
						commit
						07e50cd47d
					
				
					 3 changed files with 39 additions and 5 deletions
				
			
		
							
								
								
									
										2
									
								
								.github/workflows/nightly.yml
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.github/workflows/nightly.yml
									
										
									
									
										vendored
									
									
								
							|  | @ -28,7 +28,7 @@ jobs: | |||
|         npm i -g asar | ||||
|         bash scripts/injectPolyfills.sh | ||||
|         sed -i -e "s/nightly/nightly-$(git rev-parse HEAD | cut -c 1-7)/" src/index.js | ||||
|         bash scripts/strip.sh | ||||
|         node scripts/strip.js | ||||
|         npx asar pack src app.asar | ||||
| 
 | ||||
|     - name: Upload artifact | ||||
|  |  | |||
							
								
								
									
										38
									
								
								scripts/strip.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								scripts/strip.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,38 @@ | |||
| const fs = require('fs'); | ||||
| const { join } = require('path'); | ||||
| 
 | ||||
| const stripCode = (code) => code | ||||
|   .replace(/(^| )\/\/.*$/gm, '') | ||||
|   .replaceAll('const ', 'const#') | ||||
|   .replaceAll('let ', 'let#') | ||||
|   .replaceAll('var ', 'var#') | ||||
|   .replaceAll('class ', 'class#') | ||||
|   .replaceAll('get ', 'get#') | ||||
|   .replaceAll('delete ', 'delete#') | ||||
|   .replaceAll(' extends ', '#extends#') | ||||
|   .replaceAll('typeof ', 'typeof#') | ||||
|   .replaceAll(' of ', '#of#') | ||||
|   .replaceAll(' in ', '#in#') | ||||
|   .replaceAll('await ', 'await#') | ||||
|   .replaceAll('new ', 'new#') | ||||
|   .replaceAll('return ', 'return#') | ||||
|   .replaceAll('function ', 'function#') | ||||
|   .replaceAll('void ', 'void#') | ||||
|   .replaceAll('throw ', 'throw#') | ||||
|   .replaceAll('async ', 'async#') | ||||
|   .replaceAll('else ', 'else#') | ||||
|   .replace(/((['"`])[\s\S]*?\2)|[ \n]/g, (_, g1) => g1 || '') | ||||
|   .replaceAll('#', ' ') | ||||
|   .replaceAll('? ?', '??'); | ||||
| 
 | ||||
| const stripFile = (jsPath) => { | ||||
|   console.log(jsPath); | ||||
|   fs.writeFileSync(jsPath, stripCode(fs.readFileSync(jsPath, 'utf8'))); | ||||
| }; | ||||
| 
 | ||||
| const tree = (dirPath) => fs.readdirSync(dirPath).forEach((x) => { | ||||
|   if (x.endsWith('.js')) return stripFile(join(dirPath, x)); | ||||
|   if (!x.includes('.')) return tree(join(dirPath, x)); | ||||
| }); | ||||
| 
 | ||||
| tree(join(__dirname, '..', 'src')); | ||||
|  | @ -1,4 +0,0 @@ | |||
| #!/bin/sh | ||||
| 
 | ||||
| find src -type f -name "*.js" -exec sed -i -E 's@[[:blank:]]*([^:]//).*@@;T;/./!d' {} + # Remove // comments (ignore URLs) | ||||
| find src -type f -name "*.js" -exec sed -i '/^[[:space:]]*$/d' {} + # Remove whitespace | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue