Skip to content

Commit e57e02e

Browse files
use ts for build
1 parent c1d3c5b commit e57e02e

File tree

5 files changed

+47
-11
lines changed

5 files changed

+47
-11
lines changed

.github/workflows/prepare_data.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ jobs:
1212

1313
steps:
1414
- name: Checkout Repository
15-
uses: actions/checkout@v2
15+
uses: actions/checkout@v3
1616

1717
- name: Setup Node.js
1818
uses: actions/setup-node@v3
1919
with:
20-
node-version: '16'
20+
node-version: '22'
2121

2222
- name: Install Dependencies
2323
run: npm install
2424

2525
- name: Run Script to Prepare data
26-
run: node build_scripts/prepare_data.mjs
26+
run: npm run build
2727

2828
- name: Commit and Push Changes
2929
env:

build_scripts/prepare_data.mjs renamed to build_scripts/prepare_data.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { join } from 'path';
22
import { writeFileSync, readFileSync } from 'fs';
3-
import { getAllDirs } from './utils/utils.mjs';
3+
import { getAllDirs } from './utils/utils';
44
import { node } from 'utils';
55

66
const STATIC_DATA_FOLDER = './static_data';
77
const RAW_DATA_FILE_NAME = 'raw_data.json';
88
const DIST_DATA_FILE_NAME = 'data.json';
99

10-
function uglifyFileContent(content) {
10+
function uglifyFileContent(content: string) {
1111
const uglifiedContent = content.replace(/("[^"]*")|\s/g, (match, group1) => {
1212
if (group1) {
1313
return group1;
@@ -18,19 +18,19 @@ function uglifyFileContent(content) {
1818
return uglifiedContent;
1919
}
2020

21-
function processFile(inputFilePath, outputFilePath) {
21+
function processFile(inputFilePath: string, outputFilePath: string) {
2222
try {
2323
const content = readFileSync(inputFilePath, 'utf-8');
2424
const uglifiedContent = uglifyFileContent(content);
2525

2626
writeFileSync(outputFilePath, uglifiedContent, 'utf-8');
2727
console.log(`Data of ${inputFilePath} file prepared`);
28-
} catch (error) {
28+
} catch (error: any) {
2929
console.error('Error:', error.message);
3030
}
3131
}
3232

33-
function prepareProjects(projectsFolders) {
33+
function prepareProjects(projectsFolders: string[]) {
3434
projectsFolders.forEach(projectFolder => {
3535
const distFolder = join(projectFolder, 'dist');
3636

build_scripts/utils/utils.mjs renamed to build_scripts/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readdirSync } from 'fs';
22
import { join } from 'path';
33
import { node } from 'utils';
44

5-
export function getAllDirs(path) {
5+
export function getAllDirs(path: string) {
66
const files = readdirSync(path);
77

88
return files.map(fileName => {

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
"name": "test",
33
"version": "0.1.0",
44
"private": false,
5-
"scripts": {},
5+
"scripts": {
6+
"build": "ts-node ./build_scripts/prepare_data.ts"
7+
},
68
"browserslist": {
79
"production": [
810
">0.2%",
@@ -17,5 +19,10 @@
1719
},
1820
"dependencies": {
1921
"utils": "github:alexanderPolosatov/utils"
22+
},
23+
"devDependencies": {
24+
"ts-node": "^10.9.2",
25+
"@types/node": "^20.14.9",
26+
"typescript": "5.6.3"
2027
}
21-
}
28+
}

tsconfig.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
// This is an alias to @tsconfig/node16: https://github.com/tsconfig/bases
3+
"extends": "ts-node/node16/tsconfig.json",
4+
// Most ts-node options can be specified here using their programmatic names.
5+
"ts-node": {
6+
// It is faster to skip typechecking.
7+
// Remove if you want ts-node to do typechecking.
8+
// "transpileOnly": true,
9+
"files": true,
10+
"compilerOptions": {
11+
// "rootDir": "./build_scripts",
12+
// compilerOptions specified here will override those declared below,
13+
// but *only* in ts-node. Useful if you want ts-node and tsc to use
14+
// different options with a single tsconfig.json.
15+
}
16+
},
17+
"compilerOptions": {
18+
"target": "es2020",
19+
"module": "commonjs",
20+
"strict": true,
21+
"esModuleInterop": true,
22+
"skipLibCheck": true,
23+
"allowJs": true,
24+
"forceConsistentCasingInFileNames": true,
25+
"outDir": "./dist",
26+
"sourceMap": true,
27+
"noImplicitAny": true
28+
}
29+
}

0 commit comments

Comments
 (0)