javascript - הידור קבצי tsx עם הפקודה tsc בקובץ deploy.sh
אז ניסיתי לקמפל קבצי tsx לקבצי jsx ולפרוס אותם לתיקייה מסוימת. יש לי תיקיית web שמטפלת בצד הלקוח ואז תיקיית backend שמטפלת בכל הדברים של הצד השרת רק בשביל הקשר מסוים. בתיקיית ה-web שלי יצרתי פרויקט react-typescript ואני רוצה להיות מסוגל לקמפל אותו ל-jsx בלי קובץ tsconfig. זה מה שיש לי ב-deploy.sh:
deploy script for the web front-end
This file is responsible for preprocessing all TypeScript files, making sure
all dependencies are up-to-date, and copying all necessary files into the
web deploy directory.
This is the resource folder where maven expects to find our files
TARGETFOLDER=../backend/src/main/resources
This is the folder that we used with the Spark.staticFileLocation command
WEBFOLDERNAME=web
step 1: make sure we have someplace to put everything. We will delete the
old folder tree, and then make it from scratch
rm -rf $TARGETFOLDER
mkdir $TARGETFOLDER
mkdir $TARGETFOLDER/$WEBFOLDERNAME
there are many more steps to be done. For now, we will just copy an HTML file
cp src/index.html $TARGETFOLDER/$WEBFOLDERNAME
step 2: update our npm dependencies
npm update
step 3: copy javascript files
cp node_modules/jquery/dist/jquery.min.js $TARGETFOLDER/$WEBFOLDERNAME
step 4: compile TypeScript files
node_modules/typescript/bin/tsc src/App.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/create.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/Navbar.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/home.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/PostLists.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/index.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/ideaList.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/ideaDetails.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
node_modules/typescript/bin/tsc src/useFetch.tsx --jsx preserve --esModuleInterOp --strict --outFile $TARGETFOLDER/$WEBFOLDERNAME/app.jsx
step 5: copy css files
cp src/style.css $TARGETFOLDER/$WEBFOLDERNAME
אז כפי שאתם יכולים לראות בשלב 4 אני מנסה לאסוף את כל הרכיבים שלי לגרסאות ה-JSX שלהם ולהעביר אותם לתיקייה, אבל אני מקבל שגיאת קומפיילר כשאני מריץ sh deploy.sh, שכשאני מריץ רק npm start על הפרויקט שלי אני לא מקבל. כל עזרה או עצה לגבי מה לעשות תהיה מוערכת מאוד!
עריכה: אלו חלק מהשגיאות שאני מקבל, שלא הייתי מקבל כשאני מריץ npm run:
src/home.tsx(10,26): error TS2531: Object is possibly 'null'.
src/IdeaDetails.tsx(11,18): error TS2531: Object is possibly 'null'.
src/IdeaDetails.tsx(12,21): error TS2531: Object is possibly 'null'.
src/IdeaDetails.tsx(21,31): error TS2339: Property 'ideaTitle' does not exist on type 'never'.
src/IdeaDetails.tsx(22,41): error TS2339: Property 'author' does not exist on type 'never'.
src/IdeaDetails.tsx(23,32): error TS2339: Property 'body' does not exist on type 'never'.
src/IdeaDetails.tsx(24,32): error TS2339: Property 'score' does not exist on type 'never'.
src/PostList.tsx(1,1): error TS6131: Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'.
src/create.tsx(1,1): error TS6131: Cannot compile modules using option 'outFile' unless the '--module' flag is 'amd' or 'system'.
אני גם העברתי את TypeScript מתלות של מפתחים לתלות רגילה וזה עדיין לא עובד. אם בכל זאת אצליח לקבל את הקבצים האלה קומפיילים ב-JS בהצלחה, אני צריך אז להריץ mvn package כדי להפוך את ממשק המשתמש שלי לקובץ jar כדי שאוכל להעלות אותו ל-Heroku דרך ה-backend.