@bagelink/workspace 1.7.3 → 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 +12 -7
- package/dist/bin/bgl.cjs +1 -1
- package/dist/bin/bgl.mjs +1 -1
- package/dist/index.cjs +7 -39
- package/dist/index.mjs +4 -36
- package/dist/shared/{workspace.BaaKkm9b.mjs → workspace.R3ocIOTb.mjs} +60 -8
- package/dist/shared/{workspace.CkP5t0--.cjs → workspace.hk0HFYa9.cjs} +63 -7
- package/package.json +1 -1
- package/src/init.ts +36 -9
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
|
|
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
|
|
43
|
-
- Create
|
|
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
|
|
|
@@ -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
|
-
-
|
|
175
|
-
-
|
|
176
|
-
-
|
|
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
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.
|
|
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.
|
|
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.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { existsSync
|
|
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.
|
|
5
|
-
export { a as generateWorkspaceConfigSync } from './shared/workspace.
|
|
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,
|
|
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([
|
|
@@ -65,7 +97,7 @@ export default defineWorkspace(configs)
|
|
|
65
97
|
{
|
|
66
98
|
type: "confirm",
|
|
67
99
|
name: "updatePackageJson",
|
|
68
|
-
message: "Add dev scripts
|
|
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) {
|
|
@@ -129,19 +174,26 @@ function updatePackageJsonScripts(root) {
|
|
|
129
174
|
"build": "vite build",
|
|
130
175
|
"preview": "vite preview"
|
|
131
176
|
};
|
|
132
|
-
let
|
|
177
|
+
let modified = false;
|
|
133
178
|
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
134
|
-
if (
|
|
135
|
-
packageJson.scripts[key]
|
|
136
|
-
|
|
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 (
|
|
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
|
|
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);
|
|
@@ -179,4 +231,4 @@ export default defineConfig(({ mode }) => {
|
|
|
179
231
|
console.log("\u2705 Created vite.config.ts");
|
|
180
232
|
}
|
|
181
233
|
|
|
182
|
-
export {
|
|
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([
|
|
@@ -72,7 +104,7 @@ export default defineWorkspace(configs)
|
|
|
72
104
|
{
|
|
73
105
|
type: "confirm",
|
|
74
106
|
name: "updatePackageJson",
|
|
75
|
-
message: "Add dev scripts
|
|
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) {
|
|
@@ -136,19 +181,26 @@ function updatePackageJsonScripts(root) {
|
|
|
136
181
|
"build": "vite build",
|
|
137
182
|
"preview": "vite preview"
|
|
138
183
|
};
|
|
139
|
-
let
|
|
184
|
+
let modified = false;
|
|
140
185
|
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
141
|
-
if (
|
|
142
|
-
packageJson.scripts[key]
|
|
143
|
-
|
|
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 (
|
|
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
|
|
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);
|
|
@@ -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
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
|
|
@@ -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
|
|
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
|
|
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
|
|
|
@@ -160,7 +176,7 @@ function updatePackageJsonScripts(root: string): void {
|
|
|
160
176
|
packageJson.scripts = {}
|
|
161
177
|
}
|
|
162
178
|
|
|
163
|
-
// Add scripts
|
|
179
|
+
// Add/overwrite dev scripts
|
|
164
180
|
const scriptsToAdd = {
|
|
165
181
|
'dev': 'vite',
|
|
166
182
|
'dev:local': 'vite --mode localhost',
|
|
@@ -168,20 +184,31 @@ function updatePackageJsonScripts(root: string): void {
|
|
|
168
184
|
'preview': 'vite preview',
|
|
169
185
|
}
|
|
170
186
|
|
|
171
|
-
|
|
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 (
|
|
174
|
-
|
|
175
|
-
|
|
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 (
|
|
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
|
|
211
|
+
console.log('ℹ️ Scripts already up to date in package.json')
|
|
185
212
|
}
|
|
186
213
|
}
|
|
187
214
|
catch (error) {
|