@bagelink/workspace 1.7.2 → 1.7.4

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
 
@@ -55,7 +58,7 @@ import { defineWorkspace } from '@bagelink/workspace'
55
58
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
56
59
 
57
60
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
58
- local: {
61
+ localhost: {
59
62
  host: 'http://localhost:8000',
60
63
  proxy: '/api',
61
64
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -101,7 +104,7 @@ export default defineConfig(({ mode }) => {
101
104
  {
102
105
  "scripts": {
103
106
  "dev": "vite",
104
- "dev:local": "vite --mode local",
107
+ "dev:local": "vite --mode localhost",
105
108
  "build": "vite build"
106
109
  }
107
110
  }
@@ -125,7 +128,7 @@ writeNetlifyConfig(config, './netlify.toml')
125
128
  import { defineWorkspace } from '@bagelink/workspace'
126
129
 
127
130
  export default defineWorkspace({
128
- local: {
131
+ localhost: {
129
132
  host: 'http://localhost:8000',
130
133
  proxy: '/api',
131
134
  },
@@ -147,7 +150,7 @@ import { defineWorkspace } from '@bagelink/workspace'
147
150
  import rootWorkspace from '../../bgl.config'
148
151
 
149
152
  export default defineWorkspace({
150
- local: rootWorkspace('local'),
153
+ localhost: rootWorkspace('localhost'),
151
154
  development: rootWorkspace('development'),
152
155
  production: {
153
156
  ...rootWorkspace('production'),
@@ -162,8 +165,9 @@ export default defineWorkspace({
162
165
 
163
166
  Interactively generate project configuration files:
164
167
  - `bgl.config.ts` - Workspace configuration
165
- - `package.json` - Add dev scripts (optional)
168
+ - `package.json` - Add/update dev scripts (optional)
166
169
  - `vite.config.ts` - Vite proxy configuration (optional)
170
+ - `netlify.toml` - Netlify deployment configuration (optional)
167
171
 
168
172
  ```bash
169
173
  npx bgl init
@@ -171,9 +175,10 @@ npx bgl init
171
175
 
172
176
  **Features:**
173
177
  - 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
178
+ - Adds/overwrites `dev` and `dev:local` scripts in package.json
179
+ - Creates vite.config.ts with proxy setup (if doesn't exist)
180
+ - Generates netlify.toml with production proxy configuration
181
+ - Safe: prompts before each step
177
182
 
178
183
  ### `npx bgl --help`
179
184
 
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.Cky2E7hz.cjs');
5
+ const init = require('../shared/workspace.hk0HFYa9.cjs');
6
6
  require('node:fs');
7
7
  require('node:path');
8
8
  require('prompts');
package/dist/bin/bgl.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import process from 'node:process';
3
- import { g as generateWorkspaceConfig } from '../shared/workspace.xXRAUM-U.mjs';
3
+ import { g as generateWorkspaceConfig } from '../shared/workspace.R3ocIOTb.mjs';
4
4
  import 'node:fs';
5
5
  import 'node:path';
6
6
  import 'prompts';
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.Cky2E7hz.cjs');
6
+ const init = require('./shared/workspace.hk0HFYa9.cjs');
7
7
  require('prompts');
8
8
 
9
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
@@ -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
+ init.writeNetlifyConfig(config, outPath, additionalConfig);
167
135
  },
168
136
  /**
169
137
  * Set build environment variables
170
138
  */
171
139
  setBuildEnv(config) {
172
- setBuildEnvVars(config);
140
+ init.setBuildEnvVars(config);
173
141
  },
174
142
  /**
175
143
  * Clear cached configuration
@@ -180,15 +148,15 @@ function createWorkspace(options = {}) {
180
148
  };
181
149
  }
182
150
 
151
+ exports.generateNetlifyConfig = init.generateNetlifyConfig;
152
+ exports.generateNetlifyRedirect = init.generateNetlifyRedirect;
183
153
  exports.generateWorkspaceConfig = init.generateWorkspaceConfig;
184
154
  exports.generateWorkspaceConfigSync = init.generateWorkspaceConfigSync;
155
+ exports.setBuildEnvVars = init.setBuildEnvVars;
156
+ exports.writeNetlifyConfig = init.writeNetlifyConfig;
185
157
  exports.createCustomProxy = createCustomProxy;
186
158
  exports.createViteProxy = createViteProxy;
187
159
  exports.createWorkspace = createWorkspace;
188
160
  exports.defineWorkspace = defineWorkspace;
189
- exports.generateNetlifyConfig = generateNetlifyConfig;
190
- exports.generateNetlifyRedirect = generateNetlifyRedirect;
191
161
  exports.mergeConfigs = mergeConfigs;
192
162
  exports.resolveConfig = resolveConfig;
193
- exports.setBuildEnvVars = setBuildEnvVars;
194
- exports.writeNetlifyConfig = writeNetlifyConfig;
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- type WorkspaceEnvironment = 'local' | 'development' | 'production';
1
+ type WorkspaceEnvironment = 'localhost' | 'development' | 'production';
2
2
  interface WorkspaceConfig {
3
3
  /**
4
4
  * The host URL of the backend API server
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- type WorkspaceEnvironment = 'local' | 'development' | 'production';
1
+ type WorkspaceEnvironment = 'localhost' | 'development' | 'production';
2
2
  interface WorkspaceConfig {
3
3
  /**
4
4
  * The host URL of the backend API server
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type WorkspaceEnvironment = 'local' | 'development' | 'production';
1
+ type WorkspaceEnvironment = 'localhost' | 'development' | 'production';
2
2
  interface WorkspaceConfig {
3
3
  /**
4
4
  * The host URL of the backend API server
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.xXRAUM-U.mjs';
5
- export { a as generateWorkspaceConfigSync } from './shared/workspace.xXRAUM-U.mjs';
4
+ import { g as generateWorkspaceConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.R3ocIOTb.mjs';
5
+ export { a as generateNetlifyConfig, b as generateNetlifyRedirect, c as generateWorkspaceConfigSync } from './shared/workspace.R3ocIOTb.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 };
@@ -3,6 +3,38 @@ import { resolve } from 'node:path';
3
3
  import process from 'node:process';
4
4
  import prompts from 'prompts';
5
5
 
6
+ function generateNetlifyRedirect(config) {
7
+ const redirect = `[[redirects]]
8
+ from = "${config.proxy}/*"
9
+ to = "${config.host}/:splat"
10
+ status = 200
11
+ force = true
12
+ headers = {X-From = "Netlify"}
13
+ `;
14
+ return redirect;
15
+ }
16
+ function generateNetlifyConfig(config, additionalConfig) {
17
+ const redirect = generateNetlifyRedirect(config);
18
+ if (additionalConfig !== void 0 && additionalConfig !== "") {
19
+ return `${redirect}
20
+ ${additionalConfig}`;
21
+ }
22
+ return redirect;
23
+ }
24
+ function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
25
+ const content = generateNetlifyConfig(config, additionalConfig);
26
+ const resolvedPath = resolve(outPath);
27
+ writeFileSync(resolvedPath, content, "utf-8");
28
+ console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
29
+ }
30
+ function setBuildEnvVars(config) {
31
+ process.env.BGL_PROXY_PATH = config.proxy;
32
+ process.env.BGL_API_HOST = config.host;
33
+ if (config.openapi_url !== void 0 && config.openapi_url !== "") {
34
+ process.env.BGL_OPENAPI_URL = config.openapi_url;
35
+ }
36
+ }
37
+
6
38
  async function generateWorkspaceConfig(root = process.cwd(), configFile = "bgl.config.ts") {
7
39
  console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
8
40
  const response = await prompts([
@@ -35,7 +67,7 @@ async function generateWorkspaceConfig(root = process.cwd(), configFile = "bgl.c
35
67
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
36
68
 
37
69
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
38
- local: {
70
+ localhost: {
39
71
  host: 'http://localhost:8000',
40
72
  proxy: '/api',
41
73
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -65,7 +97,7 @@ export default defineWorkspace(configs)
65
97
  {
66
98
  type: "confirm",
67
99
  name: "updatePackageJson",
68
- message: "Add dev scripts to package.json?",
100
+ message: "Add/update dev scripts in package.json?",
69
101
  initial: true
70
102
  },
71
103
  {
@@ -73,6 +105,12 @@ export default defineWorkspace(configs)
73
105
  name: "updateViteConfig",
74
106
  message: "Create/update vite.config.ts?",
75
107
  initial: true
108
+ },
109
+ {
110
+ type: "confirm",
111
+ name: "generateNetlify",
112
+ message: "Generate netlify.toml for deployment?",
113
+ initial: true
76
114
  }
77
115
  ]);
78
116
  if (setupResponse.updatePackageJson) {
@@ -81,6 +119,13 @@ export default defineWorkspace(configs)
81
119
  if (setupResponse.updateViteConfig) {
82
120
  updateViteConfig(root);
83
121
  }
122
+ if (setupResponse.generateNetlify) {
123
+ const prodConfig = {
124
+ host: productionHost,
125
+ proxy: "/api"
126
+ };
127
+ writeNetlifyConfig(prodConfig, resolve(root, "netlify.toml"));
128
+ }
84
129
  console.log("\n\u{1F4A1} You can edit these files to customize your configuration.\n");
85
130
  }
86
131
  function generateWorkspaceConfigSync(projectId, root = process.cwd(), configFile = "bgl.config.ts", customHost) {
@@ -89,7 +134,7 @@ function generateWorkspaceConfigSync(projectId, root = process.cwd(), configFile
89
134
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
90
135
 
91
136
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
92
- local: {
137
+ localhost: {
93
138
  host: 'http://localhost:8000',
94
139
  proxy: '/api',
95
140
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -125,23 +170,30 @@ function updatePackageJsonScripts(root) {
125
170
  }
126
171
  const scriptsToAdd = {
127
172
  "dev": "vite",
128
- "dev:local": "vite --mode local",
173
+ "dev:local": "vite --mode localhost",
129
174
  "build": "vite build",
130
175
  "preview": "vite preview"
131
176
  };
132
- let added = false;
177
+ let modified = false;
133
178
  for (const [key, value] of Object.entries(scriptsToAdd)) {
134
- if (!packageJson.scripts[key]) {
135
- packageJson.scripts[key] = value;
136
- added = true;
179
+ if (key === "dev" || key === "dev:local") {
180
+ if (packageJson.scripts[key] !== value) {
181
+ packageJson.scripts[key] = value;
182
+ modified = true;
183
+ }
184
+ } else {
185
+ if (!packageJson.scripts[key]) {
186
+ packageJson.scripts[key] = value;
187
+ modified = true;
188
+ }
137
189
  }
138
190
  }
139
- if (added) {
191
+ if (modified) {
140
192
  writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
141
193
  `, "utf-8");
142
194
  console.log("\u2705 Updated package.json with dev scripts");
143
195
  } else {
144
- console.log("\u2139\uFE0F Scripts already exist in package.json");
196
+ console.log("\u2139\uFE0F Scripts already up to date in package.json");
145
197
  }
146
198
  } catch (error) {
147
199
  console.error("\u274C Failed to update package.json:", error);
@@ -166,7 +218,7 @@ import workspace from './bgl.config'
166
218
 
167
219
  // https://vitejs.dev/config/
168
220
  export default defineConfig(({ mode }) => {
169
- const config = workspace(mode as 'local' | 'development' | 'production')
221
+ const config = workspace(mode as 'localhost' | 'development' | 'production')
170
222
 
171
223
  return {
172
224
  server: {
@@ -179,4 +231,4 @@ export default defineConfig(({ mode }) => {
179
231
  console.log("\u2705 Created vite.config.ts");
180
232
  }
181
233
 
182
- export { generateWorkspaceConfigSync as a, generateWorkspaceConfig as g };
234
+ export { generateNetlifyConfig as a, generateNetlifyRedirect as b, generateWorkspaceConfigSync as c, generateWorkspaceConfig as g, setBuildEnvVars as s, writeNetlifyConfig as w };
@@ -10,6 +10,38 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
10
10
  const process__default = /*#__PURE__*/_interopDefaultCompat(process);
11
11
  const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
12
12
 
13
+ function generateNetlifyRedirect(config) {
14
+ const redirect = `[[redirects]]
15
+ from = "${config.proxy}/*"
16
+ to = "${config.host}/:splat"
17
+ status = 200
18
+ force = true
19
+ headers = {X-From = "Netlify"}
20
+ `;
21
+ return redirect;
22
+ }
23
+ function generateNetlifyConfig(config, additionalConfig) {
24
+ const redirect = generateNetlifyRedirect(config);
25
+ if (additionalConfig !== void 0 && additionalConfig !== "") {
26
+ return `${redirect}
27
+ ${additionalConfig}`;
28
+ }
29
+ return redirect;
30
+ }
31
+ function writeNetlifyConfig(config, outPath = "./netlify.toml", additionalConfig) {
32
+ const content = generateNetlifyConfig(config, additionalConfig);
33
+ const resolvedPath = node_path.resolve(outPath);
34
+ node_fs.writeFileSync(resolvedPath, content, "utf-8");
35
+ console.log(`\u2713 Generated netlify.toml at ${resolvedPath}`);
36
+ }
37
+ function setBuildEnvVars(config) {
38
+ process__default.env.BGL_PROXY_PATH = config.proxy;
39
+ process__default.env.BGL_API_HOST = config.host;
40
+ if (config.openapi_url !== void 0 && config.openapi_url !== "") {
41
+ process__default.env.BGL_OPENAPI_URL = config.openapi_url;
42
+ }
43
+ }
44
+
13
45
  async function generateWorkspaceConfig(root = process__default.cwd(), configFile = "bgl.config.ts") {
14
46
  console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
15
47
  const response = await prompts__default([
@@ -42,7 +74,7 @@ async function generateWorkspaceConfig(root = process__default.cwd(), configFile
42
74
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
43
75
 
44
76
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
45
- local: {
77
+ localhost: {
46
78
  host: 'http://localhost:8000',
47
79
  proxy: '/api',
48
80
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -72,7 +104,7 @@ export default defineWorkspace(configs)
72
104
  {
73
105
  type: "confirm",
74
106
  name: "updatePackageJson",
75
- message: "Add dev scripts to package.json?",
107
+ message: "Add/update dev scripts in package.json?",
76
108
  initial: true
77
109
  },
78
110
  {
@@ -80,6 +112,12 @@ export default defineWorkspace(configs)
80
112
  name: "updateViteConfig",
81
113
  message: "Create/update vite.config.ts?",
82
114
  initial: true
115
+ },
116
+ {
117
+ type: "confirm",
118
+ name: "generateNetlify",
119
+ message: "Generate netlify.toml for deployment?",
120
+ initial: true
83
121
  }
84
122
  ]);
85
123
  if (setupResponse.updatePackageJson) {
@@ -88,6 +126,13 @@ export default defineWorkspace(configs)
88
126
  if (setupResponse.updateViteConfig) {
89
127
  updateViteConfig(root);
90
128
  }
129
+ if (setupResponse.generateNetlify) {
130
+ const prodConfig = {
131
+ host: productionHost,
132
+ proxy: "/api"
133
+ };
134
+ writeNetlifyConfig(prodConfig, node_path.resolve(root, "netlify.toml"));
135
+ }
91
136
  console.log("\n\u{1F4A1} You can edit these files to customize your configuration.\n");
92
137
  }
93
138
  function generateWorkspaceConfigSync(projectId, root = process__default.cwd(), configFile = "bgl.config.ts", customHost) {
@@ -96,7 +141,7 @@ function generateWorkspaceConfigSync(projectId, root = process__default.cwd(), c
96
141
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
97
142
 
98
143
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
99
- local: {
144
+ localhost: {
100
145
  host: 'http://localhost:8000',
101
146
  proxy: '/api',
102
147
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -132,23 +177,30 @@ function updatePackageJsonScripts(root) {
132
177
  }
133
178
  const scriptsToAdd = {
134
179
  "dev": "vite",
135
- "dev:local": "vite --mode local",
180
+ "dev:local": "vite --mode localhost",
136
181
  "build": "vite build",
137
182
  "preview": "vite preview"
138
183
  };
139
- let added = false;
184
+ let modified = false;
140
185
  for (const [key, value] of Object.entries(scriptsToAdd)) {
141
- if (!packageJson.scripts[key]) {
142
- packageJson.scripts[key] = value;
143
- added = true;
186
+ if (key === "dev" || key === "dev:local") {
187
+ if (packageJson.scripts[key] !== value) {
188
+ packageJson.scripts[key] = value;
189
+ modified = true;
190
+ }
191
+ } else {
192
+ if (!packageJson.scripts[key]) {
193
+ packageJson.scripts[key] = value;
194
+ modified = true;
195
+ }
144
196
  }
145
197
  }
146
- if (added) {
198
+ if (modified) {
147
199
  node_fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
148
200
  `, "utf-8");
149
201
  console.log("\u2705 Updated package.json with dev scripts");
150
202
  } else {
151
- console.log("\u2139\uFE0F Scripts already exist in package.json");
203
+ console.log("\u2139\uFE0F Scripts already up to date in package.json");
152
204
  }
153
205
  } catch (error) {
154
206
  console.error("\u274C Failed to update package.json:", error);
@@ -173,7 +225,7 @@ import workspace from './bgl.config'
173
225
 
174
226
  // https://vitejs.dev/config/
175
227
  export default defineConfig(({ mode }) => {
176
- const config = workspace(mode as 'local' | 'development' | 'production')
228
+ const config = workspace(mode as 'localhost' | 'development' | 'production')
177
229
 
178
230
  return {
179
231
  server: {
@@ -186,5 +238,9 @@ export default defineConfig(({ mode }) => {
186
238
  console.log("\u2705 Created vite.config.ts");
187
239
  }
188
240
 
241
+ exports.generateNetlifyConfig = generateNetlifyConfig;
242
+ exports.generateNetlifyRedirect = generateNetlifyRedirect;
189
243
  exports.generateWorkspaceConfig = generateWorkspaceConfig;
190
244
  exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
245
+ exports.setBuildEnvVars = setBuildEnvVars;
246
+ exports.writeNetlifyConfig = writeNetlifyConfig;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/workspace",
3
3
  "type": "module",
4
- "version": "1.7.2",
4
+ "version": "1.7.4",
5
5
  "description": "Monorepo workspace tooling for Bagel projects with proxy and config management",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
package/src/init.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import type { WorkspaceConfig } from './types'
1
2
  import { existsSync, readFileSync, writeFileSync } from 'node:fs'
2
3
  import { resolve } from 'node:path'
3
4
  import process from 'node:process'
4
5
  import prompts from 'prompts'
6
+ import { writeNetlifyConfig } from './netlify'
5
7
 
6
8
  /**
7
9
  * Generate bgl.config.ts file interactively
@@ -48,7 +50,7 @@ export async function generateWorkspaceConfig(
48
50
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
49
51
 
50
52
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
51
- local: {
53
+ localhost: {
52
54
  host: 'http://localhost:8000',
53
55
  proxy: '/api',
54
56
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -75,12 +77,12 @@ export default defineWorkspace(configs)
75
77
  console.log(` Production host: ${productionHost}`)
76
78
  console.log(` Local dev host: http://localhost:8000\n`)
77
79
 
78
- // Ask if they want to update package.json and vite.config
80
+ // Ask if they want to update package.json, vite.config, and netlify.toml
79
81
  const setupResponse = await prompts([
80
82
  {
81
83
  type: 'confirm',
82
84
  name: 'updatePackageJson',
83
- message: 'Add dev scripts to package.json?',
85
+ message: 'Add/update dev scripts in package.json?',
84
86
  initial: true,
85
87
  },
86
88
  {
@@ -89,6 +91,12 @@ export default defineWorkspace(configs)
89
91
  message: 'Create/update vite.config.ts?',
90
92
  initial: true,
91
93
  },
94
+ {
95
+ type: 'confirm',
96
+ name: 'generateNetlify',
97
+ message: 'Generate netlify.toml for deployment?',
98
+ initial: true,
99
+ },
92
100
  ])
93
101
 
94
102
  if (setupResponse.updatePackageJson) {
@@ -99,6 +107,14 @@ export default defineWorkspace(configs)
99
107
  updateViteConfig(root)
100
108
  }
101
109
 
110
+ if (setupResponse.generateNetlify) {
111
+ const prodConfig: WorkspaceConfig = {
112
+ host: productionHost,
113
+ proxy: '/api',
114
+ }
115
+ writeNetlifyConfig(prodConfig, resolve(root, 'netlify.toml'))
116
+ }
117
+
102
118
  console.log('\n💡 You can edit these files to customize your configuration.\n')
103
119
  }
104
120
 
@@ -117,7 +133,7 @@ export function generateWorkspaceConfigSync(
117
133
  import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
118
134
 
119
135
  const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
120
- local: {
136
+ localhost: {
121
137
  host: 'http://localhost:8000',
122
138
  proxy: '/api',
123
139
  openapi_url: 'http://localhost:8000/openapi.json',
@@ -160,28 +176,39 @@ function updatePackageJsonScripts(root: string): void {
160
176
  packageJson.scripts = {}
161
177
  }
162
178
 
163
- // Add scripts if they don't exist
179
+ // Add/overwrite dev scripts
164
180
  const scriptsToAdd = {
165
181
  'dev': 'vite',
166
- 'dev:local': 'vite --mode local',
182
+ 'dev:local': 'vite --mode localhost',
167
183
  'build': 'vite build',
168
184
  'preview': 'vite preview',
169
185
  }
170
186
 
171
- let added = false
187
+ // Always overwrite dev and dev:local, preserve others if they exist
188
+ let modified = false
172
189
  for (const [key, value] of Object.entries(scriptsToAdd)) {
173
- if (!packageJson.scripts[key]) {
174
- packageJson.scripts[key] = value
175
- added = true
190
+ if (key === 'dev' || key === 'dev:local') {
191
+ // Always overwrite these
192
+ if (packageJson.scripts[key] !== value) {
193
+ packageJson.scripts[key] = value
194
+ modified = true
195
+ }
196
+ }
197
+ else {
198
+ // Only add if doesn't exist
199
+ if (!packageJson.scripts[key]) {
200
+ packageJson.scripts[key] = value
201
+ modified = true
202
+ }
176
203
  }
177
204
  }
178
205
 
179
- if (added) {
206
+ if (modified) {
180
207
  writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf-8')
181
208
  console.log('✅ Updated package.json with dev scripts')
182
209
  }
183
210
  else {
184
- console.log('ℹ️ Scripts already exist in package.json')
211
+ console.log('ℹ️ Scripts already up to date in package.json')
185
212
  }
186
213
  }
187
214
  catch (error) {
@@ -218,7 +245,7 @@ import workspace from './bgl.config'
218
245
 
219
246
  // https://vitejs.dev/config/
220
247
  export default defineConfig(({ mode }) => {
221
- const config = workspace(mode as 'local' | 'development' | 'production')
248
+ const config = workspace(mode as 'localhost' | 'development' | 'production')
222
249
 
223
250
  return {
224
251
  server: {
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type WorkspaceEnvironment = 'local' | 'development' | 'production'
1
+ export type WorkspaceEnvironment = 'localhost' | 'development' | 'production'
2
2
 
3
3
  export interface WorkspaceConfig {
4
4
  /**