@bagelink/workspace 1.8.0 → 1.8.5
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 +290 -7
- package/bin/bgl.ts +160 -11
- package/dist/bin/bgl.cjs +1283 -18
- package/dist/bin/bgl.mjs +1279 -15
- package/dist/composable.cjs +21 -0
- package/dist/composable.d.cts +50 -0
- package/dist/composable.d.mts +50 -0
- package/dist/composable.d.ts +50 -0
- package/dist/composable.mjs +18 -0
- package/dist/index.cjs +3 -155
- package/dist/index.d.cts +4 -133
- package/dist/index.d.mts +4 -133
- package/dist/index.d.ts +4 -133
- package/dist/index.mjs +2 -139
- package/dist/shared/workspace.CefUteAh.d.cts +49 -0
- package/dist/shared/workspace.CefUteAh.d.mts +49 -0
- package/dist/shared/workspace.CefUteAh.d.ts +49 -0
- package/dist/shared/workspace.Dx9_TIij.cjs +86 -0
- package/dist/shared/workspace.Twuo1PFw.mjs +78 -0
- package/dist/vite.cjs +110 -0
- package/dist/vite.d.cts +98 -0
- package/dist/vite.d.mts +98 -0
- package/dist/vite.d.ts +98 -0
- package/dist/vite.mjs +99 -0
- package/env.d.ts +29 -0
- package/package.json +28 -5
- package/src/build.ts +45 -0
- package/src/composable.ts +65 -0
- package/src/detect.ts +90 -0
- package/src/dev.ts +162 -0
- package/src/index.ts +11 -71
- package/src/init.ts +60 -12
- package/src/lint.ts +323 -0
- package/src/netlify.ts +54 -3
- package/src/proxy.ts +23 -3
- package/src/sdk.ts +196 -0
- package/src/types.ts +5 -0
- package/src/vite.ts +139 -0
- package/src/workspace.ts +107 -23
- package/templates/dev-runner.ts +61 -0
- package/templates/tsconfig.app.json +23 -0
- package/dist/shared/workspace.Bwsdwbt-.cjs +0 -575
- package/dist/shared/workspace.Dq-27S1f.mjs +0 -560
package/dist/index.d.ts
CHANGED
|
@@ -1,140 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
* Initialize a new workspace with flat structure
|
|
96
|
-
*/
|
|
97
|
-
declare function initWorkspace(root?: string): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Add a new project to the workspace
|
|
100
|
-
*/
|
|
101
|
-
declare function addProject(name: string, root?: string): Promise<void>;
|
|
102
|
-
/**
|
|
103
|
-
* List all projects in workspace
|
|
104
|
-
*/
|
|
105
|
-
declare function listProjects(root?: string): string[];
|
|
1
|
+
import { W as WorkspaceEnvironment, a as WorkspaceConfig } from './shared/workspace.CefUteAh.js';
|
|
2
|
+
export { P as ProxyConfig, b as WorkspaceOptions } from './shared/workspace.CefUteAh.js';
|
|
3
|
+
export { RuntimeWorkspaceConfig, getApiUrl, useWorkspace } from './composable.js';
|
|
106
4
|
|
|
107
5
|
/**
|
|
108
6
|
* Define workspace configuration
|
|
109
7
|
* Simple helper to get config from a config map
|
|
110
8
|
*/
|
|
111
9
|
declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
|
|
112
|
-
/**
|
|
113
|
-
* Create a workspace instance for managing project configuration
|
|
114
|
-
* Supports both single project and monorepo setups
|
|
115
|
-
*/
|
|
116
|
-
declare function createWorkspace(options?: WorkspaceOptions): {
|
|
117
|
-
/**
|
|
118
|
-
* Get resolved config for the specified environment
|
|
119
|
-
*/
|
|
120
|
-
getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
|
|
121
|
-
/**
|
|
122
|
-
* Create Vite proxy configuration
|
|
123
|
-
*/
|
|
124
|
-
createProxy(config: WorkspaceConfig): ProxyConfig;
|
|
125
|
-
/**
|
|
126
|
-
* Generate Netlify configuration file
|
|
127
|
-
*/
|
|
128
|
-
generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
|
|
129
|
-
/**
|
|
130
|
-
* Set build environment variables
|
|
131
|
-
*/
|
|
132
|
-
setBuildEnv(config: WorkspaceConfig): void;
|
|
133
|
-
/**
|
|
134
|
-
* Clear cached configuration
|
|
135
|
-
*/
|
|
136
|
-
clearCache(): void;
|
|
137
|
-
};
|
|
138
10
|
|
|
139
|
-
export {
|
|
140
|
-
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
|
11
|
+
export { WorkspaceConfig, WorkspaceEnvironment, defineWorkspace };
|
package/dist/index.mjs
CHANGED
|
@@ -1,146 +1,9 @@
|
|
|
1
|
-
|
|
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.Dq-27S1f.mjs';
|
|
5
|
-
export { d as addProject, a as generateNetlifyConfig, b as generateNetlifyRedirect, c as generateWorkspaceConfigSync, i as initWorkspace, l as listProjects } from './shared/workspace.Dq-27S1f.mjs';
|
|
6
|
-
import 'prompts';
|
|
7
|
-
|
|
8
|
-
async function resolveConfig(mode = "development", options = {}) {
|
|
9
|
-
const root = options.root ?? process.cwd();
|
|
10
|
-
const configFile = options.configFile ?? "bgl.config.ts";
|
|
11
|
-
const localConfigPath = resolve(root, configFile);
|
|
12
|
-
const localConfig = await loadConfig(localConfigPath, mode);
|
|
13
|
-
if (localConfig) {
|
|
14
|
-
return localConfig;
|
|
15
|
-
}
|
|
16
|
-
let currentDir = root;
|
|
17
|
-
const rootDir = resolve("/");
|
|
18
|
-
while (currentDir !== rootDir) {
|
|
19
|
-
const parentDir = resolve(currentDir, "..");
|
|
20
|
-
const parentConfigPath = join(parentDir, configFile);
|
|
21
|
-
if (existsSync(parentConfigPath)) {
|
|
22
|
-
const config = await loadConfig(parentConfigPath, mode);
|
|
23
|
-
if (config) {
|
|
24
|
-
return config;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
currentDir = parentDir;
|
|
28
|
-
}
|
|
29
|
-
if (options.interactive !== false) {
|
|
30
|
-
await generateWorkspaceConfig(root, configFile);
|
|
31
|
-
const newConfig = await loadConfig(localConfigPath, mode);
|
|
32
|
-
if (newConfig) {
|
|
33
|
-
return newConfig;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
throw new Error(`No bgl.config.ts found in ${root} or parent directories`);
|
|
37
|
-
}
|
|
38
|
-
async function loadConfig(configPath, mode) {
|
|
39
|
-
if (!existsSync(configPath)) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
try {
|
|
43
|
-
const module = await import(`file://${configPath}`);
|
|
44
|
-
const configMap = module.default ?? module.configs ?? module.config;
|
|
45
|
-
if (typeof configMap === "function") {
|
|
46
|
-
return configMap(mode);
|
|
47
|
-
}
|
|
48
|
-
if (typeof configMap === "object" && configMap !== null) {
|
|
49
|
-
const modeConfig = configMap[mode];
|
|
50
|
-
if (mode in configMap && modeConfig !== void 0 && modeConfig !== null) {
|
|
51
|
-
return modeConfig;
|
|
52
|
-
}
|
|
53
|
-
return configMap;
|
|
54
|
-
}
|
|
55
|
-
return null;
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.warn(`Failed to load config from ${configPath}:`, error);
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function mergeConfigs(base, override) {
|
|
62
|
-
return {
|
|
63
|
-
...base,
|
|
64
|
-
...override
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function createViteProxy(config) {
|
|
69
|
-
const proxy = {};
|
|
70
|
-
if (config.proxy && config.host) {
|
|
71
|
-
proxy[config.proxy] = {
|
|
72
|
-
target: config.host,
|
|
73
|
-
changeOrigin: true,
|
|
74
|
-
rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
|
|
75
|
-
secure: true
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
if (config.host) {
|
|
79
|
-
proxy["/files"] = {
|
|
80
|
-
target: config.host,
|
|
81
|
-
changeOrigin: true,
|
|
82
|
-
secure: true
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return proxy;
|
|
86
|
-
}
|
|
87
|
-
function createCustomProxy(paths, target, options = {}) {
|
|
88
|
-
const proxy = {};
|
|
89
|
-
for (const path of paths) {
|
|
90
|
-
proxy[path] = {
|
|
91
|
-
target,
|
|
92
|
-
changeOrigin: options.changeOrigin ?? true,
|
|
93
|
-
secure: options.secure ?? true,
|
|
94
|
-
...options.rewrite === true && {
|
|
95
|
-
rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return proxy;
|
|
100
|
-
}
|
|
1
|
+
export { getApiUrl, useWorkspace } from './composable.mjs';
|
|
101
2
|
|
|
102
3
|
function defineWorkspace(configs) {
|
|
103
4
|
return (mode = "development") => {
|
|
104
5
|
return configs[mode] || configs.development;
|
|
105
6
|
};
|
|
106
7
|
}
|
|
107
|
-
function createWorkspace(options = {}) {
|
|
108
|
-
let cachedConfig = null;
|
|
109
|
-
return {
|
|
110
|
-
/**
|
|
111
|
-
* Get resolved config for the specified environment
|
|
112
|
-
*/
|
|
113
|
-
async getConfig(mode = "development") {
|
|
114
|
-
if (!cachedConfig) {
|
|
115
|
-
cachedConfig = await resolveConfig(mode, options);
|
|
116
|
-
}
|
|
117
|
-
return cachedConfig;
|
|
118
|
-
},
|
|
119
|
-
/**
|
|
120
|
-
* Create Vite proxy configuration
|
|
121
|
-
*/
|
|
122
|
-
createProxy(config) {
|
|
123
|
-
return createViteProxy(config);
|
|
124
|
-
},
|
|
125
|
-
/**
|
|
126
|
-
* Generate Netlify configuration file
|
|
127
|
-
*/
|
|
128
|
-
generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
|
|
129
|
-
writeNetlifyConfig(config, outPath, additionalConfig);
|
|
130
|
-
},
|
|
131
|
-
/**
|
|
132
|
-
* Set build environment variables
|
|
133
|
-
*/
|
|
134
|
-
setBuildEnv(config) {
|
|
135
|
-
setBuildEnvVars(config);
|
|
136
|
-
},
|
|
137
|
-
/**
|
|
138
|
-
* Clear cached configuration
|
|
139
|
-
*/
|
|
140
|
-
clearCache() {
|
|
141
|
-
cachedConfig = null;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
8
|
|
|
146
|
-
export {
|
|
9
|
+
export { defineWorkspace };
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
ws?: boolean;
|
|
42
|
+
followRedirects?: boolean;
|
|
43
|
+
autoRewrite?: boolean;
|
|
44
|
+
protocolRewrite?: string;
|
|
45
|
+
configure?: (proxy: any, options: any) => void;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
ws?: boolean;
|
|
42
|
+
followRedirects?: boolean;
|
|
43
|
+
autoRewrite?: boolean;
|
|
44
|
+
protocolRewrite?: string;
|
|
45
|
+
configure?: (proxy: any, options: any) => void;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
ws?: boolean;
|
|
42
|
+
followRedirects?: boolean;
|
|
43
|
+
autoRewrite?: boolean;
|
|
44
|
+
protocolRewrite?: string;
|
|
45
|
+
configure?: (proxy: any, options: any) => void;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type { ProxyConfig as P, WorkspaceEnvironment as W, WorkspaceConfig as a, WorkspaceOptions as b };
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const node_fs = require('node:fs');
|
|
4
|
+
const node_path = require('node:path');
|
|
5
|
+
const process = require('node:process');
|
|
6
|
+
|
|
7
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
8
|
+
|
|
9
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
10
|
+
|
|
11
|
+
function generateNetlifyRedirect(config) {
|
|
12
|
+
const redirect = `# API Proxy Configuration
|
|
13
|
+
# Environment variables are set in Netlify UI or netlify.toml [build.environment] section
|
|
14
|
+
|
|
15
|
+
[[redirects]]
|
|
16
|
+
from = "${config.proxy}/*"
|
|
17
|
+
to = "${config.host}/:splat"
|
|
18
|
+
status = 200
|
|
19
|
+
force = true
|
|
20
|
+
headers = {X-From = "Netlify"}
|
|
21
|
+
`;
|
|
22
|
+
return redirect;
|
|
23
|
+
}
|
|
24
|
+
function generateNetlifyConfigTemplate() {
|
|
25
|
+
return `# Standard Netlify configuration for Bagelink projects
|
|
26
|
+
# Uses environment variables for proxy configuration
|
|
27
|
+
|
|
28
|
+
[build.environment]
|
|
29
|
+
# Set these in Netlify UI or override here
|
|
30
|
+
# BGL_PROXY_PATH = "/api"
|
|
31
|
+
# BGL_API_HOST = "https://your-project.bagel.to"
|
|
32
|
+
|
|
33
|
+
[[redirects]]
|
|
34
|
+
# Proxy API requests to backend
|
|
35
|
+
# Uses BGL_PROXY_PATH and BGL_API_HOST from environment
|
|
36
|
+
from = "/api/*"
|
|
37
|
+
to = "https://your-project.bagel.to/:splat"
|
|
38
|
+
status = 200
|
|
39
|
+
force = true
|
|
40
|
+
headers = {X-From = "Netlify"}
|
|
41
|
+
|
|
42
|
+
# Example: Multiple API backends
|
|
43
|
+
# [[redirects]]
|
|
44
|
+
# from = "/api/v2/*"
|
|
45
|
+
# to = "https://api-v2.example.com/:splat"
|
|
46
|
+
# status = 200
|
|
47
|
+
# force = true
|
|
48
|
+
`;
|
|
49
|
+
}
|
|
50
|
+
function generateNetlifyConfig(config, additionalConfig, useTemplate = false) {
|
|
51
|
+
if (useTemplate) {
|
|
52
|
+
return generateNetlifyConfigTemplate();
|
|
53
|
+
}
|
|
54
|
+
const redirect = generateNetlifyRedirect(config);
|
|
55
|
+
if (additionalConfig !== void 0 && additionalConfig !== "") {
|
|
56
|
+
return `${redirect}
|
|
57
|
+
${additionalConfig}`;
|
|
58
|
+
}
|
|
59
|
+
return redirect;
|
|
60
|
+
}
|
|
61
|
+
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig, useTemplate = false) {
|
|
62
|
+
const content = generateNetlifyConfig(config, additionalConfig, useTemplate);
|
|
63
|
+
const resolvedPath = node_path.resolve(outPath);
|
|
64
|
+
node_fs.writeFileSync(resolvedPath, content, "utf-8");
|
|
65
|
+
console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
|
|
66
|
+
if (!useTemplate) {
|
|
67
|
+
console.log("\n\u{1F4A1} Tip: For environment-based config, set these in Netlify UI:");
|
|
68
|
+
console.log(` BGL_PROXY_PATH = "${config.proxy}"`);
|
|
69
|
+
console.log(` BGL_API_HOST = "${config.host}"`);
|
|
70
|
+
if (config.openapi_url) {
|
|
71
|
+
console.log(` BGL_OPENAPI_URL = "${config.openapi_url}"`);
|
|
72
|
+
}
|
|
73
|
+
console.log("");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function setBuildEnvVars(config) {
|
|
77
|
+
process__default.env.BGL_PROXY_PATH = config.proxy;
|
|
78
|
+
process__default.env.BGL_API_HOST = config.host;
|
|
79
|
+
if (config.openapi_url !== void 0 && config.openapi_url !== "") {
|
|
80
|
+
process__default.env.BGL_OPENAPI_URL = config.openapi_url;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
exports.generateNetlifyConfig = generateNetlifyConfig;
|
|
85
|
+
exports.setBuildEnvVars = setBuildEnvVars;
|
|
86
|
+
exports.writeNetlifyConfig = writeNetlifyConfig;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
|
|
5
|
+
function generateNetlifyRedirect(config) {
|
|
6
|
+
const redirect = `# API Proxy Configuration
|
|
7
|
+
# Environment variables are set in Netlify UI or netlify.toml [build.environment] section
|
|
8
|
+
|
|
9
|
+
[[redirects]]
|
|
10
|
+
from = "${config.proxy}/*"
|
|
11
|
+
to = "${config.host}/:splat"
|
|
12
|
+
status = 200
|
|
13
|
+
force = true
|
|
14
|
+
headers = {X-From = "Netlify"}
|
|
15
|
+
`;
|
|
16
|
+
return redirect;
|
|
17
|
+
}
|
|
18
|
+
function generateNetlifyConfigTemplate() {
|
|
19
|
+
return `# Standard Netlify configuration for Bagelink projects
|
|
20
|
+
# Uses environment variables for proxy configuration
|
|
21
|
+
|
|
22
|
+
[build.environment]
|
|
23
|
+
# Set these in Netlify UI or override here
|
|
24
|
+
# BGL_PROXY_PATH = "/api"
|
|
25
|
+
# BGL_API_HOST = "https://your-project.bagel.to"
|
|
26
|
+
|
|
27
|
+
[[redirects]]
|
|
28
|
+
# Proxy API requests to backend
|
|
29
|
+
# Uses BGL_PROXY_PATH and BGL_API_HOST from environment
|
|
30
|
+
from = "/api/*"
|
|
31
|
+
to = "https://your-project.bagel.to/:splat"
|
|
32
|
+
status = 200
|
|
33
|
+
force = true
|
|
34
|
+
headers = {X-From = "Netlify"}
|
|
35
|
+
|
|
36
|
+
# Example: Multiple API backends
|
|
37
|
+
# [[redirects]]
|
|
38
|
+
# from = "/api/v2/*"
|
|
39
|
+
# to = "https://api-v2.example.com/:splat"
|
|
40
|
+
# status = 200
|
|
41
|
+
# force = true
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
function generateNetlifyConfig(config, additionalConfig, useTemplate = false) {
|
|
45
|
+
if (useTemplate) {
|
|
46
|
+
return generateNetlifyConfigTemplate();
|
|
47
|
+
}
|
|
48
|
+
const redirect = generateNetlifyRedirect(config);
|
|
49
|
+
if (additionalConfig !== void 0 && additionalConfig !== "") {
|
|
50
|
+
return `${redirect}
|
|
51
|
+
${additionalConfig}`;
|
|
52
|
+
}
|
|
53
|
+
return redirect;
|
|
54
|
+
}
|
|
55
|
+
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig, useTemplate = false) {
|
|
56
|
+
const content = generateNetlifyConfig(config, additionalConfig, useTemplate);
|
|
57
|
+
const resolvedPath = resolve(outPath);
|
|
58
|
+
writeFileSync(resolvedPath, content, "utf-8");
|
|
59
|
+
console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
|
|
60
|
+
if (!useTemplate) {
|
|
61
|
+
console.log("\n\u{1F4A1} Tip: For environment-based config, set these in Netlify UI:");
|
|
62
|
+
console.log(` BGL_PROXY_PATH = "${config.proxy}"`);
|
|
63
|
+
console.log(` BGL_API_HOST = "${config.host}"`);
|
|
64
|
+
if (config.openapi_url) {
|
|
65
|
+
console.log(` BGL_OPENAPI_URL = "${config.openapi_url}"`);
|
|
66
|
+
}
|
|
67
|
+
console.log("");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function setBuildEnvVars(config) {
|
|
71
|
+
process.env.BGL_PROXY_PATH = config.proxy;
|
|
72
|
+
process.env.BGL_API_HOST = config.host;
|
|
73
|
+
if (config.openapi_url !== void 0 && config.openapi_url !== "") {
|
|
74
|
+
process.env.BGL_OPENAPI_URL = config.openapi_url;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { generateNetlifyConfig as g, setBuildEnvVars as s, writeNetlifyConfig as w };
|