create-tina-app 1.1.4 → 1.1.6

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.js CHANGED
@@ -31,11 +31,11 @@ module.exports = __toCommonJS(src_exports);
31
31
  var import_metrics = require("@tinacms/metrics");
32
32
  var import_commander = require("commander");
33
33
  var import_prompts = __toESM(require("prompts"));
34
- var import_path4 = __toESM(require("path"));
34
+ var import_node_path = __toESM(require("path"));
35
35
 
36
36
  // package.json
37
37
  var name = "create-tina-app";
38
- var version = "1.1.4";
38
+ var version = "1.1.6";
39
39
 
40
40
  // src/util/fileUtil.ts
41
41
  var import_fs_extra = __toESM(require("fs-extra"));
@@ -111,7 +111,7 @@ function install(root, dependencies, { packageManager, isOnline, devDependencies
111
111
  return new Promise((resolve, reject) => {
112
112
  let args;
113
113
  const command = packageManager;
114
- if (dependencies && dependencies.length) {
114
+ if (dependencies == null ? void 0 : dependencies.length) {
115
115
  switch (packageManager) {
116
116
  case "yarn":
117
117
  args = ["add", "--exact"];
@@ -241,41 +241,53 @@ function tryGitInit(root) {
241
241
  }
242
242
 
243
243
  // src/index.ts
244
- var import_process = require("process");
244
+ var import_node_process = require("process");
245
245
 
246
246
  // src/util/examples.ts
247
- var import_got = __toESM(require("got"));
248
- var import_stream = require("stream");
249
- var import_util = require("util");
250
- var import_tar = __toESM(require("tar"));
251
- var pipeline = (0, import_util.promisify)(import_stream.Stream.pipeline);
247
+ var import_node_stream = require("stream");
248
+ var import_promises = require("stream/promises");
249
+ var import_tar = require("tar");
252
250
  async function getRepoInfo(url, examplePath) {
253
251
  const [, username, name2, t, _branch, ...file] = url.pathname.split("/");
254
252
  const filePath = examplePath ? examplePath.replace(/^\//, "") : file.join("/");
255
- if (t === void 0) {
256
- const infoResponse = await (0, import_got.default)(
257
- `https://api.github.com/repos/${username}/${name2}`
258
- ).catch((e) => e);
259
- if (infoResponse.statusCode !== 200) {
253
+ if (t === void 0 || t === "" && _branch === void 0) {
254
+ try {
255
+ const infoResponse = await fetch(
256
+ `https://api.github.com/repos/${username}/${name2}`
257
+ );
258
+ if (infoResponse.status !== 200) {
259
+ return;
260
+ }
261
+ const info = await infoResponse.json();
262
+ return { username, name: name2, branch: info.default_branch, filePath };
263
+ } catch {
260
264
  return;
261
265
  }
262
- const info = JSON.parse(infoResponse.body);
263
- return { username, name: name2, branch: info["default_branch"], filePath };
264
266
  }
265
267
  const branch = examplePath ? `${_branch}/${file.join("/")}`.replace(new RegExp(`/${filePath}|/$`), "") : _branch;
266
268
  if (username && name2 && branch && t === "tree") {
267
269
  return { username, name: name2, branch, filePath };
268
270
  }
269
271
  }
270
- function downloadAndExtractRepo(root, { username, name: name2, branch, filePath }) {
271
- return pipeline(
272
- import_got.default.stream(
272
+ async function downloadTarStream(url) {
273
+ const res = await fetch(url);
274
+ if (!res.body) {
275
+ throw new Error(`Failed to download: ${url}`);
276
+ }
277
+ return import_node_stream.Readable.fromWeb(res.body);
278
+ }
279
+ async function downloadAndExtractRepo(root, { username, name: name2, branch, filePath }) {
280
+ await (0, import_promises.pipeline)(
281
+ await downloadTarStream(
273
282
  `https://codeload.github.com/${username}/${name2}/tar.gz/${branch}`
274
283
  ),
275
- import_tar.default.extract(
276
- { cwd: root, strip: filePath ? filePath.split("/").length + 1 : 1 },
277
- [`${name2}-${branch}${filePath ? `/${filePath}` : ""}`]
278
- )
284
+ (0, import_tar.x)({
285
+ cwd: root,
286
+ strip: filePath ? filePath.split("/").length + 1 : 1,
287
+ filter: (p) => p.startsWith(
288
+ `${name2}-${branch.replace(/\//g, "-")}${filePath ? `/${filePath}/` : "/"}`
289
+ )
290
+ })
279
291
  );
280
292
  }
281
293
 
@@ -334,9 +346,12 @@ var downloadExample = async (example, root) => {
334
346
  const repoInfo2 = repoInfo;
335
347
  console.log(
336
348
  `Downloading files from repo ${import_chalk4.default.cyan(
337
- repoInfo.username + "/" + repoInfo.name
349
+ `${repoInfo == null ? void 0 : repoInfo.username}/${repoInfo == null ? void 0 : repoInfo.name}`
338
350
  )}. This might take a moment.`
339
351
  );
352
+ if (!repoInfo2) {
353
+ throw new Error("downloadExample Failed. Repo info not found");
354
+ }
340
355
  await downloadAndExtractRepo(root, repoInfo2);
341
356
  } else {
342
357
  const exampleFile = import_path3.default.join(__dirname, "..", "examples", example.value);
@@ -377,8 +392,8 @@ var run = async () => {
377
392
  name: "packageManager",
378
393
  type: "select",
379
394
  choices: [
380
- { title: "Yarn", value: "yarn" },
381
- { title: "NPM", value: "npm" },
395
+ { title: "yarn", value: "yarn" },
396
+ { title: "npm", value: "npm" },
382
397
  { title: "pnpm", value: "pnpm" }
383
398
  ]
384
399
  });
@@ -403,15 +418,15 @@ var run = async () => {
403
418
  });
404
419
  if (typeof res2.example !== "string") {
405
420
  console.error(import_chalk5.default.red("Input must be a string"));
406
- (0, import_process.exit)(1);
421
+ (0, import_node_process.exit)(1);
407
422
  }
408
423
  example = res2.example;
409
424
  }
410
- const chosenExample = EXAMPLES.find((x) => x.value === example);
425
+ const chosenExample = EXAMPLES.find((x2) => x2.value === example);
411
426
  if (!chosenExample) {
412
427
  console.error(
413
428
  `The example provided is not a valid example. Please provide one of the following; ${EXAMPLES.map(
414
- (x) => x.value
429
+ (x2) => x2.value
415
430
  )}`
416
431
  );
417
432
  }
@@ -422,8 +437,8 @@ var run = async () => {
422
437
  useYarn: Boolean(res.packageManager === "yarn")
423
438
  }
424
439
  });
425
- const root = import_path4.default.join(process.cwd(), dirName);
426
- if (!await isWriteable(import_path4.default.dirname(root))) {
440
+ const root = import_node_path.default.join(process.cwd(), dirName);
441
+ if (!await isWriteable(import_node_path.default.dirname(root))) {
427
442
  console.error(
428
443
  "The application path is not writable, please check folder permissions and try again."
429
444
  );
@@ -432,12 +447,20 @@ var run = async () => {
432
447
  );
433
448
  process.exit(1);
434
449
  }
435
- const appName = import_path4.default.basename(root);
450
+ const appName = import_node_path.default.basename(root);
436
451
  await makeDir(root);
437
452
  process.chdir(root);
438
453
  if (!isFolderEmpty(root, appName)) {
439
454
  process.exit(1);
440
455
  }
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
+ }
441
464
  await downloadExample(chosenExample, root);
442
465
  console.log(
443
466
  logText("Installing packages. This might take a couple of minutes.")
@@ -450,7 +473,7 @@ var run = async () => {
450
473
  }
451
474
  console.log(`${successText("Starter successfully created!")}`);
452
475
  console.log(import_chalk5.default.bold("\nTo launch your app, run:\n"));
453
- console.log(" " + cmdText(`cd ${appName}`));
476
+ console.log(` ${cmdText(`cd ${appName}`)}`);
454
477
  console.log(
455
478
  ` ${cmdText(
456
479
  `${displayedCommand} ${packageManager === "npm" ? "run " : ""}dev`
@@ -1,6 +1,3 @@
1
- /**
2
-
3
- */
4
1
  export declare type RepoInfo = {
5
2
  username: string;
6
3
  name: string;
@@ -10,6 +7,6 @@ export declare type RepoInfo = {
10
7
  export declare function isUrlOk(url: string): Promise<boolean>;
11
8
  export declare function getRepoInfo(url: URL, examplePath?: string): Promise<RepoInfo | undefined>;
12
9
  export declare function hasRepo({ username, name, branch, filePath, }: RepoInfo): Promise<boolean>;
13
- export declare function hasExample(name: string): Promise<boolean>;
10
+ export declare function existsInRepo(nameOrUrl: string): Promise<boolean>;
14
11
  export declare function downloadAndExtractRepo(root: string, { username, name, branch, filePath }: RepoInfo): Promise<void>;
15
12
  export declare function downloadAndExtractExample(root: string, name: string): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-tina-app",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "dist",
@@ -18,6 +18,9 @@
18
18
  }
19
19
  ]
20
20
  },
21
+ "engines": {
22
+ "node": ">=18.18.0"
23
+ },
21
24
  "publishConfig": {
22
25
  "registry": "https://registry.npmjs.org"
23
26
  },
@@ -26,22 +29,23 @@
26
29
  "directory": "packages/create-tina-app"
27
30
  },
28
31
  "devDependencies": {
29
- "@types/fs-extra": "^9.0.13",
30
- "@types/node": "^16.11.7",
31
- "@types/prompts": "^2.0.14",
32
- "@types/tar": "4.0.3",
33
- "typescript": "4.6.4",
34
- "@tinacms/scripts": "1.1.5"
32
+ "@types/cross-spawn": "^6.0.6",
33
+ "@types/fs-extra": "^11.0.4",
34
+ "@types/node": "^20.14.12",
35
+ "@types/prompts": "^2.4.9",
36
+ "@types/tar": "6.1.13",
37
+ "typescript": "^4.6.4",
38
+ "@tinacms/scripts": "1.1.6"
35
39
  },
36
40
  "dependencies": {
37
- "chalk": "^4.1.2",
38
- "commander": "^8.3.0",
41
+ "chalk": "4.1.2",
42
+ "commander": "^12.1.0",
39
43
  "cross-spawn": "^7.0.3",
40
- "fs-extra": "^10.0.0",
41
- "got": "^11.8.5",
44
+ "fs-extra": "^11.2.0",
45
+ "got": "^14.4.2",
42
46
  "prompts": "^2.4.2",
43
- "tar": "4.4.18",
44
- "@tinacms/metrics": "1.0.4"
47
+ "tar": "7.4.0",
48
+ "@tinacms/metrics": "1.0.5"
45
49
  },
46
50
  "scripts": {
47
51
  "types": "pnpm tsc",