Merge branch 'release/3.1.4'
This commit is contained in:
commit
2ce35a396e
|
|
@ -94,25 +94,35 @@ class TemplateLoader {
|
||||||
}
|
}
|
||||||
|
|
||||||
final configContent = packageConfigFile.readAsStringSync();
|
final configContent = packageConfigFile.readAsStringSync();
|
||||||
|
final config = jsonDecode(configContent) as Map<String, dynamic>;
|
||||||
|
final packages = config['packages'] as List<dynamic>;
|
||||||
|
|
||||||
// 简单的正则匹配提取 swagger_generator_flutter 的 rootUri
|
final package = packages.firstWhere(
|
||||||
// 格式示例: "name": "swagger_generator_flutter", ... "rootUri": "file:///path/to/package"
|
(p) => p['name'] == 'swagger_generator_flutter',
|
||||||
final pattern = RegExp(
|
orElse: () => null,
|
||||||
r'"name"\s*:\s*"swagger_generator_flutter"[^}]*"rootUri"\s*:\s*"([^"]+)"',
|
|
||||||
multiLine: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final match = pattern.firstMatch(configContent);
|
if (package != null) {
|
||||||
if (match != null) {
|
final rootUri = package['rootUri'] as String;
|
||||||
var rootUri = match.group(1)!;
|
String packagePath;
|
||||||
|
|
||||||
// 移除 file:// 前缀
|
// 处理 file:// 协议
|
||||||
if (rootUri.startsWith('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()) {
|
if (Directory(templateDir).existsSync()) {
|
||||||
dirs.add(templateDir);
|
dirs.add(templateDir);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:mustache_template/mustache_template.dart';
|
import 'package:mustache_template/mustache_template.dart';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
name: swagger_generator_flutter
|
name: swagger_generator_flutter
|
||||||
description: A powerful Swagger/OpenAPI code generator for Flutter projects with Dio + Retrofit support
|
description: A powerful Swagger/OpenAPI code generator for Flutter projects with Dio + Retrofit support
|
||||||
|
|
||||||
version: 3.1.0
|
version: 3.1.4
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=3.0.0 <4.0.0'
|
sdk: '>=3.0.0 <4.0.0'
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue