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

Side by Side Diff: sdk/lib/_internal/dartdoc/bin/dartdoc.dart

Issue 13811012: Revert "Have dartdoc document exports." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 8 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 | sdk/lib/_internal/dartdoc/lib/dartdoc.dart » ('j') | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * To generate docs for a library, run this script with the path to an 6 * To generate docs for a library, run this script with the path to an
7 * entrypoint .dart file, like: 7 * entrypoint .dart file, like:
8 * 8 *
9 * $ dart dartdoc.dart foo.dart 9 * $ dart dartdoc.dart foo.dart
10 * 10 *
11 * This will create a "docs" directory with the docs for your libraries. To 11 * This will create a "docs" directory with the docs for your libraries. To
12 * create these beautiful docs, dartdoc parses your library and every library 12 * create these beautiful docs, dartdoc parses your library and every library
13 * it imports (recursively). From each library, it parses all classes and 13 * it imports (recursively). From each library, it parses all classes and
14 * members, finds the associated doc comments and builds crosslinked docs from 14 * members, finds the associated doc comments and builds crosslinked docs from
15 * them. 15 * them.
16 */ 16 */
17 library dartdoc; 17 library dartdoc;
18 18
19 import 'dart:async'; 19 import 'dart:async';
20 import 'dart:io'; 20 import 'dart:io';
21 21
22 // TODO(rnystrom): Use "package:" URL (#4968). 22 // TODO(rnystrom): Use "package:" URL (#4968).
23 import '../lib/dartdoc.dart'; 23 import '../lib/dartdoc.dart';
24 import '../lib/src/dartdoc/utils.dart';
25 import 'package:args/args.dart'; 24 import 'package:args/args.dart';
26 import 'package:pathos/path.dart' as path; 25 import 'package:pathos/path.dart' as path;
27 26
28 /** 27 /**
29 * Run this from the `lib/_internal/dartdoc` directory. 28 * Run this from the `lib/_internal/dartdoc` directory.
30 */ 29 */
31 main() { 30 main() {
32 // Need this because ArgParser.getUsage doesn't show command invocation. 31 // Need this because ArgParser.getUsage doesn't show command invocation.
33 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:'; 32 final USAGE = 'Usage dartdoc [options] <entrypoint(s)>\n[options] include:';
34 33
35 final args = new Options().arguments; 34 final args = new Options().arguments;
36 35
37 final dartdoc = new Dartdoc(); 36 final dartdoc = new Dartdoc();
38 37
39 final argParser = new ArgParser(); 38 final argParser = new ArgParser();
40 39
41 final Path libPath = scriptDir.append('../../../../'); 40 final Path libPath = scriptDir.append('../../../../');
42 41
43 String packageRoot; 42 Path packageRoot;
44 43
45 argParser.addFlag('no-code', 44 argParser.addFlag('no-code',
46 help: 'Do not include source code in the documentation.', 45 help: 'Do not include source code in the documentation.',
47 defaultsTo: false, negatable: false, 46 defaultsTo: false, negatable: false,
48 callback: (noCode) => dartdoc.includeSource = !noCode); 47 callback: (noCode) => dartdoc.includeSource = !noCode);
49 48
50 argParser.addOption('mode', abbr: 'm', 49 argParser.addOption('mode', abbr: 'm',
51 help: 'Define how HTML pages are generated.', 50 help: 'Define how HTML pages are generated.',
52 allowed: ['static', 'live-nav'], allowedHelp: { 51 allowed: ['static', 'live-nav'], allowedHelp: {
53 'static': 'Generates completely static HTML containing\n' 52 'static': 'Generates completely static HTML containing\n'
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 dartdoc.excludedLibraries = allLibs; 159 dartdoc.excludedLibraries = allLibs;
161 } 160 }
162 }, allowMultiple: true); 161 }, allowMultiple: true);
163 162
164 argParser.addOption('package-root', 163 argParser.addOption('package-root',
165 help: 'Sets the package directory to the specified directory.\n' 164 help: 'Sets the package directory to the specified directory.\n'
166 'If omitted the package directory is the closest packages directory to' 165 'If omitted the package directory is the closest packages directory to'
167 ' the entrypoint.', 166 ' the entrypoint.',
168 callback: (packageDir) { 167 callback: (packageDir) {
169 if(packageDir != null) { 168 if(packageDir != null) {
170 packageRoot = packageDir; 169 packageRoot = new Path(packageDir);
171 } 170 }
172 }); 171 });
173 172
174 // TODO(amouravski): This method is deprecated. Remove on April 22. 173 // TODO(amouravski): This method is deprecated. Remove on April 22.
175 argParser.addOption('pkg', 174 argParser.addOption('pkg',
176 help: 'Deprecated: same as --package-root.', 175 help: 'Deprecated: same as --package-root.',
177 callback: (packageDir) { 176 callback: (packageDir) {
178 if(packageDir != null) { 177 if(packageDir != null) {
179 packageRoot = packageDir; 178 packageRoot = new Path(packageDir);
180 } 179 }
181 }); 180 });
182 181
183 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc'); 182 dartdoc.dartdocPath = libPath.append('lib/_internal/dartdoc');
184 183
185 if (args.isEmpty) { 184 if (args.isEmpty) {
186 print('No arguments provided.'); 185 print('No arguments provided.');
187 print(USAGE); 186 print(USAGE);
188 print(argParser.getUsage()); 187 print(argParser.getUsage());
189 exit(1); 188 exit(1);
190 } 189 }
191 190
192 final entrypoints = <Uri>[]; 191 final entrypoints = <Path>[];
193 try { 192 try {
194 final option = argParser.parse(args); 193 final option = argParser.parse(args);
195 194
196 // This checks to see if the root of all entrypoints is the same. 195 // This checks to see if the root of all entrypoints is the same.
197 // If it is not, then we display a warning, as package imports might fail. 196 // If it is not, then we display a warning, as package imports might fail.
198 var entrypointRoot; 197 var entrypointRoot;
199 for (final entrypoint in option.rest) { 198 for(final arg in option.rest) {
200 var uri = Uri.parse(entrypoint); 199 var entrypoint = new Path(arg);
201 if (uri.scheme == '') uri = pathToFileUri(entrypoint); 200 entrypoints.add(entrypoint);
202 entrypoints.add(uri);
203 201
204 if (uri.scheme != 'file') continue;
205 if (entrypointRoot == null) { 202 if (entrypointRoot == null) {
206 entrypointRoot = path.dirname(entrypoint); 203 entrypointRoot = entrypoint.directoryPath;
207 } else if (entrypointRoot != path.dirname(entrypoint)) { 204 } else if (entrypointRoot.toNativePath() !=
205 entrypoint.directoryPath.toNativePath()) {
208 print('Warning: entrypoints are at different directories. "package:"' 206 print('Warning: entrypoints are at different directories. "package:"'
209 ' imports may fail.'); 207 ' imports may fail.');
210 } 208 }
211 } 209 }
212 } on FormatException catch (e) { 210 } on FormatException catch (e) {
213 print(e.message); 211 print(e.message);
214 print(USAGE); 212 print(USAGE);
215 print(argParser.getUsage()); 213 print(argParser.getUsage());
216 exit(1); 214 exit(1);
217 } 215 }
218 216
219 if (entrypoints.isEmpty) { 217 if (entrypoints.isEmpty) {
220 print('No entrypoints provided.'); 218 print('No entrypoints provided.');
221 print(argParser.getUsage()); 219 print(argParser.getUsage());
222 exit(1); 220 exit(1);
223 } 221 }
224 222
225 if (packageRoot == null) packageRoot = _getPackageRoot(entrypoints); 223 if (packageRoot == null) {
224 // Check if there's a `packages` directory in the entry point directory.
225 var script = path.normalize(path.absolute(entrypoints[0].toNativePath()));
226 var dir = path.join(path.dirname(script), 'packages/');
227 if (new Directory(dir).existsSync()) {
228 // TODO(amouravski): convert all of dartdoc to use pathos.
229 packageRoot = new Path(dir);
230 } else {
231 // If there is not, then check if the entrypoint is somewhere in a `lib`
232 // directory.
233 dir = path.dirname(script);
234 var parts = path.split(dir);
235 var libDir = parts.lastIndexOf('lib');
236 if (libDir > 0) {
237 packageRoot = new Path(path.join(path.joinAll(parts.take(libDir)),
238 'packages'));
239 }
240 }
241 }
226 242
227 cleanOutputDirectory(dartdoc.outputDir); 243 cleanOutputDirectory(dartdoc.outputDir);
228 244
229 // Start the analysis and documentation. 245 // Start the analysis and documentation.
230 dartdoc.documentLibraries(entrypoints, libPath, packageRoot) 246 dartdoc.documentLibraries(entrypoints, libPath, packageRoot)
231 .then((_) { 247 .then((_) {
232 print('Copying static files...'); 248 print('Copying static files...');
233 Future.wait([ 249 Future.wait([
234 // Prepare the dart2js script code and copy static resources. 250 // Prepare the dart2js script code and copy static resources.
235 // TODO(amouravski): move compileScript out and pre-generate the client 251 // TODO(amouravski): move compileScript out and pre-generate the client
236 // scripts. This takes a long time and the js hardly ever changes. 252 // scripts. This takes a long time and the js hardly ever changes.
237 compileScript(dartdoc.mode, dartdoc.outputDir, libPath), 253 compileScript(dartdoc.mode, dartdoc.outputDir, libPath),
238 copyDirectory(scriptDir.append('../static'), dartdoc.outputDir) 254 copyDirectory(scriptDir.append('../static'), dartdoc.outputDir)
239 ]); 255 ]);
240 }) 256 })
241 .then((_) { 257 .then((_) {
242 print(dartdoc.status); 258 print(dartdoc.status);
243 if (dartdoc.totals == 0) { 259 if (dartdoc.totals == 0) {
244 exit(1); 260 exit(1);
245 } 261 }
246 }) 262 })
247 .catchError((e) { 263 .catchError((e) {
248 print('Error: generation failed: ${e}'); 264 print('Error: generation failed: ${e}');
249 dartdoc.cleanup(); 265 dartdoc.cleanup();
250 exit(1); 266 exit(1);
251 }) 267 })
252 .whenComplete(() => dartdoc.cleanup()); 268 .whenComplete(() => dartdoc.cleanup());
253 } 269 }
254
255 String _getPackageRoot(List<Uri> entrypoints) {
256 // Check if there's a `packages` directory in the entry point directory.
257 var fileEntrypoint = entrypoints.firstWhere(
258 (entrypoint) => entrypoint.scheme == 'file',
259 orElse: () => null);
260 if (fileEntrypoint != null) {
261 var script = path.normalize(path.absolute(fileUriToPath(fileEntrypoint)));
262 var dir = path.join(path.dirname(script), 'packages/');
263 if (new Directory(dir).existsSync()) return dir;
264 }
265
266 // If there is not, then check if the entrypoint is somewhere in a `lib`
267 // directory.
268 dir = path.dirname(script);
269 var parts = path.split(dir);
270 var libDir = parts.lastIndexOf('lib');
271 if (libDir > 0) {
272 return path.join(path.joinAll(parts.take(libDir)), 'packages');
273 } else {
274 return null;
275 }
276 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/dartdoc/lib/dartdoc.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698