XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

fixup: remove fix-imports

6771a129
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

3 个文件 +1 -78
Modified .github/workflows/build.yml +0 -1
@@ -19,7 +19,6 @@ jobs:
19 19 - run: npm run lint:ci
20 20 - run: npm run prettier
21 21 - run: npm run update-translations
22 - run: npm run fix-imports
23 22 - name: Fail if there are uncommitted changes
24 23 run: |
25 24 if [[ -n "$(git status --porcelain)" ]]; then
Modified package.json +1 -2
@@ -22,8 +22,7 @@
22 22 "lint:fix": "eslint --fix --ext .ts .",
23 23 "prettier": "prettier --write .",
24 24 "update-translations": "cd scripts && node update-translations.cjs",
25 "fix-imports": "cd scripts && node fix-imports.cjs",
26 "fix": "npm run update-translations && npm run fix-imports && npm run lint:fix"
25 "fix": "npm run update-translations && npm run lint:fix"
27 26 },
28 27 "license": "GNU",
29 28 "type": "module",
Deleted scripts/fix-imports.cjs +0 -75
@@ -1,75 +0,0 @@
1 /* eslint-disable */
2 const fs = require("fs");
3 const path = require("path");
4
5 const root = path.join(process.cwd(), "..");
6
7 function listFiles(dir) {
8 const entries = fs.readdirSync(dir, { withFileTypes: true });
9 let results = [];
10 for (const entry of entries) {
11 const fullPath = path.join(dir, entry.name);
12 if (entry.isDirectory()) {
13 results = results.concat(listFiles(fullPath));
14 } else {
15 results.push(fullPath);
16 }
17 }
18 return results;
19 }
20
21 const files = listFiles(path.join(root, "src"));
22
23 for (const file of files) {
24 let content;
25 try {
26 content = fs.readFileSync(file, "utf8");
27 } catch (e) {
28 continue;
29 }
30 const dir = path.dirname(file);
31 const fixedContent = content.replaceAll(/from "([^"]+)";/g, (sub, importPath) => {
32 if (importPath.startsWith("@/") || importPath.startsWith(".")) {
33 const base = importPath.startsWith("@/")
34 ? path.join(root, importPath.slice(2))
35 : path.resolve(dir, importPath);
36 let target = base;
37
38 if (fs.existsSync(target)) {
39 const stat = fs.statSync(target);
40 if (stat.isDirectory()) {
41 if (fs.existsSync(path.join(target, "index.ts"))) {
42 target = path.join(target, "index.ts");
43 } else {
44 return sub;
45 }
46 } else {
47 const ext = path.extname(target);
48 if (!ext) {
49 target += ".ts";
50 }
51 }
52 } else if (fs.existsSync(target + ".ts")) {
53 target += ".ts";
54 } else if (fs.existsSync(path.join(target, "index.ts"))) {
55 target = path.join(target, "index.ts");
56 } else {
57 return sub;
58 }
59
60 let relative = path.relative(dir, target).replace(/\\/g, "/");
61 if (!path.extname(relative)) {
62 relative += ".ts";
63 }
64 if (!relative.startsWith(".")) {
65 relative = "./" + relative;
66 }
67 console.log(`${importPath} -> ${relative}`);
68 return sub.split(importPath).join(relative);
69 }
70 return sub;
71 });
72 if (content != fixedContent) {
73 fs.writeFileSync(file, fixedContent, "utf8");
74 }
75 }