-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·133 lines (119 loc) · 4.46 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·133 lines (119 loc) · 4.46 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
#!/usr/bin/env bash
# Сборка Nib.app и Nib.dmg. Запускать на macOS.
# Требуется: Xcode Command Line Tools (xcode-select --install) или полный Xcode.
set -euo pipefail
APP_NAME="Nib"
BUNDLE_ID="local.nib.editor"
VERSION="1.2.0"
MIN_MACOS="13.0"
ARCHS="arm64 x86_64" # universal binary: Apple Silicon + Intel
ROOT="$(cd "$(dirname "$0")" && pwd)"
BUILD="$ROOT/build"
APP="$BUILD/$APP_NAME.app"
command -v swiftc >/dev/null || { echo "swiftc не найден. Выполни: xcode-select --install"; exit 1; }
SDK="$(xcrun --show-sdk-path --sdk macosx)"
SOURCES=("$ROOT"/Sources/*.swift)
[ -e "${SOURCES[0]}" ] || { echo "Нет исходников в $ROOT/Sources"; exit 1; }
echo "==> Чистка"
rm -rf "$BUILD"
mkdir -p "$APP/Contents/MacOS" "$APP/Contents/Resources" "$BUILD/slices"
for arch in $ARCHS; do
echo "==> Компиляция ($arch, ${#SOURCES[@]} файлов, macOS $MIN_MACOS+, SDK: $(basename "$SDK"))"
swiftc \
-O -whole-module-optimization \
-parse-as-library \
-sdk "$SDK" \
-target "${arch}-apple-macos${MIN_MACOS}" \
-framework SwiftUI -framework AppKit \
-o "$BUILD/slices/$APP_NAME-$arch" \
"${SOURCES[@]}"
done
echo "==> Склейка universal binary ($ARCHS)"
SLICES=""
for arch in $ARCHS; do SLICES="$SLICES $BUILD/slices/$APP_NAME-$arch"; done
lipo -create $SLICES -output "$APP/Contents/MacOS/$APP_NAME"
rm -rf "$BUILD/slices"
lipo -info "$APP/Contents/MacOS/$APP_NAME"
echo "==> Info.plist"
cat > "$APP/Contents/Info.plist" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key><string>${APP_NAME}</string>
<key>CFBundleDisplayName</key><string>${APP_NAME}</string>
<key>CFBundleExecutable</key><string>${APP_NAME}</string>
<key>CFBundleIdentifier</key><string>${BUNDLE_ID}</string>
<key>CFBundlePackageType</key><string>APPL</string>
<key>CFBundleShortVersionString</key><string>${VERSION}</string>
<key>CFBundleVersion</key><string>${VERSION}</string>
<key>CFBundleIconFile</key><string>AppIcon</string>
<key>LSMinimumSystemVersion</key><string>${MIN_MACOS}</string>
<key>NSHighResolutionCapable</key><true/>
<key>NSPrincipalClass</key><string>NSApplication</string>
<key>NSHumanReadableCopyright</key><string>Local build</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key><string>Markdown</string>
<key>CFBundleTypeRole</key><string>Editor</string>
<key>LSHandlerRank</key><string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>net.daringfireball.markdown</string>
<string>public.plain-text</string>
<string>public.text</string>
</array>
</dict>
</array>
<key>UTImportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeIdentifier</key><string>net.daringfireball.markdown</string>
<key>UTTypeDescription</key><string>Markdown</string>
<key>UTTypeConformsTo</key>
<array><string>public.plain-text</string></array>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>md</string><string>markdown</string>
<string>mdown</string><string>mkd</string><string>mdx</string>
</array>
</dict>
</dict>
</array>
</dict>
</plist>
PLIST
printf 'APPL????' > "$APP/Contents/PkgInfo"
if [ -f "$ROOT/icon_1024.png" ]; then
echo "==> Иконка"
ICONSET="$BUILD/AppIcon.iconset"
mkdir -p "$ICONSET"
for sz in 16 32 128 256 512; do
sips -z $sz $sz "$ROOT/icon_1024.png" --out "$ICONSET/icon_${sz}x${sz}.png" >/dev/null
sips -z $((sz*2)) $((sz*2)) "$ROOT/icon_1024.png" --out "$ICONSET/icon_${sz}x${sz}@2x.png" >/dev/null
done
iconutil -c icns "$ICONSET" -o "$APP/Contents/Resources/AppIcon.icns"
rm -rf "$ICONSET"
fi
echo "==> Подпись (ad-hoc)"
codesign --force --deep --sign - "$APP"
echo "==> DMG"
DMG="$BUILD/$APP_NAME-$VERSION.dmg"
STAGE="$BUILD/dmg"
mkdir -p "$STAGE"
cp -R "$APP" "$STAGE/"
ln -s /Applications "$STAGE/Applications"
hdiutil create -volname "$APP_NAME" \
-srcfolder "$STAGE" -ov -format UDZO \
"$DMG" >/dev/null
rm -rf "$STAGE"
echo
echo "Готово:"
echo " $APP"
echo " $DMG"
echo
echo "Открой DMG, перетащи $APP_NAME в Applications."
echo "Потом: правый клик на .md → Открыть в программе → $APP_NAME."