@bagelink/workspace 1.0.0
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/LICENSE +21 -0
- package/README.md +221 -0
- package/bin/bgl.ts +28 -0
- package/dist/bin/bgl.cjs +34 -0
- package/dist/bin/bgl.d.cts +1 -0
- package/dist/bin/bgl.d.mts +1 -0
- package/dist/bin/bgl.d.ts +1 -0
- package/dist/bin/bgl.mjs +28 -0
- package/dist/index.cjs +194 -0
- package/dist/index.d.cts +127 -0
- package/dist/index.d.mts +127 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.mjs +178 -0
- package/dist/shared/workspace.BbV_HGYT.mjs +96 -0
- package/dist/shared/workspace.CmoK7Tc1.cjs +104 -0
- package/package.json +70 -0
- package/src/config.ts +108 -0
- package/src/index.ts +99 -0
- package/src/init.ts +118 -0
- package/src/netlify.ts +62 -0
- package/src/proxy.ts +57 -0
- package/src/types.ts +49 -0
- package/templates/netlify.toml.template +6 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
type WorkspaceEnvironment = 'local' | '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
|
+
* Define workspace configuration
|
|
96
|
+
* Simple helper to get config from a config map
|
|
97
|
+
*/
|
|
98
|
+
declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
|
|
99
|
+
/**
|
|
100
|
+
* Create a workspace instance for managing project configuration
|
|
101
|
+
* Supports both single project and monorepo setups
|
|
102
|
+
*/
|
|
103
|
+
declare function createWorkspace(options?: WorkspaceOptions): {
|
|
104
|
+
/**
|
|
105
|
+
* Get resolved config for the specified environment
|
|
106
|
+
*/
|
|
107
|
+
getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
|
|
108
|
+
/**
|
|
109
|
+
* Create Vite proxy configuration
|
|
110
|
+
*/
|
|
111
|
+
createProxy(config: WorkspaceConfig): ProxyConfig;
|
|
112
|
+
/**
|
|
113
|
+
* Generate Netlify configuration file
|
|
114
|
+
*/
|
|
115
|
+
generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Set build environment variables
|
|
118
|
+
*/
|
|
119
|
+
setBuildEnv(config: WorkspaceConfig): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear cached configuration
|
|
122
|
+
*/
|
|
123
|
+
clearCache(): void;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
127
|
+
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
type WorkspaceEnvironment = 'local' | '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
|
+
* Define workspace configuration
|
|
96
|
+
* Simple helper to get config from a config map
|
|
97
|
+
*/
|
|
98
|
+
declare function defineWorkspace(configs: Record<WorkspaceEnvironment, WorkspaceConfig>): (mode?: WorkspaceEnvironment) => WorkspaceConfig;
|
|
99
|
+
/**
|
|
100
|
+
* Create a workspace instance for managing project configuration
|
|
101
|
+
* Supports both single project and monorepo setups
|
|
102
|
+
*/
|
|
103
|
+
declare function createWorkspace(options?: WorkspaceOptions): {
|
|
104
|
+
/**
|
|
105
|
+
* Get resolved config for the specified environment
|
|
106
|
+
*/
|
|
107
|
+
getConfig(mode?: WorkspaceEnvironment): Promise<WorkspaceConfig>;
|
|
108
|
+
/**
|
|
109
|
+
* Create Vite proxy configuration
|
|
110
|
+
*/
|
|
111
|
+
createProxy(config: WorkspaceConfig): ProxyConfig;
|
|
112
|
+
/**
|
|
113
|
+
* Generate Netlify configuration file
|
|
114
|
+
*/
|
|
115
|
+
generateNetlify(config: WorkspaceConfig, outPath?: string, additionalConfig?: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Set build environment variables
|
|
118
|
+
*/
|
|
119
|
+
setBuildEnv(config: WorkspaceConfig): void;
|
|
120
|
+
/**
|
|
121
|
+
* Clear cached configuration
|
|
122
|
+
*/
|
|
123
|
+
clearCache(): void;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
127
|
+
export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { existsSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { resolve, join } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import { g as generateWorkspaceConfig } from './shared/workspace.BbV_HGYT.mjs';
|
|
5
|
+
export { a as generateWorkspaceConfigSync } from './shared/workspace.BbV_HGYT.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 generateNetlifyRedirect(config) {
|
|
69
|
+
const redirect = `[[redirects]]
|
|
70
|
+
from = "${config.proxy}/*"
|
|
71
|
+
to = "${config.host}/:splat"
|
|
72
|
+
status = 200
|
|
73
|
+
force = true
|
|
74
|
+
headers = {X-From = "Netlify"}
|
|
75
|
+
`;
|
|
76
|
+
return redirect;
|
|
77
|
+
}
|
|
78
|
+
function generateNetlifyConfig(config, additionalConfig) {
|
|
79
|
+
const redirect = generateNetlifyRedirect(config);
|
|
80
|
+
if (additionalConfig !== void 0 && additionalConfig !== "") {
|
|
81
|
+
return `${redirect}
|
|
82
|
+
${additionalConfig}`;
|
|
83
|
+
}
|
|
84
|
+
return redirect;
|
|
85
|
+
}
|
|
86
|
+
function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
|
|
87
|
+
const content = generateNetlifyConfig(config, additionalConfig);
|
|
88
|
+
const resolvedPath = resolve(outPath);
|
|
89
|
+
writeFileSync(resolvedPath, content, "utf-8");
|
|
90
|
+
console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
|
|
91
|
+
}
|
|
92
|
+
function setBuildEnvVars(config) {
|
|
93
|
+
process.env.BGL_PROXY_PATH = config.proxy;
|
|
94
|
+
process.env.BGL_API_HOST = config.host;
|
|
95
|
+
if (config.openapi_url !== void 0 && config.openapi_url !== "") {
|
|
96
|
+
process.env.BGL_OPENAPI_URL = config.openapi_url;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function createViteProxy(config) {
|
|
101
|
+
const proxy = {};
|
|
102
|
+
if (config.proxy && config.host) {
|
|
103
|
+
proxy[config.proxy] = {
|
|
104
|
+
target: config.host,
|
|
105
|
+
changeOrigin: true,
|
|
106
|
+
rewrite: (path) => path.replace(new RegExp(`^${config.proxy}`), ""),
|
|
107
|
+
secure: true
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (config.host) {
|
|
111
|
+
proxy["/files"] = {
|
|
112
|
+
target: config.host,
|
|
113
|
+
changeOrigin: true,
|
|
114
|
+
secure: true
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return proxy;
|
|
118
|
+
}
|
|
119
|
+
function createCustomProxy(paths, target, options = {}) {
|
|
120
|
+
const proxy = {};
|
|
121
|
+
for (const path of paths) {
|
|
122
|
+
proxy[path] = {
|
|
123
|
+
target,
|
|
124
|
+
changeOrigin: options.changeOrigin ?? true,
|
|
125
|
+
secure: options.secure ?? true,
|
|
126
|
+
...options.rewrite === true && {
|
|
127
|
+
rewrite: (p) => p.replace(new RegExp(`^${path}`), "")
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
return proxy;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function defineWorkspace(configs) {
|
|
135
|
+
return (mode = "development") => {
|
|
136
|
+
return configs[mode] || configs.development;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function createWorkspace(options = {}) {
|
|
140
|
+
let cachedConfig = null;
|
|
141
|
+
return {
|
|
142
|
+
/**
|
|
143
|
+
* Get resolved config for the specified environment
|
|
144
|
+
*/
|
|
145
|
+
async getConfig(mode = "development") {
|
|
146
|
+
if (!cachedConfig) {
|
|
147
|
+
cachedConfig = await resolveConfig(mode, options);
|
|
148
|
+
}
|
|
149
|
+
return cachedConfig;
|
|
150
|
+
},
|
|
151
|
+
/**
|
|
152
|
+
* Create Vite proxy configuration
|
|
153
|
+
*/
|
|
154
|
+
createProxy(config) {
|
|
155
|
+
return createViteProxy(config);
|
|
156
|
+
},
|
|
157
|
+
/**
|
|
158
|
+
* Generate Netlify configuration file
|
|
159
|
+
*/
|
|
160
|
+
generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
|
|
161
|
+
writeNetlifyConfig(config, outPath, additionalConfig);
|
|
162
|
+
},
|
|
163
|
+
/**
|
|
164
|
+
* Set build environment variables
|
|
165
|
+
*/
|
|
166
|
+
setBuildEnv(config) {
|
|
167
|
+
setBuildEnvVars(config);
|
|
168
|
+
},
|
|
169
|
+
/**
|
|
170
|
+
* Clear cached configuration
|
|
171
|
+
*/
|
|
172
|
+
clearCache() {
|
|
173
|
+
cachedConfig = null;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import process from 'node:process';
|
|
4
|
+
import prompts from 'prompts';
|
|
5
|
+
|
|
6
|
+
async function generateWorkspaceConfig(root = process.cwd(), configFile = "bgl.config.ts") {
|
|
7
|
+
console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
|
|
8
|
+
const response = await prompts([
|
|
9
|
+
{
|
|
10
|
+
type: "text",
|
|
11
|
+
name: "projectId",
|
|
12
|
+
message: "What is your Bagel project ID?",
|
|
13
|
+
initial: "my-project",
|
|
14
|
+
validate: (value) => value.length > 0 ? true : "Project ID is required"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
type: "confirm",
|
|
18
|
+
name: "useCustomHost",
|
|
19
|
+
message: "Use custom production host?",
|
|
20
|
+
initial: false
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
type: (prev) => prev ? "text" : null,
|
|
24
|
+
name: "customHost",
|
|
25
|
+
message: "Enter production host URL:",
|
|
26
|
+
initial: "https://api.example.com"
|
|
27
|
+
}
|
|
28
|
+
]);
|
|
29
|
+
if (!response || !response.projectId) {
|
|
30
|
+
console.log("\n\u274C Config generation cancelled.\n");
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const productionHost = response.useCustomHost === true ? response.customHost : `https://${response.projectId}.bagel.to`;
|
|
34
|
+
const configContent = `import { defineWorkspace } from '@bagelink/workspace'
|
|
35
|
+
import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
|
|
36
|
+
|
|
37
|
+
const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
|
|
38
|
+
local: {
|
|
39
|
+
host: 'http://localhost:8000',
|
|
40
|
+
proxy: '/api',
|
|
41
|
+
openapi_url: 'http://localhost:8000/openapi.json',
|
|
42
|
+
},
|
|
43
|
+
development: {
|
|
44
|
+
host: '${productionHost}',
|
|
45
|
+
proxy: '/api',
|
|
46
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
47
|
+
},
|
|
48
|
+
production: {
|
|
49
|
+
host: '${productionHost}',
|
|
50
|
+
proxy: '/api',
|
|
51
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default defineWorkspace(configs)
|
|
56
|
+
`;
|
|
57
|
+
const configPath = resolve(root, configFile);
|
|
58
|
+
writeFileSync(configPath, configContent, "utf-8");
|
|
59
|
+
console.log(`
|
|
60
|
+
\u2705 Created ${configFile}`);
|
|
61
|
+
console.log(` Production host: ${productionHost}`);
|
|
62
|
+
console.log(` Local dev host: http://localhost:8000
|
|
63
|
+
`);
|
|
64
|
+
console.log("\u{1F4A1} You can edit this file to customize your configuration.\n");
|
|
65
|
+
}
|
|
66
|
+
function generateWorkspaceConfigSync(projectId, root = process.cwd(), configFile = "bgl.config.ts", customHost) {
|
|
67
|
+
const productionHost = customHost ?? `https://${projectId}.bagel.to`;
|
|
68
|
+
const configContent = `import { defineWorkspace } from '@bagelink/workspace'
|
|
69
|
+
import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
|
|
70
|
+
|
|
71
|
+
const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
|
|
72
|
+
local: {
|
|
73
|
+
host: 'http://localhost:8000',
|
|
74
|
+
proxy: '/api',
|
|
75
|
+
openapi_url: 'http://localhost:8000/openapi.json',
|
|
76
|
+
},
|
|
77
|
+
development: {
|
|
78
|
+
host: '${productionHost}',
|
|
79
|
+
proxy: '/api',
|
|
80
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
81
|
+
},
|
|
82
|
+
production: {
|
|
83
|
+
host: '${productionHost}',
|
|
84
|
+
proxy: '/api',
|
|
85
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default defineWorkspace(configs)
|
|
90
|
+
`;
|
|
91
|
+
const configPath = resolve(root, configFile);
|
|
92
|
+
writeFileSync(configPath, configContent, "utf-8");
|
|
93
|
+
console.log(`\u2705 Created ${configPath}`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { generateWorkspaceConfigSync as a, generateWorkspaceConfig as g };
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
const prompts = require('prompts');
|
|
7
|
+
|
|
8
|
+
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
+
|
|
10
|
+
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
11
|
+
const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
|
|
12
|
+
|
|
13
|
+
async function generateWorkspaceConfig(root = process__default.cwd(), configFile = "bgl.config.ts") {
|
|
14
|
+
console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
|
|
15
|
+
const response = await prompts__default([
|
|
16
|
+
{
|
|
17
|
+
type: "text",
|
|
18
|
+
name: "projectId",
|
|
19
|
+
message: "What is your Bagel project ID?",
|
|
20
|
+
initial: "my-project",
|
|
21
|
+
validate: (value) => value.length > 0 ? true : "Project ID is required"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
type: "confirm",
|
|
25
|
+
name: "useCustomHost",
|
|
26
|
+
message: "Use custom production host?",
|
|
27
|
+
initial: false
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: (prev) => prev ? "text" : null,
|
|
31
|
+
name: "customHost",
|
|
32
|
+
message: "Enter production host URL:",
|
|
33
|
+
initial: "https://api.example.com"
|
|
34
|
+
}
|
|
35
|
+
]);
|
|
36
|
+
if (!response || !response.projectId) {
|
|
37
|
+
console.log("\n\u274C Config generation cancelled.\n");
|
|
38
|
+
process__default.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const productionHost = response.useCustomHost === true ? response.customHost : `https://${response.projectId}.bagel.to`;
|
|
41
|
+
const configContent = `import { defineWorkspace } from '@bagelink/workspace'
|
|
42
|
+
import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
|
|
43
|
+
|
|
44
|
+
const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
|
|
45
|
+
local: {
|
|
46
|
+
host: 'http://localhost:8000',
|
|
47
|
+
proxy: '/api',
|
|
48
|
+
openapi_url: 'http://localhost:8000/openapi.json',
|
|
49
|
+
},
|
|
50
|
+
development: {
|
|
51
|
+
host: '${productionHost}',
|
|
52
|
+
proxy: '/api',
|
|
53
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
54
|
+
},
|
|
55
|
+
production: {
|
|
56
|
+
host: '${productionHost}',
|
|
57
|
+
proxy: '/api',
|
|
58
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export default defineWorkspace(configs)
|
|
63
|
+
`;
|
|
64
|
+
const configPath = node_path.resolve(root, configFile);
|
|
65
|
+
node_fs.writeFileSync(configPath, configContent, "utf-8");
|
|
66
|
+
console.log(`
|
|
67
|
+
\u2705 Created ${configFile}`);
|
|
68
|
+
console.log(` Production host: ${productionHost}`);
|
|
69
|
+
console.log(` Local dev host: http://localhost:8000
|
|
70
|
+
`);
|
|
71
|
+
console.log("\u{1F4A1} You can edit this file to customize your configuration.\n");
|
|
72
|
+
}
|
|
73
|
+
function generateWorkspaceConfigSync(projectId, root = process__default.cwd(), configFile = "bgl.config.ts", customHost) {
|
|
74
|
+
const productionHost = customHost ?? `https://${projectId}.bagel.to`;
|
|
75
|
+
const configContent = `import { defineWorkspace } from '@bagelink/workspace'
|
|
76
|
+
import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
|
|
77
|
+
|
|
78
|
+
const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
|
|
79
|
+
local: {
|
|
80
|
+
host: 'http://localhost:8000',
|
|
81
|
+
proxy: '/api',
|
|
82
|
+
openapi_url: 'http://localhost:8000/openapi.json',
|
|
83
|
+
},
|
|
84
|
+
development: {
|
|
85
|
+
host: '${productionHost}',
|
|
86
|
+
proxy: '/api',
|
|
87
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
88
|
+
},
|
|
89
|
+
production: {
|
|
90
|
+
host: '${productionHost}',
|
|
91
|
+
proxy: '/api',
|
|
92
|
+
openapi_url: '${productionHost}/openapi.json',
|
|
93
|
+
},
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default defineWorkspace(configs)
|
|
97
|
+
`;
|
|
98
|
+
const configPath = node_path.resolve(root, configFile);
|
|
99
|
+
node_fs.writeFileSync(configPath, configContent, "utf-8");
|
|
100
|
+
console.log(`\u2705 Created ${configPath}`);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
exports.generateWorkspaceConfig = generateWorkspaceConfig;
|
|
104
|
+
exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bagelink/workspace",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "Bagel Studio",
|
|
8
|
+
"email": "info@bagelstudio.co.il",
|
|
9
|
+
"url": "https://bagelstudio.co.il"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/bageldb/bagelink/tree/master/packages/workspace#readme",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/bageldb/bagelink.git",
|
|
16
|
+
"directory": "packages/workspace"
|
|
17
|
+
},
|
|
18
|
+
"bugs": "https://github.com/bageldb/bagelink/issues",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"bagel",
|
|
21
|
+
"bagelink",
|
|
22
|
+
"workspace",
|
|
23
|
+
"monorepo",
|
|
24
|
+
"proxy",
|
|
25
|
+
"vite",
|
|
26
|
+
"netlify"
|
|
27
|
+
],
|
|
28
|
+
"sideEffects": false,
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"require": "./dist/index.cjs",
|
|
33
|
+
"import": "./dist/index.mjs"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"main": "./dist/index.mjs",
|
|
37
|
+
"module": "./dist/index.mjs",
|
|
38
|
+
"types": "./dist/index.d.ts",
|
|
39
|
+
"bin": {
|
|
40
|
+
"bgl": "./dist/bin/bgl.mjs"
|
|
41
|
+
},
|
|
42
|
+
"files": [
|
|
43
|
+
"dist",
|
|
44
|
+
"src",
|
|
45
|
+
"bin",
|
|
46
|
+
"templates",
|
|
47
|
+
"README.md"
|
|
48
|
+
],
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"prompts": "^2.4.2"
|
|
54
|
+
},
|
|
55
|
+
"devDependencies": {
|
|
56
|
+
"@types/node": "^24.0.0",
|
|
57
|
+
"@types/prompts": "^2.4.9",
|
|
58
|
+
"rimraf": "^6.0.1",
|
|
59
|
+
"typescript": "^5.8.3",
|
|
60
|
+
"unbuild": "^3.5.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"vite": ">=5.0.0"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"dev": "unbuild --stub",
|
|
67
|
+
"build": "unbuild",
|
|
68
|
+
"clean": "rimraf dist"
|
|
69
|
+
}
|
|
70
|
+
}
|