@bagelink/workspace 1.7.33 → 1.7.35
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/README.md +137 -4
- package/bin/bgl.ts +12 -2
- package/dist/bin/bgl.cjs +9 -4
- package/dist/bin/bgl.mjs +9 -4
- package/dist/index.cjs +63 -1
- package/dist/index.d.cts +121 -4
- package/dist/index.d.mts +121 -4
- package/dist/index.d.ts +121 -4
- package/dist/index.mjs +62 -3
- package/dist/shared/{workspace.OuHxYc4s.cjs → workspace.CamNrnD_.cjs} +85 -28
- package/dist/shared/{workspace.CcKgYZPx.mjs → workspace.PLrsjsJ2.mjs} +85 -28
- package/env.d.ts +29 -0
- package/package.json +7 -1
- package/src/composable.ts +65 -0
- package/src/index.ts +4 -0
- package/src/init.ts +18 -12
- package/src/netlify.ts +54 -3
- package/src/vite.ts +135 -0
- package/src/workspace.ts +23 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
1
3
|
type WorkspaceEnvironment = 'localhost' | 'development' | 'production';
|
|
2
4
|
interface WorkspaceConfig {
|
|
3
5
|
/**
|
|
@@ -63,16 +65,17 @@ declare function generateWorkspaceConfigSync(projectId: string, root?: string, c
|
|
|
63
65
|
|
|
64
66
|
/**
|
|
65
67
|
* Generate netlify.toml redirect configuration
|
|
68
|
+
* Uses environment variables for flexibility across environments
|
|
66
69
|
*/
|
|
67
70
|
declare function generateNetlifyRedirect(config: WorkspaceConfig): string;
|
|
68
71
|
/**
|
|
69
72
|
* Generate complete netlify.toml file
|
|
70
73
|
*/
|
|
71
|
-
declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string): string;
|
|
74
|
+
declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
|
|
72
75
|
/**
|
|
73
76
|
* Write netlify.toml file to disk
|
|
74
77
|
*/
|
|
75
|
-
declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
|
|
78
|
+
declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
|
|
76
79
|
/**
|
|
77
80
|
* Set environment variables for build process
|
|
78
81
|
*/
|
|
@@ -91,6 +94,54 @@ declare function createCustomProxy(paths: string[], target: string, options?: {
|
|
|
91
94
|
secure?: boolean;
|
|
92
95
|
}): ProxyConfig;
|
|
93
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Runtime workspace configuration
|
|
99
|
+
* Provides access to workspace config injected at build time
|
|
100
|
+
*/
|
|
101
|
+
interface RuntimeWorkspaceConfig {
|
|
102
|
+
/** API proxy path (e.g., '/api') */
|
|
103
|
+
proxy: string;
|
|
104
|
+
/** API host URL (e.g., 'https://project.bagel.to') */
|
|
105
|
+
host: string;
|
|
106
|
+
/** OpenAPI specification URL (if configured) */
|
|
107
|
+
openapiUrl?: string;
|
|
108
|
+
/** Current environment mode */
|
|
109
|
+
mode: 'localhost' | 'development' | 'production';
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get workspace configuration at runtime
|
|
113
|
+
* Config is injected as environment variables during build
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { useWorkspace } from '@bagelink/workspace'
|
|
118
|
+
*
|
|
119
|
+
* const { proxy, host } = useWorkspace()
|
|
120
|
+
* const auth = initAuth({ baseURL: proxy })
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example In Vue component
|
|
124
|
+
* ```vue
|
|
125
|
+
* <script setup>
|
|
126
|
+
* import { useWorkspace } from '@bagelink/workspace'
|
|
127
|
+
*
|
|
128
|
+
* const { proxy, host, mode } = useWorkspace()
|
|
129
|
+
* </script>
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
declare function useWorkspace(): RuntimeWorkspaceConfig;
|
|
133
|
+
/**
|
|
134
|
+
* Get the full API URL by combining host and proxy
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { getApiUrl } from '@bagelink/workspace'
|
|
139
|
+
*
|
|
140
|
+
* const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function getApiUrl(): string;
|
|
144
|
+
|
|
94
145
|
/**
|
|
95
146
|
* Detect if current directory is a workspace root
|
|
96
147
|
*/
|
|
@@ -120,6 +171,72 @@ declare function generateSDK(root?: string): Promise<void>;
|
|
|
120
171
|
*/
|
|
121
172
|
declare function generateSDKForWorkspace(root?: string): Promise<void>;
|
|
122
173
|
|
|
174
|
+
interface BagelinkPluginOptions {
|
|
175
|
+
/**
|
|
176
|
+
* Path to shared package relative to project
|
|
177
|
+
* @default '../shared'
|
|
178
|
+
*/
|
|
179
|
+
sharedPath?: string;
|
|
180
|
+
/**
|
|
181
|
+
* Whether to include @shared alias
|
|
182
|
+
* @default true
|
|
183
|
+
*/
|
|
184
|
+
includeSharedAlias?: boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Additional path aliases beyond @ and @shared
|
|
187
|
+
*/
|
|
188
|
+
additionalAliases?: Record<string, string>;
|
|
189
|
+
/**
|
|
190
|
+
* Whether to auto-configure proxy
|
|
191
|
+
* @default true
|
|
192
|
+
*/
|
|
193
|
+
configureProxy?: boolean;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Vite plugin for Bagelink workspace integration
|
|
197
|
+
* Automatically configures proxy and path aliases based on bgl.config.ts
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```ts
|
|
201
|
+
* import { defineConfig } from 'vite'
|
|
202
|
+
* import vue from '@vitejs/plugin-vue'
|
|
203
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
204
|
+
* import workspace from './bgl.config'
|
|
205
|
+
*
|
|
206
|
+
* export default defineConfig({
|
|
207
|
+
* plugins: [
|
|
208
|
+
* vue(),
|
|
209
|
+
* bagelink({ workspace })
|
|
210
|
+
* ]
|
|
211
|
+
* })
|
|
212
|
+
* ```
|
|
213
|
+
*
|
|
214
|
+
* @example With custom options
|
|
215
|
+
* ```ts
|
|
216
|
+
* import { defineConfig } from 'vite'
|
|
217
|
+
* import vue from '@vitejs/plugin-vue'
|
|
218
|
+
* import { bagelink } from '@bagelink/workspace/vite'
|
|
219
|
+
* import workspace from './bgl.config'
|
|
220
|
+
*
|
|
221
|
+
* export default defineConfig({
|
|
222
|
+
* plugins: [
|
|
223
|
+
* vue(),
|
|
224
|
+
* bagelink({
|
|
225
|
+
* workspace,
|
|
226
|
+
* sharedPath: '../packages/shared',
|
|
227
|
+
* additionalAliases: {
|
|
228
|
+
* '@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
|
|
229
|
+
* }
|
|
230
|
+
* })
|
|
231
|
+
* ]
|
|
232
|
+
* })
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function bagelink(options: {
|
|
236
|
+
workspace: (mode: WorkspaceEnvironment) => WorkspaceConfig;
|
|
237
|
+
config?: BagelinkPluginOptions;
|
|
238
|
+
}): Plugin;
|
|
239
|
+
|
|
123
240
|
/**
|
|
124
241
|
* Initialize a new workspace with flat structure
|
|
125
242
|
*/
|
|
@@ -165,5 +282,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
|
|
|
165
282
|
clearCache(): void;
|
|
166
283
|
};
|
|
167
284
|
|
|
168
|
-
export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, writeNetlifyConfig };
|
|
169
|
-
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
|
285
|
+
export { addProject, bagelink, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getApiUrl, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, useWorkspace, writeNetlifyConfig };
|
|
286
|
+
export type { BagelinkPluginOptions, ProxyConfig, RuntimeWorkspaceConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import { resolve, join } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
|
-
import { g as generateWorkspaceConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.
|
|
5
|
-
export { j as addProject, a as generateNetlifyConfig, b as generateNetlifyRedirect, f as generateSDK, h as generateSDKForWorkspace, c as generateWorkspaceConfigSync, d as getWorkspaceInfo, k as initWorkspace, i as isWorkspace, l as listProjects, r as runDev, e as setupLint } from './shared/workspace.
|
|
4
|
+
import { g as generateWorkspaceConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.PLrsjsJ2.mjs';
|
|
5
|
+
export { j as addProject, a as generateNetlifyConfig, b as generateNetlifyRedirect, f as generateSDK, h as generateSDKForWorkspace, c as generateWorkspaceConfigSync, d as getWorkspaceInfo, k as initWorkspace, i as isWorkspace, l as listProjects, r as runDev, e as setupLint } from './shared/workspace.PLrsjsJ2.mjs';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
6
7
|
import 'prompts';
|
|
7
8
|
import 'node:child_process';
|
|
8
9
|
|
|
@@ -100,6 +101,64 @@ function createCustomProxy(paths, target, options = {}) {
|
|
|
100
101
|
return proxy;
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
function useWorkspace() {
|
|
105
|
+
const proxy = import.meta.env.VITE_BGL_PROXY || "/api";
|
|
106
|
+
const host = import.meta.env.VITE_BGL_HOST || "";
|
|
107
|
+
const openapiUrl = import.meta.env.VITE_BGL_OPENAPI_URL;
|
|
108
|
+
const mode = import.meta.env.MODE || "development";
|
|
109
|
+
return {
|
|
110
|
+
proxy,
|
|
111
|
+
host,
|
|
112
|
+
openapiUrl,
|
|
113
|
+
mode
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function getApiUrl() {
|
|
117
|
+
const { host, proxy } = useWorkspace();
|
|
118
|
+
return `${host}${proxy}`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function bagelink(options) {
|
|
122
|
+
const { workspace, config = {} } = options;
|
|
123
|
+
let workspaceConfig;
|
|
124
|
+
return {
|
|
125
|
+
name: "vite-plugin-bagelink",
|
|
126
|
+
enforce: "pre",
|
|
127
|
+
configResolved(resolved) {
|
|
128
|
+
workspaceConfig = workspace(resolved.mode);
|
|
129
|
+
},
|
|
130
|
+
config(userConfig, { mode }) {
|
|
131
|
+
workspaceConfig = workspace(mode);
|
|
132
|
+
const alias = {};
|
|
133
|
+
if (config.includeSharedAlias !== false) {
|
|
134
|
+
const sharedPath = config.sharedPath ?? "../shared";
|
|
135
|
+
alias["@shared"] = fileURLToPath(new URL(sharedPath, `file://${process.cwd()}/`));
|
|
136
|
+
}
|
|
137
|
+
alias["@"] = fileURLToPath(new URL("./src", `file://${process.cwd()}/`));
|
|
138
|
+
if (config.additionalAliases) {
|
|
139
|
+
Object.assign(alias, config.additionalAliases);
|
|
140
|
+
}
|
|
141
|
+
const server = config.configureProxy !== false ? {
|
|
142
|
+
proxy: createViteProxy(workspaceConfig)
|
|
143
|
+
} : void 0;
|
|
144
|
+
const define = {
|
|
145
|
+
"import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy),
|
|
146
|
+
"import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
|
|
147
|
+
...workspaceConfig.openapi_url && {
|
|
148
|
+
"import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
resolve: {
|
|
153
|
+
alias
|
|
154
|
+
},
|
|
155
|
+
define,
|
|
156
|
+
...server && { server }
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
103
162
|
function defineWorkspace(configs) {
|
|
104
163
|
return (mode = "development") => {
|
|
105
164
|
return configs[mode] || configs.development;
|
|
@@ -144,4 +203,4 @@ function createWorkspace(options = {}) {
|
|
|
144
203
|
};
|
|
145
204
|
}
|
|
146
205
|
|
|
147
|
-
export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateWorkspaceConfig, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
206
|
+
export { bagelink, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateWorkspaceConfig, getApiUrl, mergeConfigs, resolveConfig, setBuildEnvVars, useWorkspace, writeNetlifyConfig };
|
|
@@ -12,7 +12,10 @@ const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
|
12
12
|
const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
|
|
13
13
|
|
|
14
14
|
function generateNetlifyRedirect(config) {
|
|
15
|
-
const redirect =
|
|
15
|
+
const redirect = `# API Proxy Configuration
|
|
16
|
+
# Environment variables are set in Netlify UI or netlify.toml [build.environment] section
|
|
17
|
+
|
|
18
|
+
[[redirects]]
|
|
16
19
|
from = "${config.proxy}/*"
|
|
17
20
|
to = "${config.host}/:splat"
|
|
18
21
|
status = 200
|
|
@@ -21,7 +24,36 @@ function generateNetlifyRedirect(config) {
|
|
|
21
24
|
`;
|
|
22
25
|
return redirect;
|
|
23
26
|
}
|
|
24
|
-
function
|
|
27
|
+
function generateNetlifyConfigTemplate() {
|
|
28
|
+
return `# Standard Netlify configuration for Bagelink projects
|
|
29
|
+
# Uses environment variables for proxy configuration
|
|
30
|
+
|
|
31
|
+
[build.environment]
|
|
32
|
+
# Set these in Netlify UI or override here
|
|
33
|
+
# BGL_PROXY_PATH = "/api"
|
|
34
|
+
# BGL_API_HOST = "https://your-project.bagel.to"
|
|
35
|
+
|
|
36
|
+
[[redirects]]
|
|
37
|
+
# Proxy API requests to backend
|
|
38
|
+
# Uses BGL_PROXY_PATH and BGL_API_HOST from environment
|
|
39
|
+
from = "/api/*"
|
|
40
|
+
to = "https://your-project.bagel.to/:splat"
|
|
41
|
+
status = 200
|
|
42
|
+
force = true
|
|
43
|
+
headers = {X-From = "Netlify"}
|
|
44
|
+
|
|
45
|
+
# Example: Multiple API backends
|
|
46
|
+
# [[redirects]]
|
|
47
|
+
# from = "/api/v2/*"
|
|
48
|
+
# to = "https://api-v2.example.com/:splat"
|
|
49
|
+
# status = 200
|
|
50
|
+
# force = true
|
|
51
|
+
`;
|
|
52
|
+
}
|
|
53
|
+
function generateNetlifyConfig(config, additionalConfig, useTemplate = false) {
|
|
54
|
+
if (useTemplate) {
|
|
55
|
+
return generateNetlifyConfigTemplate();
|
|
56
|
+
}
|
|
25
57
|
const redirect = generateNetlifyRedirect(config);
|
|
26
58
|
if (additionalConfig !== void 0 && additionalConfig !== "") {
|
|
27
59
|
return `${redirect}
|
|
@@ -29,11 +61,20 @@ ${additionalConfig}`;
|
|
|
29
61
|
}
|
|
30
62
|
return redirect;
|
|
31
63
|
}
|
|
32
|
-
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
|
|
33
|
-
const content = generateNetlifyConfig(config, additionalConfig);
|
|
64
|
+
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig, useTemplate = false) {
|
|
65
|
+
const content = generateNetlifyConfig(config, additionalConfig, useTemplate);
|
|
34
66
|
const resolvedPath = node_path.resolve(outPath);
|
|
35
67
|
node_fs.writeFileSync(resolvedPath, content, "utf-8");
|
|
36
68
|
console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
|
|
69
|
+
if (!useTemplate) {
|
|
70
|
+
console.log("\n\u{1F4A1} Tip: For environment-based config, set these in Netlify UI:");
|
|
71
|
+
console.log(` BGL_PROXY_PATH = "${config.proxy}"`);
|
|
72
|
+
console.log(` BGL_API_HOST = "${config.host}"`);
|
|
73
|
+
if (config.openapi_url) {
|
|
74
|
+
console.log(` BGL_OPENAPI_URL = "${config.openapi_url}"`);
|
|
75
|
+
}
|
|
76
|
+
console.log("");
|
|
77
|
+
}
|
|
37
78
|
}
|
|
38
79
|
function setBuildEnvVars(config) {
|
|
39
80
|
process__default.env.BGL_PROXY_PATH = config.proxy;
|
|
@@ -216,23 +257,29 @@ function updateViteConfig(root) {
|
|
|
216
257
|
console.log("\u2139\uFE0F vite.config.ts already configured");
|
|
217
258
|
return;
|
|
218
259
|
}
|
|
219
|
-
console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the
|
|
220
|
-
console.log("
|
|
260
|
+
console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the bagelink plugin:");
|
|
261
|
+
console.log("");
|
|
262
|
+
console.log(" import { bagelink } from '@bagelink/workspace/vite'");
|
|
263
|
+
console.log(" import workspace from './bgl.config'");
|
|
264
|
+
console.log("");
|
|
265
|
+
console.log(" plugins: [");
|
|
266
|
+
console.log(" vue(),");
|
|
267
|
+
console.log(" bagelink({ workspace }),");
|
|
268
|
+
console.log(" ]");
|
|
269
|
+
console.log("");
|
|
221
270
|
return;
|
|
222
271
|
}
|
|
223
272
|
const viteConfigContent = `import { defineConfig } from 'vite'
|
|
224
|
-
import
|
|
273
|
+
import vue from '@vitejs/plugin-vue'
|
|
274
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
225
275
|
import workspace from './bgl.config'
|
|
226
276
|
|
|
227
277
|
// https://vitejs.dev/config/
|
|
228
|
-
export default defineConfig(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
proxy: createViteProxy(config),
|
|
234
|
-
},
|
|
235
|
-
}
|
|
278
|
+
export default defineConfig({
|
|
279
|
+
plugins: [
|
|
280
|
+
vue(),
|
|
281
|
+
bagelink({ workspace }),
|
|
282
|
+
],
|
|
236
283
|
})
|
|
237
284
|
`;
|
|
238
285
|
node_fs.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
@@ -749,13 +796,27 @@ function createWorkspaceRoot(root, name, projectId) {
|
|
|
749
796
|
private: true,
|
|
750
797
|
workspaces: ["*", "!node_modules"],
|
|
751
798
|
scripts: {
|
|
752
|
-
dev: "
|
|
799
|
+
"dev": "bgl dev",
|
|
800
|
+
"dev:local": "bgl dev --mode localhost",
|
|
753
801
|
"dev:verbose": "bun run --filter './[!shared]*' dev",
|
|
754
|
-
build: "bun run --filter './[!shared]*' build",
|
|
755
|
-
typecheck: "tsc --noEmit"
|
|
802
|
+
"build": "bun run --filter './[!shared]*' build",
|
|
803
|
+
"typecheck": "tsc --noEmit",
|
|
804
|
+
"lint": "eslint . --cache",
|
|
805
|
+
"lint:fix": "eslint . --cache --fix"
|
|
806
|
+
},
|
|
807
|
+
dependencies: {
|
|
808
|
+
"@bagelink/auth": "latest",
|
|
809
|
+
"@bagelink/sdk": "latest",
|
|
810
|
+
"@bagelink/vue": "latest",
|
|
811
|
+
"pinia": "latest",
|
|
812
|
+
"vue": "latest",
|
|
813
|
+
"vue-router": "latest"
|
|
756
814
|
},
|
|
757
815
|
devDependencies: {
|
|
816
|
+
"@bagelink/lint-config": "latest",
|
|
758
817
|
"@bagelink/workspace": "latest",
|
|
818
|
+
"@vitejs/plugin-vue": "latest",
|
|
819
|
+
"eslint": "latest",
|
|
759
820
|
"typescript": "^5.0.0",
|
|
760
821
|
"vite": "latest"
|
|
761
822
|
}
|
|
@@ -986,18 +1047,14 @@ export default defineWorkspace({
|
|
|
986
1047
|
node_fs.writeFileSync(node_path.resolve(projectDir, "bgl.config.ts"), bglConfigContent);
|
|
987
1048
|
const viteConfig = `import { defineConfig } from 'vite'
|
|
988
1049
|
import vue from '@vitejs/plugin-vue'
|
|
989
|
-
import {
|
|
1050
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
990
1051
|
import workspace from './bgl.config'
|
|
991
1052
|
|
|
992
|
-
export default defineConfig(
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
server: {
|
|
998
|
-
proxy: createViteProxy(config),
|
|
999
|
-
},
|
|
1000
|
-
}
|
|
1053
|
+
export default defineConfig({
|
|
1054
|
+
plugins: [
|
|
1055
|
+
vue(),
|
|
1056
|
+
bagelink({ workspace }),
|
|
1057
|
+
],
|
|
1001
1058
|
})
|
|
1002
1059
|
`;
|
|
1003
1060
|
node_fs.writeFileSync(node_path.resolve(projectDir, "vite.config.ts"), viteConfig);
|
|
@@ -5,7 +5,10 @@ import prompts from 'prompts';
|
|
|
5
5
|
import { spawn } from 'node:child_process';
|
|
6
6
|
|
|
7
7
|
function generateNetlifyRedirect(config) {
|
|
8
|
-
const redirect =
|
|
8
|
+
const redirect = `# API Proxy Configuration
|
|
9
|
+
# Environment variables are set in Netlify UI or netlify.toml [build.environment] section
|
|
10
|
+
|
|
11
|
+
[[redirects]]
|
|
9
12
|
from = "${config.proxy}/*"
|
|
10
13
|
to = "${config.host}/:splat"
|
|
11
14
|
status = 200
|
|
@@ -14,7 +17,36 @@ function generateNetlifyRedirect(config) {
|
|
|
14
17
|
`;
|
|
15
18
|
return redirect;
|
|
16
19
|
}
|
|
17
|
-
function
|
|
20
|
+
function generateNetlifyConfigTemplate() {
|
|
21
|
+
return `# Standard Netlify configuration for Bagelink projects
|
|
22
|
+
# Uses environment variables for proxy configuration
|
|
23
|
+
|
|
24
|
+
[build.environment]
|
|
25
|
+
# Set these in Netlify UI or override here
|
|
26
|
+
# BGL_PROXY_PATH = "/api"
|
|
27
|
+
# BGL_API_HOST = "https://your-project.bagel.to"
|
|
28
|
+
|
|
29
|
+
[[redirects]]
|
|
30
|
+
# Proxy API requests to backend
|
|
31
|
+
# Uses BGL_PROXY_PATH and BGL_API_HOST from environment
|
|
32
|
+
from = "/api/*"
|
|
33
|
+
to = "https://your-project.bagel.to/:splat"
|
|
34
|
+
status = 200
|
|
35
|
+
force = true
|
|
36
|
+
headers = {X-From = "Netlify"}
|
|
37
|
+
|
|
38
|
+
# Example: Multiple API backends
|
|
39
|
+
# [[redirects]]
|
|
40
|
+
# from = "/api/v2/*"
|
|
41
|
+
# to = "https://api-v2.example.com/:splat"
|
|
42
|
+
# status = 200
|
|
43
|
+
# force = true
|
|
44
|
+
`;
|
|
45
|
+
}
|
|
46
|
+
function generateNetlifyConfig(config, additionalConfig, useTemplate = false) {
|
|
47
|
+
if (useTemplate) {
|
|
48
|
+
return generateNetlifyConfigTemplate();
|
|
49
|
+
}
|
|
18
50
|
const redirect = generateNetlifyRedirect(config);
|
|
19
51
|
if (additionalConfig !== void 0 && additionalConfig !== "") {
|
|
20
52
|
return `${redirect}
|
|
@@ -22,11 +54,20 @@ ${additionalConfig}`;
|
|
|
22
54
|
}
|
|
23
55
|
return redirect;
|
|
24
56
|
}
|
|
25
|
-
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
|
|
26
|
-
const content = generateNetlifyConfig(config, additionalConfig);
|
|
57
|
+
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig, useTemplate = false) {
|
|
58
|
+
const content = generateNetlifyConfig(config, additionalConfig, useTemplate);
|
|
27
59
|
const resolvedPath = resolve(outPath);
|
|
28
60
|
writeFileSync(resolvedPath, content, "utf-8");
|
|
29
61
|
console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
|
|
62
|
+
if (!useTemplate) {
|
|
63
|
+
console.log("\n\u{1F4A1} Tip: For environment-based config, set these in Netlify UI:");
|
|
64
|
+
console.log(` BGL_PROXY_PATH = "${config.proxy}"`);
|
|
65
|
+
console.log(` BGL_API_HOST = "${config.host}"`);
|
|
66
|
+
if (config.openapi_url) {
|
|
67
|
+
console.log(` BGL_OPENAPI_URL = "${config.openapi_url}"`);
|
|
68
|
+
}
|
|
69
|
+
console.log("");
|
|
70
|
+
}
|
|
30
71
|
}
|
|
31
72
|
function setBuildEnvVars(config) {
|
|
32
73
|
process.env.BGL_PROXY_PATH = config.proxy;
|
|
@@ -209,23 +250,29 @@ function updateViteConfig(root) {
|
|
|
209
250
|
console.log("\u2139\uFE0F vite.config.ts already configured");
|
|
210
251
|
return;
|
|
211
252
|
}
|
|
212
|
-
console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the
|
|
213
|
-
console.log("
|
|
253
|
+
console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the bagelink plugin:");
|
|
254
|
+
console.log("");
|
|
255
|
+
console.log(" import { bagelink } from '@bagelink/workspace/vite'");
|
|
256
|
+
console.log(" import workspace from './bgl.config'");
|
|
257
|
+
console.log("");
|
|
258
|
+
console.log(" plugins: [");
|
|
259
|
+
console.log(" vue(),");
|
|
260
|
+
console.log(" bagelink({ workspace }),");
|
|
261
|
+
console.log(" ]");
|
|
262
|
+
console.log("");
|
|
214
263
|
return;
|
|
215
264
|
}
|
|
216
265
|
const viteConfigContent = `import { defineConfig } from 'vite'
|
|
217
|
-
import
|
|
266
|
+
import vue from '@vitejs/plugin-vue'
|
|
267
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
218
268
|
import workspace from './bgl.config'
|
|
219
269
|
|
|
220
270
|
// https://vitejs.dev/config/
|
|
221
|
-
export default defineConfig(
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
proxy: createViteProxy(config),
|
|
227
|
-
},
|
|
228
|
-
}
|
|
271
|
+
export default defineConfig({
|
|
272
|
+
plugins: [
|
|
273
|
+
vue(),
|
|
274
|
+
bagelink({ workspace }),
|
|
275
|
+
],
|
|
229
276
|
})
|
|
230
277
|
`;
|
|
231
278
|
writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
@@ -742,13 +789,27 @@ function createWorkspaceRoot(root, name, projectId) {
|
|
|
742
789
|
private: true,
|
|
743
790
|
workspaces: ["*", "!node_modules"],
|
|
744
791
|
scripts: {
|
|
745
|
-
dev: "
|
|
792
|
+
"dev": "bgl dev",
|
|
793
|
+
"dev:local": "bgl dev --mode localhost",
|
|
746
794
|
"dev:verbose": "bun run --filter './[!shared]*' dev",
|
|
747
|
-
build: "bun run --filter './[!shared]*' build",
|
|
748
|
-
typecheck: "tsc --noEmit"
|
|
795
|
+
"build": "bun run --filter './[!shared]*' build",
|
|
796
|
+
"typecheck": "tsc --noEmit",
|
|
797
|
+
"lint": "eslint . --cache",
|
|
798
|
+
"lint:fix": "eslint . --cache --fix"
|
|
799
|
+
},
|
|
800
|
+
dependencies: {
|
|
801
|
+
"@bagelink/auth": "latest",
|
|
802
|
+
"@bagelink/sdk": "latest",
|
|
803
|
+
"@bagelink/vue": "latest",
|
|
804
|
+
"pinia": "latest",
|
|
805
|
+
"vue": "latest",
|
|
806
|
+
"vue-router": "latest"
|
|
749
807
|
},
|
|
750
808
|
devDependencies: {
|
|
809
|
+
"@bagelink/lint-config": "latest",
|
|
751
810
|
"@bagelink/workspace": "latest",
|
|
811
|
+
"@vitejs/plugin-vue": "latest",
|
|
812
|
+
"eslint": "latest",
|
|
752
813
|
"typescript": "^5.0.0",
|
|
753
814
|
"vite": "latest"
|
|
754
815
|
}
|
|
@@ -979,18 +1040,14 @@ export default defineWorkspace({
|
|
|
979
1040
|
writeFileSync(resolve(projectDir, "bgl.config.ts"), bglConfigContent);
|
|
980
1041
|
const viteConfig = `import { defineConfig } from 'vite'
|
|
981
1042
|
import vue from '@vitejs/plugin-vue'
|
|
982
|
-
import {
|
|
1043
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
983
1044
|
import workspace from './bgl.config'
|
|
984
1045
|
|
|
985
|
-
export default defineConfig(
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
server: {
|
|
991
|
-
proxy: createViteProxy(config),
|
|
992
|
-
},
|
|
993
|
-
}
|
|
1046
|
+
export default defineConfig({
|
|
1047
|
+
plugins: [
|
|
1048
|
+
vue(),
|
|
1049
|
+
bagelink({ workspace }),
|
|
1050
|
+
],
|
|
994
1051
|
})
|
|
995
1052
|
`;
|
|
996
1053
|
writeFileSync(resolve(projectDir, "vite.config.ts"), viteConfig);
|
package/env.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Type definitions for Bagelink workspace environment variables
|
|
5
|
+
* These are injected by the bagelink Vite plugin at build time
|
|
6
|
+
*/
|
|
7
|
+
interface ImportMetaEnv {
|
|
8
|
+
/**
|
|
9
|
+
* API proxy path (e.g., '/api')
|
|
10
|
+
* Injected from bgl.config.ts
|
|
11
|
+
*/
|
|
12
|
+
readonly VITE_BGL_PROXY: string
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* API host URL (e.g., 'https://project.bagel.to')
|
|
16
|
+
* Injected from bgl.config.ts
|
|
17
|
+
*/
|
|
18
|
+
readonly VITE_BGL_HOST: string
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* OpenAPI specification URL (optional)
|
|
22
|
+
* Injected from bgl.config.ts if configured
|
|
23
|
+
*/
|
|
24
|
+
readonly VITE_BGL_OPENAPI_URL?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface ImportMeta {
|
|
28
|
+
readonly env: ImportMetaEnv
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/workspace",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.35",
|
|
5
5
|
"description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bagel Studio",
|
|
@@ -31,6 +31,11 @@
|
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
32
|
"require": "./dist/index.cjs",
|
|
33
33
|
"import": "./dist/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./vite": {
|
|
36
|
+
"types": "./dist/vite.d.ts",
|
|
37
|
+
"require": "./dist/vite.cjs",
|
|
38
|
+
"import": "./dist/vite.mjs"
|
|
34
39
|
}
|
|
35
40
|
},
|
|
36
41
|
"main": "./dist/index.mjs",
|
|
@@ -44,6 +49,7 @@
|
|
|
44
49
|
"src",
|
|
45
50
|
"bin",
|
|
46
51
|
"templates",
|
|
52
|
+
"env.d.ts",
|
|
47
53
|
"README.md"
|
|
48
54
|
],
|
|
49
55
|
"publishConfig": {
|