@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 +101 -8
- package/bin/bgl.ts +34 -4
- package/dist/bin/bgl.cjs +30 -5
- package/dist/bin/bgl.mjs +30 -5
- package/dist/index.cjs +13 -42
- package/dist/index.d.cts +14 -1
- package/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.mjs +4 -36
- package/dist/shared/workspace.Bwsdwbt-.cjs +575 -0
- package/dist/shared/workspace.Dq-27S1f.mjs +560 -0
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/init.ts +36 -9
- package/src/workspace.ts +432 -0
- package/dist/shared/workspace.BaaKkm9b.mjs +0 -182
- package/dist/shared/workspace.CkP5t0--.cjs +0 -190
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_fs = require('node:fs');
|
|
4
|
-
const node_path = require('node:path');
|
|
5
|
-
const process = require('node:process');
|
|
6
|
-
const prompts = require('prompts');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
9
|
-
|
|
10
|
-
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
11
|
-
const prompts__default = /*#__PURE__*/_interopDefaultCompat(prompts);
|
|
12
|
-
|
|
13
|
-
async function generateWorkspaceConfig(root = process__default.cwd(), configFile = "bgl.config.ts") {
|
|
14
|
-
console.log("\n\u{1F527} No bgl.config.ts found. Let's create one!\n");
|
|
15
|
-
const response = await prompts__default([
|
|
16
|
-
{
|
|
17
|
-
type: "text",
|
|
18
|
-
name: "projectId",
|
|
19
|
-
message: "What is your Bagel project ID?",
|
|
20
|
-
initial: "my-project",
|
|
21
|
-
validate: (value) => value.length > 0 ? true : "Project ID is required"
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
type: "confirm",
|
|
25
|
-
name: "useCustomHost",
|
|
26
|
-
message: "Use custom production host?",
|
|
27
|
-
initial: false
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
type: (prev) => prev ? "text" : null,
|
|
31
|
-
name: "customHost",
|
|
32
|
-
message: "Enter production host URL:",
|
|
33
|
-
initial: "https://api.example.com"
|
|
34
|
-
}
|
|
35
|
-
]);
|
|
36
|
-
if (!response || !response.projectId) {
|
|
37
|
-
console.log("\n\u274C Config generation cancelled.\n");
|
|
38
|
-
process__default.exit(1);
|
|
39
|
-
}
|
|
40
|
-
const productionHost = response.useCustomHost === true ? response.customHost : `https://${response.projectId}.bagel.to`;
|
|
41
|
-
const configContent = `import { defineWorkspace } from '@bagelink/workspace'
|
|
42
|
-
import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
|
|
43
|
-
|
|
44
|
-
const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
|
|
45
|
-
localhost: {
|
|
46
|
-
host: 'http://localhost:8000',
|
|
47
|
-
proxy: '/api',
|
|
48
|
-
openapi_url: 'http://localhost:8000/openapi.json',
|
|
49
|
-
},
|
|
50
|
-
development: {
|
|
51
|
-
host: '${productionHost}',
|
|
52
|
-
proxy: '/api',
|
|
53
|
-
openapi_url: '${productionHost}/openapi.json',
|
|
54
|
-
},
|
|
55
|
-
production: {
|
|
56
|
-
host: '${productionHost}',
|
|
57
|
-
proxy: '/api',
|
|
58
|
-
openapi_url: '${productionHost}/openapi.json',
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export default defineWorkspace(configs)
|
|
63
|
-
`;
|
|
64
|
-
const configPath = node_path.resolve(root, configFile);
|
|
65
|
-
node_fs.writeFileSync(configPath, configContent, "utf-8");
|
|
66
|
-
console.log(`
|
|
67
|
-
\u2705 Created ${configFile}`);
|
|
68
|
-
console.log(` Production host: ${productionHost}`);
|
|
69
|
-
console.log(` Local dev host: http://localhost:8000
|
|
70
|
-
`);
|
|
71
|
-
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");
|
|
92
|
-
}
|
|
93
|
-
function generateWorkspaceConfigSync(projectId, root = process__default.cwd(), configFile = "bgl.config.ts", customHost) {
|
|
94
|
-
const productionHost = customHost ?? `https://${projectId}.bagel.to`;
|
|
95
|
-
const configContent = `import { defineWorkspace } from '@bagelink/workspace'
|
|
96
|
-
import type { WorkspaceConfig, WorkspaceEnvironment } from '@bagelink/workspace'
|
|
97
|
-
|
|
98
|
-
const configs: Record<WorkspaceEnvironment, WorkspaceConfig> = {
|
|
99
|
-
localhost: {
|
|
100
|
-
host: 'http://localhost:8000',
|
|
101
|
-
proxy: '/api',
|
|
102
|
-
openapi_url: 'http://localhost:8000/openapi.json',
|
|
103
|
-
},
|
|
104
|
-
development: {
|
|
105
|
-
host: '${productionHost}',
|
|
106
|
-
proxy: '/api',
|
|
107
|
-
openapi_url: '${productionHost}/openapi.json',
|
|
108
|
-
},
|
|
109
|
-
production: {
|
|
110
|
-
host: '${productionHost}',
|
|
111
|
-
proxy: '/api',
|
|
112
|
-
openapi_url: '${productionHost}/openapi.json',
|
|
113
|
-
},
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default defineWorkspace(configs)
|
|
117
|
-
`;
|
|
118
|
-
const configPath = node_path.resolve(root, configFile);
|
|
119
|
-
node_fs.writeFileSync(configPath, configContent, "utf-8");
|
|
120
|
-
console.log(`\u2705 Created ${configPath}`);
|
|
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 localhost",
|
|
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 'localhost' | '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
|
-
}
|
|
188
|
-
|
|
189
|
-
exports.generateWorkspaceConfig = generateWorkspaceConfig;
|
|
190
|
-
exports.generateWorkspaceConfigSync = generateWorkspaceConfigSync;
|