Skip to content

Commit

Permalink
init setup with examples for debug, lint, test
Browse files Browse the repository at this point in the history
  • Loading branch information
scottluskcis committed Nov 20, 2024
1 parent f6820d1 commit bb5e713
Show file tree
Hide file tree
Showing 13 changed files with 3,682 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ out

# Nuxt.js build / generate output
.nuxt
dist
#dist

# Gatsby files
.cache/
Expand Down Expand Up @@ -128,3 +128,4 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.DS_Store
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "dev",
"request": "launch",
"runtimeArgs": ["dev"],
"runtimeExecutable": "pnpm",
"skipFiles": ["<node_internals>/**"],
"type": "node"
}
]
}

27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
# ts-node-project-setup

Foundation for setting up a Typescript project that has support for linting, testing, and debugging

I typically use [pnpm](https://pnpm.io/) as a Package Manager but everything will work with `npm` as well. Anywhere you see reference to `pnpm` and some command it just means it is using `pnpm`. Examples of both `pnpm` and `npm` are provided.

## Setup

1. Install your IDE of choice, such as [Visual Studio Code](https://code.visualstudio.com/)
2. Clone [this repository](https://github.com/scottluskcis/ts-node-project-setup.git) locally
3. Run `pnpm install` or `npm install`
4. Run `pnpm dev` or `npm run dev` to run the simple example

## Tests

A simple test is provided here and is setup using [Jest](https://jestjs.io/). You can run the test either running `pnpm test` or `npm run test`.

## Linting

Linting is configured for the project, run `pnpm lint` or `npm run lint`

## Debugging

A sample launch configuration has been added to use if you are using Visual Studio Code [here](.vscode/launch.json). Use VS Code Run and Debug and launch the dev configuration. Note that the launch is setup to use `pnpm` currently but you can alter this by modifying the following values to work with npm

```json
"runtimeArgs": ["run", "dev"],
"runtimeExecutable": "npm",
```
3 changes: 3 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dist/index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import globals from 'globals';
import pluginJs from '@eslint/js';
import tsEslintPlugin from '@typescript-eslint/eslint-plugin';
import tsEslintParser from '@typescript-eslint/parser';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

/** @type {import('eslint').Linter.Config} */
export default [
{
files: ['**/*.{js,mjs,cjs,ts}'],
ignores: ['dist/'],
languageOptions: {
globals: {
...globals.browser,
...globals.node,
...globals.jest,
},
parser: tsEslintParser,
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
},
plugins: {
'@typescript-eslint': tsEslintPlugin,
},
rules: {
...pluginJs.configs.recommended.rules,
...tsEslintPlugin.configs.recommended.rules,
// Add any custom rules here
},
},
];
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import('ts-jest').JestConfigWithTsJest} **/
module.exports = {
testEnvironment: "node",
transform: {
"^.+.tsx?$": ["ts-jest",{}],
},
};
5 changes: 5 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"execMap": {
"ts": "ts-node"
}
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "copilot-usage-metrics",
"version": "1.0.0",
"description": "Utility for capturing usage metrics",
"main": "index.js",
"scripts": {
"tsc": "exec tsc",
"start": "tsc && node dist/app.js",
"dev": "nodemon src/index.ts",
"lint": "eslint ./src/**/*.ts",
"test": "jest",
"test:watch": "jest --watch"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@eslint/js": "^9.15.0",
"@types/jest": "^29.5.14",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^9.15.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"nodemon": "^3.1.7",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"typescript": "^5.6.3"
}
}
Loading

0 comments on commit bb5e713

Please sign in to comment.