- Introduced a new script to check TypeScript lesson files for errors. - Created a main TypeScript file to render lessons and their details. - Added lesson definitions with starter and answer codes. - Implemented a user interface for navigating and running lessons. - Styled the application with CSS for a better user experience. - Updated README to reflect the new TypeScript section and usage instructions.
59 lines
1.5 KiB
JavaScript
59 lines
1.5 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
const rootDir = path.resolve(__dirname, "..");
|
|
const tscPath = path.join(rootDir, "node_modules", "typescript", "bin", "tsc");
|
|
|
|
const lessonFiles = [
|
|
"01-js-vs-ts/starter.ts",
|
|
"01-js-vs-ts/answer.ts",
|
|
"02-basic-type-annotations/starter.ts",
|
|
"02-basic-type-annotations/answer.ts",
|
|
"03-array-and-function-types/starter.ts",
|
|
"03-array-and-function-types/answer.ts",
|
|
"04-interface-object-shape/starter.ts",
|
|
"04-interface-object-shape/answer.ts",
|
|
"05-generic-functions/starter.ts",
|
|
"05-generic-functions/answer.ts",
|
|
"06-union-and-optional-props/starter.ts",
|
|
"06-union-and-optional-props/answer.ts",
|
|
"07-type-safe-renderer/starter.ts",
|
|
"07-type-safe-renderer/answer.ts",
|
|
"08-final-mini-app/starter.ts",
|
|
"08-final-mini-app/answer.ts",
|
|
];
|
|
|
|
const sharedArgs = [
|
|
"--noEmit",
|
|
"--pretty",
|
|
"false",
|
|
"--target",
|
|
"ES2020",
|
|
"--module",
|
|
"ESNext",
|
|
"--moduleResolution",
|
|
"Bundler",
|
|
"--strict",
|
|
"--skipLibCheck",
|
|
];
|
|
|
|
for (const lessonFile of lessonFiles) {
|
|
const filePath = path.join(rootDir, lessonFile);
|
|
|
|
console.log(`Checking ${lessonFile}`);
|
|
|
|
const result = spawnSync(process.execPath, [tscPath, ...sharedArgs, filePath], {
|
|
cwd: rootDir,
|
|
stdio: "inherit",
|
|
});
|
|
|
|
if (result.status !== 0) {
|
|
process.exit(result.status ?? 1);
|
|
}
|
|
}
|
|
|
|
console.log("All lesson files passed TypeScript checks.");
|