Skip to content

Commit

Permalink
add windows publish script
Browse files Browse the repository at this point in the history
  • Loading branch information
boyan01 committed Sep 13, 2020
1 parent 9dab9ed commit 518b54f
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 128 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.5.0

* add windows publish script.

## 0.4.1

* fix windows symbol link do not work.
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.4.1"
version: "0.5.0"
term_glyph:
dependency: transitive
description:
Expand Down
36 changes: 36 additions & 0 deletions publish.ps1
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion publish.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
cd tools
pub get
pub run ./publish.dart
pub run ./bin/publish.dart
12 changes: 6 additions & 6 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand Down
40 changes: 0 additions & 40 deletions system_clock.iml

This file was deleted.

76 changes: 76 additions & 0 deletions tools/bin/publish.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import 'dart:convert';
import 'dart:io';

import 'package:path/path.dart' as path;

main(List<String> 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<void> _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<String> get outputLines {
if (exitCode != 0) {
throw "Can't get stdout. exitCode = $exitCode";
}
final out = this.stdout.toString().trim();
return LineSplitter.split(out).toList();
}
}

Future<void> _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);
}
}
80 changes: 0 additions & 80 deletions tools/publish.dart

This file was deleted.

0 comments on commit 518b54f

Please sign in to comment.