aircitytype 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/main.js +110 -0
  2. package/package.json +2 -2
package/main.js CHANGED
@@ -3,6 +3,7 @@ console.log("start install!");
3
3
 
4
4
  const fs = require("fs");
5
5
  const fse = require("fs-extra");
6
+ const path = require('path');
6
7
 
7
8
  const source = "./node_modules/aircitytype/aircity";
8
9
  const target = "./node_modules/@types/aircity";
@@ -29,3 +30,112 @@ fs.access(source, fs.constants.F_OK, (err) => {
29
30
  });
30
31
  }
31
32
  });
33
+
34
+
35
+ // 定义JSON文件路径
36
+ const tsconfigPath = path.join(process.cwd(), 'tsconfig.json');
37
+ const jsconfigPath = path.join(process.cwd(), 'jsconfig.json');
38
+
39
+ // 函数用于检查文件是否存在并解析存在的那个文件
40
+ function checkAndParseConfigFiles(callback) {
41
+ const filesToCheck = [
42
+ { path: tsconfigPath, name: 'tsconfig.json' },
43
+ { path: jsconfigPath, name: 'jsconfig.json' }
44
+ ];
45
+
46
+ function checkNextFile(index) {
47
+ if (index >= filesToCheck.length) {
48
+ console.log('没有找到 tsconfig.json 或 jsconfig.json 文件');
49
+ return;
50
+ }
51
+
52
+ const { path, name } = filesToCheck[index];
53
+ fs.access(path, fs.constants.F_OK, (err) => {
54
+ if (!err) {
55
+ console.log(`${path} 文件存在,正在解析...`);
56
+ parseJsonFile(path, callback);
57
+ } else {
58
+ console.log(`${path} 文件不存在,检查下一个配置文件...`);
59
+ checkNextFile(index + 1); // 继续检查下一个文件
60
+ }
61
+ });
62
+ }
63
+
64
+ // 从第一个文件开始检查
65
+ checkNextFile(0);
66
+ }
67
+
68
+ // 解析并处理 JSON 文件
69
+ function parseJsonFile(filePath, callback) {
70
+ fs.readFile(filePath, 'utf8', (err, data) => {
71
+ if (err) {
72
+ console.error(`读取 ${filePath} 文件时出错:`, err);
73
+ return;
74
+ }
75
+
76
+ console.log(data)
77
+
78
+ let jsonData;
79
+ try {
80
+ jsonData = JSON.parse(data);
81
+ } catch (parseErr) {
82
+ console.error(`解析 ${filePath} 文件时出错:`, parseErr);
83
+ return;
84
+ }
85
+
86
+ console.log(`解析的配置文件内容:`, jsonData);
87
+
88
+ // 检查和修改配置
89
+ modifyCompilerOptions(jsonData);
90
+
91
+ // 将修改后的 JSON 对象转换为字符串并写回文件
92
+ const updatedJsonString = JSON.stringify(jsonData, null, 2);
93
+ fs.writeFile(filePath, updatedJsonString, 'utf8', (writeErr) => {
94
+ if (writeErr) {
95
+ console.error(`写入 ${filePath} 文件时出错:`, writeErr);
96
+ return;
97
+ }
98
+ console.log(`${filePath} 文件已成功更新`);
99
+
100
+ // 执行回调函数(如果有)
101
+ if (callback && typeof callback === 'function') {
102
+ callback(jsonData, filePath);
103
+ }
104
+ });
105
+
106
+ // 执行回调函数(如果有)
107
+ if (callback && typeof callback === 'function') {
108
+ callback(jsonData, filePath);
109
+ }
110
+ });
111
+ }
112
+
113
+ // 开始检查并解析配置文件
114
+ checkAndParseConfigFiles((jsonData, filePath) => {
115
+ // 在这里可以添加你想要执行的逻辑,例如根据解析的内容做某些事情
116
+ console.log(`完成解析 ${filePath}`);
117
+ });
118
+
119
+
120
+ // 修改 compilerOptions 中的 types 数组
121
+ function modifyCompilerOptions(jsonData) {
122
+ if (!jsonData.compilerOptions) {
123
+ jsonData.compilerOptions = {};
124
+ }
125
+
126
+ if (!jsonData.compilerOptions.types) {
127
+ jsonData.compilerOptions.types = [];
128
+ }
129
+
130
+ const typesArray = jsonData.compilerOptions.types;
131
+
132
+ // 如果 types 数组中没有 'aircity',则添加
133
+ if (!typesArray.includes('aircity')) {
134
+ typesArray.push('aircity');
135
+ console.log('已添加 "aircity" 到 types 数组');
136
+ } else {
137
+ console.log('"aircity" 已存在于 types 数组中');
138
+ }
139
+ }
140
+
141
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aircitytype",
3
- "description": "A description of your package.",
3
+ "description": "增加了types中aircity的检测",
4
4
  "scripts": {
5
5
  "test": "echo \"Error: no test specified\" && exit 1"
6
6
  },
@@ -14,5 +14,5 @@
14
14
  "bin": {
15
15
  "installdts": "./main.js"
16
16
  },
17
- "version": "1.1.3"
17
+ "version": "1.1.4"
18
18
  }