@bagelink/workspace 1.0.0 → 1.7.2
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 +21 -2
- package/dist/bin/bgl.cjs +1 -1
- package/dist/bin/bgl.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +2 -2
- package/dist/shared/{workspace.CmoK7Tc1.cjs → workspace.Cky2E7hz.cjs} +87 -1
- package/dist/shared/{workspace.BbV_HGYT.mjs → workspace.xXRAUM-U.mjs} +88 -2
- package/package.json +1 -1
- package/src/init.ts +117 -2
package/README.md
CHANGED
|
@@ -17,7 +17,7 @@ pnpm add @bagelink/workspace
|
|
|
17
17
|
|
|
18
18
|
## Quick Start
|
|
19
19
|
|
|
20
|
-
### Option 1: Run `npx bgl init`
|
|
20
|
+
### Option 1: Run `npx bgl init` (Recommended)
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
npx bgl init
|
|
@@ -26,12 +26,22 @@ 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
|
|
30
|
+
? Create/update vite.config.ts? › Yes
|
|
29
31
|
|
|
30
32
|
✅ Created bgl.config.ts
|
|
31
33
|
Production host: https://my-project.bagel.to
|
|
32
34
|
Local dev host: http://localhost:8000
|
|
35
|
+
|
|
36
|
+
✅ Updated package.json with dev scripts
|
|
37
|
+
✅ Created vite.config.ts
|
|
33
38
|
```
|
|
34
39
|
|
|
40
|
+
This will:
|
|
41
|
+
- 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
|
+
|
|
35
45
|
### Option 2: Automatic on first use
|
|
36
46
|
|
|
37
47
|
The first time you use `@bagelink/workspace`, it will automatically prompt you to create a config file if it doesn't exist.
|
|
@@ -150,12 +160,21 @@ export default defineWorkspace({
|
|
|
150
160
|
|
|
151
161
|
### `npx bgl init`
|
|
152
162
|
|
|
153
|
-
Interactively generate
|
|
163
|
+
Interactively generate project configuration files:
|
|
164
|
+
- `bgl.config.ts` - Workspace configuration
|
|
165
|
+
- `package.json` - Add dev scripts (optional)
|
|
166
|
+
- `vite.config.ts` - Vite proxy configuration (optional)
|
|
154
167
|
|
|
155
168
|
```bash
|
|
156
169
|
npx bgl init
|
|
157
170
|
```
|
|
158
171
|
|
|
172
|
+
**Features:**
|
|
173
|
+
- 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
|
|
177
|
+
|
|
159
178
|
### `npx bgl --help`
|
|
160
179
|
|
|
161
180
|
Show CLI help.
|
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.xXRAUM-U.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.Cky2E7hz.cjs');
|
|
7
7
|
require('prompts');
|
|
8
8
|
|
|
9
9
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { existsSync, writeFileSync } 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 } from './shared/workspace.xXRAUM-U.mjs';
|
|
5
|
+
export { a as generateWorkspaceConfigSync } from './shared/workspace.xXRAUM-U.mjs';
|
|
6
6
|
import 'prompts';
|
|
7
7
|
|
|
8
8
|
async function resolveConfig(mode = "development", options = {}) {
|
|
@@ -68,7 +68,27 @@ export default defineWorkspace(configs)
|
|
|
68
68
|
console.log(` Production host: ${productionHost}`);
|
|
69
69
|
console.log(` Local dev host: http://localhost:8000
|
|
70
70
|
`);
|
|
71
|
-
|
|
71
|
+
const setupResponse = await prompts__default([
|
|
72
|
+
{
|
|
73
|
+
type: "confirm",
|
|
74
|
+
name: "updatePackageJson",
|
|
75
|
+
message: "Add dev scripts to package.json?",
|
|
76
|
+
initial: true
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
type: "confirm",
|
|
80
|
+
name: "updateViteConfig",
|
|
81
|
+
message: "Create/update vite.config.ts?",
|
|
82
|
+
initial: true
|
|
83
|
+
}
|
|
84
|
+
]);
|
|
85
|
+
if (setupResponse.updatePackageJson) {
|
|
86
|
+
updatePackageJsonScripts(root);
|
|
87
|
+
}
|
|
88
|
+
if (setupResponse.updateViteConfig) {
|
|
89
|
+
updateViteConfig(root);
|
|
90
|
+
}
|
|
91
|
+
console.log("\n\u{1F4A1} You can edit these files to customize your configuration.\n");
|
|
72
92
|
}
|
|
73
93
|
function generateWorkspaceConfigSync(projectId, root = process__default.cwd(), configFile = "bgl.config.ts", customHost) {
|
|
74
94
|
const productionHost = customHost ?? `https://${projectId}.bagel.to`;
|
|
@@ -99,6 +119,72 @@ export default defineWorkspace(configs)
|
|
|
99
119
|
node_fs.writeFileSync(configPath, configContent, "utf-8");
|
|
100
120
|
console.log(`\u2705 Created ${configPath}`);
|
|
101
121
|
}
|
|
122
|
+
function updatePackageJsonScripts(root) {
|
|
123
|
+
const packageJsonPath = node_path.resolve(root, "package.json");
|
|
124
|
+
if (!node_fs.existsSync(packageJsonPath)) {
|
|
125
|
+
console.log("\u26A0\uFE0F No package.json found, skipping script update");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const packageJson = JSON.parse(node_fs.readFileSync(packageJsonPath, "utf-8"));
|
|
130
|
+
if (!packageJson.scripts) {
|
|
131
|
+
packageJson.scripts = {};
|
|
132
|
+
}
|
|
133
|
+
const scriptsToAdd = {
|
|
134
|
+
"dev": "vite",
|
|
135
|
+
"dev:local": "vite --mode local",
|
|
136
|
+
"build": "vite build",
|
|
137
|
+
"preview": "vite preview"
|
|
138
|
+
};
|
|
139
|
+
let added = false;
|
|
140
|
+
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
141
|
+
if (!packageJson.scripts[key]) {
|
|
142
|
+
packageJson.scripts[key] = value;
|
|
143
|
+
added = true;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (added) {
|
|
147
|
+
node_fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
148
|
+
`, "utf-8");
|
|
149
|
+
console.log("\u2705 Updated package.json with dev scripts");
|
|
150
|
+
} else {
|
|
151
|
+
console.log("\u2139\uFE0F Scripts already exist in package.json");
|
|
152
|
+
}
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("\u274C Failed to update package.json:", error);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
function updateViteConfig(root) {
|
|
158
|
+
const viteConfigPath = node_path.resolve(root, "vite.config.ts");
|
|
159
|
+
const viteConfigExists = node_fs.existsSync(viteConfigPath);
|
|
160
|
+
if (viteConfigExists) {
|
|
161
|
+
const existingConfig = node_fs.readFileSync(viteConfigPath, "utf-8");
|
|
162
|
+
if (existingConfig.includes("@bagelink/workspace")) {
|
|
163
|
+
console.log("\u2139\uFE0F vite.config.ts already configured");
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the workspace configuration.");
|
|
167
|
+
console.log(" See: https://github.com/bageldb/bagelink/tree/master/packages/workspace#readme");
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const viteConfigContent = `import { defineConfig } from 'vite'
|
|
171
|
+
import { createViteProxy } from '@bagelink/workspace'
|
|
172
|
+
import workspace from './bgl.config'
|
|
173
|
+
|
|
174
|
+
// https://vitejs.dev/config/
|
|
175
|
+
export default defineConfig(({ mode }) => {
|
|
176
|
+
const config = workspace(mode as 'local' | 'development' | 'production')
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
server: {
|
|
180
|
+
proxy: createViteProxy(config),
|
|
181
|
+
},
|
|
182
|
+
}
|
|
183
|
+
})
|
|
184
|
+
`;
|
|
185
|
+
node_fs.writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
186
|
+
console.log("\u2705 Created vite.config.ts");
|
|
187
|
+
}
|
|
102
188
|
|
|
103
189
|
exports.generateWorkspaceConfig = generateWorkspaceConfig;
|
|
104
190
|
exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs';
|
|
1
|
+
import { writeFileSync, existsSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import prompts from 'prompts';
|
|
@@ -61,7 +61,27 @@ export default defineWorkspace(configs)
|
|
|
61
61
|
console.log(` Production host: ${productionHost}`);
|
|
62
62
|
console.log(` Local dev host: http://localhost:8000
|
|
63
63
|
`);
|
|
64
|
-
|
|
64
|
+
const setupResponse = await prompts([
|
|
65
|
+
{
|
|
66
|
+
type: "confirm",
|
|
67
|
+
name: "updatePackageJson",
|
|
68
|
+
message: "Add dev scripts to package.json?",
|
|
69
|
+
initial: true
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: "confirm",
|
|
73
|
+
name: "updateViteConfig",
|
|
74
|
+
message: "Create/update vite.config.ts?",
|
|
75
|
+
initial: true
|
|
76
|
+
}
|
|
77
|
+
]);
|
|
78
|
+
if (setupResponse.updatePackageJson) {
|
|
79
|
+
updatePackageJsonScripts(root);
|
|
80
|
+
}
|
|
81
|
+
if (setupResponse.updateViteConfig) {
|
|
82
|
+
updateViteConfig(root);
|
|
83
|
+
}
|
|
84
|
+
console.log("\n\u{1F4A1} You can edit these files to customize your configuration.\n");
|
|
65
85
|
}
|
|
66
86
|
function generateWorkspaceConfigSync(projectId, root = process.cwd(), configFile = "bgl.config.ts", customHost) {
|
|
67
87
|
const productionHost = customHost ?? `https://${projectId}.bagel.to`;
|
|
@@ -92,5 +112,71 @@ export default defineWorkspace(configs)
|
|
|
92
112
|
writeFileSync(configPath, configContent, "utf-8");
|
|
93
113
|
console.log(`\u2705 Created ${configPath}`);
|
|
94
114
|
}
|
|
115
|
+
function updatePackageJsonScripts(root) {
|
|
116
|
+
const packageJsonPath = resolve(root, "package.json");
|
|
117
|
+
if (!existsSync(packageJsonPath)) {
|
|
118
|
+
console.log("\u26A0\uFE0F No package.json found, skipping script update");
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
try {
|
|
122
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
123
|
+
if (!packageJson.scripts) {
|
|
124
|
+
packageJson.scripts = {};
|
|
125
|
+
}
|
|
126
|
+
const scriptsToAdd = {
|
|
127
|
+
"dev": "vite",
|
|
128
|
+
"dev:local": "vite --mode local",
|
|
129
|
+
"build": "vite build",
|
|
130
|
+
"preview": "vite preview"
|
|
131
|
+
};
|
|
132
|
+
let added = false;
|
|
133
|
+
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
134
|
+
if (!packageJson.scripts[key]) {
|
|
135
|
+
packageJson.scripts[key] = value;
|
|
136
|
+
added = true;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (added) {
|
|
140
|
+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
141
|
+
`, "utf-8");
|
|
142
|
+
console.log("\u2705 Updated package.json with dev scripts");
|
|
143
|
+
} else {
|
|
144
|
+
console.log("\u2139\uFE0F Scripts already exist in package.json");
|
|
145
|
+
}
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error("\u274C Failed to update package.json:", error);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function updateViteConfig(root) {
|
|
151
|
+
const viteConfigPath = resolve(root, "vite.config.ts");
|
|
152
|
+
const viteConfigExists = existsSync(viteConfigPath);
|
|
153
|
+
if (viteConfigExists) {
|
|
154
|
+
const existingConfig = readFileSync(viteConfigPath, "utf-8");
|
|
155
|
+
if (existingConfig.includes("@bagelink/workspace")) {
|
|
156
|
+
console.log("\u2139\uFE0F vite.config.ts already configured");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
console.log("\u26A0\uFE0F vite.config.ts exists. Please manually add the workspace configuration.");
|
|
160
|
+
console.log(" See: https://github.com/bageldb/bagelink/tree/master/packages/workspace#readme");
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const viteConfigContent = `import { defineConfig } from 'vite'
|
|
164
|
+
import { createViteProxy } from '@bagelink/workspace'
|
|
165
|
+
import workspace from './bgl.config'
|
|
166
|
+
|
|
167
|
+
// https://vitejs.dev/config/
|
|
168
|
+
export default defineConfig(({ mode }) => {
|
|
169
|
+
const config = workspace(mode as 'local' | 'development' | 'production')
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
server: {
|
|
173
|
+
proxy: createViteProxy(config),
|
|
174
|
+
},
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
`;
|
|
178
|
+
writeFileSync(viteConfigPath, viteConfigContent, "utf-8");
|
|
179
|
+
console.log("\u2705 Created vite.config.ts");
|
|
180
|
+
}
|
|
95
181
|
|
|
96
182
|
export { generateWorkspaceConfigSync as a, generateWorkspaceConfig as g };
|
package/package.json
CHANGED
package/src/init.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { writeFileSync } from 'node:fs'
|
|
1
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
2
2
|
import { resolve } from 'node:path'
|
|
3
3
|
import process from 'node:process'
|
|
4
4
|
import prompts from 'prompts'
|
|
@@ -74,7 +74,32 @@ export default defineWorkspace(configs)
|
|
|
74
74
|
console.log(`\n✅ Created ${configFile}`)
|
|
75
75
|
console.log(` Production host: ${productionHost}`)
|
|
76
76
|
console.log(` Local dev host: http://localhost:8000\n`)
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
// Ask if they want to update package.json and vite.config
|
|
79
|
+
const setupResponse = await prompts([
|
|
80
|
+
{
|
|
81
|
+
type: 'confirm',
|
|
82
|
+
name: 'updatePackageJson',
|
|
83
|
+
message: 'Add dev scripts to package.json?',
|
|
84
|
+
initial: true,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
type: 'confirm',
|
|
88
|
+
name: 'updateViteConfig',
|
|
89
|
+
message: 'Create/update vite.config.ts?',
|
|
90
|
+
initial: true,
|
|
91
|
+
},
|
|
92
|
+
])
|
|
93
|
+
|
|
94
|
+
if (setupResponse.updatePackageJson) {
|
|
95
|
+
updatePackageJsonScripts(root)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (setupResponse.updateViteConfig) {
|
|
99
|
+
updateViteConfig(root)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
console.log('\n💡 You can edit these files to customize your configuration.\n')
|
|
78
103
|
}
|
|
79
104
|
|
|
80
105
|
/**
|
|
@@ -116,3 +141,93 @@ export default defineWorkspace(configs)
|
|
|
116
141
|
writeFileSync(configPath, configContent, 'utf-8')
|
|
117
142
|
console.log(`✅ Created ${configPath}`)
|
|
118
143
|
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Update package.json to add dev scripts
|
|
147
|
+
*/
|
|
148
|
+
function updatePackageJsonScripts(root: string): void {
|
|
149
|
+
const packageJsonPath = resolve(root, 'package.json')
|
|
150
|
+
|
|
151
|
+
if (!existsSync(packageJsonPath)) {
|
|
152
|
+
console.log('⚠️ No package.json found, skipping script update')
|
|
153
|
+
return
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8'))
|
|
158
|
+
|
|
159
|
+
if (!packageJson.scripts) {
|
|
160
|
+
packageJson.scripts = {}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Add scripts if they don't exist
|
|
164
|
+
const scriptsToAdd = {
|
|
165
|
+
'dev': 'vite',
|
|
166
|
+
'dev:local': 'vite --mode local',
|
|
167
|
+
'build': 'vite build',
|
|
168
|
+
'preview': 'vite preview',
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
let added = false
|
|
172
|
+
for (const [key, value] of Object.entries(scriptsToAdd)) {
|
|
173
|
+
if (!packageJson.scripts[key]) {
|
|
174
|
+
packageJson.scripts[key] = value
|
|
175
|
+
added = true
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (added) {
|
|
180
|
+
writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`, 'utf-8')
|
|
181
|
+
console.log('✅ Updated package.json with dev scripts')
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
console.log('ℹ️ Scripts already exist in package.json')
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
console.error('❌ Failed to update package.json:', error)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Create or update vite.config.ts
|
|
194
|
+
*/
|
|
195
|
+
function updateViteConfig(root: string): void {
|
|
196
|
+
const viteConfigPath = resolve(root, 'vite.config.ts')
|
|
197
|
+
const viteConfigExists = existsSync(viteConfigPath)
|
|
198
|
+
|
|
199
|
+
if (viteConfigExists) {
|
|
200
|
+
const existingConfig = readFileSync(viteConfigPath, 'utf-8')
|
|
201
|
+
|
|
202
|
+
// Check if it already imports from @bagelink/workspace
|
|
203
|
+
if (existingConfig.includes('@bagelink/workspace')) {
|
|
204
|
+
console.log('ℹ️ vite.config.ts already configured')
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Ask to overwrite
|
|
209
|
+
console.log('⚠️ vite.config.ts exists. Please manually add the workspace configuration.')
|
|
210
|
+
console.log(' See: https://github.com/bageldb/bagelink/tree/master/packages/workspace#readme')
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Create new vite.config.ts
|
|
215
|
+
const viteConfigContent = `import { defineConfig } from 'vite'
|
|
216
|
+
import { createViteProxy } from '@bagelink/workspace'
|
|
217
|
+
import workspace from './bgl.config'
|
|
218
|
+
|
|
219
|
+
// https://vitejs.dev/config/
|
|
220
|
+
export default defineConfig(({ mode }) => {
|
|
221
|
+
const config = workspace(mode as 'local' | 'development' | 'production')
|
|
222
|
+
|
|
223
|
+
return {
|
|
224
|
+
server: {
|
|
225
|
+
proxy: createViteProxy(config),
|
|
226
|
+
},
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
`
|
|
230
|
+
|
|
231
|
+
writeFileSync(viteConfigPath, viteConfigContent, 'utf-8')
|
|
232
|
+
console.log('✅ Created vite.config.ts')
|
|
233
|
+
}
|