@codabytez/create-next-template 0.1.1 → 0.1.3

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 (2) hide show
  1. package/dist/index.js +50 -17
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ var import_path5 = __toESM(require("path"));
37
37
  // src/helpers/copy.ts
38
38
  var import_fs_extra = __toESM(require("fs-extra"));
39
39
  var import_path = __toESM(require("path"));
40
- var TEMPLATES_DIR = import_path.default.join(__dirname, "../../templates");
40
+ var TEMPLATES_DIR = import_path.default.join(__dirname, "../templates");
41
41
  async function copyTemplate(templateName, destPath) {
42
42
  const templatePath = import_path.default.join(TEMPLATES_DIR, templateName);
43
43
  if (!await import_fs_extra.default.pathExists(templatePath)) return;
@@ -76,8 +76,8 @@ var import_path3 = __toESM(require("path"));
76
76
 
77
77
  // src/helpers/run.ts
78
78
  var import_execa = require("execa");
79
- async function runCommand(command, args, cwd) {
80
- await (0, import_execa.execa)(command, args, { cwd, stdio: "inherit" });
79
+ async function runCommand(command, args2, cwd) {
80
+ await (0, import_execa.execa)(command, args2, { cwd, stdio: "inherit" });
81
81
  }
82
82
 
83
83
  // src/helpers/packages.ts
@@ -259,20 +259,23 @@ async function runInstaller({
259
259
  projectName,
260
260
  projectPath,
261
261
  packageManager,
262
- features
262
+ features,
263
+ inPlace
263
264
  }) {
264
265
  const s = p.spinner();
265
- if (await import_fs_extra5.default.pathExists(projectPath)) {
266
- const overwrite = await p.confirm({
267
- message: `Directory "${projectName}" already exists. Overwrite?`
268
- });
269
- if (!overwrite || p.isCancel(overwrite)) {
270
- p.cancel("Operation cancelled");
271
- process.exit(0);
266
+ if (!inPlace) {
267
+ if (await import_fs_extra5.default.pathExists(projectPath)) {
268
+ const overwrite = await p.confirm({
269
+ message: `Directory "${projectName}" already exists. Overwrite?`
270
+ });
271
+ if (!overwrite || p.isCancel(overwrite)) {
272
+ p.cancel("Operation cancelled");
273
+ process.exit(0);
274
+ }
275
+ await import_fs_extra5.default.remove(projectPath);
272
276
  }
273
- await import_fs_extra5.default.remove(projectPath);
277
+ await import_fs_extra5.default.ensureDir(projectPath);
274
278
  }
275
- await import_fs_extra5.default.ensureDir(projectPath);
276
279
  s.start("Scaffolding project structure");
277
280
  await copyTemplate("base", projectPath);
278
281
  for (const feature of features) {
@@ -317,8 +320,8 @@ async function runInstaller({
317
320
  const hasAppwrite = features.includes("appwrite");
318
321
  console.log();
319
322
  p.outro(
320
- import_chalk.default.green("\u2714 Project created successfully!\n\n") + ` ${import_chalk.default.cyan("cd")} ${projectName}
321
- ` + (hasShadcn ? ` ${import_chalk.default.cyan("npx shadcn@latest init")} ${import_chalk.default.gray("# set up shadcn/ui")}
323
+ import_chalk.default.green("\u2714 Project created successfully!\n\n") + (inPlace ? "" : ` ${import_chalk.default.cyan("cd")} ${projectName}
324
+ `) + (hasShadcn ? ` ${import_chalk.default.cyan("npx shadcn@latest init")} ${import_chalk.default.gray("# set up shadcn/ui")}
322
325
  ` : "") + (hasPrisma ? ` ${import_chalk.default.gray("# update DATABASE_URL in .env, then:")}
323
326
  ${import_chalk.default.cyan("npx prisma migrate dev")}
324
327
  ` : "") + (hasConvex ? ` ${import_chalk.default.cyan("npx convex dev")} ${import_chalk.default.gray("# start Convex backend")}
@@ -328,12 +331,41 @@ async function runInstaller({
328
331
  }
329
332
 
330
333
  // src/index.ts
334
+ var args = process.argv.slice(2);
335
+ if (args.includes("--help") || args.includes("-h")) {
336
+ console.log(
337
+ `
338
+ ${import_chalk2.default.bgCyan(import_chalk2.default.black(" create-next-template "))}
339
+
340
+ ${import_chalk2.default.bold("Usage:")}
341
+ pnpx @codabytez/create-next-template ${import_chalk2.default.green("[directory]")}
342
+
343
+ ${import_chalk2.default.bold("Arguments:")}
344
+ ${import_chalk2.default.green("directory")} Where to scaffold the project.
345
+ Use ${import_chalk2.default.cyan(".")} to scaffold into the current directory,
346
+ or omit to be prompted for a name.
347
+
348
+ ${import_chalk2.default.bold("Options:")}
349
+ ${import_chalk2.default.cyan("-h, --help")} Show this help message
350
+
351
+ ${import_chalk2.default.bold("Examples:")}
352
+ pnpx @codabytez/create-next-template
353
+ pnpx @codabytez/create-next-template ${import_chalk2.default.green("my-app")}
354
+ pnpx @codabytez/create-next-template ${import_chalk2.default.green(".")}
355
+ `
356
+ );
357
+ process.exit(0);
358
+ }
331
359
  async function main() {
332
360
  console.log();
333
361
  p2.intro(import_chalk2.default.bgCyan(import_chalk2.default.black(" create-next-template ")));
362
+ const dirArg = args.find((a) => !a.startsWith("-"));
363
+ const inPlace = dirArg === ".";
364
+ const defaultName = inPlace ? import_path6.default.basename(process.cwd()) : dirArg ?? void 0;
334
365
  const projectName = await p2.text({
335
366
  message: "What is your project name?",
336
367
  placeholder: "my-next-app",
368
+ initialValue: defaultName,
337
369
  validate(value) {
338
370
  if (!value) return "Project name is required";
339
371
  if (!/^[a-z0-9-_]+$/.test(value))
@@ -393,12 +425,13 @@ async function main() {
393
425
  `You selected multiple databases (${dbChoices.join(", ")}). This is supported but may require manual configuration.`
394
426
  );
395
427
  }
396
- const projectPath = import_path6.default.resolve(process.cwd(), projectName);
428
+ const projectPath = inPlace ? process.cwd() : import_path6.default.resolve(process.cwd(), projectName);
397
429
  await runInstaller({
398
430
  projectName,
399
431
  projectPath,
400
432
  packageManager,
401
- features: selectedFeatures
433
+ features: selectedFeatures,
434
+ inPlace
402
435
  });
403
436
  }
404
437
  main().catch((err) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codabytez/create-next-template",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "CLI to scaffold Next.js projects with your preferred stack",
5
5
  "bin": {
6
6
  "create-next-template": "./dist/index.js"