Unverified Commit bd413bff authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Add flutter create for the web (#34018)

parent ef5fc1ae
...@@ -143,6 +143,14 @@ class CreateCommand extends FlutterCommand { ...@@ -143,6 +143,14 @@ class CreateCommand extends FlutterCommand {
defaultsTo: false, defaultsTo: false,
help: 'Generate a project using the AndroidX support libraries', help: 'Generate a project using the AndroidX support libraries',
); );
argParser.addFlag(
'web',
negatable: true,
defaultsTo: false,
hide: true,
help: '(Experimental) Generate the web specific tooling. Only supported '
'on non-stable branches',
);
} }
@override @override
...@@ -367,6 +375,7 @@ class CreateCommand extends FlutterCommand { ...@@ -367,6 +375,7 @@ class CreateCommand extends FlutterCommand {
androidX: argResults['androidx'], androidX: argResults['androidx'],
androidLanguage: argResults['android-language'], androidLanguage: argResults['android-language'],
iosLanguage: argResults['ios-language'], iosLanguage: argResults['ios-language'],
web: argResults['web'],
); );
final String relativeDirPath = fs.path.relative(projectDirPath); final String relativeDirPath = fs.path.relative(projectDirPath);
...@@ -576,6 +585,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi ...@@ -576,6 +585,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
String flutterRoot, String flutterRoot,
bool renderDriverTest = false, bool renderDriverTest = false,
bool withPluginHook = false, bool withPluginHook = false,
bool web = false,
}) { }) {
flutterRoot = fs.path.normalize(flutterRoot); flutterRoot = fs.path.normalize(flutterRoot);
...@@ -603,6 +613,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi ...@@ -603,6 +613,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
'iosLanguage': iosLanguage, 'iosLanguage': iosLanguage,
'flutterRevision': FlutterVersion.instance.frameworkRevision, 'flutterRevision': FlutterVersion.instance.frameworkRevision,
'flutterChannel': FlutterVersion.instance.channel, 'flutterChannel': FlutterVersion.instance.channel,
'web': web && !FlutterVersion.instance.isStable,
}; };
} }
......
...@@ -586,23 +586,7 @@ class WebProject { ...@@ -586,23 +586,7 @@ class WebProject {
/// The html file used to host the flutter web application. /// The html file used to host the flutter web application.
File get indexFile => parent.directory.childDirectory('web').childFile('index.html'); File get indexFile => parent.directory.childDirectory('web').childFile('index.html');
Future<void> ensureReadyForPlatformSpecificTooling() async { Future<void> ensureReadyForPlatformSpecificTooling() async {}
/// Generate index.html in build/web. Eventually we could support
/// a custom html under the web sub directory.
final Directory outputDir = fs.directory(getWebBuildDirectory());
if (!outputDir.existsSync()) {
outputDir.createSync(recursive: true);
}
final Template template = Template.fromName('web/index.html.tmpl');
template.render(
outputDir,
<String, dynamic>{
'appName': parent.manifest.appName,
},
printStatusWhenWriting: false,
overwriteExisting: true,
);
}
} }
/// Deletes [directory] with all content. /// Deletes [directory] with all content.
......
...@@ -85,6 +85,11 @@ class Template { ...@@ -85,6 +85,11 @@ class Template {
return null; return null;
relativeDestinationPath = relativeDestinationPath.replaceAll('$platform-$language.tmpl', platform); relativeDestinationPath = relativeDestinationPath.replaceAll('$platform-$language.tmpl', platform);
} }
// Only build a web project if explicitly asked.
final bool web = context['web'];
if (relativeDestinationPath.contains('web') && !web) {
return null;
}
final String projectName = context['projectName']; final String projectName = context['projectName'];
final String androidIdentifier = context['androidIdentifier']; final String androidIdentifier = context['androidIdentifier'];
final String pluginClass = context['pluginClass']; final String pluginClass = context['pluginClass'];
......
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{appName}}</title> <title>{{projectName}}</title>
<script defer src="main.dart.js" type="application/javascript"></script>
</head> </head>
<body> <body>
<script src="main.dart.js" type="application/javascript"></script>
</body> </body>
</html> </html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment