-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjustfile
More file actions
76 lines (60 loc) · 2.73 KB
/
justfile
File metadata and controls
76 lines (60 loc) · 2.73 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
[private]
@default:
just --list
# Ensure you have a `publish` token saved on your machine.
[private]
@ensure-npm-login:
npm whoami || npm login
# Create a new package from template
create-package package:
#!/usr/bin/env bash
set -euo pipefail
# Remove @digabi/ prefix if present
PACKAGE_NAME="{{ if package =~ "^@digabi/" { replace(package, "@digabi/", "") } else { package } }}"
PACKAGE_DIR="packages/${PACKAGE_NAME}"
FULL_PACKAGE_NAME="@digabi/${PACKAGE_NAME}"
WORKFLOW_FILE=".github/workflows/publish.yml"
# Check if package already exists
if [ -d "${PACKAGE_DIR}" ]; then
echo "Error: Package '${PACKAGE_NAME}' already exists at ${PACKAGE_DIR}"
exit 1
fi
# Check if yq is installed
if ! command -v yq &> /dev/null; then
echo "Error: yq is not installed. Please install it with: brew install yq"
exit 1
fi
echo "Creating new package: ${FULL_PACKAGE_NAME}"
# Copy template
cp -r .template "${PACKAGE_DIR}"
# Replace placeholders in all files
find "${PACKAGE_DIR}" -type f -exec sed -i '' "s/__PACKAGE_NAME__/${PACKAGE_NAME}/g" {} +
# Rename test file
mv "${PACKAGE_DIR}/__tests__/__PACKAGE_NAME__.test.ts" "${PACKAGE_DIR}/__tests__/${PACKAGE_NAME}.test.ts"
echo "✓ Package structure created at ${PACKAGE_DIR}"
# Add package to publish workflow
echo "Adding ${FULL_PACKAGE_NAME} to publish workflow..."
yq eval -i ".on.workflow_dispatch.inputs.package.options += [\"${FULL_PACKAGE_NAME}\"]" "${WORKFLOW_FILE}"
yq eval -i ".on.workflow_dispatch.inputs.package.options |= sort" "${WORKFLOW_FILE}"
echo "✓ Added to ${WORKFLOW_FILE}"
echo ""
echo "Next steps:"
echo "1. Update ${PACKAGE_DIR}/package.json with proper description"
echo "2. Implement your code in ${PACKAGE_DIR}/src/"
echo "3. Run: just publish-initial ${PACKAGE_NAME}"
echo ""
# Publish initial version of a new package to npm
publish-initial package: (ensure-npm-login)
#!/usr/bin/env bash
set -euo pipefail
PACKAGE_NAME="{{ if package =~ "^@digabi/" { package } else { "@digabi/" + package } }}"
echo "Publishing initial version of ${PACKAGE_NAME}..."
npm publish --workspace="${PACKAGE_NAME}" \
|| echo "\nPublish failed! Maybe your token isn't a Publish token? Run 'npm logout' and try again."
echo ""
echo "Next steps:"
echo "1. Sign into npmjs.com and navigate to the package settings"
echo "2. Setup 'Trusted publisher' for GitHub Actions"
echo "3. Set 'publishing access' to 'require two-factor authentication and disallow tokens'"
echo "4. Test the workflow by creating a new version with publish.yml from github actions UI"
echo ""