Permalink
Browse files

feature: Testing for necessary, installed commands

  • Loading branch information...
MikeMitterer committed Dec 15, 2017
1 parent 36047ff commit 6477ea7eadc75f6557619f21a87b8ad3a84bb243
Showing with 104 additions and 17 deletions.
  1. +3 −2 bin/sitegen.dart
  2. +10 −1 lib/sitegen.dart
  3. +20 −11 lib/src/Application.dart
  4. +62 −0 lib/src/CommandManager.dart
  5. +6 −2 lib/src/Config.dart
  6. +3 −1 pubspec.yaml
@@ -1,6 +1,7 @@
import 'dart:async';
import 'package:sitegen/sitegen.dart';

void main(List<String> arguments) {
Future main(List<String> arguments) async {
final Application application = new Application();
application.run( arguments );
await application.run( arguments );
}
@@ -7,6 +7,8 @@ import 'dart:math';

import 'package:intl/intl.dart';
import 'package:args/args.dart';
import 'package:command_wrapper/command_wrapper.dart';
import 'package:which/which.dart';

import 'package:logging/logging.dart';
import 'package:logging_handlers/logging_handlers_shared.dart';
@@ -23,6 +25,7 @@ import 'package:system_info/system_info.dart';
import 'package:packages/packages.dart';

part "src/Application.dart";
part "src/CommandManager.dart";
part "src/Options.dart";
part "src/Config.dart";
part "src/Init.dart";
@@ -31,8 +34,14 @@ part "src/Generator.dart";

bool _runsOnOSX() => (SysInfo.operatingSystemName == "Mac OS X");

void main(List<String> arguments) {
final _commands = new List<CommandWrapper>();

Future main(List<String> arguments) async {
final Application application = new Application();

application.run( arguments );
}




@@ -19,14 +19,23 @@ class Application {

Application() : options = new Options();

void run(List<String> args) {
Future run(final List<String> args) async {

try {
final CommandManager cm = await CommandManager.getInstance();
final ArgResults argResults = options.parse(args);
final Config config = new Config(argResults);
final Config config = new Config(argResults, cm);

_configLogging(config.loglevel);

try {
_testPreconditions(cm);

} catch(error) {
_logger.shout(error.toString());
return;
}

if (argResults.wasParsed(Options._ARG_HELP) || (config.dirstoscan.length == 0 && args.length == 0)) {
options.showUsage();
return;
@@ -306,6 +315,15 @@ class Application {

// -- private -------------------------------------------------------------

void _testPreconditions(final CommandManager cm) {
if((cm.containsKey(CommandManager.SASS) || cm.containsKey(CommandManager.SASSC))
&& cm.containsKey(CommandManager.AUTOPREFIXER)) {
return;
}
throw "Please install SASS (${CommandManager.SASS} | ${CommandManager.SASSC}) "
"and AutoPrefixer (${CommandManager.AUTOPREFIXER})";
}

void _compileSCSSFile(final String folder, final Config config) {
Validate.notBlank(folder);
Validate.notNull(config);
@@ -354,15 +372,6 @@ class Application {
return;
}

// Nur zum testen!
final ProcessResult result = await Process.run("pwd", []);
if (result.exitCode != 0) {
_logger.info("sassc faild with: ${(result.stderr as String).trim()}!");
_vickiSay("got a sassc error",config);
return;
}
_logger.fine(result.stdout.trim());

final String content = """
tell application "${config.browser}"
set windowList to every window
@@ -0,0 +1,62 @@
part of sitegen;

class CommandManager {
static String SASS = "sass";
static String SASSC = "sassc";
static String OSASCRIPT = "osascript";
static String AUTOPREFIXER = "autoprefixer-cli";
static String SAY = "say";

static CommandManager _commandmanager;

final Map<String,Command> _commands;

static Future<CommandManager> getInstance() async {
if(_commandmanager == null) {
final commands = await _getAvailableCommands();
_commandmanager = new CommandManager._private(commands);
}
return _commandmanager;
}

Command operator [](final String key) => _commands[key];

bool containsKey(final String key) => _commands.containsKey(key);

// - private -----------------------------------------------------------------------------------

CommandManager._private(this._commands);
}

class Command {
final String name;
final String exe;
final CommandWrapper wrapper;

Command(this.name, this.exe, this.wrapper);

}

/// Test if necessary commands are available
Future<Map<String,Command>> _getAvailableCommands() async {
final Map<String,Command> commands = new Map<String,Command>();
final List<String> names
= <String>[

CommandManager.SASS,
CommandManager.SASSC,
CommandManager.OSASCRIPT,
CommandManager.AUTOPREFIXER,
CommandManager.SAY
];

await Future.forEach(names, (final String binName) async {
try {
final String exe = await which(binName);
commands[binName] = new Command(binName,exe,new CommandWrapper(binName));
} catch(_) { }

});

return commands;
}
@@ -42,8 +42,9 @@ class Config {
final ArgResults _argResults;
final Map<String,dynamic> _settings = new Map<String,dynamic>();
final Packages _packages = new Packages();
final CommandManager _commandmanager;

Config(this._argResults) {
Config(this._argResults, this._commandmanager) {

_settings[Options._ARG_LOGLEVEL] = 'info';

@@ -59,7 +60,7 @@ class Config {
_settings[Config._CONF_YAML_DELIMITER] = '~~~';
_settings[Config._CONF_USE_MARKDOWN] = true;
_settings[Config._CONF_DEFAULT_TEMPLATE] = "default.html";
_settings[Config._CONF_SASS_COMPILER] = "sassc";
_settings[Config._CONF_SASS_COMPILER] = _commandmanager.containsKey("sassc") ? "sassc" : "sass";
_settings[Config._CONF_SASS_PATH] = "";
_settings[Config._CONF_BROWSER] = "Chromium";

@@ -233,7 +234,10 @@ class Config {
} else {
print(" ${prepareKey(key)} ${value}");
}
});

_commandmanager._commands.forEach((final String name,final Command command) {
print(" ${prepareKey(name)} ${command.exe}");
});
}

@@ -36,7 +36,9 @@ dependencies:

packages: ^0.1.0
#path: /Volumes/Daten/DevLocal/DevDart/Packages


command_wrapper: "^0.2.0"

dev_dependencies:
test: any
grinder: any

0 comments on commit 6477ea7

Please sign in to comment.