Skip to content
This repository was archived by the owner on Sep 14, 2021. It is now read-only.

Commit 26d64c8

Browse files
committed
Merge pull request #13 from chalin/chalin-new-sync-all-option-0604
feat(dart_doc_syncer): sync selected projects and other improvements + Fatal errors from git commands are now reported (rather than ignored). docsync.json "schema" and SyncData class have changed: name is now taken to represent the example folder name; e.g., 'architecture'; it is omitted from the data file since its value can be derived. + Added title, e.g. 'Architecture Overview'. + Added docPart, e.g. 'guide' (from 'guide/architecture'). docHref and liveExampleHref can now be relative URIs. + By default gh-pages not built unless there our source changes (this makes processing all examples much quicker); use --force-build to change this default behavior. + New command-line flags (see command help for details): + An ng.io branch other than master can be specified. --keep-tmp, --no-push, --force-build + Tmp directory is set to ~/tmp or /tmp if possible, otherwise fallback to script bin folder. + Dry-run no longer forces verbosity. + Updates to README.md file generation.
2 parents 315e737 + 6e4d6f4 commit 26d64c8

12 files changed

+335
-122
lines changed

bin/dart_doc_syncer.dart

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,47 @@ import 'package:dart_doc_syncer/options.dart';
99
/// Syncs an example application living in the angular.io repository to a
1010
/// dedicated repository that will contain a generated cleaned-up version.
1111
///
12-
/// dart_doc_syncer [-h|-n|-v] [<exampleName> | <examplePath> <exampleRepo>]
12+
/// dart_doc_syncer [-h|options] [<exampleName> | <examplePath> <exampleRepo>]
1313
Future main(List<String> _args) async {
1414
var args = processArgs(_args);
15-
Logger.root.level = dryRun || verbose ? Level.ALL : Level.WARNING;
15+
Logger.root.level = options.verbose ? Level.ALL : Level.WARNING;
1616
Logger.root.onRecord.listen((LogRecord rec) {
1717
var msg = '${rec.message}';
18-
if (!dryRun) msg = '${rec.level.name}: ${rec.time}: ' + msg;
18+
if (!options.dryRun && !options.verbose)
19+
msg = '${rec.level.name}: ${rec.time}: ' + msg;
1920
print(msg);
2021
});
2122

22-
var path, repositoryUri;
23+
var exampleName, path, repositoryUri;
2324
switch (args.length) {
25+
case 0:
26+
if (options.match == null)
27+
printUsageAndExit('No examples specified; name example or use --match');
28+
// #NotReached
29+
break;
2430
case 1:
25-
var e2u = new Example2Uri(args[0]);
31+
exampleName = args[0];
32+
var e2u = new Example2Uri(exampleName);
2633
path = e2u.path;
2734
repositoryUri = e2u.repositoryUri;
2835
break;
2936
case 2:
3037
path = args[0];
3138
repositoryUri = args[1];
39+
exampleName = getExampleName(path);
3240
break;
3341
default:
34-
printUsageAndExit("Expected 1 or 2 arguments but found ${args.length}");
42+
printUsageAndExit("Too many arguments (${args.length})");
3543
// #NotReached
3644
}
3745

3846
final documentation = new DocumentationUpdater();
39-
await documentation.updateRepository(path, repositoryUri);
40-
41-
print('Done updating $repositoryUri');
47+
if (options.match == null) {
48+
await documentation.updateRepository(path, repositoryUri,
49+
clean: !options.keepTmp, exampleName: exampleName, push: options.push);
50+
print('Done updating $repositoryUri');
51+
} else {
52+
await documentation.updateMatchingRepo(options.match,
53+
clean: !options.keepTmp, push: options.push);
54+
}
4255
}

bin/sync_all.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import 'package:logging/logging.dart';
88
Future main(List<String> _args) async {
99
processArgs(_args);
1010

11-
Logger.root.level = dryRun || verbose ? Level.ALL : Level.WARNING;
11+
Logger.root.level = options.verbose ? Level.ALL : Level.WARNING;
1212
Logger.root.onRecord.listen((LogRecord rec) {
1313
var msg = '${rec.message}';
14-
if (!dryRun) msg = '${rec.level.name}: ${rec.time}: ' + msg;
14+
if (!options.dryRun && !options.verbose) msg = '${rec.level.name}: ${rec.time}: ' + msg;
1515
print(msg);
1616
});
1717

lib/documentation_updater.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@ abstract class DocumentationUpdater {
1010
/// Updates [outRepositoryUri] based on the content of the example under
1111
/// [examplePath] in the angular.io repository.
1212
Future<bool> updateRepository(String examplePath, String outRepositoryUri,
13-
{bool push, bool clean});
13+
{String exampleName, bool push, bool clean});
14+
15+
/// Updates all example repositories containing a doc syncer data file
16+
/// and whose path matches [re].
17+
Future<int> updateMatchingRepo(RegExp re, {bool push, bool clean});
1418
}

lib/example2uri.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:path/path.dart' as p;
2+
13
class Example2Uri {
24
final String _exampleName;
35

@@ -8,3 +10,13 @@ class Example2Uri {
810
String get repositoryUri =>
911
'[email protected]:angular-examples/$_exampleName.git';
1012
}
13+
14+
/// [path] is assumed to be of the form
15+
/// 'public/docs/_examples/<exampleName>/dart';
16+
/// returns <exampleName>.
17+
String getExampleName(String path) {
18+
assert (p.basename(path) == 'dart');
19+
var name = p.basename(p.dirname(path));
20+
assert (name.isNotEmpty);
21+
return name;
22+
}

lib/src/generate_doc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Future assembleDocumentationExample(Directory snapshot, Directory out,
5050
/// Rewrites all files under the [path] directory by filtering out the
5151
/// documentation tags.
5252
Future _removeDocTagsFromApplication(String path) async {
53-
if (Process.dryRun) return new Future.value(null);
53+
if (Process.options.dryRun) return new Future.value(null);
5454

5555
final files = await new Directory(path)
5656
.list(recursive: true)

lib/src/generate_gh_pages.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ import 'dart:io';
44
import 'package:path/path.dart' as p;
55

66
import 'runner.dart' as Process; // TODO(chalin) tmp name to avoid code changes
7-
8-
final String _basePath = p.dirname(Platform.script.path);
7+
import 'options.dart';
98

109
/// Returns the path to the folder where the application assets have been
1110
/// generated.
1211
Future<String> generateApplication(
1312
Directory example, String exampleName) async {
14-
final applicationPath = p.join(_basePath, '.tmp/${exampleName}_app');
13+
final applicationPath = p.join(workDirPath, '${exampleName}_app');
1514

1615
// Copy the application code into a seperate folder.
1716
await Process.run('cp', ['-a', p.join(example.path, '.'), applicationPath]);

lib/src/generate_readme.dart

Lines changed: 48 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:async';
22
import 'dart:convert';
33
import 'dart:io';
44

5+
import 'package:dart_doc_syncer/example2uri.dart';
56
import 'package:logging/logging.dart';
67
import 'package:path/path.dart' as p;
78

@@ -11,21 +12,21 @@ final Logger _logger = new Logger('generateReadme');
1112

1213
/// Generates a README file for the example at [path].
1314
Future generateReadme(String path, {String angularIoPath}) async {
14-
final syncDataFile = new File(p.join(path, '.docsync.json'));
15+
final syncDataFile = new File(p.join(path, exampleConfigFileName));
1516
final dataExists = await syncDataFile.exists();
1617

1718
final syncData = dataExists
1819
? new SyncData.fromJson(await syncDataFile.readAsStringSync(),
1920
path: angularIoPath)
20-
: new SyncData(name: p.basename(path), path: angularIoPath);
21+
: new SyncData(title: p.basename(path), path: angularIoPath);
2122

2223
await _generateReadme(path, syncData);
2324
if (dataExists) await syncDataFile.delete();
2425
}
2526

2627
/// Generates a README file for the example at [path] based on [syncData].
2728
Future _generateReadme(String path, SyncData syncData) async {
28-
final warningMessage = (syncData.docHref == null)
29+
final warningMessage = (syncData.docHref.isEmpty)
2930
? '''
3031
**WARNING:** This example is preliminary and subject to change.
3132
@@ -40,21 +41,25 @@ Future _generateReadme(String path, SyncData syncData) async {
4041
return '- $link';
4142
}).join('\n');
4243

43-
final liveExampleSection = syncData.liveExampleHref == null
44-
? 'To run your own copy:\n'
45-
: 'You can run a [hosted copy](${syncData.liveExampleHref}) of this'
46-
'sample. Or run your own copy:\n';
44+
final liveExampleSection = syncData.liveExampleHref.isEmpty
45+
? 'To run your own copy:'
46+
: 'You can run a [hosted copy](${syncData.liveExampleHref}) of this '
47+
'sample. Or run your own copy:';
48+
49+
final newIssueUri = '//github.com/angular/angular.io/issues/new'
50+
'?labels=dart,example&title=%5BDart%5D%5Bexample%5D%20'
51+
'${syncData.id}%3A%20';
4752

4853
final readmeContent = '''
4954
$warningMessage
5055
51-
${syncData.name}
52-
---------------
56+
## ${syncData.title}
5357
5458
Welcome to the example application used in angular.io/dart's
55-
[${syncData.name}](${syncData.docHref ?? syncData.repoHref}) page.
59+
[${syncData.title}](${syncData.docHref}) page.
5660
5761
$liveExampleSection
62+
5863
1. Clone this repo.
5964
2. Download the dependencies:
6065
@@ -74,41 +79,61 @@ $linkSection
7479
[the angular.io repository](${syncData.repoHref}) by running the
7580
[dart-doc-syncer](//github.com/angular/dart-doc-syncer) tool.
7681
If you find a problem with this sample's code, please open an
77-
[issue at angular/angular.io](https://github.com/angular/angular.io/issues/new).
82+
[issue at angular/angular.io]($newIssueUri).
7883
''';
7984

8085
final readmeFile = new File(p.join(path, 'README.md'));
8186
_logger.fine('Generating $readmeFile.');
82-
if (dryRun) return new Future.value(null);
8387
await readmeFile.writeAsStringSync(readmeContent);
8488
}
8589

8690
/// Holds metadata about the example application that is used to generate a
8791
/// README file.
8892
class SyncData {
89-
final String name;
93+
final String name; // e.g., 'architecture'
94+
final String title; // e.g. 'Architecture Overview'
95+
final String docPart; // e.g. 'guide' (from 'guide/architecture')
9096
final String docHref;
9197
final String repoHref;
9298
final String liveExampleHref;
9399
final List<String> links;
94100

101+
String get id => p.join(docPart, name); // e.g. 'quickstart' or 'guide/architecture'
102+
95103
SyncData(
96-
{this.name,
97-
this.docHref,
98-
this.liveExampleHref,
104+
{String name: '',
105+
this.title: '',
106+
String docPart: '',
107+
String docHref: '',
108+
String liveExampleHref: '',
99109
this.links: const [],
100-
String repoHref,
110+
String repoHref: '',
101111
String path})
102-
: this.repoHref =
103-
repoHref ?? '//github.com/angular/angular.io/tree/master/' + path;
112+
: this.name = name.isEmpty ? getExampleName(path) : name,
113+
this.docPart = docPart,
114+
this.docHref = docHref.isEmpty
115+
? p.join(dartDocUriPrefix, docPart, '${getExampleName(path)}.html')
116+
: docHref.startsWith('http')
117+
? docHref
118+
: p.join(dartDocUriPrefix, docPart, docHref),
119+
this.liveExampleHref = liveExampleHref.isEmpty
120+
? p.join(exampleHostUriPrefix, getExampleName(path))
121+
: liveExampleHref.startsWith('http')
122+
? liveExampleHref
123+
: p.join(exampleHostUriPrefix, liveExampleHref),
124+
this.repoHref = repoHref.isEmpty
125+
? '//github.com/angular/angular.io/tree/master/' + path
126+
: repoHref;
104127

105128
factory SyncData.fromJson(String json, {String path}) {
106129
final data = JSON.decode(json);
107130
return new SyncData(
108-
name: data['name'],
109-
docHref: data['docHref'],
110-
repoHref: data['repoHref'],
111-
liveExampleHref: data['liveExampleHref'],
131+
name: data['name'] ?? '',
132+
title: data['title'] ?? '',
133+
docPart: data['docPart'] ?? '',
134+
docHref: data['docHref'] ?? '',
135+
repoHref: data['repoHref'] ?? '',
136+
liveExampleHref: data['liveExampleHref'] ?? '',
112137
links: data['links'] ?? [],
113138
path: path);
114139
}

0 commit comments

Comments
 (0)