[flutter_tools] generates version.json for web using flutter tool (#64644)
Generates version.json in web directory of project. version.json can be used in the future version of package_info which will support web. version.json has the following keys : app_name, version and build_number. This file is generated every time a user runs or builds the project. Co-authored-by: Jonah Williams <jonahwilliams@google.com>
This commit is contained in:
committed by
GitHub
parent
e3c6979d1b
commit
3dde3e034c
@@ -30,6 +30,7 @@ import '../convert.dart';
|
||||
import '../dart/package_map.dart';
|
||||
import '../devfs.dart';
|
||||
import '../globals.dart' as globals;
|
||||
import '../project.dart';
|
||||
import '../web/bootstrap.dart';
|
||||
import '../web/chrome.dart';
|
||||
|
||||
@@ -788,6 +789,7 @@ class WebDevFS implements DevFS {
|
||||
webAssetServer.writeBytes('stack_trace_mapper.js', stackTraceMapper.readAsBytesSync());
|
||||
webAssetServer.writeFile('manifest.json', '{"info":"manifest not generated in run mode."}');
|
||||
webAssetServer.writeFile('flutter_service_worker.js', '// Service worker not loaded in run mode.');
|
||||
webAssetServer.writeFile('version.json', FlutterProject.current().getVersionInfo());
|
||||
webAssetServer.writeFile(
|
||||
'main.dart.js',
|
||||
generateBootstrapScript(
|
||||
|
||||
@@ -14,6 +14,7 @@ import '../../base/io.dart';
|
||||
import '../../build_info.dart';
|
||||
import '../../dart/package_map.dart';
|
||||
import '../../globals.dart' as globals;
|
||||
import '../../project.dart';
|
||||
import '../build_system.dart';
|
||||
import '../depfile.dart';
|
||||
import 'assets.dart';
|
||||
@@ -295,6 +296,11 @@ class WebReleaseBundle extends Target {
|
||||
environment.outputDir.childFile(globals.fs.path.basename(outputFile.path)).path
|
||||
);
|
||||
}
|
||||
|
||||
final String versionInfo = FlutterProject.current().getVersionInfo();
|
||||
environment.outputDir
|
||||
.childFile('version.json')
|
||||
.writeAsStringSync(versionInfo);
|
||||
final Directory outputDirectory = environment.outputDir.childDirectory('assets');
|
||||
outputDirectory.createSync(recursive: true);
|
||||
final Depfile depfile = await copyAssets(
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:meta/meta.dart';
|
||||
import 'package:xml/xml.dart';
|
||||
import 'package:yaml/yaml.dart';
|
||||
|
||||
import '../src/convert.dart';
|
||||
import 'android/gradle_utils.dart' as gradle;
|
||||
import 'artifacts.dart';
|
||||
import 'base/common.dart';
|
||||
@@ -263,6 +264,16 @@ class FlutterProject {
|
||||
}
|
||||
await injectPlugins(this, checkProjects: checkProjects);
|
||||
}
|
||||
|
||||
/// Returns a json encoded string containing the [appName], [version], and [buildNumber] that is used to generate version.json
|
||||
String getVersionInfo() {
|
||||
final Map<String, String> versionFileJson = <String, String>{
|
||||
'app_name': manifest.appName,
|
||||
'version': manifest.buildName,
|
||||
'build_number': manifest.buildNumber
|
||||
};
|
||||
return jsonEncode(versionFileJson);
|
||||
}
|
||||
}
|
||||
|
||||
/// Base class for projects per platform.
|
||||
|
||||
Reference in New Issue
Block a user