mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 06:07:20 +08:00 
			
		
		
		
	feat(TypeScript): Add the workflow file for CI check (#1280)
* feat(TypeScript): Add the workflow file for CI check * fix: Install TypeScript Execute (tsx) * test: Test failed * test: Test successful * test: on windows * Add a bug * feat: type checking * test: Test successful * feat: add main * fix: use process * feat: use es-main * Test failure * feat: streamlined configuration * Apply suggestions from code review Co-authored-by: Yudong Jin <krahets@163.com> * feat: remove lock file * Test failure * Test success --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
		
							
								
								
									
										26
									
								
								.github/workflows/typescript.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								.github/workflows/typescript.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
				
			|||||||
 | 
					name: TypeScript
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					on:
 | 
				
			||||||
 | 
					  push:
 | 
				
			||||||
 | 
					    branches: ['main']
 | 
				
			||||||
 | 
					    paths: ['codes/typescript/**/*.ts']
 | 
				
			||||||
 | 
					  pull_request:
 | 
				
			||||||
 | 
					    branches: ['main']
 | 
				
			||||||
 | 
					    paths: ['codes/typescript/**/*.ts']
 | 
				
			||||||
 | 
					  workflow_dispatch:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					jobs:
 | 
				
			||||||
 | 
					  build:
 | 
				
			||||||
 | 
					    runs-on: ${{ matrix.os }}
 | 
				
			||||||
 | 
					    strategy:
 | 
				
			||||||
 | 
					      matrix:
 | 
				
			||||||
 | 
					        os: [ubuntu-latest, macos-latest]
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      - uses: actions/checkout@v4
 | 
				
			||||||
 | 
					      - uses: actions/setup-node@v4
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          node-version: 20.x
 | 
				
			||||||
 | 
					      - name: Install dependencies
 | 
				
			||||||
 | 
					        run: cd codes/typescript && npm install
 | 
				
			||||||
 | 
					      - name: Check TypeScript code
 | 
				
			||||||
 | 
					        run: cd codes/typescript && npm run check
 | 
				
			||||||
							
								
								
									
										2
									
								
								codes/typescript/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								codes/typescript/.gitignore
									
									
									
									
										vendored
									
									
								
							@ -1,4 +1,2 @@
 | 
				
			|||||||
node_modules
 | 
					node_modules
 | 
				
			||||||
out
 | 
					 | 
				
			||||||
package.json
 | 
					 | 
				
			||||||
package-lock.json
 | 
					package-lock.json
 | 
				
			||||||
 | 
				
			|||||||
@ -91,9 +91,8 @@ class GraphAdjList {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// need to add the package @types/node contains type definitions for Node.js, npm i --save-dev @types/node
 | 
					/* Driver Code */
 | 
				
			||||||
if (require.main === module) {
 | 
					if (import.meta.url.endsWith(process.argv[1])) {
 | 
				
			||||||
    /* Driver Code */
 | 
					 | 
				
			||||||
    /* 初始化无向图 */
 | 
					    /* 初始化无向图 */
 | 
				
			||||||
    const v0 = new Vertex(1),
 | 
					    const v0 = new Vertex(1),
 | 
				
			||||||
        v1 = new Vertex(3),
 | 
					        v1 = new Vertex(3),
 | 
				
			||||||
 | 
				
			|||||||
@ -122,7 +122,7 @@ class MaxHeap {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* Driver Code */
 | 
					/* Driver Code */
 | 
				
			||||||
if (require.main === module) {
 | 
					if (import.meta.url.endsWith(process.argv[1])) {
 | 
				
			||||||
    /* 初始化大顶堆 */
 | 
					    /* 初始化大顶堆 */
 | 
				
			||||||
    const maxHeap = new MaxHeap([9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2]);
 | 
					    const maxHeap = new MaxHeap([9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2]);
 | 
				
			||||||
    console.log('\n输入列表并建堆后');
 | 
					    console.log('\n输入列表并建堆后');
 | 
				
			||||||
 | 
				
			|||||||
@ -4,8 +4,8 @@
 | 
				
			|||||||
 * Author: yuan0221 (yl1452491917@gmail.com)
 | 
					 * Author: yuan0221 (yl1452491917@gmail.com)
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { arrToTree } = require('../modules/TreeNode');
 | 
					import { arrToTree } from '../modules/TreeNode';
 | 
				
			||||||
const { printTree } = require('../modules/PrintUtil');
 | 
					import { printTree } from '../modules/PrintUtil';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Order = 'pre' | 'in' | 'post';
 | 
					type Order = 'pre' | 'in' | 'post';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -148,4 +148,4 @@ console.log('中序遍历为:' + res);
 | 
				
			|||||||
res = abt.postOrder();
 | 
					res = abt.postOrder();
 | 
				
			||||||
console.log('后序遍历为:' + res);
 | 
					console.log('后序遍历为:' + res);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export { };
 | 
					export {};
 | 
				
			||||||
 | 
				
			|||||||
@ -79,9 +79,6 @@ function showTrunks(p: Trunk | null) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    showTrunks(p.prev);
 | 
					    showTrunks(p.prev);
 | 
				
			||||||
    process.stdout.write(p.str);
 | 
					    process.stdout.write(p.str);
 | 
				
			||||||
    // ts-node to execute, we need to install type definitions for node
 | 
					 | 
				
			||||||
    // solve: npm i --save-dev @types/node
 | 
					 | 
				
			||||||
    // restart the vscode
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 打印堆 */
 | 
					/* 打印堆 */
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										11
									
								
								codes/typescript/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								codes/typescript/package.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					    "private": true,
 | 
				
			||||||
 | 
					    "type": "module",
 | 
				
			||||||
 | 
					    "scripts": {
 | 
				
			||||||
 | 
					        "check": "tsc"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "devDependencies": {
 | 
				
			||||||
 | 
					        "@types/node": "^20.12.7",
 | 
				
			||||||
 | 
					        "typescript": "^5.4.5"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,8 +1,12 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    "compilerOptions": {
 | 
					    "compilerOptions": {
 | 
				
			||||||
        "target": "ES6",
 | 
					        "baseUrl": ".",
 | 
				
			||||||
        "module": "CommonJS",
 | 
					        "module": "esnext",
 | 
				
			||||||
        "outDir": "out",
 | 
					        "moduleResolution": "node",
 | 
				
			||||||
        "sourceMap": true
 | 
					        "types": ["@types/node"],
 | 
				
			||||||
    }
 | 
					        "noEmit": true,
 | 
				
			||||||
 | 
					        "target": "esnext",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    "include": ["chapter_*/*.ts"],
 | 
				
			||||||
 | 
					    "exclude": ["node_modules"]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user