| 
									
										
										
										
											2024-05-29 05:10:39 +00:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | # https://docs.sheetjs.com/docs/demos/cli/nodesea | 
					
						
							|  |  |  | cd /tmp | 
					
						
							|  |  |  | rm -rf sheetjs-sea | 
					
						
							|  |  |  | mkdir sheetjs-sea | 
					
						
							|  |  |  | cd sheetjs-sea | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | node --version | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | npm init -y | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cat >sheet2csv.js <<EOF | 
					
						
							|  |  |  | // For NodeJS SEA, the CommonJS \`require\` must be used | 
					
						
							|  |  |  | const { createRequire } = require('node:module'); | 
					
						
							|  |  |  | require = createRequire(__filename); | 
					
						
							|  |  |  | const { readFile, utils } = require("xlsx"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // argv[2] is the first argument to the script | 
					
						
							|  |  |  | const filename = process.argv[2]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // read file | 
					
						
							|  |  |  | const wb = readFile(filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // generate CSV of first sheet | 
					
						
							|  |  |  | const ws = wb.Sheets[wb.SheetNames[0]]; | 
					
						
							|  |  |  | const csv = utils.sheet_to_csv(ws); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // print to terminal | 
					
						
							|  |  |  | console.log(csv); | 
					
						
							|  |  |  | EOF | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-07-18 22:19:02 +00:00
										 |  |  | npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz | 
					
						
							| 
									
										
										
										
											2024-05-29 05:10:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ### Script Test | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | curl -o pres.numbers https://docs.sheetjs.com/pres.numbers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | node sheet2csv.js pres.numbers | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ### SEA Bundle | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cat >sheet2csv.json <<EOF | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   "main": "sheet2csv.js", | 
					
						
							|  |  |  |   "output": "sheet2csv.blob" | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | EOF | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | node --experimental-sea-config sheet2csv.json | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | cp `which node` sheet2csv | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-17 04:49:35 +00:00
										 |  |  | ## NOTE: codesign required for macOS  | 
					
						
							|  |  |  | command -v codesign | 
					
						
							|  |  |  | has_cs=$? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [[ "$has_cs" == "0" ]]; then codesign --remove-signature ./sheet2csv; fi | 
					
						
							| 
									
										
										
										
											2024-05-29 05:10:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | npx -y postject --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA sheet2csv NODE_SEA_BLOB sheet2csv.blob | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-17 04:49:35 +00:00
										 |  |  | if [[ "$has_cs" == "0" ]]; then codesign -s - ./sheet2csv; fi | 
					
						
							| 
									
										
										
										
											2024-05-29 05:10:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ./sheet2csv pres.numbers | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-02-17 04:49:35 +00:00
										 |  |  | if [[ "$has_cs" == "0" ]]; then codesign -dv ./sheet2csv; fi |