Skip to content

Commit

Permalink
add service locator and some logs changes
Browse files Browse the repository at this point in the history
  • Loading branch information
YehudaKremer committed Apr 7, 2022
1 parent 7ec0996 commit 13a4918
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 115 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 3.5.0

- added two new command `msix:build` and `msix:pack` for [unsupported features](https://github.com/YehudaKremer/msix#heavy_exclamation_mark-unsupported-features) ([#120](https://github.com/YehudaKremer/msix/issues/120))
- logs change: from single log `creating msix installer...` we have now two logs: `building msix files...` and `packing msix files...`

## 3.4.1

- fix [#119](https://github.com/YehudaKremer/msix/issues/119)
Expand Down
54 changes: 31 additions & 23 deletions lib/msix.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:cli_util/cli_logging.dart' show Logger, Ansi;
import 'package:get_it/get_it.dart';
import 'src/app_installer.dart';
import 'src/windows_build.dart';
import 'src/configuration.dart';
Expand All @@ -17,26 +18,29 @@ class Msix {
late Configuration _config;

Msix(List<String> arguments) {
_logger = arguments.contains('-v')
/// register singleton [Logger] service
GetIt.I.registerSingleton<Logger>(arguments.contains('-v')
? Logger.verbose()
: Logger.standard(ansi: Ansi(true));
_config = Configuration(arguments, _logger);
: Logger.standard(ansi: Ansi(true)));

/// register singleton [Configuration] service
GetIt.I.registerSingleton<Configuration>(Configuration(arguments));

_logger = GetIt.I<Logger>();
_config = GetIt.I<Configuration>();
}

static void registerWith() {}

/// Execute with the `msix:build` command
Future<void> build() async {
await _initConfig();

var loggerProgress = _logger.progress('building msix files');
await _buildMsixFiles();
loggerProgress.finish(showTiming: true);

final msixPath = _config.msixPath.contains('build/windows')
? _config.msixPath.substring(_config.msixPath.indexOf('build/windows'))
: _config.msixPath;
_logger.write('unpackaged msix files created in: ');
_logger.write('unpackaged msix files created in: '.green);
_logger.stdout(
File(msixPath).parent.path.blue.emphasized.replaceAll('/', r'\'));
}
Expand All @@ -53,12 +57,10 @@ class Msix {
exit(-1);
}

var loggerProgress = _logger.progress('packing msix files');
if (_config.signMsix && !_config.store) {
await SignTool(_config, _logger).getCertificatePublisher();
await SignTool().getCertificatePublisher();
}
await _packMsixFiles();
loggerProgress.finish(showTiming: true);

_printMsixOutputLocation();
}
Expand All @@ -74,7 +76,7 @@ class Msix {
Future<void> publish() async {
await _initConfig();
await _config.validateAppInstallerConfigValues();
var appInstaller = AppInstaller(_config, _logger);
var appInstaller = AppInstaller();
await appInstaller.validatePublishVersion();

await _createMsix();
Expand All @@ -85,7 +87,7 @@ class Msix {
await appInstaller.generateAppInstallerWebSite();
loggerProgress.finish(showTiming: true);

_logger.write('appinstaller created: '.green.emphasized);
_logger.write('appinstaller created: '.green);
_logger
.stdout(_config.appInstallerPath.blue.emphasized.replaceAll('/', r'\'));
}
Expand All @@ -96,44 +98,50 @@ class Msix {
}

Future<void> _createMsix() async {
var loggerProgress = _logger.progress('creating msix installer');
await _buildMsixFiles();
await _packMsixFiles();
loggerProgress.finish(showTiming: true);
}

Future<void> _buildMsixFiles() async {
if (_config.buildWindows) {
await WindowsBuild(_config, _logger).build();
await WindowsBuild().build();
}

var loggerProgress = _logger.progress('building msix files');

await _config.validateWindowsBuildFiles();
final assets = Assets(_config, _logger);
final assets = Assets();
await assets.cleanTemporaryFiles(clearMsixFiles: true);
await assets.createIcons();
await assets.copyVCLibsFiles();

if (_config.signMsix && !_config.store) {
await SignTool(_config, _logger).getCertificatePublisher();
await SignTool().getCertificatePublisher();
}
await AppxManifest(_config, _logger).generateAppxManifest();
await MakePri(_config, _logger).generatePRI();
await AppxManifest().generateAppxManifest();
await MakePri().generatePRI();

loggerProgress.finish(showTiming: true);
}

Future<void> _packMsixFiles() async {
await MakeAppx(_config, _logger).pack();
await Assets(_config, _logger).cleanTemporaryFiles();
var loggerProgress = _logger.progress('packing msix files');

await MakeAppx().pack();
await Assets().cleanTemporaryFiles();

if (_config.signMsix && !_config.store) {
final signTool = SignTool(_config, _logger);
final signTool = SignTool();
if (_config.installCert) await signTool.installCertificate();
await signTool.sign();
}

loggerProgress.finish(showTiming: true);
}

/// print the location of the created msix file
void _printMsixOutputLocation() {
_logger.write('msix created: '.green.emphasized);
_logger.write('msix created: '.green);
_logger.stdout((_config.msixPath.contains('build/windows')
? _config.msixPath
.substring(_config.msixPath.indexOf('build/windows'))
Expand Down
7 changes: 3 additions & 4 deletions lib/src/app_installer.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'dart:convert' show HtmlEscape, base64Encode;
import 'package:cli_dialog/cli_dialog.dart' show CLI_Dialog;
import 'package:get_it/get_it.dart';
import 'package:image/image.dart'
show Image, copyResize, decodeImage, encodePng, trim;
import 'package:path/path.dart' show basename;
Expand All @@ -10,15 +11,13 @@ import 'configuration.dart';

/// Handles the creation of .appinstaller file and msix versions
class AppInstaller {
final Configuration _config;
final Logger _logger;
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();

String get _versionsFolderPath => '${_config.publishFolderPath}/versions';
String get _msixVersionPath =>
'$_versionsFolderPath/${_config.appName}_${_config.msixVersion}.msix';

AppInstaller(this._config, this._logger);

/// Ask the user if he want to increment the version
/// if the current publish version is the same or lower than the last published version.
Future<void> validatePublishVersion() async {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/appx_manifest.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import 'dart:io';
import 'package:cli_util/cli_logging.dart' show Logger;
import 'package:get_it/get_it.dart';
import 'capabilities.dart';
import 'configuration.dart';
import 'extensions.dart';

/// Handles the creation of the manifest file
class AppxManifest {
final Configuration _config;
final Logger _logger;

AppxManifest(this._config, this._logger);
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();

/// Generates the manifest file according to the user configuration values
Future<void> generateAppxManifest() async {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/assets.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:isolate';
import 'package:get_it/get_it.dart';
import 'package:image/image.dart'
show
Image,
Expand All @@ -16,13 +17,11 @@ import 'extensions.dart';

/// Handles all the msix and user assets files
class Assets {
final Configuration _config;
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();
late Image image;
final Logger _logger;
String get _msixIconsFolderPath => '${_config.buildFilesFolder}/Images';

Assets(this._config, this._logger);

/// Generate new app icons or copy default app icons
Future<void> createIcons() async {
_logger.trace('create app icons');
Expand Down
5 changes: 3 additions & 2 deletions lib/src/configuration.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:args/args.dart' show ArgParser, ArgResults;
import 'package:cli_util/cli_logging.dart' show Logger;
import 'package:get_it/get_it.dart';
import 'package:package_config/package_config.dart' show findPackageConfig;
import 'package:path/path.dart' show extension, basename;
import 'package:pub_semver/pub_semver.dart';
Expand All @@ -10,7 +11,7 @@ import 'extensions.dart';
/// Handles loading and validating the configuration values
class Configuration {
final List<String> _arguments;
final Logger _logger;
final Logger _logger = GetIt.I<Logger>();
late ArgResults _args;
String msixAssetsPath = '';
String? appName;
Expand Down Expand Up @@ -60,7 +61,7 @@ class Configuration {
String pubspecYamlPath = "pubspec.yaml";
String osMinVersion = '10.0.17763.0';

Configuration(this._arguments, this._logger);
Configuration(this._arguments);

/// Gets the configuration values from from [_arguments] or pubspec.yaml file
Future<void> getConfigValues() async {
Expand Down
7 changes: 3 additions & 4 deletions lib/src/makeappx.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:io';
import 'package:cli_util/cli_logging.dart' show Logger;
import 'package:get_it/get_it.dart';
import 'configuration.dart';

/// Use the makeappx.exe tool to generate manifest file
class MakeAppx {
final Configuration _config;
final Logger _logger;

MakeAppx(this._config, this._logger);
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();

Future<void> pack() async {
_logger.trace('packing');
Expand Down
7 changes: 3 additions & 4 deletions lib/src/makepri.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import 'dart:io';
import 'package:cli_util/cli_logging.dart' show Logger;
import 'package:get_it/get_it.dart';
import 'configuration.dart';
import 'extensions.dart';

/// Use the makepri.exe tool to generate package resource indexing files
class MakePri {
final Configuration _config;
final Logger _logger;

MakePri(this._config, this._logger);
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();

Future<void> generatePRI() async {
_logger.trace('generate package resource indexing files');
Expand Down
13 changes: 5 additions & 8 deletions lib/src/sign_tool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';
import 'package:cli_dialog/cli_dialog.dart' show CLI_Dialog;
import 'package:cli_util/cli_logging.dart' show Logger;
import 'package:get_it/get_it.dart';
import 'package:path/path.dart' show extension, basename;
import 'extensions.dart';
import 'configuration.dart';
Expand All @@ -11,10 +12,8 @@ var _publisherRegex = RegExp(

/// Handles the certificate sign functionality
class SignTool {
final Configuration _config;
final Logger _logger;

SignTool(this._config, this._logger);
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();

/// Use Powershell script to get the Publisher ("Subject") of the certificate
Future<void> getCertificatePublisher() async {
Expand Down Expand Up @@ -106,14 +105,12 @@ class SignTool {
if (importCertificate.exitCode != 0) {
var error = importCertificate.stderr.toString();
if (error.contains('was canceled by the user')) {
_logger.stderr(
'the certificate installation was canceled'.red.emphasized);
_logger.stderr('the certificate installation was canceled'.red);
} else {
throw error;
}
} else {
_logger.stdout(
'the certificate installed successfully '.green.emphasized);
_logger.stdout('the certificate installed successfully '.green);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/src/windows_build.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:io';
import 'package:cli_util/cli_logging.dart' show Logger;
import 'package:get_it/get_it.dart';

import 'configuration.dart';

Expand All @@ -8,10 +9,8 @@ const mainCppPath = 'windows/runner/main.cpp';

/// Handles windows files build steps
class WindowsBuild {
final Configuration _config;
final Logger _logger;

WindowsBuild(this._config, this._logger);
final Logger _logger = GetIt.I<Logger>();
final Configuration _config = GetIt.I<Configuration>();

/// Run "flutter build windows" command
Future<void> build() async {
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies:
yaml: ^3.1.0
path: ^1.8.0
package_config: ^2.0.2
get_it: ^7.2.0
image: ^3.1.0
cli_util: ^0.3.5
cli_dialog: ^0.5.0
Expand Down
Loading

0 comments on commit 13a4918

Please sign in to comment.