@bagelink/workspace 1.7.3 → 1.8.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/README.md CHANGED
@@ -26,8 +26,9 @@ npx bgl init
26
26
 
27
27
  ? What is your Bagel project ID? › my-project
28
28
  ? Use custom production host? › No / Yes
29
- ? Add dev scripts to package.json? › Yes
29
+ ? Add/update dev scripts in package.json? › Yes
30
30
  ? Create/update vite.config.ts? › Yes
31
+ ? Generate netlify.toml for deployment? › Yes
31
32
 
32
33
  ✅ Created bgl.config.ts
33
34
  Production host: https://my-project.bagel.to
@@ -35,12 +36,14 @@ npx bgl init
35
36
 
36
37
  ✅ Updated package.json with dev scripts
37
38
  ✅ Created vite.config.ts
39
+ ✅ Generated netlify.toml
38
40
  ```
39
41
 
40
42
  This will:
41
43
  - Create `bgl.config.ts` with your project configuration
42
- - Add `dev`, `dev:local`, `build`, and `preview` scripts to `package.json`
43
- - Create/update `vite.config.ts` with proxy configuration
44
+ - Add/overwrite `dev` and `dev:local` scripts in `package.json`
45
+ - Create `vite.config.ts` with proxy configuration (if doesn't exist)
46
+ - Generate `netlify.toml` with production proxy configuration
44
47
 
45
48
  ### Option 2: Automatic on first use
46
49
 
@@ -158,12 +161,15 @@ export default defineWorkspace({
158
161
 
159
162
  ## CLI
160
163
 
161
- ### `npx bgl init`
164
+ ### Single Project Setup
165
+
166
+ #### `npx bgl init`
162
167
 
163
168
  Interactively generate project configuration files:
164
169
  - `bgl.config.ts` - Workspace configuration
165
- - `package.json` - Add dev scripts (optional)
170
+ - `package.json` - Add/update dev scripts (optional)
166
171
  - `vite.config.ts` - Vite proxy configuration (optional)
172
+ - `netlify.toml` - Netlify deployment configuration (optional)
167
173
 
168
174
  ```bash
169
175
  npx bgl init
@@ -171,9 +177,96 @@ npx bgl init
171
177
 
172
178
  **Features:**
173
179
  - Prompts for project ID and host configuration
174
- - Optionally adds dev scripts to package.json (`dev`, `dev:local`, `build`, `preview`)
175
- - Optionally creates vite.config.ts with proxy setup
176
- - Safe: won't overwrite existing configurations without confirmation
180
+ - Adds/overwrites `dev` and `dev:local` scripts in package.json
181
+ - Creates vite.config.ts with proxy setup (if doesn't exist)
182
+ - Generates netlify.toml with production proxy configuration
183
+ - Safe: prompts before each step
184
+
185
+ ### Workspace (Multi-Project) Setup
186
+
187
+ #### `npx bgl init --workspace`
188
+
189
+ Create a workspace with flat structure for multiple projects:
190
+
191
+ ```bash
192
+ npx bgl init --workspace
193
+
194
+ ? Workspace name: › my-workspace
195
+ ? Bagel project ID: › my-project
196
+ ? Create first project? › Yes
197
+ ? First project name: › web
198
+
199
+ ✅ Workspace created successfully!
200
+ ```
201
+
202
+ **Creates structure:**
203
+ ```
204
+ my-workspace/
205
+ ├── package.json # Workspace root
206
+ ├── bgl.config.ts # Shared config
207
+ ├── tsconfig.json
208
+ ├── shared/ # Shared code
209
+ │ ├── package.json
210
+ │ ├── utils/
211
+ │ └── types/
212
+ └── web/ # First project
213
+ ├── bgl.config.ts
214
+ ├── package.json
215
+ ├── vite.config.ts
216
+ └── src/
217
+ ```
218
+
219
+ #### `bgl add <project-name>`
220
+
221
+ Add a new project to workspace:
222
+
223
+ ```bash
224
+ bgl add admin
225
+ bgl add customer
226
+ bgl add mobile
227
+ ```
228
+
229
+ Each project:
230
+ - Gets its own directory at root level
231
+ - Inherits shared config from workspace root
232
+ - Can import from `shared/utils`, `shared/types`, etc.
233
+ - Auto-configures with Vite proxy
234
+
235
+ #### `bgl list`
236
+
237
+ List all projects in workspace:
238
+
239
+ ```bash
240
+ bgl list
241
+
242
+ Projects:
243
+ - web
244
+ - admin
245
+ - customer
246
+ ```
247
+
248
+ ### Running Workspace Projects
249
+
250
+ ```bash
251
+ # Run all projects concurrently
252
+ bun run dev
253
+
254
+ # Run specific project
255
+ bun run dev:admin
256
+ bun run dev:customer
257
+
258
+ # Build specific project
259
+ bun run build:admin
260
+
261
+ # Build all projects
262
+ bun run build
263
+ ```
264
+
265
+ **Vite automatically assigns ports:**
266
+ - First project: `http://localhost:5173`
267
+ - Second project: `http://localhost:5174`
268
+ - Third project: `http://localhost:5175`
269
+ - etc.
177
270
 
178
271
  ### `npx bgl --help`
179
272
 
package/bin/bgl.ts CHANGED
@@ -1,22 +1,52 @@
1
1
  #!/usr/bin/env node
2
2
  import process from 'node:process'
3
3
  import { generateWorkspaceConfig } from '../src/init.js'
4
+ import { addProject, initWorkspace, listProjects } from '../src/workspace.js'
4
5
 
5
- const [,, command] = process.argv
6
+ const [,, command, ...args] = process.argv
6
7
 
7
8
  async function main() {
8
9
  if (command === 'init') {
9
- await generateWorkspaceConfig()
10
+ const isWorkspace = args.includes('--workspace') || args.includes('-w')
11
+ if (isWorkspace) {
12
+ await initWorkspace()
13
+ }
14
+ else {
15
+ await generateWorkspaceConfig()
16
+ }
17
+ }
18
+ else if (command === 'add') {
19
+ const projectName = args[0]
20
+ if (!projectName) {
21
+ console.error('Error: Project name is required')
22
+ console.log('Usage: bgl add <project-name>')
23
+ process.exit(1)
24
+ }
25
+ await addProject(projectName)
26
+ }
27
+ else if (command === 'list') {
28
+ const projects = listProjects()
29
+ if (projects.length === 0) {
30
+ console.log('No projects found')
31
+ }
32
+ else {
33
+ console.log('\nProjects:')
34
+ projects.forEach(p => console.log(` - ${p}`))
35
+ console.log('')
36
+ }
10
37
  }
11
38
  else {
12
39
  console.log(`
13
40
  Bagel Workspace CLI
14
41
 
15
42
  Usage:
16
- bgl init Generate bgl.config.ts interactively
43
+ bgl init Generate bgl.config.ts for single project
44
+ bgl init --workspace Create a new workspace with multiple projects
45
+ bgl add <name> Add a new project to workspace
46
+ bgl list List all projects in workspace
17
47
 
18
48
  Options:
19
- --help, -h Show this help message
49
+ --help, -h Show this help message
20
50
  `)
21
51
  process.exit(command === '--help' || command === '-h' ? 0 : 1)
22
52
  }
package/dist/bin/bgl.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
  'use strict';
3
3
 
4
4
  const process = require('node:process');
5
- const init = require('../shared/workspace.CkP5t0--.cjs');
5
+ const workspace = require('../shared/workspace.Bwsdwbt-.cjs');
6
6
  require('node:fs');
7
7
  require('node:path');
8
8
  require('prompts');
@@ -11,19 +11,44 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
11
11
 
12
12
  const process__default = /*#__PURE__*/_interopDefaultCompat(process);
13
13
 
14
- const [, , command] = process__default.argv;
14
+ const [, , command, ...args] = process__default.argv;
15
15
  async function main() {
16
16
  if (command === "init") {
17
- await init.generateWorkspaceConfig();
17
+ const isWorkspace = args.includes("--workspace") || args.includes("-w");
18
+ if (isWorkspace) {
19
+ await workspace.initWorkspace();
20
+ } else {
21
+ await workspace.generateWorkspaceConfig();
22
+ }
23
+ } else if (command === "add") {
24
+ const projectName = args[0];
25
+ if (!projectName) {
26
+ console.error("Error: Project name is required");
27
+ console.log("Usage: bgl add <project-name>");
28
+ process__default.exit(1);
29
+ }
30
+ await workspace.addProject(projectName);
31
+ } else if (command === "list") {
32
+ const projects = workspace.listProjects();
33
+ if (projects.length === 0) {
34
+ console.log("No projects found");
35
+ } else {
36
+ console.log("\nProjects:");
37
+ projects.forEach((p) => console.log(` - ${p}`));
38
+ console.log("");
39
+ }
18
40
  } else {
19
41
  console.log(`
20
42
  Bagel Workspace CLI
21
43
 
22
44
  Usage:
23
- bgl init Generate bgl.config.ts interactively
45
+ bgl init Generate bgl.config.ts for single project
46
+ bgl init --workspace Create a new workspace with multiple projects
47
+ bgl add <name> Add a new project to workspace
48
+ bgl list List all projects in workspace
24
49
 
25
50
  Options:
26
- --help, -h Show this help message
51
+ --help, -h Show this help message
27
52
  `);
28
53
  process__default.exit(command === "--help" || command === "-h" ? 0 : 1);
29
54
  }
package/dist/bin/bgl.mjs CHANGED
@@ -1,23 +1,48 @@
1
1
  #!/usr/bin/env node
2
2
  import process from 'node:process';
3
- import { g as generateWorkspaceConfig } from '../shared/workspace.BaaKkm9b.mjs';
3
+ import { i as initWorkspace, g as generateWorkspaceConfig, d as addProject, l as listProjects } from '../shared/workspace.Dq-27S1f.mjs';
4
4
  import 'node:fs';
5
5
  import 'node:path';
6
6
  import 'prompts';
7
7
 
8
- const [, , command] = process.argv;
8
+ const [, , command, ...args] = process.argv;
9
9
  async function main() {
10
10
  if (command === "init") {
11
- await generateWorkspaceConfig();
11
+ const isWorkspace = args.includes("--workspace") || args.includes("-w");
12
+ if (isWorkspace) {
13
+ await initWorkspace();
14
+ } else {
15
+ await generateWorkspaceConfig();
16
+ }
17
+ } else if (command === "add") {
18
+ const projectName = args[0];
19
+ if (!projectName) {
20
+ console.error("Error: Project name is required");
21
+ console.log("Usage: bgl add <project-name>");
22
+ process.exit(1);
23
+ }
24
+ await addProject(projectName);
25
+ } else if (command === "list") {
26
+ const projects = listProjects();
27
+ if (projects.length === 0) {
28
+ console.log("No projects found");
29
+ } else {
30
+ console.log("\nProjects:");
31
+ projects.forEach((p) => console.log(` - ${p}`));
32
+ console.log("");
33
+ }
12
34
  } else {
13
35
  console.log(`
14
36
  Bagel Workspace CLI
15
37
 
16
38
  Usage:
17
- bgl init Generate bgl.config.ts interactively
39
+ bgl init Generate bgl.config.ts for single project
40
+ bgl init --workspace Create a new workspace with multiple projects
41
+ bgl add <name> Add a new project to workspace
42
+ bgl list List all projects in workspace
18
43
 
19
44
  Options:
20
- --help, -h Show this help message
45
+ --help, -h Show this help message
21
46
  `);
22
47
  process.exit(command === "--help" || command === "-h" ? 0 : 1);
23
48
  }
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
  const node_fs = require('node:fs');
4
4
  const node_path = require('node:path');
5
5
  const process = require('node:process');
6
- const init = require('./shared/workspace.CkP5t0--.cjs');
6
+ const workspace = require('./shared/workspace.Bwsdwbt-.cjs');
7
7
  require('prompts');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -32,7 +32,7 @@ async function resolveConfig(mode = "development", options = {}) {
32
32
  currentDir = parentDir;
33
33
  }
34
34
  if (options.interactive !== false) {
35
- await init.generateWorkspaceConfig(root, configFile);
35
+ await workspace.generateWorkspaceConfig(root, configFile);
36
36
  const newConfig = await loadConfig(localConfigPath, mode);
37
37
  if (newConfig) {
38
38
  return newConfig;
@@ -70,38 +70,6 @@ function mergeConfigs(base, override) {
70
70
  };
71
71
  }
72
72
 
73
- function generateNetlifyRedirect(config) {
74
- const redirect = `[[redirects]]
75
- from = "${config.proxy}/*"
76
- to = "${config.host}/:splat"
77
- status = 200
78
- force = true
79
- headers = {X-From = "Netlify"}
80
- `;
81
- return redirect;
82
- }
83
- function generateNetlifyConfig(config, additionalConfig) {
84
- const redirect = generateNetlifyRedirect(config);
85
- if (additionalConfig !== void 0 && additionalConfig !== "") {
86
- return `${redirect}
87
- ${additionalConfig}`;
88
- }
89
- return redirect;
90
- }
91
- function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
92
- const content = generateNetlifyConfig(config, additionalConfig);
93
- const resolvedPath = node_path.resolve(outPath);
94
- node_fs.writeFileSync(resolvedPath, content, "utf-8");
95
- console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
96
- }
97
- function setBuildEnvVars(config) {
98
- process__default.env.BGL_PROXY_PATH = config.proxy;
99
- process__default.env.BGL_API_HOST = config.host;
100
- if (config.openapi_url !== void 0 && config.openapi_url !== "") {
101
- process__default.env.BGL_OPENAPI_URL = config.openapi_url;
102
- }
103
- }
104
-
105
73
  function createViteProxy(config) {
106
74
  const proxy = {};
107
75
  if (config.proxy && config.host) {
@@ -163,13 +131,13 @@ function createWorkspace(options = {}) {
163
131
  * Generate Netlify configuration file
164
132
  */
165
133
  generateNetlify(config, outPath = "./netlify.toml", additionalConfig) {
166
- writeNetlifyConfig(config, outPath, additionalConfig);
134
+ workspace.writeNetlifyConfig(config, outPath, additionalConfig);
167
135
  },
168
136
  /**
169
137
  * Set build environment variables
170
138
  */
171
139
  setBuildEnv(config) {
172
- setBuildEnvVars(config);
140
+ workspace.setBuildEnvVars(config);
173
141
  },
174
142
  /**
175
143
  * Clear cached configuration
@@ -180,15 +148,18 @@ function createWorkspace(options = {}) {
180
148
  };
181
149
  }
182
150
 
183
- exports.generateWorkspaceConfig = init.generateWorkspaceConfig;
184
- exports.generateWorkspaceConfigSync = init.generateWorkspaceConfigSync;
151
+ exports.addProject = workspace.addProject;
152
+ exports.generateNetlifyConfig = workspace.generateNetlifyConfig;
153
+ exports.generateNetlifyRedirect = workspace.generateNetlifyRedirect;
154
+ exports.generateWorkspaceConfig = workspace.generateWorkspaceConfig;
155
+ exports.generateWorkspaceConfigSync = workspace.generateWorkspaceConfigSync;
156
+ exports.initWorkspace = workspace.initWorkspace;
157
+ exports.listProjects = workspace.listProjects;
158
+ exports.setBuildEnvVars = workspace.setBuildEnvVars;
159
+ exports.writeNetlifyConfig = workspace.writeNetlifyConfig;
185
160
  exports.createCustomProxy = createCustomProxy;
186
161
  exports.createViteProxy = createViteProxy;
187
162
  exports.createWorkspace = createWorkspace;
188
163
  exports.defineWorkspace = defineWorkspace;
189
- exports.generateNetlifyConfig = generateNetlifyConfig;
190
- exports.generateNetlifyRedirect = generateNetlifyRedirect;
191
164
  exports.mergeConfigs = mergeConfigs;
192
165
  exports.resolveConfig = resolveConfig;
193
- exports.setBuildEnvVars = setBuildEnvVars;
194
- exports.writeNetlifyConfig = writeNetlifyConfig;
package/dist/index.d.cts CHANGED
@@ -91,6 +91,19 @@ declare function createCustomProxy(paths: string[], target: string, options?: {
91
91
  secure?: boolean;
92
92
  }): ProxyConfig;
93
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[];
106
+
94
107
  /**
95
108
  * Define workspace configuration
96
109
  * Simple helper to get config from a config map
@@ -123,5 +136,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
123
136
  clearCache(): void;
124
137
  };
125
138
 
126
- export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
139
+ export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, initWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
127
140
  export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
package/dist/index.d.mts CHANGED
@@ -91,6 +91,19 @@ declare function createCustomProxy(paths: string[], target: string, options?: {
91
91
  secure?: boolean;
92
92
  }): ProxyConfig;
93
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[];
106
+
94
107
  /**
95
108
  * Define workspace configuration
96
109
  * Simple helper to get config from a config map
@@ -123,5 +136,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
123
136
  clearCache(): void;
124
137
  };
125
138
 
126
- export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
139
+ export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, initWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
127
140
  export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
package/dist/index.d.ts CHANGED
@@ -91,6 +91,19 @@ declare function createCustomProxy(paths: string[], target: string, options?: {
91
91
  secure?: boolean;
92
92
  }): ProxyConfig;
93
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[];
106
+
94
107
  /**
95
108
  * Define workspace configuration
96
109
  * Simple helper to get config from a config map
@@ -123,5 +136,5 @@ declare function createWorkspace(options?: WorkspaceOptions): {
123
136
  clearCache(): void;
124
137
  };
125
138
 
126
- export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
139
+ export { addProject, createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, generateWorkspaceConfigSync, initWorkspace, listProjects, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
127
140
  export type { ProxyConfig, WorkspaceConfig, WorkspaceEnvironment, WorkspaceOptions };
package/dist/index.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { existsSync, writeFileSync } from 'node:fs';
1
+ import { existsSync } from 'node:fs';
2
2
  import { resolve, join } from 'node:path';
3
3
  import process from 'node:process';
4
- import { g as generateWorkspaceConfig } from './shared/workspace.BaaKkm9b.mjs';
5
- export { a as generateWorkspaceConfigSync } from './shared/workspace.BaaKkm9b.mjs';
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
6
  import 'prompts';
7
7
 
8
8
  async function resolveConfig(mode = "development", options = {}) {
@@ -65,38 +65,6 @@ function mergeConfigs(base, override) {
65
65
  };
66
66
  }
67
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
68
  function createViteProxy(config) {
101
69
  const proxy = {};
102
70
  if (config.proxy && config.host) {
@@ -175,4 +143,4 @@ function createWorkspace(options = {}) {
175
143
  };
176
144
  }
177
145
 
178
- export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateNetlifyConfig, generateNetlifyRedirect, generateWorkspaceConfig, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };
146
+ export { createCustomProxy, createViteProxy, createWorkspace, defineWorkspace, generateWorkspaceConfig, mergeConfigs, resolveConfig, setBuildEnvVars, writeNetlifyConfig };