FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
SchemaPin/scripts/publish_javascript.sh at main · ThirdKeyAI/SchemaPin · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
ThirdKeyAI
/
SchemaPin
Public
Notifications
You must be signed in to change notification settings
Fork
6
Star
16
Code
Issues
0
Pull requests
3
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
SchemaPin
/
scripts
/
publish_javascript.sh
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
349 lines (287 loc) · 9.02 KB
Breadcrumbs
SchemaPin
/
scripts
/
publish_javascript.sh
Copy path
File metadata and controls
executable file
·
349 lines (287 loc) · 9.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#!
/bin/bash
#
#
JavaScript package publishing script for SchemaPin.
#
#
This script handles publishing to npm with proper validation and safety checks.
#
set
-e
#
Exit on any error
#
Colors for output
RED=
'
\033[0;31m
'
GREEN=
'
\033[0;32m
'
YELLOW=
'
\033[1;33m
'
BLUE=
'
\033[0;34m
'
NC=
'
\033[0m
'
#
No Color
#
Directories
SCRIPT_DIR=
"
$(
cd
"
$(
dirname
"
${BASH_SOURCE[0]}
"
)
"
&&
pwd
)
"
ROOT_DIR=
"
$(
dirname
"
$SCRIPT_DIR
"
)
"
JS_DIR=
"
$ROOT_DIR
/javascript
"
DIST_DIR=
"
$ROOT_DIR
/dist
"
#
Functions
log_info
() {
echo
-e
"
${BLUE}
ℹ️
$1
${NC}
"
}
log_success
() {
echo
-e
"
${GREEN}
✅
$1
${NC}
"
}
log_warning
() {
echo
-e
"
${YELLOW}
⚠️
$1
${NC}
"
}
log_error
() {
echo
-e
"
${RED}
❌
$1
${NC}
"
}
check_prerequisites
() {
log_info
"
Checking publishing prerequisites...
"
#
Check if npm is installed
if
!
command
-v npm
&
>
/dev/null
;
then
log_error
"
npm is not installed
"
return
1
fi
log_success
"
npm is installed
"
#
Check if we're in the right directory
if
[
!
-f
"
$JS_DIR
/package.json
"
]
;
then
log_error
"
package.json not found in
$JS_DIR
"
return
1
fi
log_success
"
Found package.json
"
#
Check if user is logged in to npm
if
!
npm whoami
&
>
/dev/null
;
then
log_warning
"
Not logged in to npm. Run 'npm login' first.
"
return
1
fi
local
npm_user=
$(
npm whoami
)
log_success
"
Logged in to npm as:
$npm_user
"
#
Check if package exists in dist
if
[
!
-f
"
$DIST_DIR
"
/
*
.tgz ]
;
then
log_error
"
No .tgz package found in
$DIST_DIR
. Run build_packages.py first.
"
return
1
fi
log_success
"
Found package in dist directory
"
#
Check git status
if
command
-v git
&
>
/dev/null
&&
[
-d
"
$ROOT_DIR
/.git
"
]
;
then
if
[
-n
"
$(
git status --porcelain
)
"
]
;
then
log_warning
"
Git repository has uncommitted changes
"
log_warning
"
Consider committing changes before publishing
"
else
log_success
"
Git repository is clean
"
fi
fi
return
0
}
validate_package
() {
log_info
"
Validating package...
"
cd
"
$JS_DIR
"
#
Run tests
if
!
npm
test
;
then
log_error
"
Tests failed
"
return
1
fi
log_success
"
Tests passed
"
#
Check package.json for required fields
local
package_name=
$(
node -p
"
require('./package.json').name
"
)
local
package_version=
$(
node -p
"
require('./package.json').version
"
)
local
package_description=
$(
node -p
"
require('./package.json').description
"
)
if
[
-z
"
$package_name
"
]
||
[
"
$package_name
"
=
"
undefined
"
]
;
then
log_error
"
Package name is missing
"
return
1
fi
if
[
-z
"
$package_version
"
]
||
[
"
$package_version
"
=
"
undefined
"
]
;
then
log_error
"
Package version is missing
"
return
1
fi
if
[
-z
"
$package_description
"
]
||
[
"
$package_description
"
=
"
undefined
"
]
;
then
log_error
"
Package description is missing
"
return
1
fi
log_success
"
Package metadata is valid
"
log_info
"
Package:
$package_name
@
$package_version
"
log_info
"
Description:
$package_description
"
#
Validate package contents
if
!
npm pack --dry-run
;
then
log_error
"
Package validation failed
"
return
1
fi
log_success
"
Package validation passed
"
return
0
}
check_version_exists
() {
local
package_name=
"
$1
"
local
version=
"
$2
"
log_info
"
Checking if version
$version
already exists on npm...
"
#
Check if version exists on npm
if
npm view
"
$package_name
@
$version
"
version
&
>
/dev/null
;
then
log_error
"
Version
$version
already exists on npm
"
log_error
"
Please update the version number in package.json
"
return
1
fi
log_success
"
Version
$version
is available
"
return
0
}
publish_to_npm
() {
local
tag=
"
$1
"
local
registry=
"
$2
"
cd
"
$JS_DIR
"
local
package_name=
$(
node -p
"
require('./package.json').name
"
)
local
package_version=
$(
node -p
"
require('./package.json').version
"
)
log_info
"
Publishing
$package_name
@
$package_version
to npm...
"
if
[
-n
"
$tag
"
]
;
then
log_info
"
Using tag:
$tag
"
fi
if
[
-n
"
$registry
"
]
;
then
log_info
"
Using registry:
$registry
"
fi
#
Build npm publish command
local
cmd=
"
npm publish
"
if
[
-n
"
$tag
"
]
;
then
cmd=
"
$cmd
--tag
$tag
"
fi
if
[
-n
"
$registry
"
]
;
then
cmd=
"
$cmd
--registry
$registry
"
fi
#
Add access public for scoped packages
cmd=
"
$cmd
--access public
"
log_info
"
Running:
$cmd
"
if
eval
"
$cmd
"
;
then
log_success
"
Successfully published to npm!
"
if
[
-n
"
$registry
"
]
&&
[[
"
$registry
"
==
*
"
test
"
*
]]
;
then
log_info
"
Check your package at: https://www.npmjs.com/package/
$package_name
"
else
log_info
"
Check your package at: https://www.npmjs.com/package/
$package_name
"
fi
return
0
else
log_error
"
npm publish failed
"
return
1
fi
}
test_installation
() {
local
package_name=
"
$1
"
local
version=
"
$2
"
log_info
"
Testing installation of
$package_name
@
$version
...
"
#
Create temporary directory
local
temp_dir=
$(
mktemp -d
)
cd
"
$temp_dir
"
#
Initialize test project
cat
>
package.json
<<
EOF
{
"name": "schemapin-install-test",
"version": "1.0.0",
"type": "module"
}
EOF
#
Install the package
if
npm install
"
$package_name
@
$version
"
;
then
log_success
"
Package installation successful
"
#
Test basic import
cat
>
test.js
<<
'
EOF
'
import { KeyManager, SchemaPinCore } from 'schemapin';
try {
const { privateKey, publicKey } = KeyManager.generateKeypair();
const core = new SchemaPinCore();
console.log('✅ Basic functionality test passed');
} catch (error) {
console.error('❌ Basic functionality test failed:', error);
process.exit(1);
}
EOF
if
node test.js
;
then
log_success
"
Functionality test passed
"
cd
"
$ROOT_DIR
"
rm -rf
"
$temp_dir
"
return
0
else
log_error
"
Functionality test failed
"
cd
"
$ROOT_DIR
"
rm -rf
"
$temp_dir
"
return
1
fi
else
log_error
"
Package installation failed
"
cd
"
$ROOT_DIR
"
rm -rf
"
$temp_dir
"
return
1
fi
}
publish_workflow
() {
local
skip_test=
"
$1
"
log_info
"
Starting JavaScript package publishing workflow...
"
#
Check prerequisites
if
!
check_prerequisites
;
then
return
1
fi
#
Validate package
if
!
validate_package
;
then
return
1
fi
cd
"
$JS_DIR
"
local
package_name=
$(
node -p
"
require('./package.json').name
"
)
local
package_version=
$(
node -p
"
require('./package.json').version
"
)
#
Check if version already exists
if
!
check_version_exists
"
$package_name
"
"
$package_version
"
;
then
return
1
fi
#
Confirm publication
echo
log_warning
"
You are about to publish
$package_name
@
$package_version
to npm!
"
log_warning
"
This action cannot be undone. Make sure you have:
"
echo
"
- Tested the package thoroughly
"
echo
"
- Updated the version number
"
echo
"
- Updated the changelog
"
echo
"
- Committed all changes to git
"
echo
read
-p
"
Type 'yes' to continue with npm publish:
"
confirm
if
[
"
$confirm
"
!=
"
yes
"
]
;
then
log_error
"
npm publish cancelled
"
return
1
fi
#
Publish to npm
if
!
publish_to_npm
;
then
return
1
fi
#
Test installation
if
[
"
$skip_test
"
!=
"
true
"
]
;
then
log_info
"
Waiting 30 seconds for npm to propagate...
"
sleep 30
if
!
test_installation
"
$package_name
"
"
$package_version
"
;
then
log_warning
"
Installation test failed, but package was published
"
fi
fi
log_success
"
JavaScript package publishing completed successfully!
"
return
0
}
#
Main script
case
"
${1
:-
workflow}
"
in
"
check
"
)
check_prerequisites
;;
"
validate
"
)
validate_package
;;
"
publish
"
)
publish_to_npm
"
$2
"
"
$3
"
;;
"
test-install
"
)
cd
"
$JS_DIR
"
package_name=
$(
node -p
"
require('./package.json').name
"
)
package_version=
$(
node -p
"
require('./package.json').version
"
)
test_installation
"
$package_name
"
"
$package_version
"
;;
"
workflow
"
)
publish_workflow
"
$2
"
;;
*
)
echo
"
Usage:
$0
{check|validate|publish|test-install|workflow}
"
echo
echo
"
Commands:
"
echo
"
check - Check prerequisites for publishing
"
echo
"
validate - Validate package before publishing
"
echo
"
publish - Publish to npm (optionally with tag and registry)
"
echo
"
test-install - Test installation of published package
"
echo
"
workflow - Complete publishing workflow (default)
"
echo
echo
"
Examples:
"
echo
"
$0
check
"
echo
"
$0
publish beta
"
echo
"
$0
workflow skip-test
"
exit
1
;;
esac
Back
|
FazBrowse Home
|
New Git URL