-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-to-npm.sh
More file actions
executable file
Β·174 lines (147 loc) Β· 5.57 KB
/
deploy-to-npm.sh
File metadata and controls
executable file
Β·174 lines (147 loc) Β· 5.57 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
#!/bin/bash
# n8n-nodes-sinch NPM Deployment Script
# This script publishes the package to NPM using your personal access token
set -e
echo "π n8n-nodes-sinch NPM Deployment"
echo "=================================="
# Check if we're in the right directory
if [[ ! -f "package.json" ]]; then
echo "β Error: package.json not found. Run from project root."
exit 1
fi
# Validate package name against expected development or production variants
PACKAGE_NAME=$(grep -m1 '"name"' package.json | cut -d'"' -f4)
EXPECTED_DEV_NAME="n8n-nodes-sinch-dev"
EXPECTED_ALT_DEV_NAME="n8n-nodes-sinch-build-dev" # legacy name
EXPECTED_PROD_NAME="@sinch-engage/n8n-nodes-sinch"
EXPECTED_SINCH_NAME="@sinch/n8n-nodes-sinch"
if [[ "$PACKAGE_NAME" != "$EXPECTED_DEV_NAME" && "$PACKAGE_NAME" != "$EXPECTED_ALT_DEV_NAME" && "$PACKAGE_NAME" != "$EXPECTED_PROD_NAME" && "$PACKAGE_NAME" != "$EXPECTED_SINCH_NAME" ]]; then
echo "β Error: Unexpected package name '$PACKAGE_NAME'." >&2
echo " Acceptable names: $EXPECTED_DEV_NAME | $EXPECTED_ALT_DEV_NAME | $EXPECTED_PROD_NAME | $EXPECTED_SINCH_NAME" >&2
echo " Update package.json 'name' or adjust script expectations before deploying." >&2
exit 1
fi
# Function to auto-bump version
bump_version() {
CURRENT_VERSION=$(grep '"version"' package.json | cut -d'"' -f4)
NPM_VERSION=$(npm view "$PACKAGE_NAME" version 2>/dev/null || echo "")
# Use the higher of the two as the base
if [[ -n "$NPM_VERSION" && "$NPM_VERSION" != "$CURRENT_VERSION" ]]; then
echo "β οΈ npm version ($NPM_VERSION) differs from package.json ($CURRENT_VERSION). Using npm version as base."
BASE_VERSION="$NPM_VERSION"
else
BASE_VERSION="$CURRENT_VERSION"
fi
# Increment the trailing numeric component (e.g. 1.0.0-alpha-0.3 -> 1.0.0-alpha-0.4)
VERSION_PREFIX="${BASE_VERSION%.*}"
VERSION_PATCH="${BASE_VERSION##*.}"
NEW_VERSION="${VERSION_PREFIX}.$((VERSION_PATCH + 1))"
echo ""
echo "π’ Version bump: $BASE_VERSION -> $NEW_VERSION"
# Write new version to package.json
sed -i '' "s/\"version\": \"$CURRENT_VERSION\"/\"version\": \"$NEW_VERSION\"/" package.json
PACKAGE_VERSION="$NEW_VERSION"
}
# Check if package is built
if [[ ! -d "dist" ]]; then
echo "π¦ Building package..."
npm run build
fi
# Function to prompt for NPM token
get_npm_token() {
# If already logged in (npm whoami succeeds), skip token prompt
if npm whoami >/dev/null 2>&1; then
echo "π Using existing npm authentication: $(npm whoami)"
return 0
fi
if [[ -z "$NPM_TOKEN" ]]; then
echo ""
echo "π NPM Authentication Required"
echo "------------------------------"
echo "You need an NPM access token with publish permissions."
echo "Get your token from: https://www.npmjs.com/settings/tokens"
echo ""
read -p "Enter your NPM access token: " NPM_TOKEN
if [[ -z "$NPM_TOKEN" ]]; then
echo "β Error: NPM token is required"
exit 1
fi
fi
}
# Function to configure NPM
setup_npm() {
echo ""
echo "π§ Configuring NPM..."
# Only set auth token if not already logged-in
if ! npm whoami >/dev/null 2>&1; then
echo "Setting NPM token..."
npm config set //registry.npmjs.org/:_authToken "$NPM_TOKEN"
else
echo "Already authenticated as $(npm whoami). Skipping token config."
fi
# Verify NPM is configured
echo "Verifying NPM configuration..."
npm whoami
}
# Function to publish package
publish_package() {
echo ""
echo "π€ Publishing to NPM..."
echo "Package: $(grep -m1 '"name"' package.json | cut -d'"' -f4)"
echo "Version: $(grep '"version"' package.json | cut -d'"' -f4)"
echo "Registry: https://registry.npmjs.org/"
echo ""
# Confirm before publishing
read -p "Ready to publish? (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "β Publishing cancelled"
exit 0
fi
# Publish with alpha tag first
npm publish --tag alpha --access public
if [[ $? -eq 0 ]]; then
echo ""
echo "β
Successfully published as alpha!"
echo ""
PACKAGE_NAME=$(grep -m1 '"name"' package.json | cut -d'"' -f4)
PACKAGE_VERSION=$(grep -m1 '"version"' package.json | cut -d'"' -f4)
echo "π¦ Package Details:"
echo " Name: $PACKAGE_NAME"
echo " Version: $PACKAGE_VERSION"
echo " NPM URL: https://www.npmjs.com/package/$PACKAGE_NAME"
echo ""
echo "π Alpha installation:"
echo " npm install $PACKAGE_NAME@alpha"
echo ""
# Prompt to also tag as latest
read -p "Also tag this version as 'latest'? (y/N): " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
npm dist-tag add "$PACKAGE_NAME@$PACKAGE_VERSION" latest
echo ""
echo "β
Also tagged as latest!"
echo " npm install $PACKAGE_NAME@latest"
else
echo "Skipped latest tag. Run manually if needed:"
echo " npm dist-tag add $PACKAGE_NAME@$PACKAGE_VERSION latest"
fi
else
echo ""
echo "β Publishing failed!"
echo "Check the error messages above and try again."
exit 1
fi
}
# Main execution
PACKAGE_NAME=$(grep -m1 '"name"' package.json | cut -d'"' -f4)
PACKAGE_VERSION=$(grep '"version"' package.json | cut -d'"' -f4)
echo "Current package info:"
echo " Name: $PACKAGE_NAME"
echo " Version: $PACKAGE_VERSION"
bump_version
get_npm_token
setup_npm
publish_package
echo ""
echo "π Deployment complete!"