Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: pkg/docgen/lib/docgen.dart

Issue 172873008: pkg/docgen: support dartdoc-viewer with the viewer app at the root of the repo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /// **docgen** is a tool for creating machine readable representations of Dart 5 /// **docgen** is a tool for creating machine readable representations of Dart
6 /// code metadata, including: classes, members, comments and annotations. 6 /// code metadata, including: classes, members, comments and annotations.
7 /// 7 ///
8 /// docgen is run on a `.dart` file or a directory containing `.dart` files. 8 /// docgen is run on a `.dart` file or a directory containing `.dart` files.
9 /// 9 ///
10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR] 10 /// $ dart docgen.dart [OPTIONS] [FILE/DIR]
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 /// Convenience methods wrapped up in a class to pull down the docgen viewer for 657 /// Convenience methods wrapped up in a class to pull down the docgen viewer for
658 /// a viewable website, and start up a server for viewing. 658 /// a viewable website, and start up a server for viewing.
659 class _Viewer { 659 class _Viewer {
660 static String _dartdocViewerString = path.join(Directory.current.path, 660 static String _dartdocViewerString = path.join(Directory.current.path,
661 'dartdoc-viewer'); 661 'dartdoc-viewer');
662 static Directory _dartdocViewerDir = new Directory(_dartdocViewerString); 662 static Directory _dartdocViewerDir = new Directory(_dartdocViewerString);
663 static Directory _topLevelTempDir; 663 static Directory _topLevelTempDir;
664 static Directory _webDocsDir; 664 static Directory _webDocsDir;
665 static bool movedViewerCode = false; 665 static bool movedViewerCode = false;
666 666
667 static String _viewerCodePath;
668
669 /*
670 * dartdoc-viewer currently has the web app code under a 'client' directory
671 *
672 * This is confusing for folks that want to clone and modify the code.
673 * It also includes a number of python files and other content related to
674 * app engine hosting that are not needed.
675 *
676 * This logic exists to support the current model and a (future) updated
677 * dartdoc-viewer repo where the 'client' content exists at the root of the
678 * project and the other content is removed.
679 */
680 static String get viewerCodePath {
681 if(_viewerCodePath == null) {
682 var pubspecFileName = 'pubspec.yaml';
683
684 var thePath = _dartdocViewerDir.path;
685
686 if(!FileSystemEntity.isFileSync(path.join(thePath, pubspecFileName))) {
687 thePath = path.join(thePath, 'client');
688 print('trying the fallback: $thePath');
689 if (!FileSystemEntity.isFileSync(path.join(thePath, pubspecFileName))) {
690 throw new StateError('Could not find a pubspec file');
691 }
692 }
693
694 _viewerCodePath = thePath;
695 }
696 return _viewerCodePath;
697 }
698
667 /// If our dartdoc-viewer code is already checked out, move it to a temporary 699 /// If our dartdoc-viewer code is already checked out, move it to a temporary
668 /// directory outside of the package directory, so we don't try to process it 700 /// directory outside of the package directory, so we don't try to process it
669 /// for documentation. 701 /// for documentation.
670 static void ensureMovedViewerCode() { 702 static void ensureMovedViewerCode() {
671 // TODO(efortuna): This will need to be modified to run on anyone's package 703 // TODO(efortuna): This will need to be modified to run on anyone's package
672 // outside of the checkout! 704 // outside of the checkout!
673 if (_dartdocViewerDir.existsSync()) { 705 if (_dartdocViewerDir.existsSync()) {
674 _topLevelTempDir = new Directory( 706 _topLevelTempDir = new Directory(
675 _Generator._rootDirectory).createTempSync(); 707 _Generator._rootDirectory).createTempSync();
676 _dartdocViewerDir.renameSync(_topLevelTempDir.path); 708 _dartdocViewerDir.renameSync(_topLevelTempDir.path);
(...skipping 14 matching lines...) Expand all
691 else { 723 else {
692 var processResult = Process.runSync('git', ['clone', '-b', 'master', 724 var processResult = Process.runSync('git', ['clone', '-b', 'master',
693 'git://github.com/dart-lang/dartdoc-viewer.git'], 725 'git://github.com/dart-lang/dartdoc-viewer.git'],
694 runInShell: true); 726 runInShell: true);
695 727
696 if (processResult.exitCode == 0) { 728 if (processResult.exitCode == 0) {
697 /// Move the generated json/yaml docs directory to the dartdoc-viewer 729 /// Move the generated json/yaml docs directory to the dartdoc-viewer
698 /// directory, to run as a webpage. 730 /// directory, to run as a webpage.
699 var processResult = Process.runSync(_Generator._pubScript, 731 var processResult = Process.runSync(_Generator._pubScript,
700 ['upgrade'], runInShell: true, 732 ['upgrade'], runInShell: true,
701 workingDirectory: path.join(_dartdocViewerDir.path, 'client')); 733 workingDirectory: path.join(viewerCodePath, 'client'));
702 print('process output: ${processResult.stdout}'); 734 print('process output: ${processResult.stdout}');
703 print('process stderr: ${processResult.stderr}'); 735 print('process stderr: ${processResult.stderr}');
704 736
705 var dir = new Directory(_Generator._outputDirectory == null? 'docs' : 737 var dir = new Directory(_Generator._outputDirectory == null? 'docs' :
706 _Generator._outputDirectory); 738 _Generator._outputDirectory);
707 _webDocsDir = new Directory(path.join(_dartdocViewerDir.path, 'client', 739 _webDocsDir = new Directory(path.join(viewerCodePath, 'client',
708 'web', 'docs')); 740 'web', 'docs'));
709 if (dir.existsSync()) { 741 if (dir.existsSync()) {
710 // Move the docs folder to dartdoc-viewer/client/web/docs 742 // Move the docs folder to dartdoc-viewer/client/web/docs
711 dir.renameSync(_webDocsDir.path); 743 dir.renameSync(_webDocsDir.path);
712 } 744 }
713 } else { 745 } else {
714 print('Error cloning git repository:'); 746 print('Error cloning git repository:');
715 print('process output: ${processResult.stdout}'); 747 print('process output: ${processResult.stdout}');
716 print('process stderr: ${processResult.stderr}'); 748 print('process stderr: ${processResult.stderr}');
717 } 749 }
718 } 750 }
719 } 751 }
720 752
721 static void _compile() { 753 static void _compile() {
722 if (_webDocsDir.existsSync()) { 754 if (_webDocsDir.existsSync()) {
723 // Compile the code to JavaScript so we can run on any browser. 755 // Compile the code to JavaScript so we can run on any browser.
724 print('Compile app to JavaScript for viewing.'); 756 print('Compile app to JavaScript for viewing.');
725 var processResult = Process.runSync(_Generator._dartBinary, 757 var processResult = Process.runSync(_Generator._dartBinary,
726 ['deploy.dart'], workingDirectory : path.join(_dartdocViewerDir.path, 758 ['deploy.dart'], workingDirectory : path.join(viewerCodePath,
727 'client'), runInShell: true); 759 'client'), runInShell: true);
728 print('process output: ${processResult.stdout}'); 760 print('process output: ${processResult.stdout}');
729 print('process stderr: ${processResult.stderr}'); 761 print('process stderr: ${processResult.stderr}');
730 var outputDir = path.join(_dartdocViewerDir.path, 'client', 'out', 'web'); 762 var outputDir = path.join(viewerCodePath, 'client', 'out', 'web');
731 print('Docs are available at $outputDir'); 763 print('Docs are available at $outputDir');
732 } 764 }
733 } 765 }
734 766
735 /// A simple HTTP server. Implemented here because this is part of the SDK, 767 /// A simple HTTP server. Implemented here because this is part of the SDK,
736 /// so it shouldn't have any external dependencies. 768 /// so it shouldn't have any external dependencies.
737 static void _runServer() { 769 static void _runServer() {
738 // Launch a server to serve out of the directory dartdoc-viewer/client/web. 770 // Launch a server to serve out of the directory dartdoc-viewer/client/web.
739 HttpServer.bind('localhost', 8080).then((HttpServer httpServer) { 771 HttpServer.bind('localhost', 8080).then((HttpServer httpServer) {
740 print('Server launched. Navigate your browser to: ' 772 print('Server launched. Navigate your browser to: '
741 'http://localhost:${httpServer.port}'); 773 'http://localhost:${httpServer.port}');
742 httpServer.listen((HttpRequest request) { 774 httpServer.listen((HttpRequest request) {
743 var response = request.response; 775 var response = request.response;
744 var basePath = path.join(_dartdocViewerDir.path, 'client', 'out', 776 var basePath = path.join(viewerCodePath, 'client', 'out',
745 'web'); 777 'web');
746 var requestPath = path.join(basePath, request.uri.path.substring(1)); 778 var requestPath = path.join(basePath, request.uri.path.substring(1));
747 bool found = true; 779 bool found = true;
748 var file = new File(requestPath); 780 var file = new File(requestPath);
749 if (file.existsSync()) { 781 if (file.existsSync()) {
750 // Set the correct header type. 782 // Set the correct header type.
751 if (requestPath.endsWith('.html')) { 783 if (requestPath.endsWith('.html')) {
752 response.headers.set('Content-Type', 'text/html'); 784 response.headers.set('Content-Type', 'text/html');
753 } else if (requestPath.endsWith('.js')) { 785 } else if (requestPath.endsWith('.js')) {
754 response.headers.set('Content-Type', 'application/javascript'); 786 response.headers.set('Content-Type', 'application/javascript');
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 .map((e) => originalMirror.getField(e.simpleName).reflectee) 2233 .map((e) => originalMirror.getField(e.simpleName).reflectee)
2202 .where((e) => e != null) 2234 .where((e) => e != null)
2203 .toList(); 2235 .toList();
2204 } 2236 }
2205 2237
2206 Map toMap() => { 2238 Map toMap() => {
2207 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName, 2239 'name': Indexable.getDocgenObject(mirror, owningLibrary).docName,
2208 'parameters': parameters 2240 'parameters': parameters
2209 }; 2241 };
2210 } 2242 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698