Skip to content

Commit e499422

Browse files
committed
refactor: 改用 TypeScript
1 parent 2d7c1f9 commit e499422

16 files changed

+109
-210
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,5 @@ test/fixtures/*/project
6666
lib/app-plugin
6767
*.d.ts
6868
.lcui
69-
build
69+
build
70+
lib

lib/compiler/xml-loader.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/compiler/yaml-loader.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

lib/types.d.ts

Lines changed: 0 additions & 105 deletions
This file was deleted.

lib/types.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"react": "^18.2.0",
3636
"react-dom": "^18.2.0",
3737
"sass": "^1.64.2",
38-
"simple-git": "^3.3.0",
38+
"simple-git": "^3.25.0",
3939
"typescript": "^5.4.5",
4040
"winston": "^3.10.0",
4141
"xml-js": "^1.6.11",

lib/compiler/file-loader.js renamed to src/compiler/file-loader.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { createHash } from "crypto";
22
import path from "path";
3+
import { LoaderContext, ModuleMetadata } from "../types.js";
34

45
/**
5-
* @param {LoaderContext} loaderContext
6-
* @param {string} name
7-
* @returns {string}
86
* @see https://github.com/webpack/loader-utils/blob/master/lib/interpolateName.js
97
*/
10-
function interpolateName(loaderContext, name, content) {
8+
function interpolateName(
9+
loaderContext: LoaderContext,
10+
name: string | ((p: string) => string),
11+
content: string
12+
) {
1113
let filename;
1214

1315
if (typeof name === "function") {
@@ -66,17 +68,13 @@ function interpolateName(loaderContext, name, content) {
6668
.replace(/\[folder\]/gi, () => folder);
6769
}
6870

69-
/**
70-
*
71-
* @param {*} resourcePath
72-
* @param {*} outputPath
73-
*/
74-
function generateMetadata(resourcePath, outputPath) {
75-
/** @type {ModuleMetadata} */
76-
const metadata = {
71+
function generateMetadata(resourcePath: string, outputPath: string) {
72+
const metadata: ModuleMetadata = {
7773
type: "asset",
7874
path: resourcePath,
7975
outputPath: outputPath,
76+
headerFiles: [],
77+
initCode: "",
8078
};
8179

8280
if (/\.(ttf|woff|woff2)$/i.test(resourcePath)) {

lib/compiler/index.js renamed to src/compiler/index.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import XMLLoader from "./xml-loader.js";
1111
import YAMLLoader from "./yaml-loader.js";
1212
import JSONLoader from "./json-loader.js";
1313
import { resolveRootDir } from "../utils.js";
14+
import { CompilerOptions, Loader, LoaderOptions, LoaderRule, ModuleRuleUseConfig } from "../types.js";
1415

1516
/** @type {Record<string, Loader>} */
1617
const loaderMap = {
@@ -43,12 +44,8 @@ function getDirs() {
4344
};
4445
}
4546

46-
/**
47-
* 确定加载器配置
48-
* @param {ModuleRuleUseConfig} config
49-
*/
50-
function resolveLoaders(config) {
51-
let loaders;
47+
function resolveLoaders(config: ModuleRuleUseConfig) {
48+
let loaders: (LoaderRule | string)[];
5249

5350
if (typeof config === "string") {
5451
loaders = [{ loader: config, options: {} }];
@@ -58,8 +55,8 @@ function resolveLoaders(config) {
5855
loaders = [config];
5956
}
6057
return loaders.map((item) => {
61-
let loader;
62-
let options = {};
58+
let loader: Loader;
59+
let options: LoaderOptions = {};
6360

6461
if (typeof item === "string") {
6562
loader = loaderMap[item];
@@ -173,12 +170,10 @@ function createLogger(logFile, verbose) {
173170
});
174171
}
175172

176-
/**
177-
* @param {string} file 文件或目录路径
178-
* @param {CompilerOptions} compilerOptions 编译选项
179-
*/
180-
export default async function compile(file, compilerOptions) {
181-
/** @type {CompilerOptions} */
173+
export default async function compile(
174+
file: string,
175+
compilerOptions: CompilerOptions
176+
) {
182177
const options = {
183178
...getDirs(),
184179
...compilerOptions,
File renamed without changes.

lib/compiler/sass-loader.js renamed to src/compiler/sass-loader.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import path from 'path';
2-
import * as sass from 'sass';
3-
import fs from 'fs-extra';
1+
import path from "path";
2+
import * as sass from "sass";
3+
import fs from "fs-extra";
4+
import { LoaderContext } from "../types.js";
45

5-
/**
6-
* @type {Loader}
7-
*/
8-
export default function SassLoader(content) {
6+
export default function SassLoader(this: LoaderContext, content: string) {
97
const { dir, ext } = path.parse(this.resourcePath);
108
const result = sass.compileString(`${content}`, {
119
importer: {

0 commit comments

Comments
 (0)