@leadcms/sdk 1.2.85-pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +205 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/cms.d.ts +104 -0
- package/dist/lib/cms.d.ts.map +1 -0
- package/dist/lib/cms.js +532 -0
- package/dist/lib/cms.js.map +1 -0
- package/dist/lib/config.d.ts +45 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +194 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/scripts/fetch-leadcms-content.mjs +361 -0
- package/dist/scripts/generate-env-js.mjs +24 -0
- package/dist/scripts/leadcms-helpers.mjs +208 -0
- package/dist/scripts/sse-watcher.mjs +325 -0
- package/dist/templates/docker/Dockerfile +34 -0
- package/dist/templates/docker/nginx.conf +70 -0
- package/dist/templates/docker/preview/Dockerfile +75 -0
- package/dist/templates/docker/preview/nginx.conf +128 -0
- package/dist/templates/docker/preview/supervisord.conf +63 -0
- package/dist/templates/scripts/inject-runtime-env.sh +33 -0
- package/leadcms.config.json.sample +8 -0
- package/package.json +76 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# LeadCMS Live Preview Dockerfile
|
|
2
|
+
# Multi-service container for development/preview with live updates
|
|
3
|
+
# Includes nginx reverse proxy, development server, and LeadCMS SSE watcher
|
|
4
|
+
# Works with any static site generator that supports live preview
|
|
5
|
+
#
|
|
6
|
+
# Requirements for your project:
|
|
7
|
+
# - npm run livepreview: Start development server on port 3000
|
|
8
|
+
# - LeadCMS SDK scripts available
|
|
9
|
+
#
|
|
10
|
+
# Usage from project root:
|
|
11
|
+
# docker build -f preview/Dockerfile -t my-leadcms-site-preview .
|
|
12
|
+
# docker run -p 80:80 -e LEADCMS_URL=... -e LEADCMS_API_KEY=... my-leadcms-site-preview
|
|
13
|
+
|
|
14
|
+
FROM node:20-alpine
|
|
15
|
+
|
|
16
|
+
# Install nginx and supervisor for multi-service management
|
|
17
|
+
RUN apk add --no-cache nginx supervisor wget
|
|
18
|
+
|
|
19
|
+
# Create required directories
|
|
20
|
+
RUN mkdir -p /var/log/supervisor /run/nginx
|
|
21
|
+
|
|
22
|
+
# Set working directory
|
|
23
|
+
WORKDIR /app
|
|
24
|
+
|
|
25
|
+
# Copy package files first for better Docker layer caching
|
|
26
|
+
COPY package*.json ./
|
|
27
|
+
|
|
28
|
+
# Build arguments for LeadCMS configuration
|
|
29
|
+
ARG LEADCMS_URL
|
|
30
|
+
ARG LEADCMS_API_KEY
|
|
31
|
+
ARG LEADCMS_DEFAULT_LANGUAGE=en
|
|
32
|
+
|
|
33
|
+
# Export build args as environment variables
|
|
34
|
+
ENV LEADCMS_URL=$LEADCMS_URL
|
|
35
|
+
ENV LEADCMS_API_KEY=$LEADCMS_API_KEY
|
|
36
|
+
ENV LEADCMS_DEFAULT_LANGUAGE=$LEADCMS_DEFAULT_LANGUAGE
|
|
37
|
+
|
|
38
|
+
# Support Next.js environment variables for backward compatibility
|
|
39
|
+
ENV NEXT_PUBLIC_LEADCMS_URL=$LEADCMS_URL
|
|
40
|
+
ENV NEXT_PUBLIC_LEADCMS_DEFAULT_LANGUAGE=$LEADCMS_DEFAULT_LANGUAGE
|
|
41
|
+
|
|
42
|
+
# Install dependencies
|
|
43
|
+
RUN npm ci --verbose
|
|
44
|
+
|
|
45
|
+
# Copy application code
|
|
46
|
+
COPY . .
|
|
47
|
+
|
|
48
|
+
# Copy nginx configuration for development proxy
|
|
49
|
+
COPY preview/nginx.conf /etc/nginx/nginx.conf
|
|
50
|
+
|
|
51
|
+
# Copy supervisor configuration for multi-service management
|
|
52
|
+
COPY preview/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
|
53
|
+
|
|
54
|
+
# Create startup script
|
|
55
|
+
RUN echo '#!/bin/sh' > /start.sh && \
|
|
56
|
+
echo '# Fetch initial LeadCMS content if configuration is available' >> /start.sh && \
|
|
57
|
+
echo 'if [ ! -z "$LEADCMS_URL" ] && [ ! -z "$LEADCMS_API_KEY" ]; then' >> /start.sh && \
|
|
58
|
+
echo ' echo "Fetching initial LeadCMS content..."' >> /start.sh && \
|
|
59
|
+
echo ' npx leadcms fetch || echo "Warning: Could not fetch initial content"' >> /start.sh && \
|
|
60
|
+
echo 'fi' >> /start.sh && \
|
|
61
|
+
echo '' >> /start.sh && \
|
|
62
|
+
echo '# Start supervisor to manage all services' >> /start.sh && \
|
|
63
|
+
echo 'exec /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf' >> /start.sh
|
|
64
|
+
|
|
65
|
+
RUN chmod +x /start.sh
|
|
66
|
+
|
|
67
|
+
# Expose port 80 (nginx will proxy to development server on port 3000)
|
|
68
|
+
EXPOSE 80
|
|
69
|
+
|
|
70
|
+
# Health check
|
|
71
|
+
HEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \
|
|
72
|
+
CMD wget --spider -q http://localhost:80 || exit 1
|
|
73
|
+
|
|
74
|
+
# Start all services via supervisor
|
|
75
|
+
CMD ["/start.sh"]
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# LeadCMS Live Preview nginx Configuration
|
|
2
|
+
# Reverse proxy configuration for development/preview mode
|
|
3
|
+
# Proxies requests to development server with WebSocket support for live reload
|
|
4
|
+
|
|
5
|
+
user nginx;
|
|
6
|
+
worker_processes auto;
|
|
7
|
+
error_log /var/log/nginx/error.log notice;
|
|
8
|
+
pid /var/run/nginx.pid;
|
|
9
|
+
|
|
10
|
+
events {
|
|
11
|
+
worker_connections 1024;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
http {
|
|
15
|
+
include /etc/nginx/mime.types;
|
|
16
|
+
default_type application/octet-stream;
|
|
17
|
+
|
|
18
|
+
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
19
|
+
'$status $body_bytes_sent "$http_referer" '
|
|
20
|
+
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
21
|
+
|
|
22
|
+
access_log /var/log/nginx/access.log main;
|
|
23
|
+
|
|
24
|
+
sendfile on;
|
|
25
|
+
tcp_nopush on;
|
|
26
|
+
keepalive_timeout 65;
|
|
27
|
+
types_hash_max_size 2048;
|
|
28
|
+
|
|
29
|
+
# WebSocket upgrade support for live reload functionality
|
|
30
|
+
map $http_upgrade $connection_upgrade {
|
|
31
|
+
default upgrade;
|
|
32
|
+
'' close;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
server {
|
|
36
|
+
listen 80;
|
|
37
|
+
server_name _;
|
|
38
|
+
|
|
39
|
+
# Main application proxy with WebSocket support
|
|
40
|
+
location / {
|
|
41
|
+
proxy_pass http://localhost:3000;
|
|
42
|
+
proxy_set_header Host $host;
|
|
43
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
44
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
45
|
+
proxy_set_header X-Forwarded-Host $server_name;
|
|
46
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
47
|
+
|
|
48
|
+
# WebSocket support for live reload (framework-agnostic)
|
|
49
|
+
proxy_http_version 1.1;
|
|
50
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
51
|
+
proxy_set_header Connection $connection_upgrade;
|
|
52
|
+
proxy_cache_bypass $http_upgrade;
|
|
53
|
+
|
|
54
|
+
# Timeout and connection settings
|
|
55
|
+
proxy_connect_timeout 5s;
|
|
56
|
+
proxy_read_timeout 60s;
|
|
57
|
+
proxy_send_timeout 60s;
|
|
58
|
+
|
|
59
|
+
# DNS resolver for Docker networking
|
|
60
|
+
resolver 127.0.0.11 8.8.8.8 1.1.1.1 valid=10s;
|
|
61
|
+
resolver_timeout 5s;
|
|
62
|
+
|
|
63
|
+
# CORS headers for development
|
|
64
|
+
add_header 'Access-Control-Allow-Origin' '*' always;
|
|
65
|
+
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS, PATCH, DELETE, POST, PUT' always;
|
|
66
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
|
|
67
|
+
add_header 'Access-Control-Allow-Credentials' 'true' always;
|
|
68
|
+
|
|
69
|
+
# Handle CORS preflight requests
|
|
70
|
+
if ($request_method = 'OPTIONS') {
|
|
71
|
+
add_header 'Access-Control-Allow-Origin' '*';
|
|
72
|
+
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS, PATCH, DELETE, POST, PUT';
|
|
73
|
+
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
|
|
74
|
+
add_header 'Access-Control-Allow-Credentials' 'true';
|
|
75
|
+
return 204;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
# Hot reload endpoints (framework-specific paths)
|
|
80
|
+
# Next.js hot reload
|
|
81
|
+
location /_next/webpack-hmr {
|
|
82
|
+
proxy_pass http://localhost:3000;
|
|
83
|
+
proxy_redirect off;
|
|
84
|
+
proxy_http_version 1.1;
|
|
85
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
86
|
+
proxy_set_header Connection "upgrade";
|
|
87
|
+
proxy_set_header Host $host;
|
|
88
|
+
proxy_set_header X-Real-IP $remote_addr;
|
|
89
|
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
90
|
+
proxy_set_header X-Forwarded-Host $server_name;
|
|
91
|
+
proxy_set_header X-Forwarded-Proto $scheme;
|
|
92
|
+
proxy_cache_bypass $http_upgrade;
|
|
93
|
+
|
|
94
|
+
# Extended timeouts for WebSocket connections
|
|
95
|
+
proxy_connect_timeout 3s;
|
|
96
|
+
proxy_read_timeout 120s;
|
|
97
|
+
proxy_send_timeout 120s;
|
|
98
|
+
resolver 127.0.0.11 8.8.8.8 1.1.1.1 valid=10s;
|
|
99
|
+
resolver_timeout 5s;
|
|
100
|
+
|
|
101
|
+
# Disable buffering for real-time updates
|
|
102
|
+
proxy_buffering off;
|
|
103
|
+
proxy_cache off;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# Astro/Vite dev server WebSocket
|
|
107
|
+
location /vite-dev-ping {
|
|
108
|
+
proxy_pass http://localhost:3000;
|
|
109
|
+
proxy_http_version 1.1;
|
|
110
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
111
|
+
proxy_set_header Connection $connection_upgrade;
|
|
112
|
+
proxy_set_header Host $host;
|
|
113
|
+
proxy_cache_bypass $http_upgrade;
|
|
114
|
+
proxy_buffering off;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
# Generic WebSocket support for other frameworks
|
|
118
|
+
location ~* \.(ws|socket)$ {
|
|
119
|
+
proxy_pass http://localhost:3000;
|
|
120
|
+
proxy_http_version 1.1;
|
|
121
|
+
proxy_set_header Upgrade $http_upgrade;
|
|
122
|
+
proxy_set_header Connection $connection_upgrade;
|
|
123
|
+
proxy_set_header Host $host;
|
|
124
|
+
proxy_cache_bypass $http_upgrade;
|
|
125
|
+
proxy_buffering off;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# LeadCMS Live Preview Supervisor Configuration
|
|
2
|
+
# Manages multiple services in a single container:
|
|
3
|
+
# - nginx: Reverse proxy on port 80
|
|
4
|
+
# - livepreview: Development server on port 3000 (framework-agnostic)
|
|
5
|
+
# - sse-watcher: LeadCMS live content updates
|
|
6
|
+
|
|
7
|
+
[supervisord]
|
|
8
|
+
nodaemon=true
|
|
9
|
+
loglevel=info
|
|
10
|
+
logfile=/dev/stdout
|
|
11
|
+
logfile_maxbytes=0
|
|
12
|
+
pidfile=/var/run/supervisord.pid
|
|
13
|
+
silent=false
|
|
14
|
+
|
|
15
|
+
[program:nginx]
|
|
16
|
+
command=nginx -g "daemon off;"
|
|
17
|
+
stdout_logfile=/dev/stdout
|
|
18
|
+
stdout_logfile_maxbytes=0
|
|
19
|
+
stderr_logfile=/dev/stderr
|
|
20
|
+
stderr_logfile_maxbytes=0
|
|
21
|
+
stdout_events_enabled=true
|
|
22
|
+
stderr_events_enabled=true
|
|
23
|
+
autorestart=true
|
|
24
|
+
redirect_stderr=false
|
|
25
|
+
priority=100
|
|
26
|
+
|
|
27
|
+
[program:livepreview]
|
|
28
|
+
# Framework-agnostic development server command
|
|
29
|
+
# Your project should implement: npm run livepreview
|
|
30
|
+
# Examples:
|
|
31
|
+
# - Next.js: "next dev"
|
|
32
|
+
# - Astro: "astro dev"
|
|
33
|
+
# - Gatsby: "gatsby develop"
|
|
34
|
+
# - Nuxt: "nuxt dev"
|
|
35
|
+
command=npm run livepreview
|
|
36
|
+
directory=/app
|
|
37
|
+
stdout_logfile=/dev/stdout
|
|
38
|
+
stdout_logfile_maxbytes=0
|
|
39
|
+
stderr_logfile=/dev/stderr
|
|
40
|
+
stderr_logfile_maxbytes=0
|
|
41
|
+
stdout_events_enabled=true
|
|
42
|
+
stderr_events_enabled=true
|
|
43
|
+
autorestart=true
|
|
44
|
+
redirect_stderr=false
|
|
45
|
+
environment=NODE_ENV=development
|
|
46
|
+
priority=200
|
|
47
|
+
|
|
48
|
+
[program:sse-watcher]
|
|
49
|
+
# LeadCMS SSE watcher for live content updates
|
|
50
|
+
command=npx leadcms watch
|
|
51
|
+
directory=/app
|
|
52
|
+
stdout_logfile=/dev/stdout
|
|
53
|
+
stdout_logfile_maxbytes=0
|
|
54
|
+
stderr_logfile=/dev/stderr
|
|
55
|
+
stderr_logfile_maxbytes=0
|
|
56
|
+
stdout_events_enabled=true
|
|
57
|
+
stderr_events_enabled=true
|
|
58
|
+
autorestart=true
|
|
59
|
+
redirect_stderr=false
|
|
60
|
+
environment=NODE_ENV=development
|
|
61
|
+
priority=300
|
|
62
|
+
# Only start if LeadCMS configuration is available
|
|
63
|
+
startsecs=10
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# This script updates public/__env.js with current NEXT_PUBLIC_ env vars at container startup
|
|
3
|
+
set -e
|
|
4
|
+
|
|
5
|
+
ENV_JS_PATH="/usr/share/nginx/html/__env.js"
|
|
6
|
+
|
|
7
|
+
if [ ! -f "$ENV_JS_PATH" ]; then
|
|
8
|
+
echo "__env.js not found at $ENV_JS_PATH, skipping runtime env injection."
|
|
9
|
+
exit 0
|
|
10
|
+
fi
|
|
11
|
+
|
|
12
|
+
echo "Updating $ENV_JS_PATH with current NEXT_PUBLIC_ env vars..."
|
|
13
|
+
|
|
14
|
+
# Find all env vars starting with NEXT_PUBLIC_ and output only defined ones
|
|
15
|
+
JS="window.__env = {"
|
|
16
|
+
FIRST=1
|
|
17
|
+
while IFS='=' read -r KEY VAL; do
|
|
18
|
+
if [[ $KEY == NEXT_PUBLIC_* ]]; then
|
|
19
|
+
# Strip leading/trailing quotes if present
|
|
20
|
+
STRIPPED_VAL=$(printf '%s' "$VAL" | sed 's/^"//;s/"$//')
|
|
21
|
+
# Escape backslashes and double quotes for JS string
|
|
22
|
+
ESCAPED_VAL=$(printf '%s' "$STRIPPED_VAL" | sed 's/\\/\\\\/g; s/"/\\"/g')
|
|
23
|
+
if [ $FIRST -eq 0 ]; then
|
|
24
|
+
JS="$JS,"
|
|
25
|
+
fi
|
|
26
|
+
JS="$JS \"$KEY\": \"$ESCAPED_VAL\""
|
|
27
|
+
FIRST=0
|
|
28
|
+
fi
|
|
29
|
+
done < <(env)
|
|
30
|
+
JS="$JS};"
|
|
31
|
+
|
|
32
|
+
echo "$JS" > "$ENV_JS_PATH"
|
|
33
|
+
echo "Injected runtime envs into $ENV_JS_PATH."
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leadcms/sdk",
|
|
3
|
+
"version": "1.2.85-pre",
|
|
4
|
+
"description": "Official SDK and CLI tools for LeadCMS - framework-agnostic content management",
|
|
5
|
+
"main": "dist/lib/cms.js",
|
|
6
|
+
"types": "dist/lib/cms.d.ts",
|
|
7
|
+
"bin": {
|
|
8
|
+
"leadcms": "dist/cli/index.js"
|
|
9
|
+
},
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=18.0.0",
|
|
12
|
+
"npm": ">=8.0.0"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "npm run clean && tsc && npm run copy-assets && npm run fix-permissions",
|
|
16
|
+
"clean": "rm -rf dist",
|
|
17
|
+
"copy-assets": "cp -r src/scripts dist/ && cp -r src/templates dist/",
|
|
18
|
+
"fix-permissions": "chmod +x dist/cli/index.js && chmod +x dist/scripts/*.sh 2>/dev/null || true",
|
|
19
|
+
"dev": "npm run build && concurrently \"tsc --watch\" \"npm run watch-assets\"",
|
|
20
|
+
"watch-assets": "nodemon --watch src/scripts --watch src/templates --ext '*' --exec 'npm run copy-assets'",
|
|
21
|
+
"test": "npm run build && node dist/cli/index.js --help > /dev/null && echo '✅ CLI tests passed'",
|
|
22
|
+
"prepublishOnly": "npm run build",
|
|
23
|
+
"leadcms:fetch": "node src/scripts/fetch-leadcms-content.mjs",
|
|
24
|
+
"leadcms:watch": "node src/scripts/sse-watcher.mjs",
|
|
25
|
+
"leadcms:generate-env": "node src/scripts/generate-env-js.mjs"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"axios": "^1.0.0",
|
|
29
|
+
"dotenv": "^16.0.0",
|
|
30
|
+
"eventsource": "^2.0.0",
|
|
31
|
+
"gray-matter": "^4.0.3",
|
|
32
|
+
"js-yaml": "^4.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@types/eventsource": "^1.1.15",
|
|
36
|
+
"@types/js-yaml": "^4.0.9",
|
|
37
|
+
"@types/node": "^20.0.0",
|
|
38
|
+
"concurrently": "^9.2.1",
|
|
39
|
+
"nodemon": "^3.1.10",
|
|
40
|
+
"typescript": "^5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist/",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE",
|
|
46
|
+
"leadcms.config.json.sample"
|
|
47
|
+
],
|
|
48
|
+
"keywords": [
|
|
49
|
+
"leadcms",
|
|
50
|
+
"cms",
|
|
51
|
+
"headless-cms",
|
|
52
|
+
"sdk",
|
|
53
|
+
"typescript",
|
|
54
|
+
"content-management",
|
|
55
|
+
"mdx",
|
|
56
|
+
"markdown",
|
|
57
|
+
"json",
|
|
58
|
+
"i18n",
|
|
59
|
+
"localization",
|
|
60
|
+
"static-content",
|
|
61
|
+
"framework-agnostic"
|
|
62
|
+
],
|
|
63
|
+
"repository": {
|
|
64
|
+
"type": "git",
|
|
65
|
+
"url": "https://github.com/LeadCMS/leadcms.sdk.git"
|
|
66
|
+
},
|
|
67
|
+
"bugs": {
|
|
68
|
+
"url": "https://github.com/LeadCMS/leadcms.sdk/issues"
|
|
69
|
+
},
|
|
70
|
+
"homepage": "https://github.com/LeadCMS/leadcms.sdk#readme",
|
|
71
|
+
"author": "LeadCMS Team",
|
|
72
|
+
"license": "MIT",
|
|
73
|
+
"publishConfig": {
|
|
74
|
+
"access": "public"
|
|
75
|
+
}
|
|
76
|
+
}
|