<commit_before>#
# Build script for the-law-factory
#
# "make" will create the following files:
#   - public/built/main.js - concatenated scripts
#   - public/built/main.css - concatenated stylesheets
#   - public/index.built.html - index that uses the above instead of linking to multiple files
#
#   Also note that if no public/config.js file exists when calling "make", it will be copied
#   from public/config.js.example.
#
# "make clean" will remove what "make" created.
#
# "make install" will put everything needed in a "prod" directory alongside "public" and
# replace the index inside by the built version.
#

SRCDIR := public
BUILTDIR := $(SRCDIR)/built
INSTALLDIR := prod
INSTALLTMPDIR := prod.tmp
INSTALLOLDDIR := prod.old
SRCINDEX := $(SRCDIR)/index.html
BUILTINDEX := $(SRCDIR)/index.built.html
IBUILTINDEX := $(patsubst $(SRCDIR)/%,$(INSTALLTMPDIR)/%,$(BUILTINDEX))
BUILTCSS := $(BUILTDIR)/main.css
BUILTJS := $(BUILTDIR)/main.js

ALLCSS := $(shell find $(SRCDIR) -name *.css)
ALLJS := $(shell find $(SRCDIR) -name *.js)

all: $(BUILTINDEX) $(BUILTJS) $(BUILTCSS)
install: all $(INSTALLTMPDIR) $(INSTALLTMPDIR)/index.html $(INSTALLDIR)

include Depends.mk

# Create depends by extracting references to css/js files from index
Depends.mk: $(SRCINDEX) $(ALLCSS) $(ALLJS)
	grep '<script type="text/javascript" src' $(SRCINDEX) | sed -r 's;.*src="([^"]+)".*;$(BUILTJS): $(SRCDIR)/\1;' > Depends.mk
	grep '<link rel="stylesheet" href' $(SRCINDEX) | sed -r 's;.*href="([^"]+)".*;$(BUILTCSS): $(SRCDIR)/\1;' >> Depends.mk

$(BUILTINDEX): $(SRCINDEX)
	cat $< \
	| sed -r '0,/(<script type="text\/javascript" src[^>]+><\/script>)/s//<script src="$(subst /,\/,$(patsubst $(SRCDIR)/%,%,$(BUILTJS)))"><\/script>\n\1/' \
	| sed -r '0,/(<link rel="stylesheet" href[^>]+>)/s//<link href="$(subst /,\/,$(patsubst $(SRCDIR)/%,%,$(BUILTCSS)))" rel="stylesheet">\n\1/' \
	| sed -r 's/(<script type="text\/javascript" src[^>]+><\/script>)/<!-- \1 -->/' \
	| sed -r 's/(<link rel="stylesheet" href[^>]+>)/<!-- \1 -->/' \
	> $@

# Copy config.js.example if config.js does net exist
$(SRCDIR)/config.js: $(SRCDIR)/config.js.example
	[ ! -f $@ ] && cp $^ $@ || true
	touch $@

$(BUILTJS):
	mkdir -p $$(dirname $@)
	cat $^ | sed -r 's/# sourceMappingURL=[^ ]+\.map//g' > $@

$(BUILTCSS):
	mkdir -p $$(dirname $@)
	cat $^ > $@

.PHONY: clean
clean:
	rm -f Depends.mk $(BUILTINDEX) $(BUILTJS) $(BUILTCSS)
	[ -d $(BUILTDIR) ] && rmdir $(BUILTDIR) || true

.PHONY: $(INSTALLTMPDIR)
$(INSTALLTMPDIR):
	[ -d $(INSTALLTMPDIR) ] && rm -r $(INSTALLTMPDIR) || true
	cp -R $(SRCDIR) $(INSTALLTMPDIR)

.PHONY: $(INSTALLTMPDIR)/index.html<commit_msg>force browsers to load new prod versions<commit_after>#
# Build script for the-law-factory
#
# "make" will create the following files:
#   - public/built/main.js - concatenated scripts
#   - public/built/main.css - concatenated stylesheets
#   - public/index.built.html - index that uses the above instead of linking to multiple files
#
#   Also note that if no public/config.js file exists when calling "make", it will be copied
#   from public/config.js.example.
#
# "make clean" will remove what "make" created.
#
# "make install" will put everything needed in a "prod" directory alongside "public" and
# replace the index inside by the built version.
#

SRCDIR := public
BUILTDIR := $(SRCDIR)/built
INSTALLDIR := prod
INSTALLTMPDIR := prod.tmp
INSTALLOLDDIR := prod.old
SRCINDEX := $(SRCDIR)/index.html
BUILTINDEX := $(SRCDIR)/index.built.html
IBUILTINDEX := $(patsubst $(SRCDIR)/%,$(INSTALLTMPDIR)/%,$(BUILTINDEX))
BUILTCSS := $(BUILTDIR)/main.css
BUILTJS := $(BUILTDIR)/main.js
BUILDTIME := $(shell date +%y%m%d-%H%M)

ALLCSS := $(shell find $(SRCDIR) -name *.css)
ALLJS := $(shell find $(SRCDIR) -name *.js)

all: $(BUILTINDEX) $(BUILTJS) $(BUILTCSS)
install: all $(INSTALLTMPDIR) $(INSTALLTMPDIR)/index.html $(INSTALLDIR)

include Depends.mk

# Create depends by extracting references to css/js files from index
Depends.mk: $(SRCINDEX) $(ALLCSS) $(ALLJS)
	grep '<script type="text/javascript" src' $(SRCINDEX) | sed -r 's;.*src="([^"]+)".*;$(BUILTJS): $(SRCDIR)/\1;' > Depends.mk
	grep '<link rel="stylesheet" href' $(SRCINDEX) | sed -r 's;.*href="([^"]+)".*;$(BUILTCSS): $(SRCDIR)/\1;' >> Depends.mk

$(BUILTINDEX): $(SRCINDEX)
	cat $< \
	| sed -r '0,/(<script type="text\/javascript" src[^>]+><\/script>)/s//<script src="$(subst /,\/,$(patsubst $(SRCDIR)/%,%,$(BUILTJS)))?$(BUILDTIME)"><\/script>\n\1/' \
	| sed -r '0,/(<link rel="stylesheet" href[^>]+>)/s//<link href="$(subst /,\/,$(patsubst $(SRCDIR)/%,%,$(BUILTCSS)))?$(BUILDTIME)" rel="stylesheet">\n\1/' \
	| sed -r 's/(<script type="text\/javascript" src[^>]+><\/script>)/<!-- \1 -->/' \
	| sed -r 's/(<link rel="stylesheet" href[^>]+>)/<!-- \1 -->/' \
	> $@

# Copy config.js.example if config.js does net exist
$(SRCDIR)/config.js: $(SRCDIR)/config.js.example
	[ ! -f $@ ] && cp $^ $@ || true
	touch $@

$(BUILTJS):
	mkdir -p $$(dirname $@)
	cat $^ | sed -r 's/# sourceMappingURL=[^ ]+\.map//g' > $@

$(BUILTCSS):
	mkdir -p $$(dirname $@)
	cat $^ > $@

.PHONY: clean
clean:
	rm -f Depends.mk $(BUILTINDEX) $(BUILTJS) $(BUILTCSS)
	[ -d $(BUILTDIR) ] && rmdir $(BUILTDIR) || true

.PHONY: $(INSTALLTMPDIR)
$(INSTALLTMPDIR):
	[ -d $(INSTALLTMPDIR) ] && rm -r $(INSTALLTMPDIR) || true
	cp -R $(SRCDIR) $(INSTALLTMPDIR)

.PHONY: $(INSTALLTMPDIR)/index.html
{'fraction_non_alphanumeric': 0.22891340938844212, 'fraction_numerical': 0.0029923321488685246, 'mean_word_length': 4.227761485826002, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2505873', 'n_tokens_mistral': 2070, 'n_tokens_neox': 2030, 'n_words': 491}