@dazhicheng/openapi 1.1.10 → 1.1.12

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.
package/src/util.ts CHANGED
@@ -20,12 +20,13 @@ export const mkdir = (dir: string) => {
20
20
  }
21
21
  };
22
22
 
23
- export const prettierFile = async (content: string): Promise<[string, boolean]> => {
23
+ export const prettierFile = async (content: string, filePath?: string): Promise<[string, boolean]> => {
24
24
  let result = content;
25
25
  let hasError = false;
26
26
  try {
27
27
  const prettier = await import("prettier");
28
- const prettierOptions = await prettier.resolveConfig(process.cwd());
28
+ // resolveConfig 从"文件所在目录"往上找 .prettierrc;传 cwd(目录)会拿不到
29
+ const prettierOptions = await prettier.resolveConfig(filePath || process.cwd());
29
30
  result = await prettier.format(content, {
30
31
  parser: "typescript",
31
32
  ...prettierOptions,
@@ -41,7 +42,7 @@ export const prettierFile = async (content: string): Promise<[string, boolean]>
41
42
  export const writeFile = async (folderPath: string, fileName: string, content: string) => {
42
43
  const filePath = path.join(folderPath, fileName);
43
44
  mkdir(path.dirname(filePath));
44
- const [prettierContent, hasError] = await prettierFile(content);
45
+ const [prettierContent, hasError] = await prettierFile(content, filePath);
45
46
  fs.writeFileSync(filePath, prettierContent, {
46
47
  encoding: "utf8",
47
48
  });
@@ -1,54 +1,54 @@
1
- declare namespace {{ namespace }} {
2
- {% for type in list -%}
3
- {%- if type.props.length %}
4
- {%- if type.isEnum %}
5
- enum {{ type.typeName | safe }}
6
- {%- else %}
7
- {{ declareType }} {{ type.typeName | safe }} {{ equalSymbol }}
8
- {%- endif %}
9
- {%- for prop in type.props %}
10
- {%- if prop.length > 1 %}
11
- {
12
- {%- endif %}
13
- {%- if prop.length == 1 %}
14
- {%- if not prop[0].$ref or prop[0].name %}
15
- {
16
- {%- endif %}
17
- {%- endif %}
18
- {%- for p in prop %}
19
- {%- if p.desc %}
20
- /** {{ p.desc }} */
21
- {%- endif %}
22
- {%- if p["$ref"] and not p.name %}
23
- // {{ p.$ref }}
24
- {{ p.type | safe }}
25
- {%- else %}
26
- {%- if nullable %}
27
- '{{ p.name }}': {{ p.type | safe }}{{'' if p.required else '| null'}};
28
- {%- else %}
29
- '{{ p.name }}'{{ '' if p.required else '?' }}: {{ p.type | safe }};
30
- {%- endif %}
31
- {%- endif %}
32
- {%- endfor %}
33
- {%- if prop.length > 1 %}
34
- }
35
- {%- endif %}
36
- {%- if prop.length == 1 %}
37
- {%- if not prop[0].$ref or prop[0].name %}
38
- }
39
- {%- endif %}
40
- {%- endif %}
41
- {%- if prop.length == 0 %}
42
- {}
43
- {%- endif %}
44
- {{ '' if loop.last === true else ' & ' }}
45
- {%- endfor %}
46
- {%- else %}
47
- {%- if type.isEnum %}
48
- enum {{ type.typeName | safe }} {{ type.type }};
49
- {%- else %}
50
- type {{ type.typeName | safe }} = {{ type.type }};
51
- {%- endif %}
52
- {%- endif %}
53
- {% endfor %}
54
- }
1
+ declare namespace {{ namespace }} {
2
+ {% for type in list -%}
3
+ {%- if type.props.length %}
4
+ {%- if type.isEnum %}
5
+ enum {{ type.typeName | safe }}
6
+ {%- else %}
7
+ {{ declareType }} {{ type.typeName | safe }} {{ equalSymbol }}
8
+ {%- endif %}
9
+ {%- for prop in type.props %}
10
+ {%- if prop.length > 1 %}
11
+ {
12
+ {%- endif %}
13
+ {%- if prop.length == 1 %}
14
+ {%- if not prop[0].$ref or prop[0].name %}
15
+ {
16
+ {%- endif %}
17
+ {%- endif %}
18
+ {%- for p in prop %}
19
+ {%- if p.desc %}
20
+ /** {{ p.desc }} */
21
+ {%- endif %}
22
+ {%- if p["$ref"] and not p.name %}
23
+ // {{ p.$ref }}
24
+ {{ p.type | safe }}
25
+ {%- else %}
26
+ {%- if nullable %}
27
+ '{{ p.name }}': {{ p.type | safe }}{{'' if p.required else '| null'}};
28
+ {%- else %}
29
+ '{{ p.name }}'{{ '' if p.required else '?' }}: {{ p.type | safe }};
30
+ {%- endif %}
31
+ {%- endif %}
32
+ {%- endfor %}
33
+ {%- if prop.length > 1 %}
34
+ }
35
+ {%- endif %}
36
+ {%- if prop.length == 1 %}
37
+ {%- if not prop[0].$ref or prop[0].name %}
38
+ }
39
+ {%- endif %}
40
+ {%- endif %}
41
+ {%- if prop.length == 0 %}
42
+ {}
43
+ {%- endif %}
44
+ {{ '' if loop.last === true else ' & ' }}
45
+ {%- endfor %}
46
+ {%- else %}
47
+ {%- if type.isEnum %}
48
+ enum {{ type.typeName | safe }} {{ type.type }};
49
+ {%- else %}
50
+ type {{ type.typeName | safe }} = {{ type.type }};
51
+ {%- endif %}
52
+ {%- endif %}
53
+ {% endfor %}
54
+ }
@@ -1,14 +1,14 @@
1
- // @ts-ignore
2
- /* eslint-disable */
3
- // API 更新时间:{{ apiResourceModifyTime }}
4
- // API 唯一标识:{{ apiResourceId }}
5
- {% for api in list -%}
6
- import * as {{ api.controllerName }} from './{{ api.fileName }}'
7
- {% endfor -%}
8
-
9
-
10
- export default {
11
- {% for api in list -%}
12
- {{ api.controllerName }},
13
- {% endfor -%}
14
- }
1
+ // @ts-ignore
2
+ /* eslint-disable */
3
+ // API 更新时间:{{ apiResourceModifyTime }}
4
+ // API 唯一标识:{{ apiResourceId }}
5
+ {% for api in list -%}
6
+ import * as {{ api.controllerName }} from './{{ api.fileName }}'
7
+ {% endfor -%}
8
+
9
+
10
+ export default {
11
+ {% for api in list -%}
12
+ {{ api.controllerName }},
13
+ {% endfor -%}
14
+ }