<commit_before>// Copyright (c) 2012, the Dart project authors.  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.

/**
 * This generates the reference documentation for the core libraries that come
 * with dart. It is built on top of dartdoc, which is a general-purpose library
 * for generating docs from any Dart code. This library extends that to include
 * additional information and styling specific to our standard library.
 *
 * Usage:
 *
 *     $ dart apidoc.dart [--out=<output directory>]
 */

#library('apidoc');

#import('dart:io');
#import('dart:json');
#import('html_diff.dart');
#import('../../pkg/dartdoc/mirrors/mirrors.dart');
#import('../../pkg/dartdoc/mirrors/mirrors_util.dart');
#import('../../pkg/dartdoc/dartdoc.dart', prefix: 'doc');
#import('../../lib/compiler/implementation/library_map.dart');

HtmlDiff _diff;

void main() {
  final args = new Options().arguments;

  int mode = doc.MODE_STATIC;
  Path outputDir = const Path('docs');
  bool generateAppCache = false;

  // Parse the command-line arguments.
  for (int i = 0; i < args.length; i++) {
    final arg = args[i];

    switch (arg) {
      case '--mode=static':
        mode = doc.MODE_STATIC;
        break;

      case '--mode=live-nav':
        mode = doc.MODE_LIVE_NAV;
        break;

      case '--generate-app-cache=true':
        generateAppCache = true;
        break;

      default:
        if (arg.startsWith('--out=')) {
          outputDir = new Path.fromNative(arg.substring('--out='.length));
        } else {
          print('Unknown option: $arg');
          return;
        }
        break;
    }
  }

  doc.cleanOutputDirectory(outputDir);

  // Compile the client-side code to JS.
  // TODO(bob): Right path.

  final clientScript = (mode == doc.MODE_STATIC) ?
      'static' : 'live-nav';
  final Future compiled = doc.compileScript(
      doc.scriptDir.append('../../pkg/dartdoc/client-$clientScript.dart'),
      outputDir.append('client-$clientScript.js'));

  // TODO(rnystrom): Use platform-specific path separator.
  // The basic dartdoc-provided static content.
  final Future copiedStatic = doc.copyDirectory(
      doc.scriptDir.append('../../pkg/dartdoc/static'),
      outputDir);

  // The apidoc-specific static content.
  final Future copiedApiDocStatic = doc.copyDirectory(
      doc.scriptDir.append('static'),
      outputDir);

  print('Parsing MDN data...');
  final mdnFile = new File.fromPath(doc.scriptDir.append('mdn/database.json'));
  final mdn = JSON.parse(mdnFile.readAsTextSync());

  print('Cross-referencing dart:html...');
  HtmlDiff.initialize(doc.libPath);
  _diff = new HtmlDiff(printWarnings:false);
  _diff.run();

  // Process handwritten HTML documentation.
  final htmldoc = new Htmldoc();
  htmldoc.documentLibraries(
    <Path>[doc.scriptDir.append('../../lib/html/doc/html.dartdoc')],
    doc.libPath);
  print('Processing handwritten HTML documentation...');

  // Process libraries.

  // TODO(johnniwinther): Libraries for the compilation seem to be more like
  // URIs. Perhaps Path should have a toURI() method.
  // Add all of the core libraries.
  final apidocLibraries = <Path>[];
  DART2JS_LIBRARY_MAP.forEach((String name, LibraryInfo info) {
    if (!info.isInternal) {
      apidocLibraries.add(new Path('dart:$name'));
    }
  });
  apidocLibraries.add(doc.scriptDir.append('../../pkg/unittest/unittest.dart'));
  apidocLibraries.add(doc.scriptDir.append('../../pkg/intl/intl.dart'));

  print('Generating docs...');
  final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache);
  // Select the libraries to include in the produced documentation:
  apidoc.includeApi = true;
  apidoc.includedLibraries = <String>[
    'unittest',
    'intl',
  ];

  Futures.wait([compiled, copiedStatic, copiedApiDocStatic]).then((_) {
    apidoc.documentLibraries(apidocLibraries, doc.libPath);
  });
}

/**<commit_msg>Add all api docs from pkg. Right now we only have "intl" and "unittest". This changes the code to find all of them.<commit_after>// Copyright (c) 2012, the Dart project authors.  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.

/**
 * This generates the reference documentation for the core libraries that come
 * with dart. It is built on top of dartdoc, which is a general-purpose library
 * for generating docs from any Dart code. This library extends that to include
 * additional information and styling specific to our standard library.
 *
 * Usage:
 *
 *     $ dart apidoc.dart [--out=<output directory>]
 */

#library('apidoc');

#import('dart:io');
#import('dart:json');
#import('html_diff.dart');
#import('../../pkg/dartdoc/mirrors/mirrors.dart');
#import('../../pkg/dartdoc/mirrors/mirrors_util.dart');
#import('../../pkg/dartdoc/dartdoc.dart', prefix: 'doc');
#import('../../lib/compiler/implementation/library_map.dart');

HtmlDiff _diff;

void main() {
  final args = new Options().arguments;

  int mode = doc.MODE_STATIC;
  Path outputDir = const Path('docs');
  bool generateAppCache = false;

  // Parse the command-line arguments.
  for (int i = 0; i < args.length; i++) {
    final arg = args[i];

    switch (arg) {
      case '--mode=static':
        mode = doc.MODE_STATIC;
        break;

      case '--mode=live-nav':
        mode = doc.MODE_LIVE_NAV;
        break;

      case '--generate-app-cache=true':
        generateAppCache = true;
        break;

      default:
        if (arg.startsWith('--out=')) {
          outputDir = new Path.fromNative(arg.substring('--out='.length));
        } else {
          print('Unknown option: $arg');
          return;
        }
        break;
    }
  }

  doc.cleanOutputDirectory(outputDir);

  // Compile the client-side code to JS.
  // TODO(bob): Right path.

  final clientScript = (mode == doc.MODE_STATIC) ?
      'static' : 'live-nav';
  final Future compiled = doc.compileScript(
      doc.scriptDir.append('../../pkg/dartdoc/client-$clientScript.dart'),
      outputDir.append('client-$clientScript.js'));

  // TODO(rnystrom): Use platform-specific path separator.
  // The basic dartdoc-provided static content.
  final Future copiedStatic = doc.copyDirectory(
      doc.scriptDir.append('../../pkg/dartdoc/static'),
      outputDir);

  // The apidoc-specific static content.
  final Future copiedApiDocStatic = doc.copyDirectory(
      doc.scriptDir.append('static'),
      outputDir);

  print('Parsing MDN data...');
  final mdnFile = new File.fromPath(doc.scriptDir.append('mdn/database.json'));
  final mdn = JSON.parse(mdnFile.readAsTextSync());

  print('Cross-referencing dart:html...');
  HtmlDiff.initialize(doc.libPath);
  _diff = new HtmlDiff(printWarnings:false);
  _diff.run();

  // Process handwritten HTML documentation.
  final htmldoc = new Htmldoc();
  htmldoc.documentLibraries(
    <Path>[doc.scriptDir.append('../../lib/html/doc/html.dartdoc')],
    doc.libPath);
  print('Processing handwritten HTML documentation...');

  // Process libraries.

  // TODO(johnniwinther): Libraries for the compilation seem to be more like
  // URIs. Perhaps Path should have a toURI() method.
  // Add all of the core libraries.
  final apidocLibraries = <Path>[];
  DART2JS_LIBRARY_MAP.forEach((String name, LibraryInfo info) {
    if (!info.isInternal) {
      apidocLibraries.add(new Path('dart:$name'));
    }
  });

  final includedLibraries = <String>[];
  var lister = new Directory.fromPath(
      doc.scriptDir.append('../../pkg/')).list();
  lister.onDir = (dirPath) {
    var path = new Path(dirPath);
    var libname = path.filename;
    path = path.append('${libname}.dart');
    if (new File.fromPath(path).existsSync()) {
      apidocLibraries.add(path);
      includedLibraries.add(libname);
    } else {
      print('Warning: could not find package at $path');
    }
  };
  lister.onDone = (success) {
    print('Generating docs...');
    final apidoc = new Apidoc(mdn, htmldoc, outputDir, mode, generateAppCache);
    // Select the libraries to include in the produced documentation:
    apidoc.includeApi = true;
    apidoc.includedLibraries = includedLibraries;

    Futures.wait([compiled, copiedStatic, copiedApiDocStatic]).then((_) {
      apidoc.documentLibraries(apidocLibraries, doc.libPath);
    });
  };
}

/**
{'fraction_non_alphanumeric': 0.14684652703822032, 'fraction_numerical': 0.0014199503017394391, 'mean_word_length': 3.1553588987217305, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '1518964', 'n_tokens_mistral': 2706, 'n_tokens_neox': 2591, 'n_words': 670}