Mrm TypeScript Task

4.1.22 · active · verified Sun Apr 19

mrm-task-typescript is an Mrm task designed to automate the initial setup and configuration of TypeScript within a JavaScript project. It currently stands at version 4.1.22. As part of the Mrm monorepo, its releases are often coordinated with other Mrm tasks, typically seeing version bumps (sometimes 'bump only') to ensure compatibility across the Mrm ecosystem. This task distinguishes itself by providing a declarative and automated way to standardize TypeScript configuration across multiple projects or within an organization, reducing manual setup errors and ensuring best practices are applied consistently. It handles the creation of `tsconfig.json`, integrates a type-checking script into `package.json`, and installs necessary TypeScript-related dependencies, streamlining the developer workflow for adopting TypeScript.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to create a new project, initialize npm, and apply the `mrm typescript` task to configure TypeScript, including `tsconfig.json` and a type-checking script.

import * as path from 'path';
import * as fs from 'fs';
import { execSync } from 'child_process';

const projectName = 'my-ts-project';
const projectPath = path.join(process.cwd(), projectName);

console.log(`Creating project directory: ${projectPath}`);
fs.mkdirSync(projectPath, { recursive: true });
process.chdir(projectPath);

console.log('Initializing npm...');
execSync('npm init -y', { stdio: 'inherit' });

console.log('Running mrm typescript task...');
execSync('npx mrm typescript', { stdio: 'inherit' });

console.log('\nVerifying setup:');
console.log('Content of tsconfig.json:');
console.log(fs.readFileSync('tsconfig.json', 'utf8'));

console.log('\nContent of package.json scripts:');
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
console.log(packageJson.scripts);

// Create a sample TypeScript file to demonstrate compilation
fs.mkdirSync('src', { recursive: true });
fs.writeFileSync('src/index.ts', `
function greet(name: string): string {
  return \`Hello, \${name}!\`;
}
console.log(greet("TypeScript User"));
`);

console.log('\nAttempting to run type check script...');
execSync('npm run typecheck', { stdio: 'inherit' });

console.log('\nTypeScript setup complete! To clean up, run:');
console.log(`rm -rf ${projectName}`);

view raw JSON →