mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-26 20:24:42 +01:00
Print the version number.
This commit is contained in:
parent
3206281e15
commit
aa614bd0cc
@ -2,6 +2,9 @@
|
|||||||
// MIT-style license that can be found in the LICENSE file or at
|
// MIT-style license that can be found in the LICENSE file or at
|
||||||
// https://opensource.org/licenses/MIT.
|
// https://opensource.org/licenses/MIT.
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
import 'dart:isolate';
|
||||||
|
|
||||||
import 'package:args/args.dart';
|
import 'package:args/args.dart';
|
||||||
import 'package:stack_trace/stack_trace.dart';
|
import 'package:stack_trace/stack_trace.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@ -24,9 +27,19 @@ void main(List<String> args) {
|
|||||||
abbr: 'c', help: 'Whether to emit terminal colors.', defaultsTo: true)
|
abbr: 'c', help: 'Whether to emit terminal colors.', defaultsTo: true)
|
||||||
..addFlag('trace', help: 'Print full Dart stack traces for exceptions.')
|
..addFlag('trace', help: 'Print full Dart stack traces for exceptions.')
|
||||||
..addFlag('help',
|
..addFlag('help',
|
||||||
abbr: 'h', help: 'Print this usage information.', negatable: false);
|
abbr: 'h', help: 'Print this usage information.', negatable: false)
|
||||||
|
..addFlag('version',
|
||||||
|
help: 'Print the version of Dart Sass.', negatable: false);
|
||||||
var options = argParser.parse(getArguments(args));
|
var options = argParser.parse(getArguments(args));
|
||||||
|
|
||||||
|
if (options['version']) {
|
||||||
|
_loadVersion().then((version) {
|
||||||
|
print(version);
|
||||||
|
exit(0);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (options['help'] || options.rest.isEmpty) {
|
if (options['help'] || options.rest.isEmpty) {
|
||||||
print("Compile Sass to CSS.\n");
|
print("Compile Sass to CSS.\n");
|
||||||
print("Usage: sass <input>\n");
|
print("Usage: sass <input>\n");
|
||||||
@ -56,3 +69,16 @@ void main(List<String> args) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads and returns the current version of Sass.
|
||||||
|
Future<String> _loadVersion() async {
|
||||||
|
var version = const String.fromEnvironment('version');
|
||||||
|
if (version != null) return version;
|
||||||
|
|
||||||
|
var libDir = p.fromUri(
|
||||||
|
await Isolate.resolvePackageUri(Uri.parse('package:sass/')));
|
||||||
|
var pubspec = readFile(p.join(libDir, '..', 'pubspec.yaml'));
|
||||||
|
return pubspec.split("\n")
|
||||||
|
.firstWhere((line) => line.startsWith('version: '))
|
||||||
|
.split(" ").last;
|
||||||
|
}
|
||||||
|
@ -22,3 +22,4 @@ dev_dependencies:
|
|||||||
js: "^0.6.0"
|
js: "^0.6.0"
|
||||||
node_preamble: "^1.0.0"
|
node_preamble: "^1.0.0"
|
||||||
test: "^0.12.0"
|
test: "^0.12.0"
|
||||||
|
yaml: "^2.0.0"
|
||||||
|
@ -7,6 +7,7 @@ import 'dart:isolate';
|
|||||||
|
|
||||||
import 'package:grinder/grinder.dart';
|
import 'package:grinder/grinder.dart';
|
||||||
import 'package:node_preamble/preamble.dart' as preamble;
|
import 'package:node_preamble/preamble.dart' as preamble;
|
||||||
|
import 'package:yaml/yaml.dart';
|
||||||
|
|
||||||
main(args) => grind(args);
|
main(args) => grind(args);
|
||||||
|
|
||||||
@ -29,7 +30,8 @@ js() {
|
|||||||
_ensureBuild();
|
_ensureBuild();
|
||||||
var destination = new File('build/sass.dart.js');
|
var destination = new File('build/sass.dart.js');
|
||||||
Dart2js.compile(new File('bin/sass.dart'),
|
Dart2js.compile(new File('bin/sass.dart'),
|
||||||
outFile: destination, extraArgs: ['-Dnode=true']);
|
outFile: destination,
|
||||||
|
extraArgs: ['-Dnode=true', '-Dversion=${_loadVersion()}']);
|
||||||
var text = destination.readAsStringSync();
|
var text = destination.readAsStringSync();
|
||||||
destination.writeAsStringSync("${preamble.getPreamble()}\n$text");
|
destination.writeAsStringSync("${preamble.getPreamble()}\n$text");
|
||||||
}
|
}
|
||||||
@ -38,3 +40,7 @@ js() {
|
|||||||
void _ensureBuild() {
|
void _ensureBuild() {
|
||||||
new Directory('build').createSync(recursive: true);
|
new Directory('build').createSync(recursive: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads the version number from pubspec.yaml.
|
||||||
|
String _loadVersion() =>
|
||||||
|
loadYaml(new File('pubspec.yaml').readAsStringSync())['version'];
|
||||||
|
Loading…
Reference in New Issue
Block a user