nca-ai-cms-astro-plugin 1.0.3 → 1.0.4
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/package.json +1 -1
- package/src/env.d.ts +12 -0
- package/src/index.ts +19 -1
- package/src/utils/envUtils.ts +4 -2
- package/update.md +16 -0
package/package.json
CHANGED
package/src/env.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface ImportMetaEnv {
|
|
2
|
+
readonly PROD: boolean;
|
|
3
|
+
readonly DEV: boolean;
|
|
4
|
+
readonly EDITOR_ADMIN: string;
|
|
5
|
+
readonly EDITOR_PASSWORD: string;
|
|
6
|
+
readonly GOOGLE_GEMINI_API_KEY: string;
|
|
7
|
+
readonly [key: string]: string | boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ImportMeta {
|
|
11
|
+
readonly env: ImportMetaEnv;
|
|
12
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ export default function ncaAiCms(
|
|
|
9
9
|
options: NcaAiCmsPluginOptions = {}
|
|
10
10
|
): AstroIntegration {
|
|
11
11
|
const contentPath = options.contentPath ?? 'nca-ai-cms-content';
|
|
12
|
-
const autoPublish = options.autoPublish ??
|
|
12
|
+
const autoPublish = options.autoPublish ?? import.meta.env.PROD;
|
|
13
13
|
|
|
14
14
|
return {
|
|
15
15
|
name: 'nca-ai-cms-astro-plugin',
|
|
@@ -51,80 +51,98 @@ export default function ncaAiCms(
|
|
|
51
51
|
injectRoute({
|
|
52
52
|
pattern: '/api/generate-content',
|
|
53
53
|
entrypoint: 'nca-ai-cms-astro-plugin/api/generate-content.ts',
|
|
54
|
+
prerender: false,
|
|
54
55
|
});
|
|
55
56
|
injectRoute({
|
|
56
57
|
pattern: '/api/generate-image',
|
|
57
58
|
entrypoint: 'nca-ai-cms-astro-plugin/api/generate-image.ts',
|
|
59
|
+
prerender: false,
|
|
58
60
|
});
|
|
59
61
|
injectRoute({
|
|
60
62
|
pattern: '/api/save',
|
|
61
63
|
entrypoint: 'nca-ai-cms-astro-plugin/api/save.ts',
|
|
64
|
+
prerender: false,
|
|
62
65
|
});
|
|
63
66
|
injectRoute({
|
|
64
67
|
pattern: '/api/save-image',
|
|
65
68
|
entrypoint: 'nca-ai-cms-astro-plugin/api/save-image.ts',
|
|
69
|
+
prerender: false,
|
|
66
70
|
});
|
|
67
71
|
injectRoute({
|
|
68
72
|
pattern: '/api/prompts',
|
|
69
73
|
entrypoint: 'nca-ai-cms-astro-plugin/api/prompts.ts',
|
|
74
|
+
prerender: false,
|
|
70
75
|
});
|
|
71
76
|
injectRoute({
|
|
72
77
|
pattern: '/api/scheduler',
|
|
73
78
|
entrypoint: 'nca-ai-cms-astro-plugin/api/scheduler.ts',
|
|
79
|
+
prerender: false,
|
|
74
80
|
});
|
|
75
81
|
injectRoute({
|
|
76
82
|
pattern: '/api/scheduler/generate',
|
|
77
83
|
entrypoint: 'nca-ai-cms-astro-plugin/api/scheduler/generate.ts',
|
|
84
|
+
prerender: false,
|
|
78
85
|
});
|
|
79
86
|
injectRoute({
|
|
80
87
|
pattern: '/api/scheduler/publish',
|
|
81
88
|
entrypoint: 'nca-ai-cms-astro-plugin/api/scheduler/publish.ts',
|
|
89
|
+
prerender: false,
|
|
82
90
|
});
|
|
83
91
|
injectRoute({
|
|
84
92
|
pattern: '/api/scheduler/[id]',
|
|
85
93
|
entrypoint: 'nca-ai-cms-astro-plugin/api/scheduler/[id].ts',
|
|
94
|
+
prerender: false,
|
|
86
95
|
});
|
|
87
96
|
injectRoute({
|
|
88
97
|
pattern: '/api/articles/[id]',
|
|
89
98
|
entrypoint: 'nca-ai-cms-astro-plugin/api/articles/[id].ts',
|
|
99
|
+
prerender: false,
|
|
90
100
|
});
|
|
91
101
|
injectRoute({
|
|
92
102
|
pattern: '/api/articles/[id]/apply',
|
|
93
103
|
entrypoint: 'nca-ai-cms-astro-plugin/api/articles/[id]/apply.ts',
|
|
104
|
+
prerender: false,
|
|
94
105
|
});
|
|
95
106
|
injectRoute({
|
|
96
107
|
pattern: '/api/articles/[id]/regenerate-text',
|
|
97
108
|
entrypoint:
|
|
98
109
|
'nca-ai-cms-astro-plugin/api/articles/[id]/regenerate-text.ts',
|
|
110
|
+
prerender: false,
|
|
99
111
|
});
|
|
100
112
|
injectRoute({
|
|
101
113
|
pattern: '/api/articles/[id]/regenerate-image',
|
|
102
114
|
entrypoint:
|
|
103
115
|
'nca-ai-cms-astro-plugin/api/articles/[id]/regenerate-image.ts',
|
|
116
|
+
prerender: false,
|
|
104
117
|
});
|
|
105
118
|
|
|
106
119
|
// Inject auth routes
|
|
107
120
|
injectRoute({
|
|
108
121
|
pattern: '/api/auth/login',
|
|
109
122
|
entrypoint: 'nca-ai-cms-astro-plugin/api/auth/login.ts',
|
|
123
|
+
prerender: false,
|
|
110
124
|
});
|
|
111
125
|
injectRoute({
|
|
112
126
|
pattern: '/api/auth/logout',
|
|
113
127
|
entrypoint: 'nca-ai-cms-astro-plugin/api/auth/logout.ts',
|
|
128
|
+
prerender: false,
|
|
114
129
|
});
|
|
115
130
|
injectRoute({
|
|
116
131
|
pattern: '/api/auth/check',
|
|
117
132
|
entrypoint: 'nca-ai-cms-astro-plugin/api/auth/check.ts',
|
|
133
|
+
prerender: false,
|
|
118
134
|
});
|
|
119
135
|
|
|
120
136
|
// Inject pages
|
|
121
137
|
injectRoute({
|
|
122
138
|
pattern: '/login',
|
|
123
139
|
entrypoint: 'nca-ai-cms-astro-plugin/pages/login.astro',
|
|
140
|
+
prerender: false,
|
|
124
141
|
});
|
|
125
142
|
injectRoute({
|
|
126
143
|
pattern: '/editor',
|
|
127
144
|
entrypoint: 'nca-ai-cms-astro-plugin/pages/editor.astro',
|
|
145
|
+
prerender: false,
|
|
128
146
|
});
|
|
129
147
|
},
|
|
130
148
|
|
package/src/utils/envUtils.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Reads an environment variable from `
|
|
2
|
+
* Reads an environment variable from `import.meta.env` (Astro/Vite)
|
|
3
|
+
* with a fallback to `process.env` for non-Vite environments.
|
|
3
4
|
*
|
|
4
5
|
* @param variable - The name of the environment variable.
|
|
5
6
|
* @param defaultValue - Optional fallback when the variable is not set.
|
|
@@ -10,7 +11,8 @@ export function getEnvVariable(
|
|
|
10
11
|
variable: string,
|
|
11
12
|
defaultValue?: string,
|
|
12
13
|
): string {
|
|
13
|
-
const value =
|
|
14
|
+
const value = (import.meta.env as Record<string, string | undefined>)[variable]
|
|
15
|
+
?? process.env[variable];
|
|
14
16
|
|
|
15
17
|
if (value !== undefined && value !== "") {
|
|
16
18
|
return value;
|
package/update.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# v1.0.4
|
|
2
|
+
|
|
3
|
+
## Fix: Environment variables and route prerendering
|
|
4
|
+
|
|
5
|
+
### Environment variables now work with Astro's .env files
|
|
6
|
+
- `getEnvVariable()` now reads from `import.meta.env` first, with a `process.env` fallback
|
|
7
|
+
- Previously only checked `process.env`, which meant `.env` / `.env.local` files were ignored in Astro dev and SSR
|
|
8
|
+
- Works in all environments: local dev, Docker, GitLab CI/CD
|
|
9
|
+
|
|
10
|
+
### All injected routes are now server-rendered
|
|
11
|
+
- Added `prerender: false` to all 18 injected routes (API, auth, pages)
|
|
12
|
+
- Consumers no longer need to set `output: 'server'` globally in their Astro config
|
|
13
|
+
- The plugin works with Astro's default `output: 'static'` — only plugin routes are server-rendered
|
|
14
|
+
|
|
15
|
+
### Minor: use `import.meta.env.PROD` for auto-publish check
|
|
16
|
+
- Replaced `process.env.NODE_ENV === 'production'` with Astro's built-in `import.meta.env.PROD`
|