dart-sass/tool/grind.dart

47 lines
1.3 KiB
Dart
Raw Normal View History

2016-08-29 00:04:48 +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.
2016-10-05 10:04:51 +02:00
import 'dart:io';
import 'dart:isolate';
2016-08-29 00:04:48 +02:00
import 'package:grinder/grinder.dart';
2016-10-05 10:04:51 +02:00
import 'package:node_preamble/preamble.dart' as preamble;
2016-10-08 00:46:58 +02:00
import 'package:yaml/yaml.dart';
2016-08-29 00:04:48 +02:00
main(args) => grind(args);
2016-10-05 10:04:51 +02:00
@DefaultTask('Run the Dart formatter.')
2016-08-29 00:04:48 +02:00
format() {
Pub.run('dart_style',
script: 'format',
arguments: ['--overwrite']
..addAll(existingSourceDirs.map((dir) => dir.path)));
}
2016-10-05 10:04:51 +02:00
@Task('Build Dart snapshot.')
snapshot() {
_ensureBuild();
Dart.run('bin/sass.dart', vmArgs: ['--snapshot=build/sass.dart.snapshot']);
}
@Task('Compile to JS.')
js() {
_ensureBuild();
var destination = new File('build/sass.dart.js');
Dart2js.compile(new File('bin/sass.dart'),
2016-10-08 00:46:58 +02:00
outFile: destination,
extraArgs: ['-Dnode=true', '-Dversion=${_loadVersion()}']);
2016-10-05 10:04:51 +02:00
var text = destination.readAsStringSync();
destination.writeAsStringSync("${preamble.getPreamble()}\n$text");
}
/// Ensure that the `build/` directory exists.
void _ensureBuild() {
new Directory('build').createSync(recursive: true);
}
2016-10-08 00:46:58 +02:00
/// Loads the version number from pubspec.yaml.
String _loadVersion() =>
loadYaml(new File('pubspec.yaml').readAsStringSync())['version'];