Skip to content

Commit 4ed0a79

Browse files
committed
chore: enhance toolchain (jest, babel, prettier)
1 parent ace0c8a commit 4ed0a79

15 files changed

+384
-145
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist
22
node_modules
3-
yarn.lock
3+
yarn.lock
4+
yarn-error.log

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"trailingComma": "es5",
3+
"tabWidth": 4,
4+
"semi": true,
5+
"singleQuote": false
6+
}

babel.config.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript",
5+
],
6+
plugins: [
7+
["@babel/plugin-proposal-decorators", { legacy: true }],
8+
["@babel/plugin-proposal-class-properties", { loose: true }],
9+
],
10+
};

jest.config.ts

+194
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
export default {
7+
// All imported modules in your tests should be mocked automatically
8+
// automock: false,
9+
10+
// Stop running tests after `n` failures
11+
// bail: 0,
12+
13+
// The directory where Jest should store its cached dependency information
14+
// cacheDirectory: "C:\\Users\\ProjectAlpha\\AppData\\Local\\Temp\\jest",
15+
16+
// Automatically clear mock calls and instances between every test
17+
clearMocks: true,
18+
19+
// Indicates whether the coverage information should be collected while executing the test
20+
// collectCoverage: false,
21+
22+
// An array of glob patterns indicating a set of files for which coverage information should be collected
23+
// collectCoverageFrom: undefined,
24+
25+
// The directory where Jest should output its coverage files
26+
coverageDirectory: "coverage",
27+
28+
// An array of regexp pattern strings used to skip coverage collection
29+
// coveragePathIgnorePatterns: [
30+
// "\\\\node_modules\\\\"
31+
// ],
32+
33+
// Indicates which provider should be used to instrument code for coverage
34+
coverageProvider: "v8",
35+
36+
// A list of reporter names that Jest uses when writing coverage reports
37+
// coverageReporters: [
38+
// "json",
39+
// "text",
40+
// "lcov",
41+
// "clover"
42+
// ],
43+
44+
// An object that configures minimum threshold enforcement for coverage results
45+
// coverageThreshold: undefined,
46+
47+
// A path to a custom dependency extractor
48+
// dependencyExtractor: undefined,
49+
50+
// Make calling deprecated APIs throw helpful error messages
51+
// errorOnDeprecated: false,
52+
53+
// Force coverage collection from ignored files using an array of glob patterns
54+
// forceCoverageMatch: [],
55+
56+
// A path to a module which exports an async function that is triggered once before all test suites
57+
// globalSetup: undefined,
58+
59+
// A path to a module which exports an async function that is triggered once after all test suites
60+
// globalTeardown: undefined,
61+
62+
// A set of global variables that need to be available in all test environments
63+
// globals: {},
64+
65+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66+
// maxWorkers: "50%",
67+
68+
// An array of directory names to be searched recursively up from the requiring module's location
69+
// moduleDirectories: [
70+
// "node_modules"
71+
// ],
72+
73+
// An array of file extensions your modules use
74+
// moduleFileExtensions: [
75+
// "js",
76+
// "json",
77+
// "jsx",
78+
// "ts",
79+
// "tsx",
80+
// "node"
81+
// ],
82+
83+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84+
// moduleNameMapper: {},
85+
86+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87+
// modulePathIgnorePatterns: [],
88+
89+
// Activates notifications for test results
90+
// notify: false,
91+
92+
// An enum that specifies notification mode. Requires { notify: true }
93+
// notifyMode: "failure-change",
94+
95+
// A preset that is used as a base for Jest's configuration
96+
// preset: undefined,
97+
98+
// Run tests from one or more projects
99+
// projects: undefined,
100+
101+
// Use this configuration option to add custom reporters to Jest
102+
// reporters: undefined,
103+
104+
// Automatically reset mock state between every test
105+
// resetMocks: false,
106+
107+
// Reset the module registry before running each individual test
108+
// resetModules: false,
109+
110+
// A path to a custom resolver
111+
// resolver: undefined,
112+
113+
// Automatically restore mock state between every test
114+
// restoreMocks: false,
115+
116+
// The root directory that Jest should scan for tests and modules within
117+
rootDir: "test",
118+
119+
// A list of paths to directories that Jest should use to search for files in
120+
// roots: [
121+
// "<rootDir>"
122+
// ],
123+
124+
// Allows you to use a custom runner instead of Jest's default test runner
125+
// runner: "jest-runner",
126+
127+
// The paths to modules that run some code to configure or set up the testing environment before each test
128+
// setupFiles: [],
129+
130+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
131+
// setupFilesAfterEnv: [],
132+
133+
// The number of seconds after which a test is considered as slow and reported as such in the results.
134+
// slowTestThreshold: 5,
135+
136+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
137+
// snapshotSerializers: [],
138+
139+
// The test environment that will be used for testing
140+
testEnvironment: "node",
141+
142+
// Options that will be passed to the testEnvironment
143+
// testEnvironmentOptions: {},
144+
145+
// Adds a location field to test results
146+
// testLocationInResults: false,
147+
148+
// The glob patterns Jest uses to detect test files
149+
// testMatch: [
150+
// "**/__tests__/**/*.[jt]s?(x)",
151+
// "**/?(*.)+(spec|test).[tj]s?(x)"
152+
// ],
153+
154+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
155+
// testPathIgnorePatterns: [
156+
// "\\\\node_modules\\\\"
157+
// ],
158+
159+
// The regexp pattern or array of patterns that Jest uses to detect test files
160+
// testRegex: [],
161+
162+
// This option allows the use of a custom results processor
163+
// testResultsProcessor: undefined,
164+
165+
// This option allows use of a custom test runner
166+
// testRunner: "jasmine2",
167+
168+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169+
// testURL: "http://localhost",
170+
171+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172+
// timers: "real",
173+
174+
// A map from regular expressions to paths to transformers
175+
// transform: undefined,
176+
177+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178+
// transformIgnorePatterns: [
179+
// "\\\\node_modules\\\\",
180+
// "\\.pnp\\.[^\\\\]+$"
181+
// ],
182+
183+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184+
// unmockedModulePathPatterns: undefined,
185+
186+
// Indicates whether each individual test should be reported during the run
187+
// verbose: undefined,
188+
189+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190+
// watchPathIgnorePatterns: [],
191+
192+
// Whether to use watchman for file crawling
193+
// watchman: true,
194+
};

package.json

+24-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,35 @@
88
"author": "moruiyi",
99
"license": "GPL-3.0-or-later",
1010
"devDependencies": {
11+
"@babel/core": "^7.12.17",
12+
"@babel/plugin-proposal-decorators": "^7.12.13",
13+
"@babel/preset-env": "^7.12.17",
14+
"@babel/preset-typescript": "^7.12.17",
15+
"@types/jest": "^26.0.20",
16+
"babel-jest": "^26.6.3",
17+
"husky": "=4",
18+
"jest": "^26.6.3",
19+
"lint-staged": "^10.5.4",
20+
"prettier": "^2.2.1",
1121
"rollup": "^2.39.0",
1222
"rollup-plugin-typescript2": "^0.30.0",
23+
"ts-node": "^9.1.1",
1324
"tslib": "^2.1.0",
1425
"typescript": "^4.1.5"
1526
},
1627
"scripts": {
17-
"build": "yarn run rollup -c"
28+
"build": "yarn run rollup -c",
29+
"test": "jest"
30+
},
31+
"husky": {
32+
"hooks": {
33+
"pre-commit": "lint-staged"
34+
}
35+
},
36+
"lint-staged": {
37+
"*.{ts,js,css,md}": "prettier --write"
38+
},
39+
"dependencies": {
40+
"@babel/plugin-proposal-class-properties": "^7.12.13"
1841
}
1942
}

rollup.config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import typescript from 'rollup-plugin-typescript2'
1+
import typescript from "rollup-plugin-typescript2";
22

33
export default {
44
input: "src/index.ts",
55
output: {
66
file: "dist/netcode.js",
7-
format: "es"
7+
format: "es",
88
},
9-
plugins: [typescript()]
10-
}
9+
plugins: [typescript()],
10+
};

src/component.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
import { Macro } from "./macro";
22

3-
export let ComponentClassType: any[] = []
4-
export function Component<T extends { new(): any }>(target: T) {
3+
export let ComponentClassType: any[] = [];
4+
export function Component<T extends { new (): any }>(target: T) {
55
target.prototype.__classId__ = ComponentClassType.push(target) - 1;
66
}
77

88
export function Param(type: ParamType): PropertyDecorator {
9-
return function(target: any, propertyKey: string | symbol) {
10-
if (!target.__schema__)
11-
target.__schema__ = { count: 0, props: {} }
9+
return function (target: any, propertyKey: string | symbol) {
10+
if (!target.__schema__) target.__schema__ = { count: 0, props: {} };
1211
const s = target.__schema__;
1312

1413
const paramIndex = s.count++;
1514
const v = { propertyKey, type, paramIndex };
16-
s.props[paramIndex] = v
17-
s.props[propertyKey] = v
18-
}
15+
s.props[paramIndex] = v;
16+
s.props[propertyKey] = v;
17+
};
1918
}
2019

20+
// prettier-ignore
2121
export enum ParamType {
22-
i8, u8, i16, u16, i32, u32, i64, u64, int, long, float, double, string, bool, f32, f64
22+
i8, u8, i16, u16, i32, u32, i64, u64, f32, f64,
23+
int, long, float, double, string, bool,
2324
}
2425

2526
export interface IComponent {
26-
owner?:number;
27-
__schema__?: Record<string | number, string | number>
27+
owner?: number;
28+
__schema__?: Record<string | number, string | number>;
2829

2930
onLoad?(): void;
3031
onStart?(): void;
@@ -33,4 +34,4 @@ export interface IComponent {
3334
update?(): void;
3435
fixedUpdate?(): void;
3536
lateUpdate?(): void;
36-
}
37+
}

src/data/serializable.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ export interface Serializable<T extends String | ArrayBuffer> {
33
deser(buffer: DataBuffer<T>): void;
44
}
55

6-
export interface DataBuffer<T extends String | ArrayBuffer> {
7-
8-
}
6+
export interface DataBuffer<T extends String | ArrayBuffer> {}

0 commit comments

Comments
 (0)