<commit_before>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:grinder/grinder.dart';
import 'package:intl/intl.dart';
import 'package:path/path.dart' as path;
import 'package:polymer/builder.dart' as polymer;

import 'webstore_client.dart';

final NumberFormat _NF = new NumberFormat.decimalPattern();

// TODO: Make the deploy-test and deploy tasks incremental.

final Directory BUILD_DIR = new Directory('build');
final Directory DIST_DIR = new Directory('dist');

// Here's how to generate refreshToken:
// https://docs.google.com/a/google.com/document/d/1OEM4GGhMrOWS4pYvtIWtkw_17C2pAlWPxUFu-7_YF-4
final String clientID = Platform.environment['SPARK_UPLOADER_CLIENTID'];
final String clientSecret =
    Platform.environment['SPARK_UPLOADER_CLIENTSECRET'];
final String refreshToken =
    Platform.environment['SPARK_UPLOADER_REFRESHTOKEN'];
final String appID = Platform.environment['SPARK_APP_ID'];

void main([List<String> args]) {
  defineTask('setup', taskFunction: setup);

  defineTask('mode-notest', taskFunction: (c) => _changeMode(useTestMode: false));
  defineTask('mode-test', taskFunction: (c) => _changeMode(useTestMode: true));

  defineTask('lint', taskFunction: lint, depends: ['setup']);

  defineTask('compile', taskFunction: compile, depends : ['setup']);
  defineTask('deploy', taskFunction: deploy, depends : ['lint']);

  defineTask('docs', taskFunction: docs, depends : ['setup']);
  defineTask('stats', taskFunction: stats);
  defineTask('archive', taskFunction: archive, depends : ['mode-notest', 'deploy']);
  defineTask('createSdk', taskFunction: createSdk);

  // For now, we won't be building the webstore version from Windows.
  if (!Platform.isWindows) {
    defineTask('release', taskFunction: release, depends : ['mode-notest', 'deploy']);
    defineTask('release-nightly',
               taskFunction : releaseNightly,
               depends : ['mode-notest', 'deploy']);
  }

  defineTask('clean', taskFunction: clean);

  startGrinder(args);
}

/**
 * Init needed dependencies.
 */
void setup(GrinderContext context) {
  // check to make sure we can locate the SDK
  if (sdkDir == null) {
    context.fail("Unable to locate the Dart SDK\n"
        "Please set the DART_SDK environment variable to the SDK path.\n"
        "  e.g.: 'export DART_SDK=your/path/to/dart/dart-sdk'");
  }

  PubTools pub = new PubTools();
  pub.get(context);

  // copy from ./packages to ./app/packages
  copyDirectory(getDir('packages'), getDir('app/packages'), context);

  BUILD_DIR.createSync();
  DIST_DIR.createSync();
}

/**
 * Runt Polymer lint on the Polymer entry point.
 */
void lint(context) {
  polymer.lint(entryPoints: ['app/spark_polymer.html']);
}

/**
 * Compile the Spark non-Polymer entry-point. This step will be removed soon in
 * favor of the Polymer-oriented [deploy].
 */
@deprecated
void compile(GrinderContext context) {
  _dart2jsCompile(context, new Directory('app'), 'spark.dart');
}

/**
 * Copy all source to `build/deploy`. Do a polymer deploy to `build/deploy-out`.
 * This builds the regular (non-test) version of the app.
 */
void deploy(GrinderContext context) {
  Directory sourceDir = joinDir(BUILD_DIR, ['deploy']);
  Directory destDir = joinDir(BUILD_DIR, ['deploy-out']);

  _polymerDeploy(context, sourceDir, destDir);

  _dart2jsCompile(
      context, joinDir(destDir, ['web']),
      'services_impl.dart', true);
  copyFile(getFile('services_impl.precompile.js'),
      getFile('services_impl.js'));
  print("done with services");
  _dart2jsCompile(
      context, joinDir(destDir, ['web']),
      'spark_polymer.html_bootstrap.dart', true);

  _runCommandSync(
      context,
      'patch ${destDir.path}/web/packages/shadow_dom/shadow_dom.debug.js tool/shadow_dom.patch');
}

// Creates a release build to be uploaded to Chrome Web Store.
// It will perform the following steps:
// - Sources will be compiled in Javascript using "compile" task
// - If the current branch/repo is not releasable, we just create an archive
//   tagged with a revision number.
// - Using increaseBuildNumber, for a given revision number a.b.c where a, b
//   and c are integers, we increase c, the build number and write it to the
//   manifest.json file.
// - We duplicate the manifest.json file to build/polymer-build/web since we'll
//   create the Chrome App from here.<commit_msg>Fixed grind to rename precompile to .js for dart2js deployment<commit_after>// Copyright (c) 2013, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:grinder/grinder.dart';
import 'package:intl/intl.dart';
import 'package:path/path.dart' as path;
import 'package:polymer/builder.dart' as polymer;

import 'webstore_client.dart';

final NumberFormat _NF = new NumberFormat.decimalPattern();

// TODO: Make the deploy-test and deploy tasks incremental.

final Directory BUILD_DIR = new Directory('build');
final Directory DIST_DIR = new Directory('dist');

// Here's how to generate refreshToken:
// https://docs.google.com/a/google.com/document/d/1OEM4GGhMrOWS4pYvtIWtkw_17C2pAlWPxUFu-7_YF-4
final String clientID = Platform.environment['SPARK_UPLOADER_CLIENTID'];
final String clientSecret =
    Platform.environment['SPARK_UPLOADER_CLIENTSECRET'];
final String refreshToken =
    Platform.environment['SPARK_UPLOADER_REFRESHTOKEN'];
final String appID = Platform.environment['SPARK_APP_ID'];

void main([List<String> args]) {
  defineTask('setup', taskFunction: setup);

  defineTask('mode-notest', taskFunction: (c) => _changeMode(useTestMode: false));
  defineTask('mode-test', taskFunction: (c) => _changeMode(useTestMode: true));

  defineTask('lint', taskFunction: lint, depends: ['setup']);

  defineTask('compile', taskFunction: compile, depends : ['setup']);
  defineTask('deploy', taskFunction: deploy, depends : ['lint']);

  defineTask('docs', taskFunction: docs, depends : ['setup']);
  defineTask('stats', taskFunction: stats);
  defineTask('archive', taskFunction: archive, depends : ['mode-notest', 'deploy']);
  defineTask('createSdk', taskFunction: createSdk);

  // For now, we won't be building the webstore version from Windows.
  if (!Platform.isWindows) {
    defineTask('release', taskFunction: release, depends : ['mode-notest', 'deploy']);
    defineTask('release-nightly',
               taskFunction : releaseNightly,
               depends : ['mode-notest', 'deploy']);
  }

  defineTask('clean', taskFunction: clean);

  startGrinder(args);
}

/**
 * Init needed dependencies.
 */
void setup(GrinderContext context) {
  // check to make sure we can locate the SDK
  if (sdkDir == null) {
    context.fail("Unable to locate the Dart SDK\n"
        "Please set the DART_SDK environment variable to the SDK path.\n"
        "  e.g.: 'export DART_SDK=your/path/to/dart/dart-sdk'");
  }

  PubTools pub = new PubTools();
  pub.get(context);

  // copy from ./packages to ./app/packages
  copyDirectory(getDir('packages'), getDir('app/packages'), context);

  BUILD_DIR.createSync();
  DIST_DIR.createSync();
}

/**
 * Runt Polymer lint on the Polymer entry point.
 */
void lint(context) {
  polymer.lint(entryPoints: ['app/spark_polymer.html']);
}

/**
 * Compile the Spark non-Polymer entry-point. This step will be removed soon in
 * favor of the Polymer-oriented [deploy].
 */
@deprecated
void compile(GrinderContext context) {
  _dart2jsCompile(context, new Directory('app'), 'spark.dart');
}

/**
 * Copy all source to `build/deploy`. Do a polymer deploy to `build/deploy-out`.
 * This builds the regular (non-test) version of the app.
 */
void deploy(GrinderContext context) {
  Directory sourceDir = joinDir(BUILD_DIR, ['deploy']);
  Directory destDir = joinDir(BUILD_DIR, ['deploy-out']);

  _polymerDeploy(context, sourceDir, destDir);

  Directory deployWeb = joinDir(destDir, ['web']);
  _dart2jsCompile(context, deployWeb, 'services_impl.dart', true);
  _copyFileWithNewName(
      joinFile(deployWeb, ['services_impl.dart.precompiled.js']),
      deployWeb, 'services_impl.dart.js', context);
  print("done with services");
  _dart2jsCompile(context, deployWeb,
      'spark_polymer.html_bootstrap.dart', true);

  _runCommandSync(
      context,
      'patch ${destDir.path}/web/packages/shadow_dom/shadow_dom.debug.js tool/shadow_dom.patch');
}

// Left out from grinder package due to plans to deprecate it in favor of hop.
void _copyFileWithNewName(File srcFile, Directory destDir, String destFilename,
                    GrinderContext context) {
  File destFile = joinFile(destDir, [destFilename]);

  if (context != null) {
    context.log('copying ${srcFile.path} to ${destFile.path}');
  }
  destDir.createSync(recursive: true);
  destFile.writeAsBytesSync(srcFile.readAsBytesSync());
}

// Creates a release build to be uploaded to Chrome Web Store.
// It will perform the following steps:
// - Sources will be compiled in Javascript using "compile" task
// - If the current branch/repo is not releasable, we just create an archive
//   tagged with a revision number.
// - Using increaseBuildNumber, for a given revision number a.b.c where a, b
//   and c are integers, we increase c, the build number and write it to the
//   manifest.json file.
// - We duplicate the manifest.json file to build/polymer-build/web since we'll
//   create the Chrome App from here.
{'fraction_non_alphanumeric': 0.1304841540208527, 'fraction_numerical': 0.003200165169815216, 'mean_word_length': 4.352486187845304, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4359068', 'n_tokens_mistral': 3064, 'n_tokens_neox': 2925, 'n_words': 866}