node-ts-scaffold
Version:
CLI tool to scaffold TypeScript projects with ESLint and Prettier
199 lines (181 loc) • 4.56 kB
text/typescript
// src/templates.ts - Template generators
interface PackageJsonOptions {
name: string;
description: string;
author: string;
}
export function createPackageJson({ name, description, author }: PackageJsonOptions): string {
return JSON.stringify(
{
name,
version: '0.1.0',
description,
author,
type: "module",
main: "build/index.js",
types: "build/index.d.ts",
scripts: {
"dev": "tsx src/index.ts",
"test": "vitest run && tsc --noEmit && eslint src/**/*.ts",
"build": "tsc",
"lint": "eslint src/**/*.ts",
"format": "prettier --write \"src/**/*.ts\""
},
keywords: [],
license: "MIT",
dependencies: {},
devDependencies: {
"@types/node": "^24.1.0",
"@typescript-eslint/eslint-plugin": "^8",
"@typescript-eslint/parser": "^8",
"eslint": "^9",
"globals": "^16.3.0",
"prettier": "^3.1.0",
"tsx": "^4.6.0",
"typescript": "^5",
"vitest": "^3"
},
engines: {
"node": ">=20.0.0"
}
},
null,
2
);
}
export function createTsConfig(): string {
return JSON.stringify(
{
"compilerOptions": {
"target": "ES2024",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"strict": true,
"outDir": "build",
"declaration": true,
"sourceMap": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"noImplicitAny": true,
"noUncheckedIndexedAccess": true,
"strictNullChecks": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "build", "test"]
},
null,
2
);
}
export function createEslintConfig(): string {
return `import js from '@eslint/js';
import tseslint from '@typescript-eslint/eslint-plugin';
import tsparser from '@typescript-eslint/parser';
import globals from 'globals';
export default [
js.configs.recommended,
{
files: ['**/*.{js,ts}'],
languageOptions: {
parser: tsparser,
parserOptions: {
ecmaVersion: 2024,
sourceType: 'module',
},
globals: {
...globals.node,
...globals.es2024,
},
},
plugins: {
'@typescript-eslint': tseslint,
},
rules: {
...tseslint.configs.recommended.rules,
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_' }],
'@typescript-eslint/explicit-function-return-type': 'warn',
'no-console': 'off',
'no-debugger': 'error',
},
},
];
`;
}
export function createPrettierConfig(): string {
return JSON.stringify(
{
"semi": false,
"trailingComma": "es5",
"singleQuote": true,
"printWidth": 100,
"tabWidth": 2
},
null,
2
);
}
export function createGitignore(): string {
return `# IDE
.idea
.vscode
.codebuddy
# Dependencies
node_modules
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Build output
build
dist
# Environment variables
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# OS
.DS_Store
Thumbs.db
`;
}
export function createSrcIndex(): string {
return `/**
* Main entry point for the application
*/
`;
}
export function createTestFile(): string {
return `import { describe, it, expect } from 'vitest';
// import { greet } from '../src/index.js';
describe('entry', () => {
// it('should greet a person by name', () => {
// expect(greet('Alice')).toBe('Hello, Alice!');
// });
//
// it('should work with any string', () => {
// expect(greet('World')).toBe('Hello, World!');
// expect(greet('TypeScript')).toBe('Hello, TypeScript!');
// });
});
`;
}
export function createVitestConfig(): string {
return `import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
globals: true,
environment: 'node',
},
});
`;
}