@bagelink/workspace 1.10.6 → 1.10.9

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.
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ function useWorkspace() {
4
+ const proxy = undefined.VITE_BGL_PROXY || void 0;
5
+ const host = undefined.VITE_BGL_HOST || "";
6
+ const openapiUrl = undefined.VITE_BGL_OPENAPI_URL;
7
+ const mode = undefined.MODE || "development";
8
+ return {
9
+ proxy,
10
+ host,
11
+ baseURL: proxy ?? host,
12
+ openapiUrl,
13
+ mode
14
+ };
15
+ }
16
+ function getApiUrl() {
17
+ const { host, proxy } = useWorkspace();
18
+ return `${host}${proxy}`;
19
+ }
20
+
21
+ exports.getApiUrl = getApiUrl;
22
+ exports.useWorkspace = useWorkspace;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Runtime workspace configuration
3
+ * Provides access to workspace config injected at build time
4
+ */
5
+ 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
+ /** Base URL for API requests (proxy if available, otherwise host) */
11
+ baseURL: string;
12
+ /** OpenAPI specification URL (if configured) */
13
+ openapiUrl?: string;
14
+ /** Current environment mode */
15
+ mode: string;
16
+ }
17
+ /**
18
+ * Get workspace configuration at runtime
19
+ * Config is injected as environment variables during build
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { useWorkspace } from '@bagelink/workspace'
24
+ *
25
+ * const { proxy, host } = useWorkspace()
26
+ * const auth = createAuth({ baseURL: proxy })
27
+ * ```
28
+ *
29
+ * @example In Vue component
30
+ * ```vue
31
+ * <script setup>
32
+ * import { useWorkspace } from '@bagelink/workspace'
33
+ *
34
+ * const { proxy, host, mode } = useWorkspace()
35
+ * </script>
36
+ * ```
37
+ */
38
+ declare function useWorkspace(): RuntimeWorkspaceConfig;
39
+ /**
40
+ * Get the full API URL by combining host and proxy
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { getApiUrl } from '@bagelink/workspace'
45
+ *
46
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
47
+ * ```
48
+ */
49
+ declare function getApiUrl(): string;
50
+
51
+ export { getApiUrl, useWorkspace };
52
+ export type { RuntimeWorkspaceConfig };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Runtime workspace configuration
3
+ * Provides access to workspace config injected at build time
4
+ */
5
+ 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
+ /** Base URL for API requests (proxy if available, otherwise host) */
11
+ baseURL: string;
12
+ /** OpenAPI specification URL (if configured) */
13
+ openapiUrl?: string;
14
+ /** Current environment mode */
15
+ mode: string;
16
+ }
17
+ /**
18
+ * Get workspace configuration at runtime
19
+ * Config is injected as environment variables during build
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { useWorkspace } from '@bagelink/workspace'
24
+ *
25
+ * const { proxy, host } = useWorkspace()
26
+ * const auth = createAuth({ baseURL: proxy })
27
+ * ```
28
+ *
29
+ * @example In Vue component
30
+ * ```vue
31
+ * <script setup>
32
+ * import { useWorkspace } from '@bagelink/workspace'
33
+ *
34
+ * const { proxy, host, mode } = useWorkspace()
35
+ * </script>
36
+ * ```
37
+ */
38
+ declare function useWorkspace(): RuntimeWorkspaceConfig;
39
+ /**
40
+ * Get the full API URL by combining host and proxy
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { getApiUrl } from '@bagelink/workspace'
45
+ *
46
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
47
+ * ```
48
+ */
49
+ declare function getApiUrl(): string;
50
+
51
+ export { getApiUrl, useWorkspace };
52
+ export type { RuntimeWorkspaceConfig };
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Runtime workspace configuration
3
+ * Provides access to workspace config injected at build time
4
+ */
5
+ 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
+ /** Base URL for API requests (proxy if available, otherwise host) */
11
+ baseURL: string;
12
+ /** OpenAPI specification URL (if configured) */
13
+ openapiUrl?: string;
14
+ /** Current environment mode */
15
+ mode: string;
16
+ }
17
+ /**
18
+ * Get workspace configuration at runtime
19
+ * Config is injected as environment variables during build
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { useWorkspace } from '@bagelink/workspace'
24
+ *
25
+ * const { proxy, host } = useWorkspace()
26
+ * const auth = createAuth({ baseURL: proxy })
27
+ * ```
28
+ *
29
+ * @example In Vue component
30
+ * ```vue
31
+ * <script setup>
32
+ * import { useWorkspace } from '@bagelink/workspace'
33
+ *
34
+ * const { proxy, host, mode } = useWorkspace()
35
+ * </script>
36
+ * ```
37
+ */
38
+ declare function useWorkspace(): RuntimeWorkspaceConfig;
39
+ /**
40
+ * Get the full API URL by combining host and proxy
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * import { getApiUrl } from '@bagelink/workspace'
45
+ *
46
+ * const apiUrl = getApiUrl() // 'https://project.bagel.to/api'
47
+ * ```
48
+ */
49
+ declare function getApiUrl(): string;
50
+
51
+ export { getApiUrl, useWorkspace };
52
+ export type { RuntimeWorkspaceConfig };
@@ -0,0 +1,19 @@
1
+ function useWorkspace() {
2
+ const proxy = import.meta.env.VITE_BGL_PROXY || void 0;
3
+ const host = import.meta.env.VITE_BGL_HOST || "";
4
+ const openapiUrl = import.meta.env.VITE_BGL_OPENAPI_URL;
5
+ const mode = import.meta.env.MODE || "development";
6
+ return {
7
+ proxy,
8
+ host,
9
+ baseURL: proxy ?? host,
10
+ openapiUrl,
11
+ mode
12
+ };
13
+ }
14
+ function getApiUrl() {
15
+ const { host, proxy } = useWorkspace();
16
+ return `${host}${proxy}`;
17
+ }
18
+
19
+ export { getApiUrl, useWorkspace };
package/dist/index.cjs CHANGED
@@ -1,170 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const node_fs = require('node:fs');
4
- const node_path = require('node:path');
5
- const process = require('node:process');
6
- const detect = require('./shared/workspace.DQ-r7Tja.cjs');
7
- require('prompts');
8
-
9
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
10
-
11
- const process__default = /*#__PURE__*/_interopDefaultCompat(process);
12
-
13
- async function resolveConfig(mode = "development", options = {}) {
14
- const root = options.root ?? process__default.cwd();
15
- const configFile = options.configFile ?? "bgl.config.ts";
16
- const localConfigPath = node_path.resolve(root, configFile);
17
- const localConfig = await loadConfig(localConfigPath, mode);
18
- if (localConfig) {
19
- return localConfig;
20
- }
21
- let currentDir = root;
22
- const rootDir = node_path.resolve("/");
23
- while (currentDir !== rootDir) {
24
- const parentDir = node_path.resolve(currentDir, "..");
25
- const parentConfigPath = node_path.join(parentDir, configFile);
26
- if (node_fs.existsSync(parentConfigPath)) {
27
- const config = await loadConfig(parentConfigPath, mode);
28
- if (config) {
29
- return config;
30
- }
31
- }
32
- currentDir = parentDir;
33
- }
34
- if (options.interactive !== false) {
35
- await detect.generateWorkspaceConfig(root, configFile);
36
- const newConfig = await loadConfig(localConfigPath, mode);
37
- if (newConfig) {
38
- return newConfig;
39
- }
40
- }
41
- throw new Error(`No bgl.config.ts found in ${root} or parent directories`);
42
- }
43
- async function loadConfig(configPath, mode) {
44
- if (!node_fs.existsSync(configPath)) {
45
- return null;
46
- }
47
- try {
48
- const module = await import(`file://${configPath}`);
49
- const configMap = module.default ?? module.configs ?? module.config;
50
- if (typeof configMap === "function") {
51
- return configMap(mode);
52
- }
53
- if (typeof configMap === "object" && configMap !== null) {
54
- const modeConfig = configMap[mode];
55
- if (mode in configMap && modeConfig !== void 0 && modeConfig !== null) {
56
- return modeConfig;
57
- }
58
- return configMap;
59
- }
60
- return null;
61
- } catch (error) {
62
- console.warn(`Failed to load config from ${configPath}:`, error);
63
- return null;
64
- }
65
- }
66
- function mergeConfigs(base, override) {
67
- return {
68
- ...base,
69
- ...override
70
- };
71
- }
72
-
73
- function createViteProxy(config) {
74
- const proxy = {};
75
- if (config.proxy && config.host) {
76
- proxy[config.proxy] = {
77
- target: config.host,
78
- changeOrigin: true,
79
- rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
80
- secure: true
81
- };
82
- }
83
- if (config.host) {
84
- proxy["/files"] = {
85
- target: config.host,
86
- changeOrigin: true,
87
- secure: true
88
- };
89
- }
90
- return proxy;
91
- }
92
- function createCustomProxy(paths, target, options = {}) {
93
- const proxy = {};
94
- for (const path of paths) {
95
- proxy[path] = {
96
- target,
97
- changeOrigin: options.changeOrigin ?? true,
98
- secure: options.secure ?? true,
99
- ...options.rewrite === true && {
100
- rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
101
- }
102
- };
103
- }
104
- return proxy;
105
- }
3
+ const composable = require('./composable.cjs');
106
4
 
107
5
  function defineWorkspace(configs) {
108
6
  return (mode = "development") => {
109
7
  return configs[mode] || configs.development;
110
8
  };
111
9
  }
112
- function createWorkspace(options = {}) {
113
- let cachedConfig = null;
114
- return {
115
- /**
116
- * Get resolved config for the specified environment
117
- */
118
- async getConfig(mode = "development") {
119
- if (!cachedConfig) {
120
- cachedConfig = await resolveConfig(mode, options);
121
- }
122
- return cachedConfig;
123
- },
124
- /**
125
- * Create Vite proxy configuration
126
- */
127
- createProxy(config) {
128
- return createViteProxy(config);
129
- },
130
- /**
131
- * Generate Netlify configuration file
132
- */
133
- generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
134
- detect.writeNetlifyConfig(config, outPath, additionalConfig);
135
- },
136
- /**
137
- * Set build environment variables
138
- */
139
- setBuildEnv(config) {
140
- detect.setBuildEnvVars(config);
141
- },
142
- /**
143
- * Clear cached configuration
144
- */
145
- clearCache() {
146
- cachedConfig = null;
147
- }
148
- };
149
- }
150
10
 
151
- exports.addProject = detect.addProject;
152
- exports.generateNetlifyConfig = detect.generateNetlifyConfig;
153
- exports.generateNetlifyRedirect = detect.generateNetlifyRedirect;
154
- exports.generateSDK = detect.generateSDK;
155
- exports.generateSDKForWorkspace = detect.generateSDKForWorkspace;
156
- exports.generateWorkspaceConfig = detect.generateWorkspaceConfig;
157
- exports.generateWorkspaceConfigSync = detect.generateWorkspaceConfigSync;
158
- exports.getWorkspaceInfo = detect.getWorkspaceInfo;
159
- exports.initWorkspace = detect.initWorkspace;
160
- exports.isWorkspace = detect.isWorkspace;
161
- exports.listProjects = detect.listProjects;
162
- exports.setBuildEnvVars = detect.setBuildEnvVars;
163
- exports.setupLint = detect.setupLint;
164
- exports.writeNetlifyConfig = detect.writeNetlifyConfig;
165
- exports.createCustomProxy = createCustomProxy;
166
- exports.createViteProxy = createViteProxy;
167
- exports.createWorkspace = createWorkspace;
11
+ exports.getApiUrl = composable.getApiUrl;
12
+ exports.useWorkspace = composable.useWorkspace;
168
13
  exports.defineWorkspace = defineWorkspace;
169
- exports.mergeConfigs = mergeConfigs;
170
- exports.resolveConfig = resolveConfig;
package/dist/index.d.cts CHANGED
@@ -1,167 +1,11 @@
1
- type WorkspaceEnvironment = 'localhost' | 'development' | 'production';
2
- interface WorkspaceConfig {
3
- /**
4
- * The host URL of the backend API server
5
- * @example 'http://localhost:8000' | 'https://project.bagel.to'
6
- */
7
- host: string;
8
- /**
9
- * The proxy path to use for API requests
10
- * @default '/api'
11
- */
12
- proxy: string;
13
- /**
14
- * Optional OpenAPI specification URL for SDK generation
15
- */
16
- openapi_url?: string;
17
- }
18
- interface WorkspaceOptions {
19
- /**
20
- * Root directory of the workspace
21
- * @default process.cwd()
22
- */
23
- root?: string;
24
- /**
25
- * Path to the config file relative to root
26
- * @default 'bgl.config.ts'
27
- */
28
- configFile?: string;
29
- /**
30
- * Enable interactive config generation if no config is found
31
- * @default true
32
- */
33
- interactive?: boolean;
34
- }
35
- interface ProxyConfig {
36
- [path: string]: {
37
- target: string;
38
- changeOrigin: boolean;
39
- rewrite?: (path: string) => string;
40
- secure: boolean;
41
- };
42
- }
43
-
44
- /**
45
- * Load and resolve bgl.config.ts with cascading support
46
- * Looks for config files from current directory up to workspace root
47
- * If no config is found, prompts to create one interactively
48
- */
49
- declare function resolveConfig(mode?: WorkspaceEnvironment, options?: WorkspaceOptions): Promise<WorkspaceConfig>;
50
- /**
51
- * Merge two configs, with the second one taking precedence
52
- */
53
- declare function mergeConfigs(base: WorkspaceConfig, override: Partial<WorkspaceConfig>): WorkspaceConfig;
54
-
55
- /**
56
- * Generate bgl.config.ts file interactively
57
- */
58
- declare function generateWorkspaceConfig(root?: string, configFile?: string): Promise<void>;
59
- /**
60
- * Generate bgl.config.ts non-interactively
61
- */
62
- declare function generateWorkspaceConfigSync(projectId: string, root?: string, configFile?: string, customHost?: string): void;
63
-
64
- /**
65
- * Generate netlify.toml redirect configuration
66
- */
67
- declare function generateNetlifyRedirect(config: WorkspaceConfig): string;
68
- /**
69
- * Generate complete netlify.toml file
70
- */
71
- declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string): string;
72
- /**
73
- * Write netlify.toml file to disk
74
- */
75
- declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
76
- /**
77
- * Set environment variables for build process
78
- */
79
- declare function setBuildEnvVars(config: WorkspaceConfig): void;
80
-
81
- /**
82
- * Create Vite proxy configuration from WorkspaceConfig
83
- */
84
- declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
85
- /**
86
- * Create custom proxy configuration
87
- */
88
- declare function createCustomProxy(paths: string[], target: string, options?: {
89
- changeOrigin?: boolean;
90
- rewrite?: boolean;
91
- secure?: boolean;
92
- }): ProxyConfig;
93
-
94
- /**
95
- * Set up linting in a project
96
- */
97
- declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
98
-
99
- /**
100
- * Generate SDK from OpenAPI spec
101
- */
102
- declare function generateSDK(root?: string): Promise<void>;
103
- /**
104
- * Generate SDK for all projects in workspace
105
- */
106
- declare function generateSDKForWorkspace(root?: string): Promise<void>;
107
-
108
- /**
109
- * Initialize a new workspace with flat structure
110
- */
111
- declare function initWorkspace(root?: string): Promise<void>;
112
- /**
113
- * Add a new project to the workspace
114
- */
115
- declare function addProject(name: string, root?: string): Promise<void>;
116
- /**
117
- * List all projects in workspace
118
- */
119
- declare function listProjects(root?: string): string[];
120
-
121
- /**
122
- * Detect if current directory is a workspace root
123
- */
124
- declare function isWorkspace(root?: string): boolean;
125
- /**
126
- * Get workspace info
127
- */
128
- declare function getWorkspaceInfo(root?: string): {
129
- isWorkspace: boolean;
130
- projects: string[];
131
- hasShared: boolean;
132
- };
1
+ import { W as WorkspaceEnvironment, a as WorkspaceConfig } from './shared/workspace.BzlV5kcN.cjs';
2
+ export { P as ProxyConfig, b as WorkspaceOptions } from './shared/workspace.BzlV5kcN.cjs';
3
+ export { RuntimeWorkspaceConfig, getApiUrl, useWorkspace } from './composable.cjs';
133
4
 
134
5
  /**
135
6
  * Define workspace configuration
136
7
  * Simple helper to get config from a config map
137
8
  */
138
9
  declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
139
- /**
140
- * Create a workspace instance for managing project configuration
141
- * Supports both single project and monorepo setups
142
- */
143
- declare function createWorkspace(options?: WorkspaceOptions): {
144
- /**
145
- * Get resolved config for the specified environment
146
- */
147
- getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
148
- /**
149
- * Create Vite proxy configuration
150
- */
151
- createProxy(config: WorkspaceConfig): ProxyConfig;
152
- /**
153
- * Generate Netlify configuration file
154
- */
155
- generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
156
- /**
157
- * Set build environment variables
158
- */
159
- setBuildEnv(config: WorkspaceConfig): void;
160
- /**
161
- * Clear cached configuration
162
- */
163
- clearCache(): void;
164
- };
165
10
 
166
- export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, setupLint, writeNetlifyConfig };
167
- export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
11
+ export { WorkspaceConfig, WorkspaceEnvironment, defineWorkspace };