@bagelink/workspace 1.10.25 → 1.10.27
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/dist/bin/bgl.cjs +1 -1
- package/dist/bin/bgl.mjs +1 -1
- package/dist/shared/{workspace.Bc_dpzhA.mjs → workspace.A649z5ed.mjs} +85 -25
- package/dist/shared/{workspace.DRlDHdPw.cjs → workspace.CSBtD5Cu.cjs} +85 -25
- package/dist/vite.cjs +1 -1
- package/dist/vite.mjs +2 -2
- package/package.json +1 -1
- package/src/workspace.ts +94 -25
package/dist/bin/bgl.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
const node_path = require('node:path');
|
|
5
5
|
const process = require('node:process');
|
|
6
6
|
const node_child_process = require('node:child_process');
|
|
7
|
-
const netlify = require('../shared/workspace.
|
|
7
|
+
const netlify = require('../shared/workspace.CSBtD5Cu.cjs');
|
|
8
8
|
const node_fs = require('node:fs');
|
|
9
9
|
const prompts = require('prompts');
|
|
10
10
|
|
package/dist/bin/bgl.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import { spawn } from 'node:child_process';
|
|
5
|
-
import { l as listProjects, w as writeNetlifyConfig, i as initWorkspace, a as addProject } from '../shared/workspace.
|
|
5
|
+
import { l as listProjects, w as writeNetlifyConfig, i as initWorkspace, a as addProject } from '../shared/workspace.A649z5ed.mjs';
|
|
6
6
|
import { existsSync, readFileSync, readdirSync, writeFileSync, unlinkSync, mkdirSync } from 'node:fs';
|
|
7
7
|
import prompts from 'prompts';
|
|
8
8
|
|
|
@@ -3,6 +3,16 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import process from 'node:process';
|
|
4
4
|
import prompts from 'prompts';
|
|
5
5
|
|
|
6
|
+
async function resolveLatestVersion(pkg) {
|
|
7
|
+
try {
|
|
8
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`);
|
|
9
|
+
if (!res.ok) return "latest";
|
|
10
|
+
const data = await res.json();
|
|
11
|
+
return `^${data.version}`;
|
|
12
|
+
} catch {
|
|
13
|
+
return "latest";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
6
16
|
async function initWorkspace(root = process.cwd()) {
|
|
7
17
|
console.log("\n\u{1F680} Creating Bagel workspace...\n");
|
|
8
18
|
const response = await prompts([
|
|
@@ -37,7 +47,24 @@ async function initWorkspace(root = process.cwd()) {
|
|
|
37
47
|
}
|
|
38
48
|
const { workspaceName, projectId, createFirstProject, firstProjectName } = response;
|
|
39
49
|
const workspaceDir = resolve(root, workspaceName);
|
|
40
|
-
|
|
50
|
+
console.log("Resolving package versions...");
|
|
51
|
+
const allPkgs = [
|
|
52
|
+
"@bagelink/auth",
|
|
53
|
+
"@bagelink/sdk",
|
|
54
|
+
"@bagelink/vue",
|
|
55
|
+
"pinia",
|
|
56
|
+
"vue",
|
|
57
|
+
"vue-router",
|
|
58
|
+
"@bagelink/lint-config",
|
|
59
|
+
"@bagelink/workspace",
|
|
60
|
+
"@vitejs/plugin-vue",
|
|
61
|
+
"eslint",
|
|
62
|
+
"vite"
|
|
63
|
+
];
|
|
64
|
+
const versions = Object.fromEntries(
|
|
65
|
+
await Promise.all(allPkgs.map(async (pkg) => [pkg, await resolveLatestVersion(pkg)]))
|
|
66
|
+
);
|
|
67
|
+
createWorkspaceRoot(root, workspaceName, projectId, versions);
|
|
41
68
|
createSharedPackage(workspaceDir);
|
|
42
69
|
if (createFirstProject && firstProjectName) {
|
|
43
70
|
await addProject(firstProjectName, workspaceDir);
|
|
@@ -53,7 +80,7 @@ async function initWorkspace(root = process.cwd()) {
|
|
|
53
80
|
}
|
|
54
81
|
console.log("");
|
|
55
82
|
}
|
|
56
|
-
function createWorkspaceRoot(root, name, projectId) {
|
|
83
|
+
function createWorkspaceRoot(root, name, projectId, versions) {
|
|
57
84
|
const workspaceDir = resolve(root, name);
|
|
58
85
|
if (existsSync(workspaceDir)) {
|
|
59
86
|
console.error(`\u274C Directory ${name} already exists`);
|
|
@@ -74,20 +101,20 @@ function createWorkspaceRoot(root, name, projectId) {
|
|
|
74
101
|
"lint:fix": "eslint . --cache --fix"
|
|
75
102
|
},
|
|
76
103
|
dependencies: {
|
|
77
|
-
"@bagelink/auth": "
|
|
78
|
-
"@bagelink/sdk": "
|
|
79
|
-
"@bagelink/vue": "
|
|
80
|
-
"pinia":
|
|
81
|
-
"vue":
|
|
82
|
-
"vue-router": "
|
|
104
|
+
"@bagelink/auth": versions["@bagelink/auth"],
|
|
105
|
+
"@bagelink/sdk": versions["@bagelink/sdk"],
|
|
106
|
+
"@bagelink/vue": versions["@bagelink/vue"],
|
|
107
|
+
"pinia": versions.pinia,
|
|
108
|
+
"vue": versions.vue,
|
|
109
|
+
"vue-router": versions["vue-router"]
|
|
83
110
|
},
|
|
84
111
|
devDependencies: {
|
|
85
|
-
"@bagelink/lint-config": "
|
|
86
|
-
"@bagelink/workspace": "
|
|
87
|
-
"@vitejs/plugin-vue": "
|
|
88
|
-
"eslint":
|
|
112
|
+
"@bagelink/lint-config": versions["@bagelink/lint-config"],
|
|
113
|
+
"@bagelink/workspace": versions["@bagelink/workspace"],
|
|
114
|
+
"@vitejs/plugin-vue": versions["@vitejs/plugin-vue"],
|
|
115
|
+
"eslint": versions.eslint,
|
|
89
116
|
"typescript": "^5.0.0",
|
|
90
|
-
"vite":
|
|
117
|
+
"vite": versions.vite
|
|
91
118
|
}
|
|
92
119
|
};
|
|
93
120
|
writeFileSync(
|
|
@@ -268,6 +295,11 @@ async function addProject(name, root = process.cwd()) {
|
|
|
268
295
|
console.log(`
|
|
269
296
|
\u{1F4E6} Creating project: ${name}
|
|
270
297
|
`);
|
|
298
|
+
console.log("Resolving package versions...");
|
|
299
|
+
const projectPkgs = ["@vitejs/plugin-vue", "vite", "vue", "pinia", "vue-router"];
|
|
300
|
+
const versions = Object.fromEntries(
|
|
301
|
+
await Promise.all(projectPkgs.map(async (pkg) => [pkg, await resolveLatestVersion(pkg)]))
|
|
302
|
+
);
|
|
271
303
|
mkdirSync(projectDir, { recursive: true });
|
|
272
304
|
const isWorkspace = existsSync(resolve(root, "bgl.config.ts"));
|
|
273
305
|
const packageJson = {
|
|
@@ -278,11 +310,14 @@ async function addProject(name, root = process.cwd()) {
|
|
|
278
310
|
build: "vite build",
|
|
279
311
|
preview: "vite preview"
|
|
280
312
|
},
|
|
281
|
-
dependencies: {
|
|
313
|
+
dependencies: {
|
|
314
|
+
"pinia": versions.pinia,
|
|
315
|
+
"vue": versions.vue,
|
|
316
|
+
"vue-router": versions["vue-router"]
|
|
317
|
+
},
|
|
282
318
|
devDependencies: {
|
|
283
|
-
"@vitejs/plugin-vue": "
|
|
284
|
-
"vite":
|
|
285
|
-
"vue": "latest"
|
|
319
|
+
"@vitejs/plugin-vue": versions["@vitejs/plugin-vue"],
|
|
320
|
+
"vite": versions.vite
|
|
286
321
|
}
|
|
287
322
|
};
|
|
288
323
|
if (isWorkspace) {
|
|
@@ -348,27 +383,52 @@ export default defineConfig({
|
|
|
348
383
|
</html>
|
|
349
384
|
`;
|
|
350
385
|
writeFileSync(resolve(projectDir, "index.html"), indexHtml);
|
|
386
|
+
const routerDir = resolve(srcDir, "router");
|
|
387
|
+
mkdirSync(routerDir, { recursive: true });
|
|
388
|
+
const routerTs = `import { createRouter, createWebHistory } from 'vue-router'
|
|
389
|
+
import HomeView from '../views/HomeView.vue'
|
|
390
|
+
|
|
391
|
+
export default createRouter({
|
|
392
|
+
history: createWebHistory(import.meta.env.BASE_URL),
|
|
393
|
+
routes: [
|
|
394
|
+
{ path: '/', component: HomeView },
|
|
395
|
+
],
|
|
396
|
+
})
|
|
397
|
+
`;
|
|
398
|
+
writeFileSync(resolve(routerDir, "index.ts"), routerTs);
|
|
399
|
+
const viewsDir = resolve(srcDir, "views");
|
|
400
|
+
mkdirSync(viewsDir, { recursive: true });
|
|
401
|
+
const homeView = `<script setup lang="ts">
|
|
402
|
+
${isWorkspace ? "import { formatDate } from 'shared/utils'\n" : ""}
|
|
403
|
+
<\/script>
|
|
404
|
+
|
|
405
|
+
<template>
|
|
406
|
+
<main>
|
|
407
|
+
<h1>${name}</h1>
|
|
408
|
+
${isWorkspace ? "<p>{{ formatDate(new Date()) }}</p>" : ""}
|
|
409
|
+
</main>
|
|
410
|
+
</template>
|
|
411
|
+
`;
|
|
412
|
+
writeFileSync(resolve(viewsDir, "HomeView.vue"), homeView);
|
|
351
413
|
const mainTs = `import { createApp } from 'vue'
|
|
414
|
+
import { createPinia } from 'pinia'
|
|
352
415
|
import { BagelVue } from '@bagelink/vue'
|
|
416
|
+
import router from './router'
|
|
353
417
|
import App from './App.vue'
|
|
354
418
|
|
|
355
419
|
createApp(App)
|
|
420
|
+
.use(createPinia())
|
|
421
|
+
.use(router)
|
|
356
422
|
.use(BagelVue)
|
|
357
423
|
.mount('#app')
|
|
358
424
|
`;
|
|
359
425
|
writeFileSync(resolve(srcDir, "main.ts"), mainTs);
|
|
360
426
|
const appVue = `<script setup lang="ts">
|
|
361
|
-
import {
|
|
362
|
-
${isWorkspace ? "import { formatDate } from 'shared/utils'\n" : ""}
|
|
363
|
-
const count = ref(0)
|
|
427
|
+
import { RouterView } from 'vue-router'
|
|
364
428
|
<\/script>
|
|
365
429
|
|
|
366
430
|
<template>
|
|
367
|
-
<
|
|
368
|
-
<h1>${name}</h1>
|
|
369
|
-
<button @click="count++">Count: {{ count }}</button>
|
|
370
|
-
${isWorkspace ? "<p>{{ formatDate(new Date()) }}</p>" : ""}
|
|
371
|
-
</div>
|
|
431
|
+
<RouterView />
|
|
372
432
|
</template>
|
|
373
433
|
`;
|
|
374
434
|
writeFileSync(resolve(srcDir, "App.vue"), appVue);
|
|
@@ -10,6 +10,16 @@ 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
|
+
async function resolveLatestVersion(pkg) {
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`);
|
|
16
|
+
if (!res.ok) return "latest";
|
|
17
|
+
const data = await res.json();
|
|
18
|
+
return `^${data.version}`;
|
|
19
|
+
} catch {
|
|
20
|
+
return "latest";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
13
23
|
async function initWorkspace(root = process__default.cwd()) {
|
|
14
24
|
console.log("\n\u{1F680} Creating Bagel workspace...\n");
|
|
15
25
|
const response = await prompts__default([
|
|
@@ -44,7 +54,24 @@ async function initWorkspace(root = process__default.cwd()) {
|
|
|
44
54
|
}
|
|
45
55
|
const { workspaceName, projectId, createFirstProject, firstProjectName } = response;
|
|
46
56
|
const workspaceDir = node_path.resolve(root, workspaceName);
|
|
47
|
-
|
|
57
|
+
console.log("Resolving package versions...");
|
|
58
|
+
const allPkgs = [
|
|
59
|
+
"@bagelink/auth",
|
|
60
|
+
"@bagelink/sdk",
|
|
61
|
+
"@bagelink/vue",
|
|
62
|
+
"pinia",
|
|
63
|
+
"vue",
|
|
64
|
+
"vue-router",
|
|
65
|
+
"@bagelink/lint-config",
|
|
66
|
+
"@bagelink/workspace",
|
|
67
|
+
"@vitejs/plugin-vue",
|
|
68
|
+
"eslint",
|
|
69
|
+
"vite"
|
|
70
|
+
];
|
|
71
|
+
const versions = Object.fromEntries(
|
|
72
|
+
await Promise.all(allPkgs.map(async (pkg) => [pkg, await resolveLatestVersion(pkg)]))
|
|
73
|
+
);
|
|
74
|
+
createWorkspaceRoot(root, workspaceName, projectId, versions);
|
|
48
75
|
createSharedPackage(workspaceDir);
|
|
49
76
|
if (createFirstProject && firstProjectName) {
|
|
50
77
|
await addProject(firstProjectName, workspaceDir);
|
|
@@ -60,7 +87,7 @@ async function initWorkspace(root = process__default.cwd()) {
|
|
|
60
87
|
}
|
|
61
88
|
console.log("");
|
|
62
89
|
}
|
|
63
|
-
function createWorkspaceRoot(root, name, projectId) {
|
|
90
|
+
function createWorkspaceRoot(root, name, projectId, versions) {
|
|
64
91
|
const workspaceDir = node_path.resolve(root, name);
|
|
65
92
|
if (node_fs.existsSync(workspaceDir)) {
|
|
66
93
|
console.error(`\u274C Directory ${name} already exists`);
|
|
@@ -81,20 +108,20 @@ function createWorkspaceRoot(root, name, projectId) {
|
|
|
81
108
|
"lint:fix": "eslint . --cache --fix"
|
|
82
109
|
},
|
|
83
110
|
dependencies: {
|
|
84
|
-
"@bagelink/auth": "
|
|
85
|
-
"@bagelink/sdk": "
|
|
86
|
-
"@bagelink/vue": "
|
|
87
|
-
"pinia":
|
|
88
|
-
"vue":
|
|
89
|
-
"vue-router": "
|
|
111
|
+
"@bagelink/auth": versions["@bagelink/auth"],
|
|
112
|
+
"@bagelink/sdk": versions["@bagelink/sdk"],
|
|
113
|
+
"@bagelink/vue": versions["@bagelink/vue"],
|
|
114
|
+
"pinia": versions.pinia,
|
|
115
|
+
"vue": versions.vue,
|
|
116
|
+
"vue-router": versions["vue-router"]
|
|
90
117
|
},
|
|
91
118
|
devDependencies: {
|
|
92
|
-
"@bagelink/lint-config": "
|
|
93
|
-
"@bagelink/workspace": "
|
|
94
|
-
"@vitejs/plugin-vue": "
|
|
95
|
-
"eslint":
|
|
119
|
+
"@bagelink/lint-config": versions["@bagelink/lint-config"],
|
|
120
|
+
"@bagelink/workspace": versions["@bagelink/workspace"],
|
|
121
|
+
"@vitejs/plugin-vue": versions["@vitejs/plugin-vue"],
|
|
122
|
+
"eslint": versions.eslint,
|
|
96
123
|
"typescript": "^5.0.0",
|
|
97
|
-
"vite":
|
|
124
|
+
"vite": versions.vite
|
|
98
125
|
}
|
|
99
126
|
};
|
|
100
127
|
node_fs.writeFileSync(
|
|
@@ -275,6 +302,11 @@ async function addProject(name, root = process__default.cwd()) {
|
|
|
275
302
|
console.log(`
|
|
276
303
|
\u{1F4E6} Creating project: ${name}
|
|
277
304
|
`);
|
|
305
|
+
console.log("Resolving package versions...");
|
|
306
|
+
const projectPkgs = ["@vitejs/plugin-vue", "vite", "vue", "pinia", "vue-router"];
|
|
307
|
+
const versions = Object.fromEntries(
|
|
308
|
+
await Promise.all(projectPkgs.map(async (pkg) => [pkg, await resolveLatestVersion(pkg)]))
|
|
309
|
+
);
|
|
278
310
|
node_fs.mkdirSync(projectDir, { recursive: true });
|
|
279
311
|
const isWorkspace = node_fs.existsSync(node_path.resolve(root, "bgl.config.ts"));
|
|
280
312
|
const packageJson = {
|
|
@@ -285,11 +317,14 @@ async function addProject(name, root = process__default.cwd()) {
|
|
|
285
317
|
build: "vite build",
|
|
286
318
|
preview: "vite preview"
|
|
287
319
|
},
|
|
288
|
-
dependencies: {
|
|
320
|
+
dependencies: {
|
|
321
|
+
"pinia": versions.pinia,
|
|
322
|
+
"vue": versions.vue,
|
|
323
|
+
"vue-router": versions["vue-router"]
|
|
324
|
+
},
|
|
289
325
|
devDependencies: {
|
|
290
|
-
"@vitejs/plugin-vue": "
|
|
291
|
-
"vite":
|
|
292
|
-
"vue": "latest"
|
|
326
|
+
"@vitejs/plugin-vue": versions["@vitejs/plugin-vue"],
|
|
327
|
+
"vite": versions.vite
|
|
293
328
|
}
|
|
294
329
|
};
|
|
295
330
|
if (isWorkspace) {
|
|
@@ -355,27 +390,52 @@ export default defineConfig({
|
|
|
355
390
|
</html>
|
|
356
391
|
`;
|
|
357
392
|
node_fs.writeFileSync(node_path.resolve(projectDir, "index.html"), indexHtml);
|
|
393
|
+
const routerDir = node_path.resolve(srcDir, "router");
|
|
394
|
+
node_fs.mkdirSync(routerDir, { recursive: true });
|
|
395
|
+
const routerTs = `import { createRouter, createWebHistory } from 'vue-router'
|
|
396
|
+
import HomeView from '../views/HomeView.vue'
|
|
397
|
+
|
|
398
|
+
export default createRouter({
|
|
399
|
+
history: createWebHistory(import.meta.env.BASE_URL),
|
|
400
|
+
routes: [
|
|
401
|
+
{ path: '/', component: HomeView },
|
|
402
|
+
],
|
|
403
|
+
})
|
|
404
|
+
`;
|
|
405
|
+
node_fs.writeFileSync(node_path.resolve(routerDir, "index.ts"), routerTs);
|
|
406
|
+
const viewsDir = node_path.resolve(srcDir, "views");
|
|
407
|
+
node_fs.mkdirSync(viewsDir, { recursive: true });
|
|
408
|
+
const homeView = `<script setup lang="ts">
|
|
409
|
+
${isWorkspace ? "import { formatDate } from 'shared/utils'\n" : ""}
|
|
410
|
+
<\/script>
|
|
411
|
+
|
|
412
|
+
<template>
|
|
413
|
+
<main>
|
|
414
|
+
<h1>${name}</h1>
|
|
415
|
+
${isWorkspace ? "<p>{{ formatDate(new Date()) }}</p>" : ""}
|
|
416
|
+
</main>
|
|
417
|
+
</template>
|
|
418
|
+
`;
|
|
419
|
+
node_fs.writeFileSync(node_path.resolve(viewsDir, "HomeView.vue"), homeView);
|
|
358
420
|
const mainTs = `import { createApp } from 'vue'
|
|
421
|
+
import { createPinia } from 'pinia'
|
|
359
422
|
import { BagelVue } from '@bagelink/vue'
|
|
423
|
+
import router from './router'
|
|
360
424
|
import App from './App.vue'
|
|
361
425
|
|
|
362
426
|
createApp(App)
|
|
427
|
+
.use(createPinia())
|
|
428
|
+
.use(router)
|
|
363
429
|
.use(BagelVue)
|
|
364
430
|
.mount('#app')
|
|
365
431
|
`;
|
|
366
432
|
node_fs.writeFileSync(node_path.resolve(srcDir, "main.ts"), mainTs);
|
|
367
433
|
const appVue = `<script setup lang="ts">
|
|
368
|
-
import {
|
|
369
|
-
${isWorkspace ? "import { formatDate } from 'shared/utils'\n" : ""}
|
|
370
|
-
const count = ref(0)
|
|
434
|
+
import { RouterView } from 'vue-router'
|
|
371
435
|
<\/script>
|
|
372
436
|
|
|
373
437
|
<template>
|
|
374
|
-
<
|
|
375
|
-
<h1>${name}</h1>
|
|
376
|
-
<button @click="count++">Count: {{ count }}</button>
|
|
377
|
-
${isWorkspace ? "<p>{{ formatDate(new Date()) }}</p>" : ""}
|
|
378
|
-
</div>
|
|
438
|
+
<RouterView />
|
|
379
439
|
</template>
|
|
380
440
|
`;
|
|
381
441
|
node_fs.writeFileSync(node_path.resolve(srcDir, "App.vue"), appVue);
|
package/dist/vite.cjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const node_path = require('node:path');
|
|
4
4
|
const process = require('node:process');
|
|
5
5
|
const node_url = require('node:url');
|
|
6
|
-
const netlify = require('./shared/workspace.
|
|
6
|
+
const netlify = require('./shared/workspace.CSBtD5Cu.cjs');
|
|
7
7
|
require('node:fs');
|
|
8
8
|
require('prompts');
|
|
9
9
|
|
package/dist/vite.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { basename } from 'node:path';
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { l as listProjects } from './shared/workspace.
|
|
5
|
-
export { g as generateNetlifyConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.
|
|
4
|
+
import { l as listProjects } from './shared/workspace.A649z5ed.mjs';
|
|
5
|
+
export { g as generateNetlifyConfig, s as setBuildEnvVars, w as writeNetlifyConfig } from './shared/workspace.A649z5ed.mjs';
|
|
6
6
|
import 'node:fs';
|
|
7
7
|
import 'prompts';
|
|
8
8
|
|
package/package.json
CHANGED
package/src/workspace.ts
CHANGED
|
@@ -3,6 +3,18 @@ import { resolve } from 'node:path'
|
|
|
3
3
|
import process from 'node:process'
|
|
4
4
|
import prompts from 'prompts'
|
|
5
5
|
|
|
6
|
+
async function resolveLatestVersion(pkg: string): Promise<string> {
|
|
7
|
+
try {
|
|
8
|
+
const res = await fetch(`https://registry.npmjs.org/${pkg}/latest`)
|
|
9
|
+
if (!res.ok) return 'latest'
|
|
10
|
+
const data = await res.json() as { version: string }
|
|
11
|
+
return `^${data.version}`
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return 'latest'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
/**
|
|
7
19
|
* Initialize a new workspace with flat structure
|
|
8
20
|
*/
|
|
@@ -45,8 +57,27 @@ export async function initWorkspace(root: string = process.cwd()): Promise<void>
|
|
|
45
57
|
|
|
46
58
|
const workspaceDir = resolve(root, workspaceName)
|
|
47
59
|
|
|
60
|
+
// Resolve actual latest versions from npm before writing package.json
|
|
61
|
+
console.log('Resolving package versions...')
|
|
62
|
+
const allPkgs = [
|
|
63
|
+
'@bagelink/auth',
|
|
64
|
+
'@bagelink/sdk',
|
|
65
|
+
'@bagelink/vue',
|
|
66
|
+
'pinia',
|
|
67
|
+
'vue',
|
|
68
|
+
'vue-router',
|
|
69
|
+
'@bagelink/lint-config',
|
|
70
|
+
'@bagelink/workspace',
|
|
71
|
+
'@vitejs/plugin-vue',
|
|
72
|
+
'eslint',
|
|
73
|
+
'vite',
|
|
74
|
+
]
|
|
75
|
+
const versions = Object.fromEntries(
|
|
76
|
+
await Promise.all(allPkgs.map(async pkg => [pkg, await resolveLatestVersion(pkg)])),
|
|
77
|
+
)
|
|
78
|
+
|
|
48
79
|
// Create workspace structure
|
|
49
|
-
createWorkspaceRoot(root, workspaceName, projectId)
|
|
80
|
+
createWorkspaceRoot(root, workspaceName, projectId, versions)
|
|
50
81
|
|
|
51
82
|
// Create shared package
|
|
52
83
|
createSharedPackage(workspaceDir)
|
|
@@ -71,7 +102,7 @@ export async function initWorkspace(root: string = process.cwd()): Promise<void>
|
|
|
71
102
|
/**
|
|
72
103
|
* Create workspace root files
|
|
73
104
|
*/
|
|
74
|
-
function createWorkspaceRoot(root: string, name: string, projectId: string): void {
|
|
105
|
+
function createWorkspaceRoot(root: string, name: string, projectId: string, versions: Record<string, string>): void {
|
|
75
106
|
const workspaceDir = resolve(root, name)
|
|
76
107
|
|
|
77
108
|
if (existsSync(workspaceDir)) {
|
|
@@ -96,20 +127,20 @@ function createWorkspaceRoot(root: string, name: string, projectId: string): voi
|
|
|
96
127
|
'lint:fix': 'eslint . --cache --fix',
|
|
97
128
|
},
|
|
98
129
|
dependencies: {
|
|
99
|
-
'@bagelink/auth': '
|
|
100
|
-
'@bagelink/sdk': '
|
|
101
|
-
'@bagelink/vue': '
|
|
102
|
-
'pinia':
|
|
103
|
-
'vue':
|
|
104
|
-
'vue-router': '
|
|
130
|
+
'@bagelink/auth': versions['@bagelink/auth'],
|
|
131
|
+
'@bagelink/sdk': versions['@bagelink/sdk'],
|
|
132
|
+
'@bagelink/vue': versions['@bagelink/vue'],
|
|
133
|
+
'pinia': versions.pinia,
|
|
134
|
+
'vue': versions.vue,
|
|
135
|
+
'vue-router': versions['vue-router'],
|
|
105
136
|
},
|
|
106
137
|
devDependencies: {
|
|
107
|
-
'@bagelink/lint-config': '
|
|
108
|
-
'@bagelink/workspace': '
|
|
109
|
-
'@vitejs/plugin-vue': '
|
|
110
|
-
'eslint':
|
|
138
|
+
'@bagelink/lint-config': versions['@bagelink/lint-config'],
|
|
139
|
+
'@bagelink/workspace': versions['@bagelink/workspace'],
|
|
140
|
+
'@vitejs/plugin-vue': versions['@vitejs/plugin-vue'],
|
|
141
|
+
'eslint': versions.eslint,
|
|
111
142
|
'typescript': '^5.0.0',
|
|
112
|
-
'vite':
|
|
143
|
+
'vite': versions.vite,
|
|
113
144
|
},
|
|
114
145
|
}
|
|
115
146
|
|
|
@@ -325,6 +356,12 @@ export async function addProject(
|
|
|
325
356
|
|
|
326
357
|
console.log(`\n📦 Creating project: ${name}\n`)
|
|
327
358
|
|
|
359
|
+
console.log('Resolving package versions...')
|
|
360
|
+
const projectPkgs = ['@vitejs/plugin-vue', 'vite', 'vue', 'pinia', 'vue-router']
|
|
361
|
+
const versions = Object.fromEntries(
|
|
362
|
+
await Promise.all(projectPkgs.map(async pkg => [pkg, await resolveLatestVersion(pkg)])),
|
|
363
|
+
)
|
|
364
|
+
|
|
328
365
|
mkdirSync(projectDir, { recursive: true })
|
|
329
366
|
|
|
330
367
|
// Determine if this is part of a workspace
|
|
@@ -339,11 +376,14 @@ export async function addProject(
|
|
|
339
376
|
build: 'vite build',
|
|
340
377
|
preview: 'vite preview',
|
|
341
378
|
},
|
|
342
|
-
dependencies: {
|
|
379
|
+
dependencies: {
|
|
380
|
+
'pinia': versions.pinia,
|
|
381
|
+
'vue': versions.vue,
|
|
382
|
+
'vue-router': versions['vue-router'],
|
|
383
|
+
} as Record<string, string>,
|
|
343
384
|
devDependencies: {
|
|
344
|
-
'@vitejs/plugin-vue': '
|
|
345
|
-
'vite':
|
|
346
|
-
'vue': 'latest',
|
|
385
|
+
'@vitejs/plugin-vue': versions['@vitejs/plugin-vue'],
|
|
386
|
+
'vite': versions.vite,
|
|
347
387
|
},
|
|
348
388
|
}
|
|
349
389
|
|
|
@@ -425,12 +465,47 @@ export default defineConfig({
|
|
|
425
465
|
|
|
426
466
|
writeFileSync(resolve(projectDir, 'index.html'), indexHtml)
|
|
427
467
|
|
|
468
|
+
// src/router/index.ts
|
|
469
|
+
const routerDir = resolve(srcDir, 'router')
|
|
470
|
+
mkdirSync(routerDir, { recursive: true })
|
|
471
|
+
const routerTs = `import { createRouter, createWebHistory } from 'vue-router'
|
|
472
|
+
import HomeView from '../views/HomeView.vue'
|
|
473
|
+
|
|
474
|
+
export default createRouter({
|
|
475
|
+
history: createWebHistory(import.meta.env.BASE_URL),
|
|
476
|
+
routes: [
|
|
477
|
+
{ path: '/', component: HomeView },
|
|
478
|
+
],
|
|
479
|
+
})
|
|
480
|
+
`
|
|
481
|
+
writeFileSync(resolve(routerDir, 'index.ts'), routerTs)
|
|
482
|
+
|
|
483
|
+
// src/views/HomeView.vue
|
|
484
|
+
const viewsDir = resolve(srcDir, 'views')
|
|
485
|
+
mkdirSync(viewsDir, { recursive: true })
|
|
486
|
+
const homeView = `<script setup lang="ts">
|
|
487
|
+
${isWorkspace ? 'import { formatDate } from \'shared/utils\'\n' : ''}
|
|
488
|
+
</script>
|
|
489
|
+
|
|
490
|
+
<template>
|
|
491
|
+
<main>
|
|
492
|
+
<h1>${name}</h1>
|
|
493
|
+
${isWorkspace ? '<p>{{ formatDate(new Date()) }}</p>' : ''}
|
|
494
|
+
</main>
|
|
495
|
+
</template>
|
|
496
|
+
`
|
|
497
|
+
writeFileSync(resolve(viewsDir, 'HomeView.vue'), homeView)
|
|
498
|
+
|
|
428
499
|
// main.ts
|
|
429
500
|
const mainTs = `import { createApp } from 'vue'
|
|
501
|
+
import { createPinia } from 'pinia'
|
|
430
502
|
import { BagelVue } from '@bagelink/vue'
|
|
503
|
+
import router from './router'
|
|
431
504
|
import App from './App.vue'
|
|
432
505
|
|
|
433
506
|
createApp(App)
|
|
507
|
+
.use(createPinia())
|
|
508
|
+
.use(router)
|
|
434
509
|
.use(BagelVue)
|
|
435
510
|
.mount('#app')
|
|
436
511
|
`
|
|
@@ -439,17 +514,11 @@ createApp(App)
|
|
|
439
514
|
|
|
440
515
|
// App.vue
|
|
441
516
|
const appVue = `<script setup lang="ts">
|
|
442
|
-
import {
|
|
443
|
-
${isWorkspace ? 'import { formatDate } from \'shared/utils\'\n' : ''}
|
|
444
|
-
const count = ref(0)
|
|
517
|
+
import { RouterView } from 'vue-router'
|
|
445
518
|
</script>
|
|
446
519
|
|
|
447
520
|
<template>
|
|
448
|
-
<
|
|
449
|
-
<h1>${name}</h1>
|
|
450
|
-
<button @click="count++">Count: {{ count }}</button>
|
|
451
|
-
${isWorkspace ? '<p>{{ formatDate(new Date()) }}</p>' : ''}
|
|
452
|
-
</div>
|
|
521
|
+
<RouterView />
|
|
453
522
|
</template>
|
|
454
523
|
`
|
|
455
524
|
|