Compare commits
4 Commits
25b0831ddd
...
2ce35a396e
| Author | SHA1 | Date |
|---|---|---|
|
|
2ce35a396e | |
|
|
983154f250 | |
|
|
3182cf330f | |
|
|
e74c771e57 |
|
|
@ -94,25 +94,35 @@ class TemplateLoader {
|
|||
}
|
||||
|
||||
final configContent = packageConfigFile.readAsStringSync();
|
||||
final config = jsonDecode(configContent) as Map<String, dynamic>;
|
||||
final packages = config['packages'] as List<dynamic>;
|
||||
|
||||
// 简单的正则匹配提取 swagger_generator_flutter 的 rootUri
|
||||
// 格式示例: "name": "swagger_generator_flutter", ... "rootUri": "file:///path/to/package"
|
||||
final pattern = RegExp(
|
||||
r'"name"\s*:\s*"swagger_generator_flutter"[^}]*"rootUri"\s*:\s*"([^"]+)"',
|
||||
multiLine: true,
|
||||
final package = packages.firstWhere(
|
||||
(p) => p['name'] == 'swagger_generator_flutter',
|
||||
orElse: () => null,
|
||||
);
|
||||
|
||||
final match = pattern.firstMatch(configContent);
|
||||
if (match != null) {
|
||||
var rootUri = match.group(1)!;
|
||||
if (package != null) {
|
||||
final rootUri = package['rootUri'] as String;
|
||||
String packagePath;
|
||||
|
||||
// 移除 file:// 前缀
|
||||
// 处理 file:// 协议
|
||||
if (rootUri.startsWith('file://')) {
|
||||
rootUri = rootUri.substring(7);
|
||||
packagePath = Uri.parse(rootUri).toFilePath();
|
||||
} else {
|
||||
// 处理相对路径 (相对于 .dart_tool/)
|
||||
// package_config.json 中的相对路径通常是 ../
|
||||
packagePath = rootUri;
|
||||
}
|
||||
|
||||
// 如果不是绝对路径,需要相对于 .dart_tool/package_config.json 所在目录解析
|
||||
if (!p.isAbsolute(packagePath)) {
|
||||
// package_config.json 在 .dart_tool 目录下
|
||||
packagePath = p.normalize(p.join('.dart_tool', packagePath));
|
||||
}
|
||||
|
||||
// 添加模板目录路径
|
||||
final templateDir = p.join(rootUri, 'lib', 'templates');
|
||||
final templateDir = p.join(packagePath, 'lib', 'templates');
|
||||
if (Directory(templateDir).existsSync()) {
|
||||
dirs.add(templateDir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:mustache_template/mustache_template.dart';
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
name: swagger_generator_flutter
|
||||
description: A powerful Swagger/OpenAPI code generator for Flutter projects with Dio + Retrofit support
|
||||
|
||||
version: 3.1.0
|
||||
version: 3.1.4
|
||||
|
||||
environment:
|
||||
sdk: '>=3.0.0 <4.0.0'
|
||||
|
|
|
|||
Loading…
Reference in New Issue