-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1570 from ManishMadan2882/basic-ui
Widget fixes
- Loading branch information
Showing
2 changed files
with
85 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,85 @@ | ||
#!/bin/bash | ||
## chmod +x publish.sh - to upgrade ownership | ||
set -e | ||
cat package.json >> package_copy.json | ||
cat package-lock.json >> package-lock_copy.json | ||
|
||
# Create backup of original files | ||
cp package.json package_original.json | ||
cp package-lock.json package-lock_original.json | ||
|
||
# Store the latest version after publishing | ||
LATEST_VERSION="" | ||
|
||
publish_package() { | ||
PACKAGE_NAME=$1 | ||
BUILD_COMMAND=$2 | ||
# Update package name in package.json | ||
jq --arg name "$PACKAGE_NAME" '.name=$name' package.json > temp.json && mv temp.json package.json | ||
|
||
# Remove 'target' key if the package name is 'docsgpt-react' | ||
if [ "$PACKAGE_NAME" = "docsgpt-react" ]; then | ||
jq 'del(.targets)' package.json > temp.json && mv temp.json package.json | ||
fi | ||
|
||
if [ -d "dist" ]; then | ||
echo "Deleting existing dist directory..." | ||
rm -rf dist | ||
fi | ||
|
||
npm version patch | ||
|
||
npm run "$BUILD_COMMAND" | ||
|
||
# Publish to npm | ||
npm publish | ||
# Clean up | ||
mv package_copy.json package.json | ||
mv package-lock_copy.json package-lock.json | ||
echo "Published ${PACKAGE_NAME}" | ||
PACKAGE_NAME=$1 | ||
BUILD_COMMAND=$2 | ||
IS_REACT=$3 | ||
|
||
echo "Preparing to publish ${PACKAGE_NAME}..." | ||
|
||
# Restore original package.json state before each publish | ||
cp package_original.json package.json | ||
cp package-lock_original.json package-lock.json | ||
|
||
# Update package name in package.json | ||
jq --arg name "$PACKAGE_NAME" '.name=$name' package.json > temp.json && mv temp.json package.json | ||
|
||
# Handle targets based on package type | ||
if [ "$IS_REACT" = "true" ]; then | ||
echo "Removing targets for React library build..." | ||
jq 'del(.targets)' package.json > temp.json && mv temp.json package.json | ||
fi | ||
|
||
# Clean dist directory | ||
if [ -d "dist" ]; then | ||
echo "Cleaning dist directory..." | ||
rm -rf dist | ||
fi | ||
|
||
# update version and store it | ||
LATEST_VERSION=$(npm version patch) | ||
echo "New version: ${LATEST_VERSION}" | ||
|
||
# Build package | ||
npm run "$BUILD_COMMAND" | ||
|
||
# Replace npm publish with npm pack for testing | ||
npm publish | ||
|
||
echo "Successfully packaged ${PACKAGE_NAME}" | ||
|
||
# Log the bundle size | ||
TARBALL="${PACKAGE_NAME}-${LATEST_VERSION#v}.tgz" | ||
if [ -f "$TARBALL" ]; then | ||
BUNDLE_SIZE=$(du -h "$TARBALL" | cut -f1) | ||
echo "Bundle size for ${PACKAGE_NAME}: ${BUNDLE_SIZE}" | ||
else | ||
echo "Error: ${TARBALL} not found." | ||
exit 1 | ||
fi | ||
} | ||
|
||
# Publish docsgpt package | ||
publish_package "docsgpt" "build" | ||
# First publish docsgpt (HTML bundle) | ||
publish_package "docsgpt" "build" "false" | ||
|
||
# Then publish docsgpt-react (React library) | ||
publish_package "docsgpt-react" "build:react" "true" | ||
|
||
# Restore original state but keep the updated version | ||
cp package_original.json package.json | ||
cp package-lock_original.json package-lock.json | ||
|
||
# Update the version in the final package.json | ||
jq --arg version "${LATEST_VERSION#v}" '.version=$version' package.json > temp.json && mv temp.json package.json | ||
|
||
# Publish docsgpt-react package | ||
publish_package "docsgpt-react" "build:react" | ||
# Run npm install to update package-lock.json with the new version | ||
npm install --package-lock-only | ||
|
||
# Cleanup backup files | ||
rm -f package_original.json | ||
rm -f package-lock_original.json | ||
rm -f temp.json | ||
|
||
rm -rf package_copy.json | ||
rm -rf package-lock_copy.json | ||
echo "---Process completed---" | ||
echo "---Process completed---" | ||
echo "Final version in package.json: $(jq -r '.version' package.json)" | ||
echo "Final version in package-lock.json: $(jq -r '.version' package-lock.json)" | ||
echo "Generated test packages:" | ||
ls *.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters