@bagelink/workspace 1.7.39 → 1.7.41

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/dist/index.cjs CHANGED
@@ -1,144 +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 workspace = require('./shared/workspace.CamNrnD_.cjs');
7
- const vite = require('./shared/workspace.DfLGMczD.cjs');
8
3
  const composable = require('./composable.cjs');
9
- require('prompts');
10
- require('node:child_process');
11
- require('node:url');
12
-
13
- function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
14
-
15
- const process__default = /*#__PURE__*/_interopDefaultCompat(process);
16
-
17
- async function resolveConfig(mode = "development", options = {}) {
18
- const root = options.root ?? process__default.cwd();
19
- const configFile = options.configFile ?? "bgl.config.ts";
20
- const localConfigPath = node_path.resolve(root, configFile);
21
- const localConfig = await loadConfig(localConfigPath, mode);
22
- if (localConfig) {
23
- return localConfig;
24
- }
25
- let currentDir = root;
26
- const rootDir = node_path.resolve("/");
27
- while (currentDir !== rootDir) {
28
- const parentDir = node_path.resolve(currentDir, "..");
29
- const parentConfigPath = node_path.join(parentDir, configFile);
30
- if (node_fs.existsSync(parentConfigPath)) {
31
- const config = await loadConfig(parentConfigPath, mode);
32
- if (config) {
33
- return config;
34
- }
35
- }
36
- currentDir = parentDir;
37
- }
38
- if (options.interactive !== false) {
39
- await workspace.generateWorkspaceConfig(root, configFile);
40
- const newConfig = await loadConfig(localConfigPath, mode);
41
- if (newConfig) {
42
- return newConfig;
43
- }
44
- }
45
- throw new Error(`No bgl.config.ts found in ${root} or parent directories`);
46
- }
47
- async function loadConfig(configPath, mode) {
48
- if (!node_fs.existsSync(configPath)) {
49
- return null;
50
- }
51
- try {
52
- const module = await import(`file://${configPath}`);
53
- const configMap = module.default ?? module.configs ?? module.config;
54
- if (typeof configMap === "function") {
55
- return configMap(mode);
56
- }
57
- if (typeof configMap === "object" && configMap !== null) {
58
- const modeConfig = configMap[mode];
59
- if (mode in configMap && modeConfig !== void 0 && modeConfig !== null) {
60
- return modeConfig;
61
- }
62
- return configMap;
63
- }
64
- return null;
65
- } catch (error) {
66
- console.warn(`Failed to load config from ${configPath}:`, error);
67
- return null;
68
- }
69
- }
70
- function mergeConfigs(base, override) {
71
- return {
72
- ...base,
73
- ...override
74
- };
75
- }
76
4
 
77
5
  function defineWorkspace(configs) {
78
6
  return (mode = "development") => {
79
7
  return configs[mode] || configs.development;
80
8
  };
81
9
  }
82
- function createWorkspace(options = {}) {
83
- let cachedConfig = null;
84
- return {
85
- /**
86
- * Get resolved config for the specified environment
87
- */
88
- async getConfig(mode = "development") {
89
- if (!cachedConfig) {
90
- cachedConfig = await resolveConfig(mode, options);
91
- }
92
- return cachedConfig;
93
- },
94
- /**
95
- * Create Vite proxy configuration
96
- */
97
- createProxy(config) {
98
- return vite.createViteProxy(config);
99
- },
100
- /**
101
- * Generate Netlify configuration file
102
- */
103
- generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
104
- workspace.writeNetlifyConfig(config, outPath, additionalConfig);
105
- },
106
- /**
107
- * Set build environment variables
108
- */
109
- setBuildEnv(config) {
110
- workspace.setBuildEnvVars(config);
111
- },
112
- /**
113
- * Clear cached configuration
114
- */
115
- clearCache() {
116
- cachedConfig = null;
117
- }
118
- };
119
- }
120
10
 
121
- exports.addProject = workspace.addProject;
122
- exports.generateNetlifyConfig = workspace.generateNetlifyConfig;
123
- exports.generateNetlifyRedirect = workspace.generateNetlifyRedirect;
124
- exports.generateSDK = workspace.generateSDK;
125
- exports.generateSDKForWorkspace = workspace.generateSDKForWorkspace;
126
- exports.generateWorkspaceConfig = workspace.generateWorkspaceConfig;
127
- exports.generateWorkspaceConfigSync = workspace.generateWorkspaceConfigSync;
128
- exports.getWorkspaceInfo = workspace.getWorkspaceInfo;
129
- exports.initWorkspace = workspace.initWorkspace;
130
- exports.isWorkspace = workspace.isWorkspace;
131
- exports.listProjects = workspace.listProjects;
132
- exports.runDev = workspace.runDev;
133
- exports.setBuildEnvVars = workspace.setBuildEnvVars;
134
- exports.setupLint = workspace.setupLint;
135
- exports.writeNetlifyConfig = workspace.writeNetlifyConfig;
136
- exports.bagelink = vite.bagelink;
137
- exports.createCustomProxy = vite.createCustomProxy;
138
- exports.createViteProxy = vite.createViteProxy;
139
11
  exports.getApiUrl = composable.getApiUrl;
140
12
  exports.useWorkspace = composable.useWorkspace;
141
- exports.createWorkspace = createWorkspace;
142
13
  exports.defineWorkspace = defineWorkspace;
143
- exports.mergeConfigs = mergeConfigs;
144
- exports.resolveConfig = resolveConfig;
package/dist/index.d.cts CHANGED
@@ -1,131 +1,11 @@
1
- import { W as WorkspaceConfig, a as WorkspaceEnvironment, b as WorkspaceOptions, P as ProxyConfig } from './shared/workspace.CSNgk3PR.cjs';
2
- export { B as BagelinkPluginOptions, c as bagelink } from './shared/workspace.CSNgk3PR.cjs';
1
+ import { W as WorkspaceEnvironment, a as WorkspaceConfig } from './shared/workspace.D1xukL92.cjs';
2
+ export { P as ProxyConfig, b as WorkspaceOptions } from './shared/workspace.D1xukL92.cjs';
3
3
  export { RuntimeWorkspaceConfig, getApiUrl, useWorkspace } from './composable.cjs';
4
- import 'vite';
5
-
6
- /**
7
- * Load and resolve bgl.config.ts with cascading support
8
- * Looks for config files from current directory up to workspace root
9
- * If no config is found, prompts to create one interactively
10
- */
11
- declare function resolveConfig(mode?: WorkspaceEnvironment, options?: WorkspaceOptions): Promise<WorkspaceConfig>;
12
- /**
13
- * Merge two configs, with the second one taking precedence
14
- */
15
- declare function mergeConfigs(base: WorkspaceConfig, override: Partial<WorkspaceConfig>): WorkspaceConfig;
16
-
17
- /**
18
- * Generate bgl.config.ts file interactively
19
- */
20
- declare function generateWorkspaceConfig(root?: string, configFile?: string): Promise<void>;
21
- /**
22
- * Generate bgl.config.ts non-interactively
23
- */
24
- declare function generateWorkspaceConfigSync(projectId: string, root?: string, configFile?: string, customHost?: string): void;
25
-
26
- /**
27
- * Generate netlify.toml redirect configuration
28
- * Uses environment variables for flexibility across environments
29
- */
30
- declare function generateNetlifyRedirect(config: WorkspaceConfig): string;
31
- /**
32
- * Generate complete netlify.toml file
33
- */
34
- declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
35
- /**
36
- * Write netlify.toml file to disk
37
- */
38
- declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
39
- /**
40
- * Set environment variables for build process
41
- */
42
- declare function setBuildEnvVars(config: WorkspaceConfig): void;
43
-
44
- /**
45
- * Create Vite proxy configuration from WorkspaceConfig
46
- */
47
- declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
48
- /**
49
- * Create custom proxy configuration
50
- */
51
- declare function createCustomProxy(paths: string[], target: string, options?: {
52
- changeOrigin?: boolean;
53
- rewrite?: boolean;
54
- secure?: boolean;
55
- }): ProxyConfig;
56
-
57
- /**
58
- * Detect if current directory is a workspace root
59
- */
60
- declare function isWorkspace(root?: string): boolean;
61
- /**
62
- * Get workspace info
63
- */
64
- declare function getWorkspaceInfo(root?: string): {
65
- isWorkspace: boolean;
66
- projects: string[];
67
- hasShared: boolean;
68
- };
69
-
70
- declare function runDev(filter?: string, additionalArgs?: string[]): Promise<number>;
71
-
72
- /**
73
- * Set up linting in a project
74
- */
75
- declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
76
-
77
- /**
78
- * Generate SDK from OpenAPI spec
79
- */
80
- declare function generateSDK(root?: string): Promise<void>;
81
- /**
82
- * Generate SDK for all projects in workspace
83
- */
84
- declare function generateSDKForWorkspace(root?: string): Promise<void>;
85
-
86
- /**
87
- * Initialize a new workspace with flat structure
88
- */
89
- declare function initWorkspace(root?: string): Promise<void>;
90
- /**
91
- * Add a new project to the workspace
92
- */
93
- declare function addProject(name: string, root?: string): Promise<void>;
94
- /**
95
- * List all projects in workspace
96
- */
97
- declare function listProjects(root?: string): string[];
98
4
 
99
5
  /**
100
6
  * Define workspace configuration
101
7
  * Simple helper to get config from a config map
102
8
  */
103
9
  declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
104
- /**
105
- * Create a workspace instance for managing project configuration
106
- * Supports both single project and monorepo setups
107
- */
108
- declare function createWorkspace(options?: WorkspaceOptions): {
109
- /**
110
- * Get resolved config for the specified environment
111
- */
112
- getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
113
- /**
114
- * Create Vite proxy configuration
115
- */
116
- createProxy(config: WorkspaceConfig): ProxyConfig;
117
- /**
118
- * Generate Netlify configuration file
119
- */
120
- generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
121
- /**
122
- * Set build environment variables
123
- */
124
- setBuildEnv(config: WorkspaceConfig): void;
125
- /**
126
- * Clear cached configuration
127
- */
128
- clearCache(): void;
129
- };
130
10
 
131
- export { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions, addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, writeNetlifyConfig };
11
+ export { WorkspaceConfig, WorkspaceEnvironment, defineWorkspace };
package/dist/index.d.mts CHANGED
@@ -1,131 +1,11 @@
1
- import { W as WorkspaceConfig, a as WorkspaceEnvironment, b as WorkspaceOptions, P as ProxyConfig } from './shared/workspace.CSNgk3PR.mjs';
2
- export { B as BagelinkPluginOptions, c as bagelink } from './shared/workspace.CSNgk3PR.mjs';
1
+ import { W as WorkspaceEnvironment, a as WorkspaceConfig } from './shared/workspace.D1xukL92.mjs';
2
+ export { P as ProxyConfig, b as WorkspaceOptions } from './shared/workspace.D1xukL92.mjs';
3
3
  export { RuntimeWorkspaceConfig, getApiUrl, useWorkspace } from './composable.mjs';
4
- import 'vite';
5
-
6
- /**
7
- * Load and resolve bgl.config.ts with cascading support
8
- * Looks for config files from current directory up to workspace root
9
- * If no config is found, prompts to create one interactively
10
- */
11
- declare function resolveConfig(mode?: WorkspaceEnvironment, options?: WorkspaceOptions): Promise<WorkspaceConfig>;
12
- /**
13
- * Merge two configs, with the second one taking precedence
14
- */
15
- declare function mergeConfigs(base: WorkspaceConfig, override: Partial<WorkspaceConfig>): WorkspaceConfig;
16
-
17
- /**
18
- * Generate bgl.config.ts file interactively
19
- */
20
- declare function generateWorkspaceConfig(root?: string, configFile?: string): Promise<void>;
21
- /**
22
- * Generate bgl.config.ts non-interactively
23
- */
24
- declare function generateWorkspaceConfigSync(projectId: string, root?: string, configFile?: string, customHost?: string): void;
25
-
26
- /**
27
- * Generate netlify.toml redirect configuration
28
- * Uses environment variables for flexibility across environments
29
- */
30
- declare function generateNetlifyRedirect(config: WorkspaceConfig): string;
31
- /**
32
- * Generate complete netlify.toml file
33
- */
34
- declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
35
- /**
36
- * Write netlify.toml file to disk
37
- */
38
- declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
39
- /**
40
- * Set environment variables for build process
41
- */
42
- declare function setBuildEnvVars(config: WorkspaceConfig): void;
43
-
44
- /**
45
- * Create Vite proxy configuration from WorkspaceConfig
46
- */
47
- declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
48
- /**
49
- * Create custom proxy configuration
50
- */
51
- declare function createCustomProxy(paths: string[], target: string, options?: {
52
- changeOrigin?: boolean;
53
- rewrite?: boolean;
54
- secure?: boolean;
55
- }): ProxyConfig;
56
-
57
- /**
58
- * Detect if current directory is a workspace root
59
- */
60
- declare function isWorkspace(root?: string): boolean;
61
- /**
62
- * Get workspace info
63
- */
64
- declare function getWorkspaceInfo(root?: string): {
65
- isWorkspace: boolean;
66
- projects: string[];
67
- hasShared: boolean;
68
- };
69
-
70
- declare function runDev(filter?: string, additionalArgs?: string[]): Promise<number>;
71
-
72
- /**
73
- * Set up linting in a project
74
- */
75
- declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
76
-
77
- /**
78
- * Generate SDK from OpenAPI spec
79
- */
80
- declare function generateSDK(root?: string): Promise<void>;
81
- /**
82
- * Generate SDK for all projects in workspace
83
- */
84
- declare function generateSDKForWorkspace(root?: string): Promise<void>;
85
-
86
- /**
87
- * Initialize a new workspace with flat structure
88
- */
89
- declare function initWorkspace(root?: string): Promise<void>;
90
- /**
91
- * Add a new project to the workspace
92
- */
93
- declare function addProject(name: string, root?: string): Promise<void>;
94
- /**
95
- * List all projects in workspace
96
- */
97
- declare function listProjects(root?: string): string[];
98
4
 
99
5
  /**
100
6
  * Define workspace configuration
101
7
  * Simple helper to get config from a config map
102
8
  */
103
9
  declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
104
- /**
105
- * Create a workspace instance for managing project configuration
106
- * Supports both single project and monorepo setups
107
- */
108
- declare function createWorkspace(options?: WorkspaceOptions): {
109
- /**
110
- * Get resolved config for the specified environment
111
- */
112
- getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
113
- /**
114
- * Create Vite proxy configuration
115
- */
116
- createProxy(config: WorkspaceConfig): ProxyConfig;
117
- /**
118
- * Generate Netlify configuration file
119
- */
120
- generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
121
- /**
122
- * Set build environment variables
123
- */
124
- setBuildEnv(config: WorkspaceConfig): void;
125
- /**
126
- * Clear cached configuration
127
- */
128
- clearCache(): void;
129
- };
130
10
 
131
- export { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions, addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, writeNetlifyConfig };
11
+ export { WorkspaceConfig, WorkspaceEnvironment, defineWorkspace };
package/dist/index.d.ts CHANGED
@@ -1,131 +1,11 @@
1
- import { W as WorkspaceConfig, a as WorkspaceEnvironment, b as WorkspaceOptions, P as ProxyConfig } from './shared/workspace.CSNgk3PR.js';
2
- export { B as BagelinkPluginOptions, c as bagelink } from './shared/workspace.CSNgk3PR.js';
1
+ import { W as WorkspaceEnvironment, a as WorkspaceConfig } from './shared/workspace.D1xukL92.js';
2
+ export { P as ProxyConfig, b as WorkspaceOptions } from './shared/workspace.D1xukL92.js';
3
3
  export { RuntimeWorkspaceConfig, getApiUrl, useWorkspace } from './composable.js';
4
- import 'vite';
5
-
6
- /**
7
- * Load and resolve bgl.config.ts with cascading support
8
- * Looks for config files from current directory up to workspace root
9
- * If no config is found, prompts to create one interactively
10
- */
11
- declare function resolveConfig(mode?: WorkspaceEnvironment, options?: WorkspaceOptions): Promise<WorkspaceConfig>;
12
- /**
13
- * Merge two configs, with the second one taking precedence
14
- */
15
- declare function mergeConfigs(base: WorkspaceConfig, override: Partial<WorkspaceConfig>): WorkspaceConfig;
16
-
17
- /**
18
- * Generate bgl.config.ts file interactively
19
- */
20
- declare function generateWorkspaceConfig(root?: string, configFile?: string): Promise<void>;
21
- /**
22
- * Generate bgl.config.ts non-interactively
23
- */
24
- declare function generateWorkspaceConfigSync(projectId: string, root?: string, configFile?: string, customHost?: string): void;
25
-
26
- /**
27
- * Generate netlify.toml redirect configuration
28
- * Uses environment variables for flexibility across environments
29
- */
30
- declare function generateNetlifyRedirect(config: WorkspaceConfig): string;
31
- /**
32
- * Generate complete netlify.toml file
33
- */
34
- declare function generateNetlifyConfig(config: WorkspaceConfig, additionalConfig?: string, useTemplate?: boolean): string;
35
- /**
36
- * Write netlify.toml file to disk
37
- */
38
- declare function writeNetlifyConfig(config: WorkspaceConfig, outPath?: string, additionalConfig?: string, useTemplate?: boolean): void;
39
- /**
40
- * Set environment variables for build process
41
- */
42
- declare function setBuildEnvVars(config: WorkspaceConfig): void;
43
-
44
- /**
45
- * Create Vite proxy configuration from WorkspaceConfig
46
- */
47
- declare function createViteProxy(config: WorkspaceConfig): ProxyConfig;
48
- /**
49
- * Create custom proxy configuration
50
- */
51
- declare function createCustomProxy(paths: string[], target: string, options?: {
52
- changeOrigin?: boolean;
53
- rewrite?: boolean;
54
- secure?: boolean;
55
- }): ProxyConfig;
56
-
57
- /**
58
- * Detect if current directory is a workspace root
59
- */
60
- declare function isWorkspace(root?: string): boolean;
61
- /**
62
- * Get workspace info
63
- */
64
- declare function getWorkspaceInfo(root?: string): {
65
- isWorkspace: boolean;
66
- projects: string[];
67
- hasShared: boolean;
68
- };
69
-
70
- declare function runDev(filter?: string, additionalArgs?: string[]): Promise<number>;
71
-
72
- /**
73
- * Set up linting in a project
74
- */
75
- declare function setupLint(root?: string, isWorkspace?: boolean): Promise<void>;
76
-
77
- /**
78
- * Generate SDK from OpenAPI spec
79
- */
80
- declare function generateSDK(root?: string): Promise<void>;
81
- /**
82
- * Generate SDK for all projects in workspace
83
- */
84
- declare function generateSDKForWorkspace(root?: string): Promise<void>;
85
-
86
- /**
87
- * Initialize a new workspace with flat structure
88
- */
89
- declare function initWorkspace(root?: string): Promise<void>;
90
- /**
91
- * Add a new project to the workspace
92
- */
93
- declare function addProject(name: string, root?: string): Promise<void>;
94
- /**
95
- * List all projects in workspace
96
- */
97
- declare function listProjects(root?: string): string[];
98
4
 
99
5
  /**
100
6
  * Define workspace configuration
101
7
  * Simple helper to get config from a config map
102
8
  */
103
9
  declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
104
- /**
105
- * Create a workspace instance for managing project configuration
106
- * Supports both single project and monorepo setups
107
- */
108
- declare function createWorkspace(options?: WorkspaceOptions): {
109
- /**
110
- * Get resolved config for the specified environment
111
- */
112
- getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
113
- /**
114
- * Create Vite proxy configuration
115
- */
116
- createProxy(config: WorkspaceConfig): ProxyConfig;
117
- /**
118
- * Generate Netlify configuration file
119
- */
120
- generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
121
- /**
122
- * Set build environment variables
123
- */
124
- setBuildEnv(config: WorkspaceConfig): void;
125
- /**
126
- * Clear cached configuration
127
- */
128
- clearCache(): void;
129
- };
130
10
 
131
- export { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions, addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateSDK, generateSDKForWorkspace, generateWorkspaceConfig, generateWorkspaceConfigSync, getWorkspaceInfo, initWorkspace, isWorkspace, listProjects, mergeConfigs, resolveConfig, runDev, setBuildEnvVars, setupLint, writeNetlifyConfig };
11
+ export { WorkspaceConfig, WorkspaceEnvironment, defineWorkspace };
package/dist/index.mjs CHANGED
@@ -1,117 +1,9 @@
1
- import { existsSync } from 'node:fs';
2
- import { resolve, join } from 'node:path';
3
- import process from 'node:process';
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 { c as createViteProxy } from './shared/workspace.D0MF8ERh.mjs';
7
- export { b as bagelink, a as createCustomProxy } from './shared/workspace.D0MF8ERh.mjs';
8
1
  export { getApiUrl, useWorkspace } from './composable.mjs';
9
- import 'prompts';
10
- import 'node:child_process';
11
- import 'node:url';
12
-
13
- async function resolveConfig(mode = "development", options = {}) {
14
- const root = options.root ?? process.cwd();
15
- const configFile = options.configFile ?? "bgl.config.ts";
16
- const localConfigPath = resolve(root, configFile);
17
- const localConfig = await loadConfig(localConfigPath, mode);
18
- if (localConfig) {
19
- return localConfig;
20
- }
21
- let currentDir = root;
22
- const rootDir = resolve("/");
23
- while (currentDir !== rootDir) {
24
- const parentDir = resolve(currentDir, "..");
25
- const parentConfigPath = join(parentDir, configFile);
26
- if (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 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 (!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
2
 
73
3
  function defineWorkspace(configs) {
74
4
  return (mode = "development") => {
75
5
  return configs[mode] || configs.development;
76
6
  };
77
7
  }
78
- function createWorkspace(options = {}) {
79
- let cachedConfig = null;
80
- return {
81
- /**
82
- * Get resolved config for the specified environment
83
- */
84
- async getConfig(mode = "development") {
85
- if (!cachedConfig) {
86
- cachedConfig = await resolveConfig(mode, options);
87
- }
88
- return cachedConfig;
89
- },
90
- /**
91
- * Create Vite proxy configuration
92
- */
93
- createProxy(config) {
94
- return createViteProxy(config);
95
- },
96
- /**
97
- * Generate Netlify configuration file
98
- */
99
- generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
100
- writeNetlifyConfig(config, outPath, additionalConfig);
101
- },
102
- /**
103
- * Set build environment variables
104
- */
105
- setBuildEnv(config) {
106
- setBuildEnvVars(config);
107
- },
108
- /**
109
- * Clear cached configuration
110
- */
111
- clearCache() {
112
- cachedConfig = null;
113
- }
114
- };
115
- }
116
8
 
117
- export { createViteProxy, createWorkspace, defineWorkspace, generateWorkspaceConfig, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
9
+ export { defineWorkspace };