create-tina-app 1.1.6 → 1.3.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.d.ts CHANGED
@@ -1 +1,2 @@
1
+ export declare const PKG_MANAGERS: string[];
1
2
  export declare const run: () => Promise<void>;
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
25
25
  // src/index.ts
26
26
  var src_exports = {};
27
27
  __export(src_exports, {
28
+ PKG_MANAGERS: () => PKG_MANAGERS,
28
29
  run: () => run
29
30
  });
30
31
  module.exports = __toCommonJS(src_exports);
@@ -35,7 +36,7 @@ var import_node_path = __toESM(require("path"));
35
36
 
36
37
  // package.json
37
38
  var name = "create-tina-app";
38
- var version = "1.1.6";
39
+ var version = "1.3.0";
39
40
 
40
41
  // src/util/fileUtil.ts
41
42
  var import_fs_extra = __toESM(require("fs-extra"));
@@ -240,9 +241,6 @@ function tryGitInit(root) {
240
241
  }
241
242
  }
242
243
 
243
- // src/index.ts
244
- var import_node_process = require("process");
245
-
246
244
  // src/util/examples.ts
247
245
  var import_node_stream = require("stream");
248
246
  var import_promises = require("stream/promises");
@@ -291,11 +289,11 @@ async function downloadAndExtractRepo(root, { username, name: name2, branch, fil
291
289
  );
292
290
  }
293
291
 
294
- // src/examples.ts
292
+ // src/templates.ts
295
293
  var import_chalk4 = __toESM(require("chalk"));
296
294
  var import_fs_extra3 = require("fs-extra");
297
295
  var import_path3 = __toESM(require("path"));
298
- var EXAMPLES = [
296
+ var TEMPLATES = [
299
297
  {
300
298
  title: "\u2B50 NextJS starter",
301
299
  description: "Kickstart your project with NextJS \u2013 our top recommendation for a seamless, performant, and versatile web experience.",
@@ -339,9 +337,9 @@ var EXAMPLES = [
339
337
  gitURL: "https://github.com/tinacms/tina-barebones-starter"
340
338
  }
341
339
  ];
342
- var downloadExample = async (example, root) => {
343
- if (example.isInternal === false) {
344
- const repoURL = new URL(example.gitURL);
340
+ var downloadTemplate = async (template, root) => {
341
+ if (template.isInternal === false) {
342
+ const repoURL = new URL(template.gitURL);
345
343
  const repoInfo = await getRepoInfo(repoURL);
346
344
  const repoInfo2 = repoInfo;
347
345
  console.log(
@@ -354,8 +352,8 @@ var downloadExample = async (example, root) => {
354
352
  }
355
353
  await downloadAndExtractRepo(root, repoInfo2);
356
354
  } else {
357
- const exampleFile = import_path3.default.join(__dirname, "..", "examples", example.value);
358
- await (0, import_fs_extra3.copy)(`${exampleFile}/`, "./");
355
+ const templateFile = import_path3.default.join(__dirname, "..", "examples", template.value);
356
+ await (0, import_fs_extra3.copy)(`${templateFile}/`, "./");
359
357
  }
360
358
  };
361
359
 
@@ -368,14 +366,36 @@ var preRunChecks = () => {
368
366
  }
369
367
  };
370
368
 
369
+ // src/util/checkPkgManagers.ts
370
+ var import_child_process2 = require("child_process");
371
+ function checkPackageExists(name2) {
372
+ return new Promise((resolve, reject) => {
373
+ (0, import_child_process2.exec)(`${name2} -v`, (error, stdout, stderr) => {
374
+ if (error) {
375
+ reject(stderr);
376
+ }
377
+ resolve(stdout);
378
+ });
379
+ });
380
+ }
381
+
371
382
  // src/index.ts
383
+ var PKG_MANAGERS = ["npm", "yarn", "pnpm"];
372
384
  var successText = import_chalk5.default.bold.green;
373
385
  var linkText = import_chalk5.default.bold.cyan;
374
386
  var cmdText = import_chalk5.default.inverse;
375
387
  var logText = import_chalk5.default.italic.gray;
376
- var program = new import_commander.Command(name);
377
388
  var projectName = "";
378
- program.version(version).option("-e, --example <example>", "Choose which example to start from").option("-d, --dir <dir>", "Choose which directory to run this script from").option("--noTelemetry", "Disable anonymous telemetry that is collected").arguments("[project-directory]").usage(`${import_chalk5.default.green("<project-directory>")} [options]`).action((name2) => {
389
+ var program = new import_commander.Command(name);
390
+ program.version(version).option(
391
+ "-t, --template <template>",
392
+ `Choose which template to start from. Valid templates are: ${TEMPLATES.map(
393
+ (x2) => x2.value
394
+ )}`
395
+ ).option(
396
+ "-p, --pkg-manager <pkg-manager>",
397
+ `Choose which package manager to use. Valid package managers are: ${PKG_MANAGERS}`
398
+ ).option("-d, --dir <dir>", "Choose which directory to run this script from").option("--noTelemetry", "Disable anonymous telemetry that is collected").arguments("[project-directory]").usage(`${import_chalk5.default.green("<project-directory>")} [options]`).action((name2) => {
379
399
  projectName = name2;
380
400
  });
381
401
  var run = async () => {
@@ -386,55 +406,74 @@ var run = async () => {
386
406
  process.chdir(opts.dir);
387
407
  }
388
408
  const telemetry = new import_metrics.Telemetry({ disabled: opts == null ? void 0 : opts.noTelemetry });
389
- let example = opts.example;
390
- const res = await (0, import_prompts.default)({
391
- message: "Which package manager would you like to use?",
392
- name: "packageManager",
393
- type: "select",
394
- choices: [
395
- { title: "yarn", value: "yarn" },
396
- { title: "npm", value: "npm" },
397
- { title: "pnpm", value: "pnpm" }
398
- ]
399
- });
400
- const packageManager = res.packageManager;
401
- const displayedCommand = packageManager;
409
+ let template = opts.template;
410
+ if (template) {
411
+ template = TEMPLATES.find((_template) => _template.value === template);
412
+ if (!template) {
413
+ console.error(
414
+ `The provided template is invalid. Please provide one of the following: ${TEMPLATES.map(
415
+ (x2) => x2.value
416
+ )}`
417
+ );
418
+ throw new Error("Invalid template.");
419
+ }
420
+ }
421
+ let pkgManager = opts.pkgManager;
422
+ if (pkgManager) {
423
+ if (!PKG_MANAGERS.find((_pkgManager) => _pkgManager === pkgManager)) {
424
+ console.error(
425
+ `The provided package manager is not supported. Please provide one of the following: ${PKG_MANAGERS}`
426
+ );
427
+ throw new Error("Invalid package manager.");
428
+ }
429
+ }
430
+ if (!pkgManager) {
431
+ const installedPkgManagers = [];
432
+ for (const pkg_manager of PKG_MANAGERS) {
433
+ try {
434
+ await checkPackageExists(pkg_manager);
435
+ installedPkgManagers.push(pkg_manager);
436
+ } catch {
437
+ }
438
+ }
439
+ if (installedPkgManagers.length === 0) {
440
+ console.error(`You have no supported package managers installed. Please install one of the following: ${PKG_MANAGERS}`);
441
+ throw new Error("No supported package managers installed.");
442
+ }
443
+ const pkgManagerRes = await (0, import_prompts.default)({
444
+ message: "Which package manager would you like to use?",
445
+ name: "packageManager",
446
+ type: "select",
447
+ choices: installedPkgManagers.map((manager) => {
448
+ return { title: manager, value: manager };
449
+ })
450
+ });
451
+ pkgManager = pkgManagerRes.packageManager;
452
+ }
402
453
  if (!projectName) {
403
- const res2 = await (0, import_prompts.default)({
454
+ const res = await (0, import_prompts.default)({
404
455
  name: "name",
405
456
  type: "text",
406
457
  message: "What is your project named?",
407
458
  initial: "my-tina-app"
408
459
  });
409
- projectName = res2.name;
460
+ projectName = res.name;
410
461
  }
411
462
  const dirName = projectName;
412
- if (!example) {
413
- const res2 = await (0, import_prompts.default)({
414
- name: "example",
463
+ if (!template) {
464
+ const templateRes = await (0, import_prompts.default)({
465
+ name: "template",
415
466
  type: "select",
416
467
  message: "What starter code would you like to use?",
417
- choices: EXAMPLES
468
+ choices: TEMPLATES
418
469
  });
419
- if (typeof res2.example !== "string") {
420
- console.error(import_chalk5.default.red("Input must be a string"));
421
- (0, import_node_process.exit)(1);
422
- }
423
- example = res2.example;
424
- }
425
- const chosenExample = EXAMPLES.find((x2) => x2.value === example);
426
- if (!chosenExample) {
427
- console.error(
428
- `The example provided is not a valid example. Please provide one of the following; ${EXAMPLES.map(
429
- (x2) => x2.value
430
- )}`
431
- );
470
+ template = TEMPLATES.find((_template) => _template.value === templateRes.template);
432
471
  }
433
472
  await telemetry.submitRecord({
434
473
  event: {
435
474
  name: "create-tina-app:invoke",
436
- example,
437
- useYarn: Boolean(res.packageManager === "yarn")
475
+ template,
476
+ pkgManager
438
477
  }
439
478
  });
440
479
  const root = import_node_path.default.join(process.cwd(), dirName);
@@ -453,35 +492,21 @@ var run = async () => {
453
492
  if (!isFolderEmpty(root, appName)) {
454
493
  process.exit(1);
455
494
  }
456
- if (!chosenExample) {
457
- console.error(
458
- `The example provided is not a valid example. Please provide one of the following; ${EXAMPLES.map(
459
- (x2) => x2.value
460
- )}`
461
- );
462
- throw new Error("Invalid example");
463
- }
464
- await downloadExample(chosenExample, root);
495
+ await downloadTemplate(template, root);
465
496
  console.log(
466
- logText("Installing packages. This might take a couple of minutes.")
497
+ logText("Installing packages. This might take a couple of minutes.\n")
467
498
  );
468
- console.log();
469
- await install(root, null, { packageManager, isOnline: true });
499
+ await install(root, null, { packageManager: pkgManager, isOnline: true });
470
500
  if (tryGitInit(root)) {
471
- console.log(logText("Initializing git repository."));
472
- console.log();
501
+ console.log(logText("Initializing git repository.\n"));
473
502
  }
474
503
  console.log(`${successText("Starter successfully created!")}`);
475
504
  console.log(import_chalk5.default.bold("\nTo launch your app, run:\n"));
476
- console.log(` ${cmdText(`cd ${appName}`)}`);
505
+ console.log(` ${cmdText(`cd ${appName}`)}`);
477
506
  console.log(
478
- ` ${cmdText(
479
- `${displayedCommand} ${packageManager === "npm" ? "run " : ""}dev`
480
- )}`
507
+ ` ${cmdText(`${pkgManager} ${pkgManager === "npm" ? "run " : ""}dev`)}`
481
508
  );
482
- console.log();
483
- console.log("Next steps:");
484
- console.log();
509
+ console.log("\nNext steps:\n");
485
510
  console.log(
486
511
  `\u2022 \u{1F4DD} Edit some content on ${linkText(
487
512
  "http://localhost:3000"
@@ -502,5 +527,6 @@ var run = async () => {
502
527
  run();
503
528
  // Annotate the CommonJS export names for ESM import in node:
504
529
  0 && (module.exports = {
530
+ PKG_MANAGERS,
505
531
  run
506
532
  });
@@ -0,0 +1,16 @@
1
+ type BaseExample = {
2
+ title: string;
3
+ description?: string;
4
+ value: string;
5
+ };
6
+ export type InternalTemplate = BaseExample & {
7
+ isInternal: true;
8
+ };
9
+ export type ExternalTemplate = BaseExample & {
10
+ isInternal: false;
11
+ gitURL: string;
12
+ };
13
+ export type Template = InternalTemplate | ExternalTemplate;
14
+ export declare const TEMPLATES: Template[];
15
+ export declare const downloadTemplate: (template: Template, root: string) => Promise<void>;
16
+ export {};
@@ -0,0 +1,2 @@
1
+ import { PKG_MANAGERS } from '..';
2
+ export declare function checkPackageExists(name: (typeof PKG_MANAGERS)[number]): Promise<unknown>;
@@ -1,4 +1,4 @@
1
- export declare type RepoInfo = {
1
+ export type RepoInfo = {
2
2
  username: string;
3
3
  name: string;
4
4
  branch: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-tina-app",
3
- "version": "1.1.6",
3
+ "version": "1.3.0",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -34,8 +34,8 @@
34
34
  "@types/node": "^20.14.12",
35
35
  "@types/prompts": "^2.4.9",
36
36
  "@types/tar": "6.1.13",
37
- "typescript": "^4.6.4",
38
- "@tinacms/scripts": "1.1.6"
37
+ "typescript": "^5.5.4",
38
+ "@tinacms/scripts": "1.2.1"
39
39
  },
40
40
  "dependencies": {
41
41
  "chalk": "4.1.2",
@@ -1,19 +0,0 @@
1
- /**
2
-
3
- */
4
- declare type BaseExample = {
5
- title: string;
6
- description?: string;
7
- value: string;
8
- };
9
- export declare type InternalExample = BaseExample & {
10
- isInternal: true;
11
- };
12
- export declare type ExternalExample = BaseExample & {
13
- isInternal: false;
14
- gitURL: string;
15
- };
16
- export declare type Example = InternalExample | ExternalExample;
17
- export declare const EXAMPLES: Example[];
18
- export declare const downloadExample: (example: Example, root: string) => Promise<void>;
19
- export {};