Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Grinder wrapper for doc generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
pq committed Jul 26, 2016
1 parent d7c00d3 commit 63c35a4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
37 changes: 20 additions & 17 deletions tool/doc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,7 @@ void main([List<String> args]) {
}

var outDir = options['out'];

if (outDir != null) {
Directory d = new Directory(outDir);
if (!d.existsSync()) {
print("Directory '${d.path}' does not exist");
return;
}
}

// Generate index
new Indexer(ruleRegistry).generate(outDir);

// Generate rule files
rules.forEach((l) => new Generator(l).generate(outDir));

// Generate options samples.
new OptionsSample(rules).generate(outDir);
generateDocs(outDir);
}

const ruleFootMatter = '''
Expand Down Expand Up @@ -87,6 +71,25 @@ String get enumerateStyleRules => rules

List<String> get sortedRules => rules.map((r) => r.name).toList()..sort();

void generateDocs(String outDir) {
if (outDir != null) {
Directory d = new Directory(outDir);
if (!d.existsSync()) {
print("Directory '${d.path}' does not exist");
return;
}
}

// Generate index
new Indexer(ruleRegistry).generate(outDir);

// Generate rule files
rules.forEach((l) => new Generator(l).generate(outDir));

// Generate options samples.
new OptionsSample(rules).generate(outDir);
}

void printUsage(ArgParser parser, [String error]) {
var message = 'Generates lint docs.';
if (error != null) {
Expand Down
26 changes: 19 additions & 7 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,31 @@ import 'dart:io';
import 'package:grinder/grinder.dart';
import 'package:unscripted/unscripted.dart';

import 'doc.dart';
import 'rule.dart';

main([List<String> args]) {
addTask(new GrinderTask('rule', taskFunction: () {
String ruleName = context.invocation.positionals.first;
_generate(ruleName);
},
_addTask('rule',
parser: (String name) =>
generateRule(name, outDir: Directory.current.path),
description: 'Generate a lint rule stub.',
positionals: [new Positional(valueHelp: 'Name of rule to generate')]));
valueHelp: 'Name of rule to generate.');

_addTask('docs',
parser: (String outDir) => generateDocs(outDir),
description: 'Generate lint rule docs.',
valueHelp: 'Documentation `lints/` directory.');

grind(args);
}

void _generate(String ruleName) {
generateRule(ruleName, outDir: Directory.current.path);
_addTask(String name, {String description, Parser parser, String valueHelp}) {
addTask(new GrinderTask(name, taskFunction: () {
String value = context.invocation.positionals.first;
parser(value);
},
description: description,
positionals: [new Positional(valueHelp: valueHelp)]));
}

typedef String Parser(String);

0 comments on commit 63c35a4

Please sign in to comment.