-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
187 lines (169 loc) · 7.22 KB
/
flake.nix
File metadata and controls
187 lines (169 loc) · 7.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
devenv.url = "github:cachix/devenv";
};
outputs =
inputs@{
self,
nixpkgs,
flake-utils,
devenv,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
inherit (nixpkgs) lib;
overlay = (
final: prev: {
build-revision = self.rev or "HEAD";
}
);
pkgs-config = {
# allowUnfree = true;
# permittedInsecurePackages = [ ];
};
pkgs = (import nixpkgs) {
inherit system;
overlays = [ overlay ];
config = pkgs-config;
};
inherit (pkgs) callPackage;
in
rec {
packages = {
devenv-up = devShell.config.procfileScript; # see https://github.com/cachix/devenv/issues/756
};
devShell = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
{
# https://devenv.sh/reference/options/
dotenv.disableHint = true;
packages = with pkgs; [
curl
gitFull
gh
libxml2
jq
nodejs
nodePackages.prettier
xmlformat
yarn-berry
];
enterShell = ''
git --version
'';
git-hooks.hooks = {
shellcheck.enable = true;
prettier = {
enable = true;
files = "\\.(js|json|ts)";
};
};
languages = {
javascript.enable = true;
};
scripts = {
release-preflight.exec = ''
set -eou pipefail
# check that gh cli is authenticated
if ! gh auth status -a >/dev/null 2>&1; then
echo "Error: run 'gh auth login -h github.com -p ssh --skip-ssh-key -w' first"
exit 1
fi
# check that repo is up-to-date
if [[ ! -z "$(git status --porcelain)" ]]; then
echo "Error: uncommitted changes detected"
git status
exit 1
fi
# check that we are on the main branch
if [[ ! "$(git branch --show-current)" == "main" ]]; then
echo "Error: not on main branch, currently on $(git branch --show-current)"
exit 1
fi
# check that package can be built
(cd ./jsx-runtime && yarn install --immutable && yarn build)
yarn install --immutable && yarn build
# bump package version
yarn version "''${1:-patch}"
tag="v$(jq -r '.version' package.json)"
git add package.json && git commit -m "release $tag"
# tag version & push to main and tag
git tag "$tag" HEAD && git push && git push origin "$tag"
# create draft release
gh release create "$tag" --draft --generate-notes
'';
run-demo.exec = ''
set -eou pipefail
mkdir -p "$DEVENV_ROOT/demo/outputs/"
echo "$1:"
tsx "$DEVENV_ROOT/demo/cli.ts" --validate "$1" "$DEVENV_ROOT/demo/outputs/$1.docx"
tsx "$DEVENV_ROOT/demo/cli.ts" --validate "$1" "$DEVENV_ROOT/demo/outputs/$1.rtf"
validate-ooxml "$DEVENV_ROOT/demo/outputs/$1.docx"
'';
run-demos.exec = ''
set -eou pipefail
for i in "$DEVENV_ROOT/demo/examples/"*.ts; do
run-demo "$(basename $i .ts)"
echo
done
'';
cat-ooxml.exec = ''
set -eou pipefail
unzip -p "$1" "''${2:-word/document.xml}" | xmllint --format -
'';
validate-ooxml.exec = ''
set -eou pipefail
xml_cat() {
unzip -p "$1" "$2" | \
xmllint --format - | \
sed 's|http://schemas.openxmlformats.org/officeDocument/2006/extended-properties|http://purl.oclc.org/ooxml/officeDocument/extendedProperties|g' | \
sed 's|http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes|http://purl.oclc.org/ooxml/officeDocument/docPropsVTypes|g' | \
sed 's|http://schemas.openxmlformats.org/officeDocument/2006/relationships|http://purl.oclc.org/ooxml/officeDocument/relationships|g' | \
sed 's|http://schemas.openxmlformats.org/wordprocessingml/2006/main|http://purl.oclc.org/ooxml/wordprocessingml/main|g' | \
sed 's|http://schemas.openxmlformats.org/drawingml/2006/main|http://purl.oclc.org/ooxml/drawingml/main|g' | \
sed 's|http://schemas.openxmlformats.org/drawingml/2006/picture|http://purl.oclc.org/ooxml/drawingml/picture|g' | \
sed 's|http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing|http://purl.oclc.org/ooxml/drawingml/wordprocessingDrawing|g'
}
xml_validation() {
echo -n "$2:"
xml_cat "$1" "$2" | xmllint --schema "$3" --noout - || \
(xml_cat "$1" "$2" | cat -n ; exit 1)
}
xml_validation "$1" "\\[Content_Types\\].xml" "$DEVENV_ROOT/schema/ooxml/opc-contentTypes.xsd"
xml_validation "$1" docProps/core.xml "$DEVENV_ROOT/schema/ooxml/opc-coreProperties.xsd"
xml_validation "$1" docProps/app.xml "$DEVENV_ROOT/schema/ooxml/shared-documentPropertiesExtended.xsd"
xml_validation "$1" _rels/.rels "$DEVENV_ROOT/schema/ooxml/opc-relationships.xsd"
wml_files=(
word/document.xml
word/styles.xml
word/settings.xml
word/fontTable.xml
)
wml_files+=(
$(unzip -lqq "$1" | grep -o -E 'word/(header|firstHeader|evenHeader|footer|firstFooter|evenFooter|numbering|footnotes|endnotes|comments)([0-9]+)?\.xml$' || echo)
)
for i in "''${wml_files[@]}"; do
xml_validation "$1" "$i" "$DEVENV_ROOT/schema/ooxml/wml.xsd"
done
rel_files=(
word/_rels/document.xml.rels
)
rel_files+=(
$(unzip -lqq "$1" | grep -o -E 'word/_rels/(header|firstHeader|evenHeader|footer|firstFooter|evenFooter|numbering|footnotes|endnotes|comments)([0-9]+)?\.xml\.rels$' || echo)
)
for i in "''${rel_files[@]}"; do
xml_validation "$1" "$i" "$DEVENV_ROOT/schema/ooxml/opc-relationships.xsd"
done
'';
};
}
];
};
}
);
}