Repository navigation
Expand file tree
/
Copy pathabxr-launch.sh
More file actions
executable file
·244 lines (202 loc) · 7.14 KB
/
Copy pathabxr-launch.sh
File metadata and controls
executable file
·244 lines (202 loc) · 7.14 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/usr/bin/env bash
do_build=true
do_publish=false
do_serve=false
# Loop through the command-line arguments
for arg in "$@"; do
case $arg in
--publish)
do_build=true
do_publish=true
do_serve=false
;;
--build)
do_build=true
do_publish=false
do_serve=false
;;
--serve)
do_build=true
do_publish=false
do_serve=true
;;
*)
echo "Unknown option: $arg (ignored)"
;;
esac
done
if $do_build; then
# Clean build and dist directories for fresh build
echo "Cleaning up previous build..."
[ -d "build" ] && rm -rf build/*
[ -d "dist" ] && rm -rf dist/*
[ -d "abxrlib-for-webxr" ] && rm -rf abxrlib-for-webxr/*
echo "building js files..."
npm run build
if [ $? -ne 0 ]; then
echo "An error occurred while running build."
# Handle the error, e.g., log it, take alternative action, or exit
# exit 1
fi
echo "\n\nwebpacking js files...\n\n"
npx webpack
if [ $? -ne 0 ]; then
echo "An error occurred while running webpack."
# Handle the error, e.g., log it, take alternative action, or exit
# exit 1
fi
# Copy built JS file to testers/dist for easy access
echo "Copying built JS file to testers/dist..."
mkdir -p testers/dist
cp dist/abxrlib-for-webxr.js testers/dist/abxrlib-for-webxr.js
echo "Built file copied to testers/dist/abxrlib-for-webxr.js"
fi
if $do_publish; then
#ABXRLIB-FOR-WEBXR PUBLISH SCRIPT
echo "publishing to npm..."
# Exit immediately if a command exits with a non-zero status
set -e
# Function to check if a command exists
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check if necessary commands are available
if ! command_exists npm; then
echo "Error: npm is not installed. Please install npm and try again."
exit 1
fi
# Function to get the latest published version
get_latest_version() {
local package_name="$1"
npm view "$package_name" version 2>/dev/null || echo "0.0.0"
}
# Find the correct package.json file (not in node_modules)
PACKAGE_JSON_PATH=$(find /opt/arborxr -maxdepth 2 -name package.json | grep -v "node_modules" | head -n 1)
if [ -z "$PACKAGE_JSON_PATH" ]; then
echo "Error: package.json not found"
exit 1
fi
# Get the directory containing package.json
PACKAGE_DIR=$(dirname "$PACKAGE_JSON_PATH")
# Change to the directory containing package.json
cd "$PACKAGE_DIR"
# Get the package name from package.json
PACKAGE_NAME=$(node -p "require('./package.json').name")
# Verify the package name
if [ "$PACKAGE_NAME" != "abxrlib-for-webxr" ]; then
echo "Error: Expected package name 'abxrlib-for-webxr', but found '$PACKAGE_NAME'"
echo "Please correct the package name in package.json"
exit 1
fi
# Get the latest published version
LATEST_VERSION=$(get_latest_version "$PACKAGE_NAME")
# Parse the version components
IFS='.' read -r major minor patch <<< "$LATEST_VERSION"
# Increment the patch version
new_patch=$((patch + 1))
# Construct the new version
NEW_VERSION="${major}.${minor}.${new_patch}"
echo "New version will be: $NEW_VERSION"
# Clean up previous build
echo "Cleaning up previous build..."
if [ -d "abxrlib-for-webxr" ]; then
rm -rf abxrlib-for-webxr/* 2>/dev/null || true
rm -rf abxrlib-for-webxr/.* 2>/dev/null || true
fi
# Run TypeScript compiler and copy files
echo "Compiling TypeScript and copying files..."
npm run build
# Create a new directory for the package
echo "Creating package directory..."
mkdir -p abxrlib-for-webxr
# Copy necessary files to the package directory
echo "Copying package files..."
cp dist/abxrlib-for-webxr.js abxrlib-for-webxr/Abxr.js
# Copy all TypeScript declaration files to root (standard npm practice)
cp build/*.d.ts abxrlib-for-webxr/
# Copy main Abxr.d.ts (this will be the main entry point)
cp build/Abxr.d.ts abxrlib-for-webxr/Abxr.d.ts
cp -R build/network abxrlib-for-webxr/
cp package.json LICENSE abxrlib-for-webxr/
cp README.md abxrlib-for-webxr/README.md
# Build directory cleanup is handled by volume mount
# Update package.json in the new directory
echo "Updating package.json for distribution..."
node -e "
const pkg = require('./abxrlib-for-webxr/package.json');
delete pkg.devDependencies;
delete pkg.scripts;
pkg.main = 'Abxr.js';
pkg.module = 'Abxr.js';
pkg.browser = 'Abxr.js';
pkg.types = 'Abxr.d.ts';
pkg.files = ['Abxr.js', 'Abxr.d.ts', '*.d.ts', 'network/**/*', 'README.md', 'LICENSE'];
pkg.version = '$NEW_VERSION';
require('fs').writeFileSync('./abxrlib-for-webxr/package.json', JSON.stringify(pkg, null, 2));
"
# Check for NPM_TOKEN environment variable
if [ -z "$NPM_TOKEN" ]; then
echo "Error: NPM_TOKEN environment variable is not set."
echo "Please set it with your npm access token before running this script."
exit 1
fi
# Use token-based authentication
echo "Using npm access token for authentication..."
npm config set //registry.npmjs.org/:_authToken="${NPM_TOKEN}"
# Verify authentication by checking who we are
echo "Verifying npm authentication..."
if npm whoami --registry=https://registry.npmjs.org/ >/dev/null 2>&1; then
NPM_USER=$(npm whoami --registry=https://registry.npmjs.org/)
echo "✅ Authenticated as: $NPM_USER"
else
echo "❌ Error: Failed to authenticate with npm registry"
echo "Please verify your NPM_TOKEN is valid and not expired"
npm config delete //registry.npmjs.org/:_authToken
exit 1
fi
# Navigate to package directory
cd abxrlib-for-webxr
# Create a tarball of the package
echo "Creating package tarball..."
npm pack
# Get the name of the created tarball
TARBALL_NAME=$(ls *.tgz)
# Publish the package
echo "Publishing version $NEW_VERSION to npm..."
if npm publish $TARBALL_NAME --access public; then
echo "✅ Package published successfully!"
else
PUBLISH_EXIT_CODE=$?
echo "❌ Failed to publish package (exit code: $PUBLISH_EXIT_CODE)"
echo ""
echo "💡 Common issues:"
echo " 1. Package name may not exist - verify 'abxrlib-for-webxr' exists in npm registry"
echo " 2. You may not have publish permissions for this package"
echo " 3. The package may be owned by a different user/organization"
echo " 4. Your npm token may not have sufficient permissions"
echo ""
echo "To check package ownership, run: npm owner ls abxrlib-for-webxr"
npm config delete //registry.npmjs.org/:_authToken
exit $PUBLISH_EXIT_CODE
fi
# Clean up - remove the token from npm config
npm config delete //registry.npmjs.org/:_authToken
# Return to original directory
cd ..
echo "Package published successfully!"
echo "Published version: $NEW_VERSION"
# Write version to a file that can be read by host
echo "$NEW_VERSION" > /tmp/published_version.txt
fi
if $do_serve; then
# Configure nginx to serve testers folder as document root
echo "Configuring nginx..."
echo 'server { listen 8000; location / { root /opt/arborxr/testers; index index.html; } }' > /etc/nginx/sites-available/default
nginx -g "daemon off;" &
# Keep container running
echo "Container is running. Access testers at:"
echo " http://localhost:8000/index.html (default)"
echo " http://localhost:8000/advanced.html"
echo " http://localhost:8000/webxr.html"
sleep infinity
fi