Move health check to /health directory for NPM forward auth exclusion 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
52 lines
1.4 KiB
Dart
52 lines
1.4 KiB
Dart
#!/usr/bin/env dart
|
|
// Generates web/health/health.json from pubspec.yaml
|
|
// Run: dart run tool/generate_health_json.dart
|
|
|
|
// ignore_for_file: avoid_print
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:yaml/yaml.dart';
|
|
|
|
void main() {
|
|
final pubspecFile = File('pubspec.yaml');
|
|
if (!pubspecFile.existsSync()) {
|
|
stderr.writeln('Error: pubspec.yaml not found');
|
|
exit(1);
|
|
}
|
|
|
|
final pubspecContent = pubspecFile.readAsStringSync();
|
|
final pubspec = loadYaml(pubspecContent) as YamlMap;
|
|
|
|
final name = pubspec['name'] as String;
|
|
final description = pubspec['description'] as String? ?? '';
|
|
final versionString = pubspec['version'] as String;
|
|
|
|
// Parse version: "1.0.3+1" -> version="1.0.3", buildNumber=1
|
|
final versionParts = versionString.split('+');
|
|
final version = versionParts[0];
|
|
final buildNumber = versionParts.length > 1 ? int.parse(versionParts[1]) : 0;
|
|
|
|
final health = {
|
|
'status': 'healthy',
|
|
'name': name,
|
|
'title': description,
|
|
'version': version,
|
|
'buildNumber': buildNumber,
|
|
'fullVersion': '$version+$buildNumber',
|
|
};
|
|
|
|
final healthDir = Directory('web/health');
|
|
if (!healthDir.existsSync()) {
|
|
healthDir.createSync(recursive: true);
|
|
}
|
|
|
|
final healthFile = File('web/health/health.json');
|
|
healthFile.writeAsStringSync(
|
|
const JsonEncoder.withIndent(' ').convert(health),
|
|
);
|
|
|
|
print('Generated web/health/health.json with version $version+$buildNumber');
|
|
}
|