<commit_before>// 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:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';

import 'package:archive/archive.dart';
import 'package:grinder/grinder.dart';
import 'package:http/http.dart' as http;
import 'package:node_preamble/preamble.dart' as preamble;
import 'package:path/path.dart' as p;
import 'package:yaml/yaml.dart';

/// The version of Dart Sass.
final String _version =
    loadYaml(new File('pubspec.yaml').readAsStringSync())['version'];

/// The version of the current Dart executable.
final String _dartVersion = Platform.version.split(" ").first;

/// The root of the Dart SDK.
final _sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable));

main(args) => grind(args);

@DefaultTask('Run the Dart formatter.')
format() {
  Pub.run('dart_style',
      script: 'format',
      arguments: ['--overwrite']
        ..addAll(existingSourceDirs.map((dir) => dir.path)));
}

@Task('Build Dart snapshot.')
snapshot() {
  _ensureBuild();
  Dart.run('bin/sass.dart', vmArgs: ['--snapshot=build/sass.dart.snapshot']);
}

@Task('Build standalone packages for all OSes.')
@Depends(snapshot)
package() async {
  var client = new http.Client();
  await _buildPackage(client, "linux", "x64");
  await _buildPackage(client, "linux", "ia32");
  await _buildPackage(client, "macos", "x64");
  await _buildPackage(client, "macos", "ia32");
  await _buildPackage(client, "windows", "x64");
  await _buildPackage(client, "windows", "ia32");
  client.close();
}

@Task('Compile to JS.')
js() {
  _ensureBuild();
  var destination = new File('build/sass.dart.js');
  Dart2js.compile(new File('bin/sass.dart'),
      outFile: destination, extraArgs: ['-Dnode=true', '-Dversion=$_version']);
  var text = destination.readAsStringSync();
  destination.writeAsStringSync("""
    ${preamble.getPreamble()}
    global.exports = exports;
    $text
  """);
}

@Task('Build a pure-JS NPM package.')
@Depends(js)
npm_package() {
  var dir = new Directory('build/npm');
  dir.deleteSync(recursive: true);
  dir.createSync(recursive: true);

  log("copying package/package.json to build/npm");
  var json = JSON.decode(
      new File('package/package.json').readAsStringSync());
  json['version'] = _version;
  new File(p.join(dir.path, 'package.json'))
      .writeAsStringSync(JSON.encode(json));<commit_msg>List the dart2js version in the --version string.<commit_after>// 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:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';

import 'package:archive/archive.dart';
import 'package:grinder/grinder.dart';
import 'package:http/http.dart' as http;
import 'package:node_preamble/preamble.dart' as preamble;
import 'package:path/path.dart' as p;
import 'package:yaml/yaml.dart';

/// The version of Dart Sass.
final String _version =
    loadYaml(new File('pubspec.yaml').readAsStringSync())['version'];

/// The version of the current Dart executable.
final String _dartVersion = Platform.version.split(" ").first;

/// The root of the Dart SDK.
final _sdkDir = p.dirname(p.dirname(Platform.resolvedExecutable));

main(args) => grind(args);

@DefaultTask('Run the Dart formatter.')
format() {
  Pub.run('dart_style',
      script: 'format',
      arguments: ['--overwrite']
        ..addAll(existingSourceDirs.map((dir) => dir.path)));
}

@Task('Build Dart snapshot.')
snapshot() {
  _ensureBuild();
  Dart.run('bin/sass.dart', vmArgs: ['--snapshot=build/sass.dart.snapshot']);
}

@Task('Build standalone packages for all OSes.')
@Depends(snapshot)
package() async {
  var client = new http.Client();
  await _buildPackage(client, "linux", "x64");
  await _buildPackage(client, "linux", "ia32");
  await _buildPackage(client, "macos", "x64");
  await _buildPackage(client, "macos", "ia32");
  await _buildPackage(client, "windows", "x64");
  await _buildPackage(client, "windows", "ia32");
  client.close();
}

@Task('Compile to JS.')
js() {
  _ensureBuild();
  var destination = new File('build/sass.dart.js');
  Dart2js.compile(new File('bin/sass.dart'), outFile: destination, extraArgs: [
    '-Dnode=true',
    '-Dversion=$_version compiled with dart2js $_dartVersion'
  ]);
  var text = destination.readAsStringSync();
  destination.writeAsStringSync("""
    ${preamble.getPreamble()}
    global.exports = exports;
    $text
  """);
}

@Task('Build a pure-JS NPM package.')
@Depends(js)
npm_package() {
  var dir = new Directory('build/npm');
  dir.deleteSync(recursive: true);
  dir.createSync(recursive: true);

  log("copying package/package.json to build/npm");
  var json = JSON.decode(
      new File('package/package.json').readAsStringSync());
  json['version'] = _version;
  new File(p.join(dir.path, 'package.json'))
      .writeAsStringSync(JSON.encode(json));
{'fraction_non_alphanumeric': 0.1665351223362273, 'fraction_numerical': 0.007103393843725336, 'mean_word_length': 4.701912260967379, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1017524', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1702, 'n_words': 406}