Pārlūkot izejas kodu

fix(create-pyth-app): don't copy node modules and rewrite their package.json files

benduran 1 nedēļu atpakaļ
vecāks
revīzija
61bea85de7

+ 10 - 4
packages/create-pyth-app/src/create-pyth-app.ts

@@ -21,6 +21,12 @@ import type {
 } from "./types.js";
 import { PACKAGE_PREFIX, PackageType, TEMPLATES_FOLDER } from "./types.js";
 
+function getPackageNameWithoutOrg(
+  packageNameWithOrg: string | null | undefined,
+) {
+  return packageNameWithOrg?.split("/")[1] ?? "";
+}
+
 /**
  * returns the folder that holds the correct templates, based on the user's
  * package choice
@@ -109,7 +115,7 @@ async function createPythApp() {
           }: InProgressCreatePythAppResponses,
         ) => {
           let msg = `Please confirm your choices:${os.EOL}`;
-          msg += `Creating a ${chalk.magenta(packageType)} package, named ${chalk.magenta(packageName)}, in ${chalk.magenta(packageType === PackageType.WEBAPP ? "apps" : folder)}/${packageName?.split("/")[1] ?? ""}.${os.EOL}`;
+          msg += `Creating a ${chalk.magenta(packageType)} package, named ${chalk.magenta(packageName)}, in ${chalk.magenta(packageType === PackageType.WEBAPP ? "apps" : folder)}/${getPackageNameWithoutOrg(packageName)}.${os.EOL}`;
           msg += "Look good?";
 
           return msg;
@@ -124,7 +130,7 @@ async function createPythApp() {
     return;
   }
 
-  const [, packageNameWithoutOrg = ""] = packageName.split("/");
+  const packageNameWithoutOrg = getPackageNameWithoutOrg(packageName);
 
   const relDest =
     packageType === PackageType.WEBAPP
@@ -153,12 +159,12 @@ async function createPythApp() {
     "updating files with the choices you made in the initial prompts",
   );
   await Promise.all(
-    destFiles.map(async (fp) => {
-      debugger;
+    destFiles.filter(fp => !fp.includes('node_module')).map(async (fp) => {
       const contents = await fs.readFile(fp, "utf8");
       const updatedContents = renderTemplate(contents, {
         description,
         name: packageName,
+        packageNameWithoutOrg,
         relativeFolder: relDest,
       });
       await fs.writeFile(fp, updatedContents, "utf8");

+ 1 - 1
packages/create-pyth-app/src/templates/cli/package.json

@@ -4,7 +4,7 @@
   "version": "0.0.0",
   "type": "module",
   "bin": {
-    "{{name}}": "./bin.js"
+    "{{packageNameWithoutOrg}}": "./bin.js"
   },
   "files": [
     "bin.js",