create-kyro 0.8.0 → 0.9.1
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/index.js +48 -51
- package/package.json +1 -1
- package/src/generators/astro.ts +20 -1
- package/src/generators/config.ts +13 -46
- package/test/generators.test.ts +8 -20
package/dist/index.js
CHANGED
|
@@ -64,26 +64,31 @@ async function promptUser() {
|
|
|
64
64
|
name: "template",
|
|
65
65
|
message: "Starting template:",
|
|
66
66
|
hint: " ",
|
|
67
|
-
initial:
|
|
67
|
+
initial: 0,
|
|
68
68
|
choices: [
|
|
69
69
|
{
|
|
70
70
|
title: "Minimal",
|
|
71
|
-
description: "
|
|
71
|
+
description: "Single Posts collection \u2014 just title & content. Perfect for getting started fast.",
|
|
72
72
|
value: "minimal"
|
|
73
73
|
},
|
|
74
|
+
{
|
|
75
|
+
title: "Starter",
|
|
76
|
+
description: "Pages, Posts, Categories, Menu + core settings. Great for blogs and small sites.",
|
|
77
|
+
value: "starter"
|
|
78
|
+
},
|
|
74
79
|
{
|
|
75
80
|
title: "Blog",
|
|
76
|
-
description: "Posts, categories, media library +
|
|
81
|
+
description: "Posts, categories, media library + all settings. Full blog setup.",
|
|
77
82
|
value: "blog"
|
|
78
83
|
},
|
|
79
84
|
{
|
|
80
85
|
title: "E-commerce",
|
|
81
|
-
description: "Products, orders, customers, coupons +
|
|
86
|
+
description: "Products, orders, customers, coupons + all settings. Online store ready.",
|
|
82
87
|
value: "ecommerce"
|
|
83
88
|
},
|
|
84
89
|
{
|
|
85
90
|
title: "Kitchen Sink",
|
|
86
|
-
description: "Everything:
|
|
91
|
+
description: "Everything: all collections + all settings. Maximum feature set.",
|
|
87
92
|
value: "kitchen-sink"
|
|
88
93
|
}
|
|
89
94
|
]
|
|
@@ -201,7 +206,10 @@ function formatPackageJson(pkg) {
|
|
|
201
206
|
|
|
202
207
|
// src/generators/config.ts
|
|
203
208
|
function generateKyroConfig(answers) {
|
|
204
|
-
const imports = [
|
|
209
|
+
const imports = [
|
|
210
|
+
"import { defineKyroConfig } from '@kyro-cms/core';",
|
|
211
|
+
"import { templateCollections } from '@kyro-cms/core/templates';"
|
|
212
|
+
];
|
|
205
213
|
if (answers.database === "sqlite") {
|
|
206
214
|
imports.push("import { createLocalAdapter } from '@kyro-cms/core';");
|
|
207
215
|
} else if (answers.database === "postgres") {
|
|
@@ -221,70 +229,40 @@ function generateKyroConfig(answers) {
|
|
|
221
229
|
adapterLines.push(` connectionString: process.env.MONGODB_URI,`);
|
|
222
230
|
adapterLines.push(` }),`);
|
|
223
231
|
}
|
|
224
|
-
let templateCollections = "";
|
|
225
232
|
let templateGlobals = "";
|
|
226
233
|
switch (answers.template) {
|
|
227
234
|
case "minimal":
|
|
228
|
-
|
|
235
|
+
templateGlobals = "import { siteSettingsGlobal, seoSettingsGlobal } from '@kyro-cms/core/templates';";
|
|
236
|
+
break;
|
|
237
|
+
case "starter":
|
|
229
238
|
templateGlobals = "import { coreSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
230
239
|
break;
|
|
231
240
|
case "blog":
|
|
232
|
-
templateCollections = "import { blogCollections, mediaCollections, authCollections } from '@kyro-cms/core/templates';";
|
|
233
241
|
templateGlobals = "import { allSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
234
242
|
break;
|
|
235
243
|
case "ecommerce":
|
|
236
|
-
|
|
237
|
-
templateGlobals = "import { allSettingsGlobals, ecommerceSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
244
|
+
templateGlobals = "import { allSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
238
245
|
break;
|
|
239
246
|
case "kitchen-sink":
|
|
240
|
-
|
|
241
|
-
templateGlobals = "import { allSettingsGlobals, ecommerceSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
247
|
+
templateGlobals = "import { allSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
242
248
|
break;
|
|
243
249
|
}
|
|
244
|
-
if (templateCollections) imports.push(templateCollections);
|
|
245
250
|
if (templateGlobals) imports.push(templateGlobals);
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
collectionsConfig = ` collections: [
|
|
249
|
-
...Object.values(minimalCollections),
|
|
250
|
-
...Object.values(mediaCollections),
|
|
251
|
-
...Object.values(authCollections),
|
|
252
|
-
],`;
|
|
253
|
-
} else if (answers.template === "blog") {
|
|
254
|
-
collectionsConfig = ` collections: [
|
|
255
|
-
...Object.values(blogCollections),
|
|
256
|
-
...Object.values(mediaCollections),
|
|
257
|
-
...Object.values(authCollections),
|
|
258
|
-
],`;
|
|
259
|
-
} else if (answers.template === "ecommerce") {
|
|
260
|
-
collectionsConfig = ` collections: [
|
|
261
|
-
...Object.values(ecommerceCollections),
|
|
262
|
-
...Object.values(mediaCollections),
|
|
263
|
-
...Object.values(authCollections),
|
|
264
|
-
],`;
|
|
265
|
-
} else if (answers.template === "kitchen-sink") {
|
|
266
|
-
collectionsConfig = ` collections: [
|
|
267
|
-
...Object.values(minimalCollections),
|
|
268
|
-
...Object.values(blogCollections),
|
|
269
|
-
...Object.values(ecommerceCollections),
|
|
270
|
-
...Object.values(kitchenSinkCollections),
|
|
271
|
-
...Object.values(mediaCollections),
|
|
272
|
-
...Object.values(authCollections),
|
|
273
|
-
],`;
|
|
274
|
-
}
|
|
251
|
+
const collectionKey = answers.template === "kitchen-sink" ? '["kitchen-sink"]' : `.${answers.template}`;
|
|
252
|
+
const collectionsConfig = ` collections: templateCollections${collectionKey},`;
|
|
275
253
|
let globalsConfig = "";
|
|
276
254
|
if (answers.template === "minimal") {
|
|
255
|
+
globalsConfig = ` globals: [siteSettingsGlobal, seoSettingsGlobal],`;
|
|
256
|
+
} else if (answers.template === "starter") {
|
|
277
257
|
globalsConfig = ` globals: coreSettingsGlobals,`;
|
|
278
|
-
} else if (answers.template === "blog" || answers.template === "ecommerce") {
|
|
279
|
-
globalsConfig =
|
|
280
|
-
} else if (answers.template === "kitchen-sink") {
|
|
281
|
-
globalsConfig = ` globals: [...allSettingsGlobals, ...ecommerceSettingsGlobals],`;
|
|
258
|
+
} else if (answers.template === "blog" || answers.template === "ecommerce" || answers.template === "kitchen-sink") {
|
|
259
|
+
globalsConfig = ` globals: allSettingsGlobals,`;
|
|
282
260
|
}
|
|
283
261
|
return `${imports.join("\n")}
|
|
284
262
|
|
|
285
|
-
export default
|
|
286
|
-
name: '${answers.projectName}',
|
|
287
|
-
prefix: '/api',
|
|
263
|
+
export default defineKyroConfig({
|
|
264
|
+
// name: '${answers.projectName}',
|
|
265
|
+
// prefix: '/api',
|
|
288
266
|
${adapterLines.join("\n")}
|
|
289
267
|
${collectionsConfig}
|
|
290
268
|
${globalsConfig}
|
|
@@ -306,7 +284,26 @@ export default defineConfig({
|
|
|
306
284
|
output: 'server',
|
|
307
285
|
integrations: [react(), kyro({ adminPath: '/admin', apiPath: '/api' }), kyroAdmin({ basePath: '/admin', apiPath: '/api' })],
|
|
308
286
|
vite: {
|
|
309
|
-
plugins: [
|
|
287
|
+
plugins: [
|
|
288
|
+
tailwind(),
|
|
289
|
+
{
|
|
290
|
+
name: 'use-sync-external-store-shim-fix',
|
|
291
|
+
enforce: 'pre',
|
|
292
|
+
resolveId(id) {
|
|
293
|
+
if (
|
|
294
|
+
id === 'use-sync-external-store/shim' ||
|
|
295
|
+
id === 'use-sync-external-store/shim/index.js'
|
|
296
|
+
) {
|
|
297
|
+
return '\\0virtual:use-sync-external-store-shim';
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
load(id) {
|
|
301
|
+
if (id === '\\0virtual:use-sync-external-store-shim') {
|
|
302
|
+
return \`export { useSyncExternalStore } from 'react';\`;
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
},
|
|
306
|
+
],
|
|
310
307
|
},
|
|
311
308
|
server: {
|
|
312
309
|
port: 4321,
|
package/package.json
CHANGED
package/src/generators/astro.ts
CHANGED
|
@@ -11,7 +11,26 @@ export default defineConfig({
|
|
|
11
11
|
output: 'server',
|
|
12
12
|
integrations: [react(), kyro({ adminPath: '/admin', apiPath: '/api' }), kyroAdmin({ basePath: '/admin', apiPath: '/api' })],
|
|
13
13
|
vite: {
|
|
14
|
-
plugins: [
|
|
14
|
+
plugins: [
|
|
15
|
+
tailwind(),
|
|
16
|
+
{
|
|
17
|
+
name: 'use-sync-external-store-shim-fix',
|
|
18
|
+
enforce: 'pre',
|
|
19
|
+
resolveId(id) {
|
|
20
|
+
if (
|
|
21
|
+
id === 'use-sync-external-store/shim' ||
|
|
22
|
+
id === 'use-sync-external-store/shim/index.js'
|
|
23
|
+
) {
|
|
24
|
+
return '\\0virtual:use-sync-external-store-shim';
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
load(id) {
|
|
28
|
+
if (id === '\\0virtual:use-sync-external-store-shim') {
|
|
29
|
+
return \`export { useSyncExternalStore } from 'react';\`;
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
15
34
|
},
|
|
16
35
|
server: {
|
|
17
36
|
port: 4321,
|
package/src/generators/config.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import type { Answers } from "../prompts.js";
|
|
2
2
|
|
|
3
3
|
export function generateKyroConfig(answers: Answers): string {
|
|
4
|
-
const imports: string[] = [
|
|
4
|
+
const imports: string[] = [
|
|
5
|
+
"import { defineKyroConfig } from '@kyro-cms/core';",
|
|
6
|
+
"import { templateCollections } from '@kyro-cms/core/templates';",
|
|
7
|
+
];
|
|
5
8
|
|
|
6
9
|
if (answers.database === "sqlite") {
|
|
7
10
|
imports.push("import { createLocalAdapter } from '@kyro-cms/core';");
|
|
@@ -24,69 +27,33 @@ export function generateKyroConfig(answers: Answers): string {
|
|
|
24
27
|
adapterLines.push(` }),`);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
let templateCollections = "";
|
|
28
30
|
let templateGlobals = "";
|
|
29
|
-
|
|
30
31
|
switch (answers.template) {
|
|
31
32
|
case "minimal":
|
|
32
|
-
templateCollections = "import { minimalCollections } from '@kyro-cms/core/templates';";
|
|
33
33
|
templateGlobals = "import { siteSettingsGlobal, seoSettingsGlobal } from '@kyro-cms/core/templates';";
|
|
34
34
|
break;
|
|
35
35
|
case "starter":
|
|
36
|
-
templateCollections = "import { starterCollections, mediaCollections, authCollections } from '@kyro-cms/core/templates';";
|
|
37
36
|
templateGlobals = "import { coreSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
38
37
|
break;
|
|
39
38
|
case "blog":
|
|
40
|
-
templateCollections = "import { blogCollections, mediaCollections, authCollections } from '@kyro-cms/core/templates';";
|
|
41
39
|
templateGlobals = "import { allSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
42
40
|
break;
|
|
43
41
|
case "ecommerce":
|
|
44
|
-
templateCollections = "import { ecommerceCollections, mediaCollections, authCollections } from '@kyro-cms/core/templates';";
|
|
45
42
|
templateGlobals = "import { allSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
46
43
|
break;
|
|
47
44
|
case "kitchen-sink":
|
|
48
|
-
templateCollections = `import { minimalCollections, starterCollections, blogCollections, ecommerceCollections, kitchenSinkCollections, mediaCollections, authCollections } from '@kyro-cms/core/templates';`;
|
|
49
45
|
templateGlobals = "import { allSettingsGlobals } from '@kyro-cms/core/templates';";
|
|
50
46
|
break;
|
|
51
47
|
}
|
|
52
48
|
|
|
53
|
-
if (templateCollections) imports.push(templateCollections);
|
|
54
49
|
if (templateGlobals) imports.push(templateGlobals);
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
collectionsConfig = ` collections: [
|
|
63
|
-
...Object.values(starterCollections),
|
|
64
|
-
...Object.values(mediaCollections),
|
|
65
|
-
...Object.values(authCollections),
|
|
66
|
-
],`;
|
|
67
|
-
} else if (answers.template === "blog") {
|
|
68
|
-
collectionsConfig = ` collections: [
|
|
69
|
-
...Object.values(blogCollections),
|
|
70
|
-
...Object.values(mediaCollections),
|
|
71
|
-
...Object.values(authCollections),
|
|
72
|
-
],`;
|
|
73
|
-
} else if (answers.template === "ecommerce") {
|
|
74
|
-
collectionsConfig = ` collections: [
|
|
75
|
-
...Object.values(ecommerceCollections),
|
|
76
|
-
...Object.values(mediaCollections),
|
|
77
|
-
...Object.values(authCollections),
|
|
78
|
-
],`;
|
|
79
|
-
} else if (answers.template === "kitchen-sink") {
|
|
80
|
-
collectionsConfig = ` collections: [
|
|
81
|
-
...Object.values(minimalCollections),
|
|
82
|
-
...Object.values(starterCollections),
|
|
83
|
-
...Object.values(blogCollections),
|
|
84
|
-
...Object.values(ecommerceCollections),
|
|
85
|
-
...Object.values(kitchenSinkCollections),
|
|
86
|
-
...Object.values(mediaCollections),
|
|
87
|
-
...Object.values(authCollections),
|
|
88
|
-
],`;
|
|
89
|
-
}
|
|
51
|
+
const collectionKey =
|
|
52
|
+
answers.template === "kitchen-sink"
|
|
53
|
+
? '["kitchen-sink"]'
|
|
54
|
+
: `.${answers.template}`;
|
|
55
|
+
|
|
56
|
+
const collectionsConfig = ` collections: templateCollections${collectionKey},`;
|
|
90
57
|
|
|
91
58
|
let globalsConfig = "";
|
|
92
59
|
if (answers.template === "minimal") {
|
|
@@ -99,9 +66,9 @@ export function generateKyroConfig(answers: Answers): string {
|
|
|
99
66
|
|
|
100
67
|
return `${imports.join("\n")}
|
|
101
68
|
|
|
102
|
-
export default
|
|
103
|
-
name: '${answers.projectName}',
|
|
104
|
-
prefix: '/api',
|
|
69
|
+
export default defineKyroConfig({
|
|
70
|
+
// name: '${answers.projectName}',
|
|
71
|
+
// prefix: '/api',
|
|
105
72
|
${adapterLines.join("\n")}
|
|
106
73
|
${collectionsConfig}
|
|
107
74
|
${globalsConfig}
|
package/test/generators.test.ts
CHANGED
|
@@ -55,42 +55,29 @@ describe("generators", () => {
|
|
|
55
55
|
...baseAnswers,
|
|
56
56
|
template: "minimal",
|
|
57
57
|
});
|
|
58
|
-
expect(minimal).toContain("
|
|
59
|
-
expect(minimal).not.toContain("
|
|
60
|
-
expect(minimal).not.toContain("authCollections");
|
|
58
|
+
expect(minimal).toContain("templateCollections.minimal");
|
|
59
|
+
expect(minimal).not.toContain("templateCollections.starter");
|
|
61
60
|
|
|
62
61
|
const starter = generateKyroConfig({
|
|
63
62
|
...baseAnswers,
|
|
64
63
|
template: "starter",
|
|
65
64
|
});
|
|
66
|
-
expect(starter).toContain("
|
|
67
|
-
expect(starter).toContain("mediaCollections");
|
|
68
|
-
expect(starter).toContain("authCollections");
|
|
65
|
+
expect(starter).toContain("templateCollections.starter");
|
|
69
66
|
|
|
70
67
|
const blog = generateKyroConfig({ ...baseAnswers, template: "blog" });
|
|
71
|
-
expect(blog).toContain("
|
|
72
|
-
expect(blog).toContain("mediaCollections");
|
|
73
|
-
expect(blog).toContain("authCollections");
|
|
68
|
+
expect(blog).toContain("templateCollections.blog");
|
|
74
69
|
|
|
75
70
|
const ecommerce = generateKyroConfig({
|
|
76
71
|
...baseAnswers,
|
|
77
72
|
template: "ecommerce",
|
|
78
73
|
});
|
|
79
|
-
expect(ecommerce).toContain("
|
|
80
|
-
expect(ecommerce).toContain("mediaCollections");
|
|
81
|
-
expect(ecommerce).toContain("authCollections");
|
|
74
|
+
expect(ecommerce).toContain("templateCollections.ecommerce");
|
|
82
75
|
|
|
83
76
|
const kitchen = generateKyroConfig({
|
|
84
77
|
...baseAnswers,
|
|
85
78
|
template: "kitchen-sink",
|
|
86
79
|
});
|
|
87
|
-
expect(kitchen).toContain("
|
|
88
|
-
expect(kitchen).toContain("starterCollections");
|
|
89
|
-
expect(kitchen).toContain("blogCollections");
|
|
90
|
-
expect(kitchen).toContain("ecommerceCollections");
|
|
91
|
-
expect(kitchen).toContain("kitchenSinkCollections");
|
|
92
|
-
expect(kitchen).toContain("mediaCollections");
|
|
93
|
-
expect(kitchen).toContain("authCollections");
|
|
80
|
+
expect(kitchen).toContain('templateCollections["kitchen-sink"]');
|
|
94
81
|
});
|
|
95
82
|
|
|
96
83
|
it("imports settings globals per template", () => {
|
|
@@ -133,7 +120,8 @@ describe("generators", () => {
|
|
|
133
120
|
|
|
134
121
|
it("uses correct template imports path", () => {
|
|
135
122
|
const config = generateKyroConfig(baseAnswers);
|
|
136
|
-
expect(config).toContain("@kyro-cms/core/templates");
|
|
123
|
+
expect(config).toContain("import { templateCollections } from '@kyro-cms/core/templates'");
|
|
124
|
+
expect(config).toContain("defineKyroConfig");
|
|
137
125
|
});
|
|
138
126
|
});
|
|
139
127
|
|