@bagelink/workspace 1.7.31 → 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/README.md
CHANGED
|
@@ -79,7 +79,66 @@ export default defineWorkspace(configs)
|
|
|
79
79
|
|
|
80
80
|
## Usage
|
|
81
81
|
|
|
82
|
-
### 1.
|
|
82
|
+
### 1. Add Type Definitions
|
|
83
|
+
|
|
84
|
+
Add to your project's `env.d.ts`:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
/// <reference types="@bagelink/workspace/env" />
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
This provides TypeScript types for injected environment variables.
|
|
91
|
+
|
|
92
|
+
### 2. Configure Vite (`vite.config.ts`)
|
|
93
|
+
|
|
94
|
+
**Recommended: Use the Vite plugin (keeps your config clean and standard)**
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { defineConfig } from 'vite'
|
|
98
|
+
import vue from '@vitejs/plugin-vue'
|
|
99
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
100
|
+
import workspace from './bgl.config'
|
|
101
|
+
|
|
102
|
+
export default defineConfig({
|
|
103
|
+
plugins: [
|
|
104
|
+
vue(),
|
|
105
|
+
bagelink({ workspace }),
|
|
106
|
+
],
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
The plugin automatically:
|
|
111
|
+
- Configures proxy based on `bgl.config.ts`
|
|
112
|
+
- Sets up `@` alias pointing to `./src`
|
|
113
|
+
- Sets up `@shared` alias (in monorepos)
|
|
114
|
+
- Keeps your vite.config.ts clean and extensible
|
|
115
|
+
|
|
116
|
+
**Advanced: Custom options**
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
import { defineConfig } from 'vite'
|
|
120
|
+
import vue from '@vitejs/plugin-vue'
|
|
121
|
+
import { bagelink } from '@bagelink/workspace/vite'
|
|
122
|
+
import { fileURLToPath } from 'node:url'
|
|
123
|
+
import workspace from './bgl.config'
|
|
124
|
+
|
|
125
|
+
export default defineConfig({
|
|
126
|
+
plugins: [
|
|
127
|
+
vue(),
|
|
128
|
+
bagelink({
|
|
129
|
+
workspace,
|
|
130
|
+
config: {
|
|
131
|
+
sharedPath: '../packages/shared',
|
|
132
|
+
additionalAliases: {
|
|
133
|
+
'@utils': fileURLToPath(new URL('./src/utils', import.meta.url))
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}),
|
|
137
|
+
],
|
|
138
|
+
})
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**Legacy: Manual proxy setup**
|
|
83
142
|
|
|
84
143
|
```typescript
|
|
85
144
|
import { defineConfig } from 'vite'
|
|
@@ -98,7 +157,47 @@ export default defineConfig(({ mode }) => {
|
|
|
98
157
|
})
|
|
99
158
|
```
|
|
100
159
|
|
|
101
|
-
###
|
|
160
|
+
### 3. Use Configuration in Your App
|
|
161
|
+
|
|
162
|
+
**Access config at runtime with `useWorkspace()`:**
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { useWorkspace } from '@bagelink/workspace'
|
|
166
|
+
|
|
167
|
+
// In your app setup
|
|
168
|
+
const { proxy, host, mode } = useWorkspace()
|
|
169
|
+
const auth = initAuth({ baseURL: proxy })
|
|
170
|
+
|
|
171
|
+
// Or get full API URL
|
|
172
|
+
import { getApiUrl } from '@bagelink/workspace'
|
|
173
|
+
const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Vue component example:**
|
|
177
|
+
|
|
178
|
+
```vue
|
|
179
|
+
<script setup lang="ts">
|
|
180
|
+
import { useWorkspace } from '@bagelink/workspace'
|
|
181
|
+
import { initAuth } from '@bagelink/auth'
|
|
182
|
+
|
|
183
|
+
const { proxy, host, mode } = useWorkspace()
|
|
184
|
+
const auth = initAuth({ baseURL: proxy })
|
|
185
|
+
|
|
186
|
+
console.log('API Host:', host)
|
|
187
|
+
console.log('Environment:', mode)
|
|
188
|
+
</script>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Access raw environment variables:**
|
|
192
|
+
|
|
193
|
+
```typescript
|
|
194
|
+
// These are injected at build time by the bagelink plugin
|
|
195
|
+
const proxy = import.meta.env.VITE_BGL_PROXY // '/api'
|
|
196
|
+
const host = import.meta.env.VITE_BGL_HOST // 'https://project.bagel.to'
|
|
197
|
+
const openapi = import.meta.env.VITE_BGL_OPENAPI_URL // optional
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### 4. Add scripts to `package.json`
|
|
102
201
|
|
|
103
202
|
```json
|
|
104
203
|
{
|
|
@@ -110,7 +209,7 @@ export default defineConfig(({ mode }) => {
|
|
|
110
209
|
}
|
|
111
210
|
```
|
|
112
211
|
|
|
113
|
-
###
|
|
212
|
+
### 5. Generate Netlify Config
|
|
114
213
|
|
|
115
214
|
```typescript
|
|
116
215
|
import { writeNetlifyConfig } from '@bagelink/workspace'
|
|
@@ -409,7 +508,41 @@ Show CLI help.
|
|
|
409
508
|
|
|
410
509
|
## API
|
|
411
510
|
|
|
412
|
-
###
|
|
511
|
+
### Runtime Functions
|
|
512
|
+
|
|
513
|
+
#### `useWorkspace()`
|
|
514
|
+
|
|
515
|
+
Get workspace configuration at runtime. Config is injected as environment variables during build.
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
import { useWorkspace } from '@bagelink/workspace'
|
|
519
|
+
|
|
520
|
+
const { proxy, host, openapiUrl, mode } = useWorkspace()
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
**Returns:**
|
|
524
|
+
```typescript
|
|
525
|
+
interface RuntimeWorkspaceConfig {
|
|
526
|
+
proxy: string // '/api'
|
|
527
|
+
host: string // 'https://project.bagel.to'
|
|
528
|
+
openapiUrl?: string // optional
|
|
529
|
+
mode: 'localhost' | 'development' | 'production'
|
|
530
|
+
}
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
#### `getApiUrl()`
|
|
534
|
+
|
|
535
|
+
Get the full API URL by combining host and proxy.
|
|
536
|
+
|
|
537
|
+
```typescript
|
|
538
|
+
import { getApiUrl } from '@bagelink/workspace'
|
|
539
|
+
|
|
540
|
+
const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
### Configuration Functions
|
|
544
|
+
|
|
545
|
+
#### `defineWorkspace(configs)`
|
|
413
546
|
|
|
414
547
|
Define workspace configuration for all environments.
|
|
415
548
|
|
package/bin/bgl.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'node:path'
|
|
2
3
|
import process from 'node:process'
|
|
3
4
|
import { isWorkspace } from '../src/detect.js'
|
|
4
5
|
import { runDev } from '../src/dev.js'
|
|
@@ -17,11 +18,19 @@ async function main() {
|
|
|
17
18
|
|| subcommand === '-w'
|
|
18
19
|
|| args.includes('--workspace')
|
|
19
20
|
|| args.includes('-w')
|
|
21
|
+
|
|
22
|
+
// Support 'bgl init .' or 'bgl init <path>'
|
|
23
|
+
let targetPath = process.cwd()
|
|
24
|
+
if (subcommand && !subcommand.startsWith('-')) {
|
|
25
|
+
// If subcommand is not a flag, treat it as a path
|
|
26
|
+
targetPath = subcommand === '.' ? process.cwd() : resolve(process.cwd(), subcommand)
|
|
27
|
+
}
|
|
28
|
+
|
|
20
29
|
if (createWorkspace) {
|
|
21
30
|
await initWorkspace()
|
|
22
31
|
}
|
|
23
32
|
else {
|
|
24
|
-
await generateWorkspaceConfig()
|
|
33
|
+
await generateWorkspaceConfig(targetPath)
|
|
25
34
|
}
|
|
26
35
|
}
|
|
27
36
|
else if (command === 'add') {
|
|
@@ -110,7 +119,8 @@ SDK Commands:
|
|
|
110
119
|
Bagel Workspace CLI
|
|
111
120
|
|
|
112
121
|
Usage:
|
|
113
|
-
bgl init
|
|
122
|
+
bgl init [path] Generate bgl.config.ts for single project
|
|
123
|
+
Examples: bgl init, bgl init ., bgl init ./my-app
|
|
114
124
|
bgl init --workspace Create a new workspace with multiple projects
|
|
115
125
|
bgl add <name> Add a new project to workspace
|
|
116
126
|
bgl list List all projects in workspace
|
package/dist/bin/bgl.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
const node_path = require('node:path');
|
|
4
5
|
const process = require('node:process');
|
|
5
|
-
const workspace = require('../shared/workspace.
|
|
6
|
+
const workspace = require('../shared/workspace.CamNrnD_.cjs');
|
|
6
7
|
require('node:fs');
|
|
7
|
-
require('node:path');
|
|
8
8
|
require('prompts');
|
|
9
9
|
require('node:child_process');
|
|
10
10
|
|
|
@@ -16,10 +16,14 @@ const [, , command, subcommand, ...args] = process__default.argv;
|
|
|
16
16
|
async function main() {
|
|
17
17
|
if (command === "init") {
|
|
18
18
|
const createWorkspace = subcommand === "--workspace" || subcommand === "-w" || args.includes("--workspace") || args.includes("-w");
|
|
19
|
+
let targetPath = process__default.cwd();
|
|
20
|
+
if (subcommand && !subcommand.startsWith("-")) {
|
|
21
|
+
targetPath = subcommand === "." ? process__default.cwd() : node_path.resolve(process__default.cwd(), subcommand);
|
|
22
|
+
}
|
|
19
23
|
if (createWorkspace) {
|
|
20
24
|
await workspace.initWorkspace();
|
|
21
25
|
} else {
|
|
22
|
-
await workspace.generateWorkspaceConfig();
|
|
26
|
+
await workspace.generateWorkspaceConfig(targetPath);
|
|
23
27
|
}
|
|
24
28
|
} else if (command === "add") {
|
|
25
29
|
const projectName = subcommand;
|
|
@@ -92,7 +96,8 @@ SDK Commands:
|
|
|
92
96
|
Bagel Workspace CLI
|
|
93
97
|
|
|
94
98
|
Usage:
|
|
95
|
-
bgl init
|
|
99
|
+
bgl init [path] Generate bgl.config.ts for single project
|
|
100
|
+
Examples: bgl init, bgl init ., bgl init ./my-app
|
|
96
101
|
bgl init --workspace Create a new workspace with multiple projects
|
|
97
102
|
bgl add <name> Add a new project to workspace
|
|
98
103
|
bgl list List all projects in workspace
|
package/dist/bin/bgl.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { resolve } from 'node:path';
|
|
2
3
|
import process from 'node:process';
|
|
3
|
-
import { k as initWorkspace, g as generateWorkspaceConfig, j as addProject, l as listProjects, i as isWorkspace, e as setupLint, h as generateSDKForWorkspace, f as generateSDK, r as runDev } from '../shared/workspace.
|
|
4
|
+
import { k as initWorkspace, g as generateWorkspaceConfig, j as addProject, l as listProjects, i as isWorkspace, e as setupLint, h as generateSDKForWorkspace, f as generateSDK, r as runDev } from '../shared/workspace.PLrsjsJ2.mjs';
|
|
4
5
|
import 'node:fs';
|
|
5
|
-
import 'node:path';
|
|
6
6
|
import 'prompts';
|
|
7
7
|
import 'node:child_process';
|
|
8
8
|
|
|
@@ -10,10 +10,14 @@ const [, , command, subcommand, ...args] = process.argv;
|
|
|
10
10
|
async function main() {
|
|
11
11
|
if (command === "init") {
|
|
12
12
|
const createWorkspace = subcommand === "--workspace" || subcommand === "-w" || args.includes("--workspace") || args.includes("-w");
|
|
13
|
+
let targetPath = process.cwd();
|
|
14
|
+
if (subcommand && !subcommand.startsWith("-")) {
|
|
15
|
+
targetPath = subcommand === "." ? process.cwd() : resolve(process.cwd(), subcommand);
|
|
16
|
+
}
|
|
13
17
|
if (createWorkspace) {
|
|
14
18
|
await initWorkspace();
|
|
15
19
|
} else {
|
|
16
|
-
await generateWorkspaceConfig();
|
|
20
|
+
await generateWorkspaceConfig(targetPath);
|
|
17
21
|
}
|
|
18
22
|
} else if (command === "add") {
|
|
19
23
|
const projectName = subcommand;
|
|
@@ -86,7 +90,8 @@ SDK Commands:
|
|
|
86
90
|
Bagel Workspace CLI
|
|
87
91
|
|
|
88
92
|
Usage:
|
|
89
|
-
bgl init
|
|
93
|
+
bgl init [path] Generate bgl.config.ts for single project
|
|
94
|
+
Examples: bgl init, bgl init ., bgl init ./my-app
|
|
90
95
|
bgl init --workspace Create a new workspace with multiple projects
|
|
91
96
|
bgl add <name> Add a new project to workspace
|
|
92
97
|
bgl list List all projects in workspace
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
const node_fs = require('node:fs');
|
|
4
4
|
const node_path = require('node:path');
|
|
5
5
|
const process = require('node:process');
|
|
6
|
-
const workspace = require('./shared/workspace.
|
|
6
|
+
const workspace = require('./shared/workspace.CamNrnD_.cjs');
|
|
7
|
+
const node_url = require('node:url');
|
|
7
8
|
require('prompts');
|
|
8
9
|
require('node:child_process');
|
|
9
10
|
|
|
@@ -105,6 +106,64 @@ function createCustomProxy(paths, target, options = {}) {
|
|
|
105
106
|
return proxy;
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
function useWorkspace() {
|
|
110
|
+
const proxy = undefined.VITE_BGL_PROXY || "/api";
|
|
111
|
+
const host = undefined.VITE_BGL_HOST || "";
|
|
112
|
+
const openapiUrl = undefined.VITE_BGL_OPENAPI_URL;
|
|
113
|
+
const mode = undefined.MODE || "development";
|
|
114
|
+
return {
|
|
115
|
+
proxy,
|
|
116
|
+
host,
|
|
117
|
+
openapiUrl,
|
|
118
|
+
mode
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function getApiUrl() {
|
|
122
|
+
const { host, proxy } = useWorkspace();
|
|
123
|
+
return `${host}${proxy}`;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function bagelink(options) {
|
|
127
|
+
const { workspace, config = {} } = options;
|
|
128
|
+
let workspaceConfig;
|
|
129
|
+
return {
|
|
130
|
+
name: "vite-plugin-bagelink",
|
|
131
|
+
enforce: "pre",
|
|
132
|
+
configResolved(resolved) {
|
|
133
|
+
workspaceConfig = workspace(resolved.mode);
|
|
134
|
+
},
|
|
135
|
+
config(userConfig, { mode }) {
|
|
136
|
+
workspaceConfig = workspace(mode);
|
|
137
|
+
const alias = {};
|
|
138
|
+
if (config.includeSharedAlias !== false) {
|
|
139
|
+
const sharedPath = config.sharedPath ?? "../shared";
|
|
140
|
+
alias["@shared"] = node_url.fileURLToPath(new URL(sharedPath, `file://${process__default.cwd()}/`));
|
|
141
|
+
}
|
|
142
|
+
alias["@"] = node_url.fileURLToPath(new URL("./src", `file://${process__default.cwd()}/`));
|
|
143
|
+
if (config.additionalAliases) {
|
|
144
|
+
Object.assign(alias, config.additionalAliases);
|
|
145
|
+
}
|
|
146
|
+
const server = config.configureProxy !== false ? {
|
|
147
|
+
proxy: createViteProxy(workspaceConfig)
|
|
148
|
+
} : void 0;
|
|
149
|
+
const define = {
|
|
150
|
+
"import.meta.env.VITE_BGL_PROXY": JSON.stringify(workspaceConfig.proxy),
|
|
151
|
+
"import.meta.env.VITE_BGL_HOST": JSON.stringify(workspaceConfig.host),
|
|
152
|
+
...workspaceConfig.openapi_url && {
|
|
153
|
+
"import.meta.env.VITE_BGL_OPENAPI_URL": JSON.stringify(workspaceConfig.openapi_url)
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
return {
|
|
157
|
+
resolve: {
|
|
158
|
+
alias
|
|
159
|
+
},
|
|
160
|
+
define,
|
|
161
|
+
...server && { server }
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
108
167
|
function defineWorkspace(configs) {
|
|
109
168
|
return (mode = "development") => {
|
|
110
169
|
return configs[mode] || configs.development;
|
|
@@ -164,9 +223,12 @@ exports.runDev = workspace.runDev;
|
|
|
164
223
|
exports.setBuildEnvVars = workspace.setBuildEnvVars;
|
|
165
224
|
exports.setupLint = workspace.setupLint;
|
|
166
225
|
exports.writeNetlifyConfig = workspace.writeNetlifyConfig;
|
|
226
|
+
exports.bagelink = bagelink;
|
|
167
227
|
exports.createCustomProxy = createCustomProxy;
|
|
168
228
|
exports.createViteProxy = createViteProxy;
|
|
169
229
|
exports.createWorkspace = createWorkspace;
|
|
170
230
|
exports.defineWorkspace = defineWorkspace;
|
|
231
|
+
exports.getApiUrl = getApiUrl;
|
|
171
232
|
exports.mergeConfigs = mergeConfigs;
|
|
172
233
|
exports.resolveConfig = resolveConfig;
|
|
234
|
+
exports.useWorkspace = useWorkspace;
|
package/dist/index.d.cts
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.d.mts
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 };
|