Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TypeScript): Add the workflow file for CI check #1280

Merged
merged 18 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 2 deletions codes/typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
node_modules
out
package.json
package-lock.json
5 changes: 2 additions & 3 deletions codes/typescript/chapter_graph/graph_adjacency_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
if (require.main === module) {
Shyam-Chen marked this conversation as resolved.
Show resolved Hide resolved
/* Driver Code */
/* Driver Code */
if (import.meta.url.endsWith(process.argv[1])) {
/* 初始化无向图 */
const v0 = new Vertex(1),
v1 = new Vertex(3),
Expand Down
2 changes: 1 addition & 1 deletion codes/typescript/chapter_heap/my_heap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class MaxHeap {
}

/* Driver Code */
if (require.main === module) {
Shyam-Chen marked this conversation as resolved.
Show resolved Hide resolved
if (import.meta.url.endsWith(process.argv[1])) {
/* 初始化大顶堆 */
const maxHeap = new MaxHeap([9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2]);
console.log('\n输入列表并建堆后');
Expand Down
6 changes: 3 additions & 3 deletions codes/typescript/chapter_tree/array_binary_tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Author: yuan0221 (yl1452491917@gmail.com)
*/

const { arrToTree } = require('../modules/TreeNode');
const { printTree } = require('../modules/PrintUtil');
import { arrToTree } from '../modules/TreeNode';
import { printTree } from '../modules/PrintUtil';

type Order = 'pre' | 'in' | 'post';

Expand Down Expand Up @@ -148,4 +148,4 @@ console.log('中序遍历为:' + res);
res = abt.postOrder();
console.log('后序遍历为:' + res);

export { };
export {};
3 changes: 0 additions & 3 deletions codes/typescript/modules/PrintUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,6 @@ function showTrunks(p: Trunk | null) {

showTrunks(p.prev);
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
}

/* 打印堆 */
Expand Down
11 changes: 11 additions & 0 deletions codes/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"private": true,
"type": "module",
"scripts": {
"check": "tsc"
},
"devDependencies": {
"@types/node": "^20.12.7",
"typescript": "^5.4.5"
}
}
14 changes: 9 additions & 5 deletions codes/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"compilerOptions": {
Shyam-Chen marked this conversation as resolved.
Show resolved Hide resolved
"target": "ES6",
"module": "CommonJS",
"outDir": "out",
"sourceMap": true
}
"baseUrl": ".",
"module": "esnext",
"moduleResolution": "node",
"types": ["@types/node"],
"noEmit": true,
"target": "esnext",
},
"include": ["chapter_*/*.ts"],
"exclude": ["node_modules"]
}