forked from sheetjs/docs.sheetjs.com
		
	
		
			
				
	
	
		
			66 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			66 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
| #!/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
 | |
| 
 | |
| npm i --save https://cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
 | |
| 
 | |
| ### 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
 | |
| 
 | |
| ## NOTE: codesign required for macOS
 | |
| command -v codesign
 | |
| has_cs=$?
 | |
| 
 | |
| if [[ "$has_cs" == "0" ]]; then codesign --remove-signature ./sheet2csv; fi
 | |
| 
 | |
| npx -y postject --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2 --macho-segment-name NODE_SEA sheet2csv NODE_SEA_BLOB sheet2csv.blob
 | |
| 
 | |
| if [[ "$has_cs" == "0" ]]; then codesign -s - ./sheet2csv; fi
 | |
| 
 | |
| ./sheet2csv pres.numbers
 | |
| 
 | |
| if [[ "$has_cs" == "0" ]]; then codesign -dv ./sheet2csv; fi
 |