sheetjs_sheetjs/Makefile

262 lines
8.4 KiB
Makefile
Raw Permalink Normal View History

SHELL=/bin/bash
LIB=xlsx
FMT=xlsx xlsm xlsb ods xls xml misc full
2022-02-10 12:40:50 +00:00
REQS=
ADDONS=dist/cpexcel.js
AUXTARGETS=
CMDS=bin/xlsx.njs
HTMLLINT=index.html
MINITGT=xlsx.mini.js
MINIFLOW=xlsx.mini.flow.js
MINIDEPS=$(shell cat misc/mini.lst)
2021-09-12 11:11:48 +00:00
ESMJSTGT=xlsx.mjs
ESMJSDEPS=$(shell cat misc/mjs.lst)
ULIB=$(shell echo $(LIB) | tr a-z A-Z)
DEPS=$(sort $(wildcard bits/*.js))
2022-02-04 20:57:47 +00:00
TSBITS=$(patsubst modules/%,bits/%,$(wildcard modules/[0-9][0-9]_*.js))
MTSBITS=$(patsubst modules/%,misc/%,$(wildcard modules/[0-9][0-9]_*.js))
TARGET=$(LIB).js
FLOWTARGET=$(LIB).flow.js
FLOWAUX=$(patsubst %.js,%.flow.js,$(AUXTARGETS))
AUXSCPTS=xlsxworker.js
FLOWTGTS=$(TARGET) $(AUXTARGETS) $(AUXSCPTS) $(MINITGT)
UGLIFYOPTS=--support-ie8 -m
2021-12-29 09:16:02 +00:00
CLOSURE=/usr/local/lib/node_modules/google-closure-compiler/compiler.jar
## Main Targets
.PHONY: all
2022-02-12 06:31:47 +00:00
all: $(TARGET) $(AUXTARGETS) $(AUXSCPTS) $(MINITGT) $(ESMJSTGT) ## Build library and auxiliary scripts
$(FLOWTGTS): %.js : %.flow.js
node -e 'process.stdout.write(require("fs").readFileSync("$<","utf8").replace(/^[ \t]*\/\*[:#][^*]*\*\/\s*(\n)?/gm,"").replace(/\/\*[:#][^*]*\*\//gm,""))' > $@
$(FLOWTARGET): $(DEPS)
cat $^ | tr -d '\15\32' > $@
$(MINIFLOW): $(MINIDEPS)
cat $^ | tr -d '\15\32' > $@
2021-09-12 11:11:48 +00:00
$(ESMJSTGT): $(ESMJSDEPS)
cat $^ | tr -d '\15\32' > $@
bits/01_version.js: package.json
echo "$(ULIB).version = '"`grep version package.json | awk '{gsub(/[^0-9a-z\.-]/,"",$$2); print $$2}'`"';" > $@
2022-03-11 05:29:05 +00:00
#bits/18_cfb.js: node_modules/cfb/xlscfb.flow.js
# cp $^ $@
2022-02-04 20:57:47 +00:00
$(TSBITS): bits/%: modules/%
2022-01-29 02:29:34 +00:00
cp $^ $@
$(MTSBITS): misc/%: modules/%
cp $^ $@
2022-01-29 02:29:34 +00:00
.PHONY: clean
clean: ## Remove targets and build artifacts
2022-05-17 21:48:05 +00:00
rm -f $(TARGET) $(FLOWTARGET) $(ESMJSTGT) $(MINITGT) $(MINIFLOW)
.PHONY: clean-data
clean-data:
rm -f *.xlsx *.xlsm *.xlsb *.xls *.xml
.PHONY: init
init: ## Initial setup for development
git submodule init
git submodule update
2020-07-31 03:54:10 +00:00
#git submodule foreach git pull origin master
git submodule foreach make all
mkdir -p tmp
DISTHDR=misc/suppress_export.js
.PHONY: dist
dist: dist-deps $(TARGET) bower.json ## Prepare JS files for distribution
mkdir -p dist
cp LICENSE dist/
uglifyjs shim.js $(UGLIFYOPTS) -o dist/shim.min.js --preamble "$$(head -n 1 bits/00_header.js)"
2022-02-26 04:32:40 +00:00
@#
<$(TARGET) sed "s/require('.*')/undefined/g;s/ process / undefined /g;s/process.versions/({})/g" > dist/$(TARGET)
<$(MINITGT) sed "s/require('.*')/undefined/g;s/ process / undefined /g;s/process.versions/({})/g" > dist/$(MINITGT)
@# core
uglifyjs $(REQS) dist/$(TARGET) $(UGLIFYOPTS) -o dist/$(LIB).core.min.js --source-map dist/$(LIB).core.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).core.min.js
2022-02-26 04:32:40 +00:00
@# full
#cat <(head -n 1 bits/00_header.js) $(DISTHDR) $(REQS) $(ADDONS) dist/$(TARGET) $(AUXTARGETS) > dist/$(LIB).full.js
uglifyjs $(DISTHDR) $(REQS) $(ADDONS) dist/$(TARGET) $(AUXTARGETS) $(UGLIFYOPTS) -o dist/$(LIB).full.min.js --source-map dist/$(LIB).full.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).full.min.js
2022-02-26 04:32:40 +00:00
@# mini
uglifyjs dist/$(MINITGT) $(UGLIFYOPTS) -o dist/$(LIB).mini.min.js --source-map dist/$(LIB).mini.min.map --preamble "$$(head -n 1 bits/00_header.js)"
misc/strip_sourcemap.sh dist/$(LIB).mini.min.js
2022-02-26 04:32:40 +00:00
@# extendscript
cat <(printf '\xEF\xBB\xBF') <(head -n 1 bits/00_header.js) shim.js $(DISTHDR) $(REQS) dist/$(TARGET) > dist/$(LIB).extendscript.js
@# zahl
cp modules/xlsx.zahl.js modules/xlsx.zahl.mjs dist/
2022-02-26 04:32:40 +00:00
@#
rm dist/$(TARGET) dist/$(MINITGT)
.PHONY: dist-deps
dist-deps: ## Copy dependencies for distribution
mkdir -p dist
cp node_modules/codepage/dist/cpexcel.full.js dist/cpexcel.js
.PHONY: aux
aux: $(AUXTARGETS)
2022-02-26 04:32:40 +00:00
BYTEFILEC=dist/xlsx.{full,core,mini}.min.js
BYTEFILER=dist/xlsx.extendscript.js xlsx.mjs
.PHONY: bytes
bytes: ## Display minified and gzipped file sizes
2022-03-11 05:29:05 +00:00
@for i in $(BYTEFILEC); do npx printj "%-30s %7d %10d" $$i $$(wc -c < $$i) $$(gzip --best --stdout $$i | wc -c); done
@for i in $(BYTEFILER); do npx printj "%-30s %7d" $$i $$(wc -c < $$i); done
2017-03-10 17:33:08 +00:00
.PHONY: git
git: ## show version string
@echo "$$(node -pe 'require("./package.json").version')"
.PHONY: nexe
2017-03-10 17:33:08 +00:00
nexe: xlsx.exe ## Build nexe standalone executable
2017-03-10 17:33:08 +00:00
xlsx.exe: bin/xlsx.njs xlsx.js
tail -n+2 $< | sed 's#\.\./#./xlsx#g' > nexe.js
nexe -i nexe.js -o $@
rm nexe.js
.PHONY: pkg
pkg: bin/xlsx.njs xlsx.js ## Build pkg standalone executable
pkg $<
## Testing
.PHONY: test mocha
test mocha: test.js ## Run test suite
mocha -R spec -t 30000
2022-07-26 02:20:22 +00:00
#* To run tests for one format, make test_<fmt>
#* To run the core test suite, make test_misc
2022-02-13 09:35:34 +00:00
.PHONY: test-esm
test-esm: test.mjs ## Run Node ESM test suite
2022-05-17 01:26:22 +00:00
npx -y mocha@9 -R spec -t 30000 $<
2022-02-13 09:35:34 +00:00
2022-06-06 23:05:27 +00:00
test.ts: test.mts
node -pe 'var data = fs.readFileSync("'$<'", "utf8"); data.split("\n").map(function(l) { return l.replace(/^describe\((.*?)function\(\)/, "Deno.test($$1async function(t)").replace(/\b(?:it|describe)\((.*?)function\(\)/g, "await t.step($$1async function(t)").replace("assert.ok", "assert.assert"); }).join("\n")' > $@
2022-07-12 04:28:03 +00:00
.PHONY: test-bun
test-bun: hotcross.mjs ## Run Bun test suite
bun $<
2022-02-13 09:35:34 +00:00
.PHONY: test-deno
test-deno: test.ts ## Run Deno test suite
2022-06-06 23:05:27 +00:00
deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc $<
2022-06-27 05:47:58 +00:00
.PHONY: test-denocp
test-denocp: testnocp.ts ## Run Deno test suite (without codepage)
deno test --allow-env --allow-read --allow-write --config misc/test.deno.jsonc $<
2022-02-13 09:35:34 +00:00
TESTFMT=$(patsubst %,test_%,$(FMT))
.PHONY: $(TESTFMT)
$(TESTFMT): test_%:
FMTS=$* make test
2022-02-13 09:35:34 +00:00
TESTESMFMT=$(patsubst %,test-esm_%,$(FMT))
.PHONY: $(TESTESMFMT)
$(TESTESMFMT): test-esm_%:
FMTS=$* make test-esm
TESTDENOFMT=$(patsubst %,test-deno_%,$(FMT))
2022-07-07 06:30:44 +00:00
.PHONY: $(TESTDENOFMT)
2022-02-13 09:35:34 +00:00
$(TESTDENOFMT): test-deno_%:
FMTS=$* make test-deno
2022-07-07 06:30:44 +00:00
TESTDENOCPFMT=$(patsubst %,test-denocp_%,$(FMT))
.PHONY: $(TESTDENOCPFMT)
$(TESTDENOCPFMT): test-denocp_%:
FMTS=$* make test-denocp
2022-07-12 04:28:03 +00:00
TESTBUNFMT=$(patsubst %,test-bun_%,$(FMT))
.PHONY: $(TESTBUNFMT)
$(TESTBUNFMT): test-bun_%:
FMTS=$* make test-bun
2017-03-14 17:24:40 +00:00
.PHONY: travis
travis: ## Run test suite with minimal output
mocha -R dot -t 30000
.PHONY: ctest
ctest: ## Build browser test fixtures
node tests/make_fixtures.js
.PHONY: ctestserv
ctestserv: ## Start a test server on port 8000
2022-07-13 07:52:29 +00:00
@cd tests && python -mSimpleHTTPServer || python3 -mhttp.server || npx -y http-server -p 8000 .
## Code Checking
.PHONY: fullint
fullint: lint mdlint ## Run all checks (removed: old-lint, tslint, flow)
.PHONY: lint
lint: $(TARGET) $(AUXTARGETS) ## Run eslint checks
2022-03-16 03:18:09 +00:00
@./node_modules/.bin/eslint --ext .js,.njs,.json,.html,.htm $(FLOWTARGET) $(AUXTARGETS) $(CMDS) $(HTMLLINT) package.json bower.json
2021-12-29 09:16:02 +00:00
@if [ -x "$(CLOSURE)" ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi
.PHONY: old-lint
old-lint: $(TARGET) $(AUXTARGETS) ## Run jshint and jscs checks
2022-03-20 01:54:41 +00:00
@./node_modules/.bin/jscs $(TARGET) $(AUXTARGETS) test.js
@./node_modules/.bin/jshint --show-non-errors $(TARGET) $(AUXTARGETS)
@./node_modules/.bin/jshint --show-non-errors $(CMDS)
@./node_modules/.bin/jshint --show-non-errors package.json bower.json test.js
@./node_modules/.bin/jshint --show-non-errors --extract=always $(HTMLLINT)
2021-12-29 09:16:02 +00:00
@if [ -x "$(CLOSURE)" ]; then java -jar $(CLOSURE) $(REQS) $(FLOWTARGET) --jscomp_warning=reportUnknownTypes >/dev/null; fi
.PHONY: tslint
tslint: $(TARGET) ## Run typescript checks
#@npm install dtslint typescript
#@npm run-script dtslint
./node_modules/.bin/dtslint types
.PHONY: flow
flow: lint ## Run flow checker
@./node_modules/.bin/flow check --all --show-all-errors --include-warnings
2022-03-11 05:29:05 +00:00
.PHONY: mjslint
mjslint: $(ESMJSTGT) ## Lint the ESM build
@npx eslint -c .eslintmjs $<
.PHONY: cov
cov: misc/coverage.html ## Run coverage test
#* To run coverage tests for one format, make cov_<fmt>
COVFMT=$(patsubst %,cov_%,$(FMT))
.PHONY: $(COVFMT)
$(COVFMT): cov_%:
FMTS=$* make cov
misc/coverage.html: $(TARGET) test.js
mocha --require blanket -R html-cov -t 30000 > $@
.PHONY: coveralls
coveralls: ## Coverage Test + Send to coveralls.io
mocha --require blanket --reporter mocha-lcov-reporter -t 30000 | node ./node_modules/coveralls/bin/coveralls.js
2017-09-24 23:40:09 +00:00
DEMOMDS=$(sort $(wildcard demos/*/README.md))
2022-05-16 03:37:09 +00:00
MDLINT=$(DEMOMDS) README.md demos/README.md
2017-09-24 23:40:09 +00:00
.PHONY: mdlint
mdlint: $(MDLINT) ## Check markdown documents
./node_modules/.bin/alex $^
./node_modules/.bin/mdspell -a -n -x -r --en-us $^
2017-09-24 23:40:09 +00:00
.PHONY: help
help:
@grep -hE '(^[a-zA-Z_-][ a-zA-Z_-]*:.*?|^#[#*])' $(MAKEFILE_LIST) | bash misc/help.sh
#* To show a spinner, append "-spin" to any target e.g. cov-spin
%-spin:
@make $* & bash misc/spin.sh $$!