@bagelink/workspace 1.7.33 → 1.7.37
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 +23 -35
- package/dist/index.d.cts +56 -46
- package/dist/index.d.mts +56 -46
- package/dist/index.d.ts +56 -46
- package/dist/index.mjs +20 -34
- package/dist/shared/workspace.CSNgk3PR.d.cts +113 -0
- package/dist/shared/workspace.CSNgk3PR.d.mts +113 -0
- package/dist/shared/workspace.CSNgk3PR.d.ts +113 -0
- package/dist/shared/{workspace.OuHxYc4s.cjs → workspace.CamNrnD_.cjs} +85 -28
- package/dist/shared/workspace.D0MF8ERh.mjs +79 -0
- package/dist/shared/workspace.DfLGMczD.cjs +87 -0
- package/dist/shared/{workspace.CcKgYZPx.mjs → workspace.PLrsjsJ2.mjs} +85 -28
- package/dist/vite.cjs +9 -0
- package/dist/vite.d.cts +2 -0
- package/dist/vite.d.mts +2 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.mjs +3 -0
- package/env.d.ts +29 -0
- package/package.json +9 -2
- 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
|
@@ -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);
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
function createViteProxy(config) {
|
|
5
|
+
const proxy = {};
|
|
6
|
+
if (config.proxy && config.host) {
|
|
7
|
+
proxy[config.proxy] = {
|
|
8
|
+
target: config.host,
|
|
9
|
+
changeOrigin: true,
|
|
10
|
+
rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
|
|
11
|
+
secure: true
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
if (config.host) {
|
|
15
|
+
proxy["/files"] = {
|
|
16
|
+
target: config.host,
|
|
17
|
+
changeOrigin: true,
|
|
18
|
+
secure: true
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return proxy;
|
|
22
|
+
}
|
|
23
|
+
function createCustomProxy(paths, target, options = {}) {
|
|
24
|
+
const proxy = {};
|
|
25
|
+
for (const path of paths) {
|
|
26
|
+
proxy[path] = {
|
|
27
|
+
target,
|
|
28
|
+
changeOrigin: options.changeOrigin ?? true,
|
|
29
|
+
secure: options.secure ?? true,
|
|
30
|
+
...options.rewrite === true && {
|
|
31
|
+
rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return proxy;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function bagelink(options) {
|
|
39
|
+
const { workspace, config = {} } = options;
|
|
40
|
+
let workspaceConfig;
|
|
41
|
+
return {
|
|
42
|
+
name: "vite-plugin-bagelink",
|
|
43
|
+
enforce: "pre",
|
|
44
|
+
configResolved(resolved) {
|
|
45
|
+
workspaceConfig = workspace(resolved.mode);
|
|
46
|
+
},
|
|
47
|
+
config(userConfig, { mode }) {
|
|
48
|
+
workspaceConfig = workspace(mode);
|
|
49
|
+
const alias = {};
|
|
50
|
+
if (config.includeSharedAlias !== false) {
|
|
51
|
+
const sharedPath = config.sharedPath ?? "../shared";
|
|
52
|
+
alias["@shared"] = fileURLToPath(new URL(sharedPath, `file://${process.cwd()}/`));
|
|
53
|
+
}
|
|
54
|
+
alias["@"] = fileURLToPath(new URL("./src", `file://${process.cwd()}/`));
|
|
55
|
+
if (config.additionalAliases) {
|
|
56
|
+
Object.assign(alias, config.additionalAliases);
|
|
57
|
+
}
|
|
58
|
+
const server = config.configureProxy !== false ? {
|
|
59
|
+
proxy: createViteProxy(workspaceConfig)
|
|
60
|
+
} : void 0;
|
|
61
|
+
const define = {
|
|
62
|
+
"import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy),
|
|
63
|
+
"import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
|
|
64
|
+
...workspaceConfig.openapi_url && {
|
|
65
|
+
"import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
resolve: {
|
|
70
|
+
alias
|
|
71
|
+
},
|
|
72
|
+
define,
|
|
73
|
+
...server && { server }
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export { createCustomProxy as a, bagelink as b, createViteProxy as c };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const node_url = require('node:url');
|
|
5
|
+
|
|
6
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
7
|
+
|
|
8
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
9
|
+
|
|
10
|
+
function createViteProxy(config) {
|
|
11
|
+
const proxy = {};
|
|
12
|
+
if (config.proxy && config.host) {
|
|
13
|
+
proxy[config.proxy] = {
|
|
14
|
+
target: config.host,
|
|
15
|
+
changeOrigin: true,
|
|
16
|
+
rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
|
|
17
|
+
secure: true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
if (config.host) {
|
|
21
|
+
proxy["/files"] = {
|
|
22
|
+
target: config.host,
|
|
23
|
+
changeOrigin: true,
|
|
24
|
+
secure: true
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return proxy;
|
|
28
|
+
}
|
|
29
|
+
function createCustomProxy(paths, target, options = {}) {
|
|
30
|
+
const proxy = {};
|
|
31
|
+
for (const path of paths) {
|
|
32
|
+
proxy[path] = {
|
|
33
|
+
target,
|
|
34
|
+
changeOrigin: options.changeOrigin ?? true,
|
|
35
|
+
secure: options.secure ?? true,
|
|
36
|
+
...options.rewrite === true && {
|
|
37
|
+
rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return proxy;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function bagelink(options) {
|
|
45
|
+
const { workspace, config = {} } = options;
|
|
46
|
+
let workspaceConfig;
|
|
47
|
+
return {
|
|
48
|
+
name: "vite-plugin-bagelink",
|
|
49
|
+
enforce: "pre",
|
|
50
|
+
configResolved(resolved) {
|
|
51
|
+
workspaceConfig = workspace(resolved.mode);
|
|
52
|
+
},
|
|
53
|
+
config(userConfig, { mode }) {
|
|
54
|
+
workspaceConfig = workspace(mode);
|
|
55
|
+
const alias = {};
|
|
56
|
+
if (config.includeSharedAlias !== false) {
|
|
57
|
+
const sharedPath = config.sharedPath ?? "../shared";
|
|
58
|
+
alias["@shared"] = node_url.fileURLToPath(new URL(sharedPath, `file://${process__default.cwd()}/`));
|
|
59
|
+
}
|
|
60
|
+
alias["@"] = node_url.fileURLToPath(new URL("./src", `file://${process__default.cwd()}/`));
|
|
61
|
+
if (config.additionalAliases) {
|
|
62
|
+
Object.assign(alias, config.additionalAliases);
|
|
63
|
+
}
|
|
64
|
+
const server = config.configureProxy !== false ? {
|
|
65
|
+
proxy: createViteProxy(workspaceConfig)
|
|
66
|
+
} : void 0;
|
|
67
|
+
const define = {
|
|
68
|
+
"import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy),
|
|
69
|
+
"import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
|
|
70
|
+
...workspaceConfig.openapi_url && {
|
|
71
|
+
"import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
return {
|
|
75
|
+
resolve: {
|
|
76
|
+
alias
|
|
77
|
+
},
|
|
78
|
+
define,
|
|
79
|
+
...server && { server }
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.bagelink = bagelink;
|
|
86
|
+
exports.createCustomProxy = createCustomProxy;
|
|
87
|
+
exports.createViteProxy = createViteProxy;
|
|
@@ -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/dist/vite.cjs
ADDED
package/dist/vite.d.cts
ADDED
package/dist/vite.d.mts
ADDED
package/dist/vite.d.ts
ADDED
package/dist/vite.mjs
ADDED
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.37",
|
|
5
5
|
"description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Bagel Studio",
|
|
@@ -31,7 +31,13 @@
|
|
|
31
31
|
"types": "./dist/index.d.ts",
|
|
32
32
|
"require": "./dist/index.cjs",
|
|
33
33
|
"import": "./dist/index.mjs"
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
|
+
"./vite": {
|
|
36
|
+
"types": "./dist/vite.d.ts",
|
|
37
|
+
"require": "./dist/vite.cjs",
|
|
38
|
+
"import": "./dist/vite.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./env": "./env.d.ts"
|
|
35
41
|
},
|
|
36
42
|
"main": "./dist/index.mjs",
|
|
37
43
|
"module": "./dist/index.mjs",
|
|
@@ -44,6 +50,7 @@
|
|
|
44
50
|
"src",
|
|
45
51
|
"bin",
|
|
46
52
|
"templates",
|
|
53
|
+
"env.d.ts",
|
|
47
54
|
"README.md"
|
|
48
55
|
],
|
|
49
56
|
"publishConfig": {
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime workspace configuration
|
|
3
|
+
* Provides access to workspace config injected at build time
|
|
4
|
+
*/
|
|
5
|
+
export interface RuntimeWorkspaceConfig {
|
|
6
|
+
/** API proxy path (e.g., '/api') */
|
|
7
|
+
proxy: string
|
|
8
|
+
/** API host URL (e.g., 'https://project.bagel.to') */
|
|
9
|
+
host: string
|
|
10
|
+
/** OpenAPI specification URL (if configured) */
|
|
11
|
+
openapiUrl?: string
|
|
12
|
+
/** Current environment mode */
|
|
13
|
+
mode: 'localhost' | 'development' | 'production'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get workspace configuration at runtime
|
|
18
|
+
* Config is injected as environment variables during build
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { useWorkspace } from '@bagelink/workspace'
|
|
23
|
+
*
|
|
24
|
+
* const { proxy, host } = useWorkspace()
|
|
25
|
+
* const auth = initAuth({ baseURL: proxy })
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @example In Vue component
|
|
29
|
+
* ```vue
|
|
30
|
+
* <script setup>
|
|
31
|
+
* import { useWorkspace } from '@bagelink/workspace'
|
|
32
|
+
*
|
|
33
|
+
* const { proxy, host, mode } = useWorkspace()
|
|
34
|
+
* </script>
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export function useWorkspace(): RuntimeWorkspaceConfig {
|
|
38
|
+
// Access env variables injected by the Vite plugin
|
|
39
|
+
const proxy = import.meta.env.VITE_BGL_PROXY || '/api'
|
|
40
|
+
const host = import.meta.env.VITE_BGL_HOST || ''
|
|
41
|
+
const openapiUrl = import.meta.env.VITE_BGL_OPENAPI_URL
|
|
42
|
+
const mode = (import.meta.env.MODE as RuntimeWorkspaceConfig['mode']) || 'development'
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
proxy,
|
|
46
|
+
host,
|
|
47
|
+
openapiUrl,
|
|
48
|
+
mode,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get the full API URL by combining host and proxy
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { getApiUrl } from '@bagelink/workspace'
|
|
58
|
+
*
|
|
59
|
+
* const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function getApiUrl(): string {
|
|
63
|
+
const { host, proxy } = useWorkspace()
|
|
64
|
+
return `${host}${proxy}`
|
|
65
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -34,10 +34,14 @@ export {
|
|
|
34
34
|
writeNetlifyConfig,
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
export { getApiUrl, useWorkspace } from './composable'
|
|
38
|
+
export type { RuntimeWorkspaceConfig } from './composable'
|
|
37
39
|
export { getWorkspaceInfo, isWorkspace } from './detect'
|
|
38
40
|
export { runDev } from './dev'
|
|
39
41
|
export { setupLint } from './lint'
|
|
40
42
|
export { generateSDK, generateSDKForWorkspace } from './sdk'
|
|
43
|
+
export { bagelink } from './vite'
|
|
44
|
+
export type { BagelinkPluginOptions } from './vite'
|
|
41
45
|
export { addProject, initWorkspace, listProjects } from './workspace'
|
|
42
46
|
|
|
43
47
|
/**
|