@lemonadecms/create 0.0.0-stage → 0.1.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/LICENSE +21 -0
  3. package/README.md +26 -2
  4. package/bin/create-lemonade.mjs +122 -0
  5. package/dist/catalog.json +604 -0
  6. package/dist/templates/angular/angular.json +54 -0
  7. package/dist/templates/angular/locks/npm-lock.json.template +7079 -0
  8. package/dist/templates/angular/locks/pnpm-lock.yaml.template +4234 -0
  9. package/dist/templates/angular/package.json +61 -0
  10. package/dist/templates/angular/src/app/app.config.server.ts +23 -0
  11. package/dist/templates/angular/src/app/app.config.ts +34 -0
  12. package/dist/templates/angular/src/app/app.ts +9 -0
  13. package/dist/templates/angular/src/app/blog.service.ts +74 -0
  14. package/dist/templates/angular/src/app/journal.html +71 -0
  15. package/dist/templates/angular/src/app/journal.ts +47 -0
  16. package/dist/templates/angular/src/index.html +14 -0
  17. package/dist/templates/angular/src/main.server.ts +5 -0
  18. package/dist/templates/angular/src/main.ts +6 -0
  19. package/dist/templates/angular/src/server.ts +79 -0
  20. package/dist/templates/angular/tsconfig.app.json +8 -0
  21. package/dist/templates/angular/tsconfig.json +21 -0
  22. package/dist/templates/astro/astro.config.mjs +7 -0
  23. package/dist/templates/astro/locks/npm-lock.json.template +5478 -0
  24. package/dist/templates/astro/locks/pnpm-lock.yaml.template +3530 -0
  25. package/dist/templates/astro/package.json +42 -0
  26. package/dist/templates/astro/src/components/BlogView.astro +92 -0
  27. package/dist/templates/astro/src/layouts/Site.astro +23 -0
  28. package/dist/templates/astro/src/pages/articles/[id].astro +13 -0
  29. package/dist/templates/astro/src/pages/index.astro +13 -0
  30. package/dist/templates/astro/src/pages/lemonade/preview/[...path].ts +4 -0
  31. package/dist/templates/astro/src/pages/lemonade/preview.ts +4 -0
  32. package/dist/templates/astro/tsconfig.json +9 -0
  33. package/dist/templates/next/app/articles/[id]/page.tsx +29 -0
  34. package/dist/templates/next/app/data.ts +12 -0
  35. package/dist/templates/next/app/error.tsx +15 -0
  36. package/dist/templates/next/app/layout.tsx +13 -0
  37. package/dist/templates/next/app/lemonade/preview/[[...path]]/route.ts +7 -0
  38. package/dist/templates/next/app/loading.tsx +7 -0
  39. package/dist/templates/next/app/not-found.tsx +8 -0
  40. package/dist/templates/next/app/page.tsx +17 -0
  41. package/dist/templates/next/app/view.tsx +111 -0
  42. package/dist/templates/next/locks/npm-lock.json.template +1158 -0
  43. package/dist/templates/next/locks/pnpm-lock.yaml.template +715 -0
  44. package/dist/templates/next/next-env.d.ts +2 -0
  45. package/dist/templates/next/next.config.mjs +8 -0
  46. package/dist/templates/next/package.json +44 -0
  47. package/dist/templates/next/proxy.ts +19 -0
  48. package/dist/templates/next/tsconfig.json +25 -0
  49. package/dist/templates/nuxt/app/app.vue +1 -0
  50. package/dist/templates/nuxt/app/components/JournalView.vue +75 -0
  51. package/dist/templates/nuxt/app/pages/articles/[id].vue +8 -0
  52. package/dist/templates/nuxt/app/pages/index.vue +8 -0
  53. package/dist/templates/nuxt/locks/npm-lock.json.template +9113 -0
  54. package/dist/templates/nuxt/locks/pnpm-lock.yaml.template +6466 -0
  55. package/dist/templates/nuxt/nuxt.config.ts +27 -0
  56. package/dist/templates/nuxt/package.json +54 -0
  57. package/dist/templates/nuxt/server/api/blog/[id].get.ts +10 -0
  58. package/dist/templates/nuxt/server/api/blog.get.ts +9 -0
  59. package/dist/templates/nuxt/server/middleware/preview.ts +9 -0
  60. package/dist/templates/nuxt/server/utils/cms-environment.ts +15 -0
  61. package/dist/templates/nuxt/tsconfig.json +7 -0
  62. package/dist/templates/shared/GETTING_STARTED.md +29 -0
  63. package/dist/templates/shared/README.md +8 -0
  64. package/dist/templates/shared/env.example.template +11 -0
  65. package/dist/templates/shared/gitignore.template +13 -0
  66. package/dist/templates/shared/model-template.json +75 -0
  67. package/dist/templates/shared/public/blog.css +255 -0
  68. package/dist/templates/shared/public/lemonade.svg +5 -0
  69. package/dist/templates/shared/schema-contract.json +37 -0
  70. package/dist/templates/shared/scripts/cms-tools.mjs +171 -0
  71. package/dist/templates/shared/scripts/environment.mjs +68 -0
  72. package/dist/templates/shared/scripts/run.mjs +122 -0
  73. package/dist/templates/shared/server/blog.d.mts +35 -0
  74. package/dist/templates/shared/server/blog.mjs +159 -0
  75. package/dist/templates/shared/server/config.d.mts +11 -0
  76. package/dist/templates/shared/server/config.mjs +42 -0
  77. package/dist/templates/shared/server/preview.d.mts +4 -0
  78. package/dist/templates/shared/server/preview.mjs +276 -0
  79. package/dist/templates/shared/src/types/cms-models.ts +37 -0
  80. package/package.json +24 -4
  81. package/src/arguments.mjs +55 -0
  82. package/src/catalog.mjs +134 -0
  83. package/src/errors.mjs +10 -0
  84. package/src/generation.mjs +103 -0
  85. package/src/paths.mjs +90 -0
  86. package/src/prompts.mjs +65 -0
package/src/paths.mjs ADDED
@@ -0,0 +1,90 @@
1
+ import { dirname, basename, resolve, parse } from 'node:path';
2
+ import { realpath, lstat } from 'node:fs/promises';
3
+ import { CreateError, invariant } from './errors.mjs';
4
+ import { homedir } from 'node:os';
5
+ // Only the exact public placeholder is allowed, including on case-insensitive disks.
6
+ export function privateConfigurationName(value) {
7
+ const folded = value.normalize('NFC').toLowerCase();
8
+ return folded === '.npmrc' || (folded.startsWith('.env') && value !== '.env.example');
9
+ }
10
+ export function safeRelative(value) {
11
+ invariant(
12
+ typeof value === 'string' &&
13
+ value.length <= 240 &&
14
+ !/[\\\x00-\x1f\x7f:<>"|?*]/.test(value),
15
+ 'Unsafe template path.',
16
+ );
17
+ const parts = value.split('/');
18
+ invariant(
19
+ parts.every(
20
+ (p) =>
21
+ p &&
22
+ p !== '.' &&
23
+ p !== '..' &&
24
+ !/[. ]$/.test(p) &&
25
+ !/^(con|prn|aux|nul|com[0-9¹²³]|lpt[0-9¹²³])(?:\.|$)/i.test(p),
26
+ ),
27
+ 'Unsafe template path.',
28
+ );
29
+ invariant(
30
+ !parts.some(
31
+ (p) =>
32
+ ['.git', 'node_modules'].includes(p.normalize('NFC').toLowerCase()) ||
33
+ privateConfigurationName(p),
34
+ ),
35
+ 'Private or generated paths cannot be bundled.',
36
+ );
37
+ return value;
38
+ }
39
+ export async function destination(value, cwd = process.cwd()) {
40
+ invariant(
41
+ typeof value === 'string' && value.length <= 4096 && !/[\x00-\x1f\x7f]/.test(value),
42
+ 'Choose a safe new directory.',
43
+ 2,
44
+ );
45
+ const path = resolve(cwd, value);
46
+ invariant(
47
+ ![parse(path).root, resolve(cwd), resolve(homedir())].includes(path),
48
+ 'Choose a new child directory.',
49
+ 6,
50
+ );
51
+ try {
52
+ for (const part of value
53
+ .slice(parse(value).root.length)
54
+ .split(/[\\/]/)
55
+ .filter(Boolean))
56
+ safeRelative(part);
57
+ safeRelative(basename(path));
58
+ } catch {
59
+ throw new CreateError(
60
+ 2,
61
+ 'Choose a portable directory name without reserved or traversal segments.',
62
+ );
63
+ }
64
+ let present;
65
+ try {
66
+ present = await lstat(path);
67
+ } catch (error) {
68
+ if (error.code !== 'ENOENT')
69
+ throw new CreateError(
70
+ 6,
71
+ 'The destination is unavailable. Choose a new directory.',
72
+ );
73
+ }
74
+ if (present)
75
+ throw new CreateError(6, 'The destination already exists. Choose a new directory.');
76
+ let parent;
77
+ try {
78
+ parent = await realpath(dirname(path));
79
+ } catch {
80
+ throw new CreateError(6, 'Choose an existing, accessible parent directory.');
81
+ }
82
+ const name =
83
+ basename(path)
84
+ .normalize('NFKD')
85
+ .toLowerCase()
86
+ .replace(/[^a-z0-9._-]+/g, '-')
87
+ .replace(/^[._-]+|[._-]+$/g, '')
88
+ .slice(0, 100) || 'lemonade-blog';
89
+ return { path: resolve(parent, basename(path)), name };
90
+ }
@@ -0,0 +1,65 @@
1
+ import { createInterface } from 'node:readline';
2
+ import { CreateError } from './errors.mjs';
3
+ import { destination } from './paths.mjs';
4
+ export async function choose(options, { input, output, signal }) {
5
+ if (signal?.aborted) throw new CreateError(130, 'Creation cancelled.');
6
+ const rl = createInterface({ input, output, terminal: true });
7
+ let pending,
8
+ ended = false;
9
+ const check = () => {
10
+ if (ended || signal?.aborted) throw new CreateError(130, 'Creation cancelled.');
11
+ };
12
+ const cancel = () => {
13
+ ended = true;
14
+ pending?.(new CreateError(130, 'Creation cancelled.'));
15
+ rl.close();
16
+ };
17
+ rl.on('SIGINT', cancel);
18
+ signal?.addEventListener('abort', cancel, { once: true });
19
+ const question = (text) =>
20
+ new Promise((resolve, reject) => {
21
+ check();
22
+ pending = reject;
23
+ rl.question(text, (answer) => {
24
+ pending = null;
25
+ resolve(answer.trim());
26
+ });
27
+ });
28
+ const closed = () => {
29
+ ended = true;
30
+ pending?.(new CreateError(130, 'Selection ended. No project was created.'));
31
+ };
32
+ rl.on('close', closed);
33
+ rl.on('error', closed);
34
+ try {
35
+ if (!options.directory)
36
+ options.directory = await question('New project directory: ');
37
+ if (!options.framework) {
38
+ const answer = await question(
39
+ 'Framework: 1 Astro, 2 Nuxt, 3 Next.js, 4 Angular: ',
40
+ );
41
+ options.framework = ['astro', 'nuxt', 'next', 'angular'][Number(answer) - 1];
42
+ if (!options.framework)
43
+ throw new CreateError(2, 'Choose a framework from 1 to 4.');
44
+ }
45
+ if (!options.managerProvided) {
46
+ const answer = await question('Package manager: 1 npm, 2 pnpm [1]: ');
47
+ options.packageManager =
48
+ answer === '2' ? 'pnpm' : !answer || answer === '1' ? 'npm' : null;
49
+ if (!options.packageManager) throw new CreateError(2, 'Choose npm or pnpm.');
50
+ }
51
+ const target = await destination(options.directory, options.cwd);
52
+ check();
53
+ output.write(
54
+ `Create ${options.framework} blog in ${JSON.stringify(target.path)} as package ${JSON.stringify(target.name)} using ${options.packageManager}.\n`,
55
+ );
56
+ if ((await question('Create files? [y/N] ')).toLowerCase() !== 'y')
57
+ throw new CreateError(130, 'Creation cancelled. No project was created.');
58
+ return options;
59
+ } finally {
60
+ pending = null;
61
+ signal?.removeEventListener('abort', cancel);
62
+ rl.removeListener('SIGINT', cancel);
63
+ rl.close();
64
+ }
65
+ }