2016-05-24 03:11:09 +02:00
|
|
|
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
|
|
|
// MIT-style license that can be found in the LICENSE file or at
|
|
|
|
// https://opensource.org/licenses/MIT.
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
2016-08-30 07:52:56 +02:00
|
|
|
import 'package:args/args.dart';
|
2016-09-08 01:34:38 +02:00
|
|
|
import 'package:stack_trace/stack_trace.dart';
|
2016-05-24 03:11:09 +02:00
|
|
|
import 'package:path/path.dart' as p;
|
2016-09-08 01:34:38 +02:00
|
|
|
|
2016-09-03 16:42:29 +02:00
|
|
|
import 'package:sass/src/exception.dart';
|
2016-09-10 23:29:01 +02:00
|
|
|
import 'package:sass/src/parse.dart';
|
2016-08-27 05:03:47 +02:00
|
|
|
import 'package:sass/src/visitor/perform.dart';
|
2016-08-15 08:51:29 +02:00
|
|
|
import 'package:sass/src/visitor/serialize.dart';
|
2016-05-24 03:11:09 +02:00
|
|
|
|
|
|
|
void main(List<String> args) {
|
2016-09-08 01:34:38 +02:00
|
|
|
var argParser = new ArgParser(allowTrailingOptions: true)
|
2016-08-30 07:52:56 +02:00
|
|
|
..addOption('precision', hide: true)
|
|
|
|
..addOption('style',
|
|
|
|
abbr: 's',
|
|
|
|
help: 'Output style.',
|
|
|
|
allowed: ['expanded'],
|
|
|
|
defaultsTo: 'expanded')
|
2016-09-08 01:34:38 +02:00
|
|
|
..addFlag('trace', help: 'Print full Dart stack traces for exceptions.')
|
2016-08-30 07:52:56 +02:00
|
|
|
..addFlag('help',
|
|
|
|
abbr: 'h', help: 'Print this usage information.', negatable: false);
|
|
|
|
var options = argParser.parse(args);
|
|
|
|
|
|
|
|
if (options['help']) {
|
|
|
|
print("Compile Sass to CSS.\n");
|
|
|
|
print("Usage: sass <input>\n");
|
|
|
|
print(argParser.usage);
|
|
|
|
exit(64);
|
|
|
|
}
|
|
|
|
|
2016-09-03 16:42:29 +02:00
|
|
|
try {
|
|
|
|
var file = options.rest.first;
|
2016-09-11 02:15:49 +02:00
|
|
|
var parse = p.extension(file) == '.sass' ? parseSass : parseScss;
|
|
|
|
var sassTree = parse(new File(file).readAsStringSync(), url: p.toUri(file));
|
2016-09-10 23:29:01 +02:00
|
|
|
var cssTree = new PerformVisitor().visitStylesheet(sassTree);
|
2016-09-03 16:42:29 +02:00
|
|
|
var css = toCss(cssTree);
|
|
|
|
if (css.isNotEmpty) print(css);
|
2016-09-08 01:34:38 +02:00
|
|
|
} on SassException catch (error, stackTrace) {
|
|
|
|
stderr.writeln(error.toString(color: true));
|
|
|
|
|
|
|
|
if (options['trace']) {
|
|
|
|
stderr.writeln();
|
|
|
|
stderr.write(new Trace.from(stackTrace));
|
|
|
|
stderr.flush();
|
|
|
|
}
|
|
|
|
|
2016-09-03 16:42:29 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
2016-05-24 03:11:09 +02:00
|
|
|
}
|