@rebasepro/cli 0.3.0 → 0.5.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/dist/index.es.js CHANGED
@@ -64,6 +64,11 @@ function findParentDir(currentDir, targetName) {
64
64
  return null;
65
65
  }
66
66
  const cliRoot = findParentDir(__dirname$2, "cli");
67
+ const PRESET_CHOICES = [
68
+ { name: "Blog — Posts, Authors, Tags (with markdown editor)", value: "blog", short: "Blog" },
69
+ { name: "E-commerce — Products, Categories, Orders", value: "ecommerce", short: "E-commerce" },
70
+ { name: "Blank — Empty project, just authentication", value: "blank", short: "Blank" }
71
+ ];
67
72
  async function createRebaseApp(rawArgs) {
68
73
  console.log(`
69
74
  ${chalk.bold("Rebase")} — Create a new project 🚀
@@ -79,9 +84,11 @@ async function promptForOptions(rawArgs, pm) {
79
84
  "--install": Boolean,
80
85
  "--database-url": String,
81
86
  "--introspect": Boolean,
87
+ "--template": String,
82
88
  "--yes": Boolean,
83
89
  "-g": "--git",
84
90
  "-i": "--install",
91
+ "-t": "--template",
85
92
  "-y": "--yes"
86
93
  },
87
94
  {
@@ -92,6 +99,11 @@ async function promptForOptions(rawArgs, pm) {
92
99
  );
93
100
  const nameArg = args._[0];
94
101
  const isNonInteractive = args["--yes"] || false;
102
+ const templateArg = args["--template"];
103
+ if (templateArg && !PRESET_CHOICES.some((p) => p.value === templateArg)) {
104
+ console.error(chalk.red(`Unknown template "${templateArg}". Available: ${PRESET_CHOICES.map((p) => p.value).join(", ")}`));
105
+ process.exit(1);
106
+ }
95
107
  if (isNonInteractive) {
96
108
  const projectName2 = nameArg || "my-rebase-app";
97
109
  const targetDirectory2 = path.resolve(process.cwd(), projectName2);
@@ -105,6 +117,7 @@ async function promptForOptions(rawArgs, pm) {
105
117
  templateDirectory: templateDirectory2,
106
118
  databaseUrl: args["--database-url"] || void 0,
107
119
  introspect: args["--introspect"] || false,
120
+ preset: templateArg || "blog",
108
121
  pm,
109
122
  pmCommands: pmCommands2
110
123
  };
@@ -125,6 +138,15 @@ async function promptForOptions(rawArgs, pm) {
125
138
  }
126
139
  });
127
140
  }
141
+ if (!templateArg) {
142
+ questions.push({
143
+ type: "list",
144
+ name: "preset",
145
+ message: "Choose a starter template:",
146
+ choices: PRESET_CHOICES,
147
+ default: "blog"
148
+ });
149
+ }
128
150
  if (!args["--git"]) {
129
151
  questions.push({
130
152
  type: "confirm",
@@ -173,6 +195,7 @@ async function promptForOptions(rawArgs, pm) {
173
195
  templateDirectory,
174
196
  databaseUrl: answers.databaseUrl?.trim() || void 0,
175
197
  introspect: answers.introspect || false,
198
+ preset: templateArg || answers.preset || "blog",
176
199
  pm,
177
200
  pmCommands
178
201
  };
@@ -205,6 +228,7 @@ async function createProject(options) {
205
228
  console.error(`${chalk.red.bold("ERROR")} Failed to copy template files: ${err instanceof Error ? err.message : String(err)}`);
206
229
  process.exit(1);
207
230
  }
231
+ await applyPreset(options.targetDirectory, options.preset);
208
232
  await replacePlaceholders(options);
209
233
  await configureEnvFile(options.targetDirectory, options.databaseUrl);
210
234
  if (options.git) {
@@ -294,6 +318,38 @@ async function createProject(options) {
294
318
  console.log(chalk.gray("GitHub: https://github.com/rebasepro/rebase"));
295
319
  console.log("");
296
320
  }
321
+ async function applyPreset(targetDirectory, preset) {
322
+ const collectionsDir = path.join(targetDirectory, "config", "collections");
323
+ const presetsDir = path.join(collectionsDir, "presets");
324
+ if (preset !== "blog") {
325
+ const presetDir = path.join(presetsDir, preset);
326
+ if (!fs.existsSync(presetDir)) {
327
+ console.warn(chalk.yellow(` Warning: Preset "${preset}" not found, falling back to blog template.`));
328
+ cleanupPresets(presetsDir);
329
+ return;
330
+ }
331
+ const blogFiles = ["posts.ts", "authors.ts", "tags.ts", "index.ts"];
332
+ for (const file of blogFiles) {
333
+ const filePath = path.join(collectionsDir, file);
334
+ if (fs.existsSync(filePath)) {
335
+ fs.unlinkSync(filePath);
336
+ }
337
+ }
338
+ const presetFiles = fs.readdirSync(presetDir).filter((f) => f.endsWith(".ts"));
339
+ for (const file of presetFiles) {
340
+ fs.copyFileSync(
341
+ path.join(presetDir, file),
342
+ path.join(collectionsDir, file)
343
+ );
344
+ }
345
+ }
346
+ cleanupPresets(presetsDir);
347
+ }
348
+ function cleanupPresets(presetsDir) {
349
+ if (fs.existsSync(presetsDir)) {
350
+ fs.rmSync(presetsDir, { recursive: true, force: true });
351
+ }
352
+ }
297
353
  async function replacePlaceholders(options) {
298
354
  const filesToProcess = [
299
355
  "package.json",