create-tina-app 1.2.0 → 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 +1 -0
- package/dist/index.js +94 -68
- package/dist/templates.d.ts +16 -0
- package/dist/util/checkPkgManagers.d.ts +2 -0
- package/package.json +2 -2
- package/dist/examples.d.ts +0 -19
package/dist/index.d.ts
CHANGED
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.
|
|
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/
|
|
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
|
|
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
|
|
343
|
-
if (
|
|
344
|
-
const repoURL = new URL(
|
|
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
|
|
358
|
-
await (0, import_fs_extra3.copy)(`${
|
|
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
|
|
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
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
|
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 =
|
|
460
|
+
projectName = res.name;
|
|
410
461
|
}
|
|
411
462
|
const dirName = projectName;
|
|
412
|
-
if (!
|
|
413
|
-
const
|
|
414
|
-
name: "
|
|
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:
|
|
468
|
+
choices: TEMPLATES
|
|
418
469
|
});
|
|
419
|
-
|
|
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
|
-
|
|
437
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(`
|
|
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 {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-tina-app",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@types/prompts": "^2.4.9",
|
|
36
36
|
"@types/tar": "6.1.13",
|
|
37
37
|
"typescript": "^5.5.4",
|
|
38
|
-
"@tinacms/scripts": "1.2.
|
|
38
|
+
"@tinacms/scripts": "1.2.1"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"chalk": "4.1.2",
|
package/dist/examples.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
type BaseExample = {
|
|
5
|
-
title: string;
|
|
6
|
-
description?: string;
|
|
7
|
-
value: string;
|
|
8
|
-
};
|
|
9
|
-
export type InternalExample = BaseExample & {
|
|
10
|
-
isInternal: true;
|
|
11
|
-
};
|
|
12
|
-
export type ExternalExample = BaseExample & {
|
|
13
|
-
isInternal: false;
|
|
14
|
-
gitURL: string;
|
|
15
|
-
};
|
|
16
|
-
export type Example = InternalExample | ExternalExample;
|
|
17
|
-
export declare const EXAMPLES: Example[];
|
|
18
|
-
export declare const downloadExample: (example: Example, root: string) => Promise<void>;
|
|
19
|
-
export {};
|