From 518b54f683c87592a963ee1442db4c52fb6e0603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=AF=E8=A8=80?= Date: Sun, 13 Sep 2020 15:56:53 +0800 Subject: [PATCH] add windows publish script --- CHANGELOG.md | 4 +++ example/pubspec.lock | 2 +- publish.ps1 | 36 +++++++++++++++++++ publish.sh | 2 +- pubspec.yaml | 12 +++---- system_clock.iml | 40 --------------------- tools/bin/publish.dart | 76 +++++++++++++++++++++++++++++++++++++++ tools/publish.dart | 80 ------------------------------------------ 8 files changed, 124 insertions(+), 128 deletions(-) create mode 100644 publish.ps1 delete mode 100644 system_clock.iml create mode 100644 tools/bin/publish.dart delete mode 100644 tools/publish.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index ec365b9..c4516c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.0 + +* add windows publish script. + ## 0.4.1 * fix windows symbol link do not work. diff --git a/example/pubspec.lock b/example/pubspec.lock index b81ff47..e6cf68e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -127,7 +127,7 @@ packages: path: ".." relative: true source: path - version: "0.4.1" + version: "0.5.0" term_glyph: dependency: transitive description: diff --git a/publish.ps1 b/publish.ps1 new file mode 100644 index 0000000..c22f699 --- /dev/null +++ b/publish.ps1 @@ -0,0 +1,36 @@ +function Test-CommandExists { + param($command) + try { + if (Get-Command $command -errorAction SilentlyContinue) { + return $true + } + else { + return $false + } + } + catch { + return $false + } +} + +$exist = Test-CommandExists "flutter" +if (!$exist) { + Write-Error "flutter command do not exist." + exit -1 +} +# set-proxy for publish +if (Test-CommandExists "proxy") { + proxy +} + +$PUB_HOSTED_URL = $env:PUB_HOSTED_URL +$env:PUB_HOSTED_URL = "" +Push-Location tools +try { + flutter pub get + flutter pub run .\bin\publish.dart +} +finally { + Pop-Location + $env:PUB_HOSTED_URL = $PUB_HOSTED_URL +} \ No newline at end of file diff --git a/publish.sh b/publish.sh index c2cb383..c62f53b 100644 --- a/publish.sh +++ b/publish.sh @@ -1,4 +1,4 @@ #!/bin/bash cd tools pub get -pub run ./publish.dart \ No newline at end of file +pub run ./bin/publish.dart \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index dce1f44..a51413f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: system_clock description: Flutter timekeeping facilities. Powered by ffi -version: 0.4.1 +version: 0.5.0 author: yangbinyhhbn@gmail.com homepage: https://github.com/boyan01/system_clock @@ -19,11 +19,11 @@ dev_dependencies: flutter: plugin: platforms: - # This plugin project was generated without specifying any - # platforms with the `--platform` argument. If you see the `fake_platform` map below, remove it and - # then add platforms following the instruction here: - # https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms - # ------------------- + # This plugin project was generated without specifying any + # platforms with the `--platform` argument. If you see the `fake_platform` map below, remove it and + # then add platforms following the instruction here: + # https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms + # ------------------- android: package: tech.soit.flutter.system_clock pluginClass: SystemClockPlugin diff --git a/system_clock.iml b/system_clock.iml deleted file mode 100644 index a8749ae..0000000 --- a/system_clock.iml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/tools/bin/publish.dart b/tools/bin/publish.dart new file mode 100644 index 0000000..421160d --- /dev/null +++ b/tools/bin/publish.dart @@ -0,0 +1,76 @@ +import 'dart:convert'; +import 'dart:io'; + +import 'package:path/path.dart' as path; + +main(List args) async { + final temDir = Directory.systemTemp.createTempSync("system_clock"); + print("temDir = ${temDir.path}"); + if (temDir.existsSync()) { + temDir.deleteSync(recursive: true); + } + temDir.createSync(recursive: true); + final rootPath = Process.runSync("git", ["rev-parse", "--show-toplevel"]); + if (rootPath.exitCode != 0) { + throw "Not a git project?"; + } + await _copy(Directory(rootPath.stdout.toString().trim()), temDir); + await _publish(temDir); +} + +Future _copy(Directory from, Directory dest) async { + final files = Process.runSync( + "git", + ["ls-files", "--cached", "--others", "--exclude-standard"], + workingDirectory: from.path, + ).outputLines.map((e) => e.platformPath).toSet(); + + from.listSync(recursive: true, followLinks: false).forEach((var entity) { + final entityRelativePath = path.relative(entity.path, from: from.path).platformPath; + if (!files.contains(entityRelativePath)) { + return; + } + final dir = Directory(path.join(dest.path, path.dirname(entityRelativePath))); + if (!dir.existsSync()) { + dir.createSync(recursive: true); + } + if (entity is File) { + entity.copySync(path.join(dest.path, entityRelativePath)); + } else if (entity is Link) { + final newFilePath = path.normalize(path.join(dest.path, entityRelativePath)); + final target = File(path.normalize(path.absolute(path.dirname(entity.absolute.path), entity.targetSync()))); + target.copySync(newFilePath); + } + }); +} + +extension on String { + String get platformPath { + if (Platform.isWindows) { + return replaceAll("/", "\\"); + } else { + return replaceAll("\\", "/"); + } + } +} + +extension on ProcessResult { + List get outputLines { + if (exitCode != 0) { + throw "Can't get stdout. exitCode = $exitCode"; + } + final out = this.stdout.toString().trim(); + return LineSplitter.split(out).toList(); + } +} + +Future _publish(Directory dir) async { + final process = await Process.start("pwsh", ["-Command", "flutter", "pub", "publish"], workingDirectory: dir.path); + process.stdin.addStream(stdin); + stdout.addStream(process.stdout); + stderr.addStream(process.stderr); + final code = await process.exitCode; + if (code != 0) { + exit(code); + } +} diff --git a/tools/publish.dart b/tools/publish.dart deleted file mode 100644 index 7e5bf6f..0000000 --- a/tools/publish.dart +++ /dev/null @@ -1,80 +0,0 @@ -import 'dart:convert'; -import 'dart:io'; -import 'package:path/path.dart' as path; - -main(List args) async { - final temDir = Directory.systemTemp.createTempSync("system_clock"); - print("temDir = ${temDir.path}"); - if (temDir.existsSync()) { - temDir.deleteSync(recursive: true); - } - temDir.createSync(recursive: true); - final rootPath = Process.runSync("git", ["rev-parse", "--show-toplevel"]); - if (rootPath.exitCode != 0) { - throw "Not a git project?"; - } - await _copy(Directory(rootPath.stdout.toString().trim()), temDir); - await _replaceSymlinkWithRealFile(temDir); - await _publish(temDir); -} - -Future _copy(Directory from, Directory dest) async { - final paths = - from.listSync(recursive: true, followLinks: false).map((e) => path.relative(e.path, from: from.path)).toList(); - - final checkIgnoreResult = - Process.runSync("git", ["check-ignore", "--no-index", ...paths], workingDirectory: from.path); - - final gitIgnored = LineSplitter.split(checkIgnoreResult.stdout.toString().trim()).toList(); - - gitIgnored.addAll([".git", "tools"]); - bool isGitIgnored(String relativePath) { - if (gitIgnored.any((element) => relativePath.startsWith(element))) { - return true; - } - return false; - } - - void copyDirectory(Directory source, Directory destination) => - source.listSync(recursive: false, followLinks: false).forEach((var entity) { - if (isGitIgnored(path.relative(entity.path, from: from.path))) { - return; - } - if (entity is Directory) { - var newDirectory = Directory(path.join(destination.path, path.basename(entity.path))); - newDirectory.createSync(); - copyDirectory(entity, newDirectory); - } else if (entity is File) { - entity.copySync(path.join(destination.path, path.basename(entity.path))); - } else if (entity is Link) { - var newLink = Link(path.join(destination.path, path.basename(entity.path))); - newLink.createSync(entity.targetSync()); - } - }); - copyDirectory(from, dest); -} - -Future _replaceSymlinkWithRealFile(Directory dir) async { - final files = dir.listSync(recursive: true); - files.forEach((file) { - if (file is File) { - final path = file.resolveSymbolicLinksSync(); - if (path != file.path) { - file.deleteSync(); - File(path).copySync(file.path); - print("replaced " + file.path + " by $path"); - } - } - }); -} - -Future _publish(Directory dir) async { - final process = await Process.start("flutter", ["pub", "publish"], workingDirectory: dir.path); - process.stdin.addStream(stdin); - stdout.addStream(process.stdout); - stderr.addStream(process.stderr); - final code = await process.exitCode; - if (code != 0) { - exit(code); - } -}