Skip to content

Fix web demos logo local to remote host. #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix local-remote host to web demos logo.
  • Loading branch information
ilopX committed Apr 29, 2022
commit 4b6868f19de87ff235c63fc46ac408df29d20c4f
28 changes: 23 additions & 5 deletions bin/deploy_flutter_demos.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ void main() async {

await Future.wait([prepareRepository, buildProject]);

prepareIndexHtmlForRemoteHost();
copyFiles();
await pushToOrigin();
clear();
}

late final tmpDir = Directory.systemTemp.createTempSync();
late final projectDir = thisPath(r'..\');
late final webBuildDir = Directory(projectDir.uri.toFilePath() + r'build\web');
late final String originUrl;

Future<void> init() async {
print('Use temp: $tmpDir');
originUrl = await repositoryOriginUrl(projectDir);
Expand All @@ -45,6 +51,23 @@ Future<void> fetchUpstream() async {
await cmd('git fetch upstream', workingDirectory: tmpDir);
}

void prepareIndexHtmlForRemoteHost() {
print('Prepare "index.html" for remote host.');

final indexHtmlFile = File(projectDir.uri.toFilePath() + r'\index.html');
final indexContent = indexHtmlFile.readAsStringSync();
final fixedIndexContent = indexContent.replaceFirst(
r'<base href="/">',
r'<base href="/design-patterns-dart/">',
);

if (indexContent == fixedIndexContent) {
throw 'Base url not found. It should be <base href="/">';
}

indexHtmlFile.writeAsStringSync(fixedIndexContent);
}

void copyFiles() {
print('Copy files:');
copyDirectory(webBuildDir, tmpDir);
Expand All @@ -66,11 +89,6 @@ Future<void> pushToOrigin() async {
);
}

late final tmpDir = Directory.systemTemp.createTempSync();
late final projectDir = thisPath(r'..\');
late final webBuildDir = Directory(projectDir.uri.toFilePath() + r'build\web');
late final String originUrl;

void clear() {
print('Clear: $tmpDir');
tmpDir.deleteSync(recursive: true);
Expand Down
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
<base href="/design-patterns-dart/">
<base href="/">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
Expand Down