Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Commit

Permalink
Merge pull request #274 from google/kevmoo_tweaks
Browse files Browse the repository at this point in the history
A few tweaks
  • Loading branch information
devoncarew committed Oct 16, 2015
2 parents 59988e5 + 201dcd1 commit eaf7111
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 57 deletions.
7 changes: 4 additions & 3 deletions lib/generators/console_full.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import 'console_full_data.dart';
* A generator for a hello world command-line application.
*/
class ConsoleFullGenerator extends DefaultGenerator {
ConsoleFullGenerator() : super('console-full', 'Console Application',
'A larger command-line application sample.',
categories: const ['dart', 'console']) {
ConsoleFullGenerator()
: super('console-full', 'Console Application',
'A larger command-line application sample.',
categories: const ['dart', 'console']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}
Expand Down
10 changes: 6 additions & 4 deletions lib/generators/console_simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import 'console_simple_data.dart';
* A generator for a hello world command-line application.
*/
class ConsoleSimpleGenerator extends DefaultGenerator {
ConsoleSimpleGenerator() : super('console-simple', 'Console Application',
'A simple command-line application.',
categories: const ['dart', 'console']) {
ConsoleSimpleGenerator()
: super('console-simple', 'Console Application',
'A simple command-line application.',
categories: const ['dart', 'console']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}

setEntrypoint(getFile('bin/main.dart'));
}

String getInstallInstructions() => "run your app using 'dart ${entrypoint.path}'";
String getInstallInstructions() =>
"run your app using 'dart ${entrypoint.path}'";
}
7 changes: 4 additions & 3 deletions lib/generators/package_simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import 'package_simple_data.dart';
* A generator for a pub library.
*/
class PackageSimpleGenerator extends DefaultGenerator {
PackageSimpleGenerator() : super('package-simple', 'Dart Package',
'A starting point for Dart libraries or applications.',
categories: const ['dart']) {
PackageSimpleGenerator()
: super('package-simple', 'Dart Package',
'A starting point for Dart libraries or applications.',
categories: const ['dart']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/generators/server_appengine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import '../src/common.dart';
* A generator for a hello world AppEngine application.
*/
class ServerAppEngineGenerator extends DefaultGenerator {
ServerAppEngineGenerator() : super('server-appengine',
'App Engine Application', 'A simple App Engine application.',
categories: const ['dart', 'appengine', 'server']) {
ServerAppEngineGenerator()
: super('server-appengine', 'App Engine Application',
'A simple App Engine application.',
categories: const ['dart', 'appengine', 'server']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/generators/server_shelf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import 'server_shelf_data.dart';
* A generator for a hello world command-line application.
*/
class ServerShelfGenerator extends DefaultGenerator {
ServerShelfGenerator() : super('server-shelf', 'Shelf Web Server',
'A web server built using the shelf package.',
categories: const ['dart', 'shelf', 'server']) {
ServerShelfGenerator()
: super('server-shelf', 'Shelf Web Server',
'A web server built using the shelf package.',
categories: const ['dart', 'shelf', 'server']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/generators/web_polymer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import 'web_polymer_data.dart';
* A generator for a polymer.dart application.
*/
class WebPolymerGenerator extends DefaultGenerator {
WebPolymerGenerator() : super('web-polymer', 'Polymer Web Application',
'A web app built using polymer.dart.',
categories: const ['dart', 'web']) {
WebPolymerGenerator()
: super('web-polymer', 'Polymer Web Application',
'A web app built using polymer.dart.',
categories: const ['dart', 'web']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}
Expand Down
7 changes: 4 additions & 3 deletions lib/generators/web_simple.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import 'web_simple_data.dart';
* A generator for a uber-simple web application.
*/
class WebSimpleGenerator extends DefaultGenerator {
WebSimpleGenerator() : super('web-simple',
'Uber Simple Web Application', 'An absolute bare-bones web app.',
categories: const ['dart', 'web']) {
WebSimpleGenerator()
: super('web-simple', 'Uber Simple Web Application',
'An absolute bare-bones web app.',
categories: const ['dart', 'web']) {
for (TemplateFile file in decodeConcatenatedData(data)) {
addTemplateFile(file);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/src/cli_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ class CliApp {
if (options['help'] || args.isEmpty) {
// Prompt to opt into advanced analytics.
if (!analytics.hasSetOptIn) {
_out("Welcome to Stagehand! We collect anonymous usage statistics and crash reports in");
_out("order to improve the tool (http://goo.gl/6wsncI). Would you like to opt-in to");
_out("additional analytics to help us improve Stagehand [y/yes/no]? ");
_out(
"""Welcome to Stagehand! We collect anonymous usage statistics and crash reports in
order to improve the tool (http://goo.gl/6wsncI). Would you like to opt-in to
additional analytics to help us improve Stagehand [y/yes/no]? """);
io.stdout.flush();
String response = io.stdin.readLineSync();
response = response.toLowerCase().trim();
Expand Down Expand Up @@ -228,7 +229,8 @@ class CliApp {
}

void _usage(ArgParser argParser) {
_out('Stagehand will generate the given application type into the current directory.');
_out(
'Stagehand will generate the given application type into the current directory.');
_out('');
_out('usage: ${APP_NAME} <generator-name>');
_out(argParser.usage);
Expand Down Expand Up @@ -262,7 +264,8 @@ class CliApp {
return dir
.listSync(followLinks: false)
.where((entity) => entity is io.Directory)
.where((entity) => !isHiddenDir(entity)).isEmpty;
.where((entity) => !isHiddenDir(entity))
.isEmpty;
}
}

Expand Down
13 changes: 8 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

name: stagehand
# When changing this version, change the lib/src/cli_app.dart version as well.
version: 0.2.3+1
version: 0.2.4-dev
description: >
A scaffolding generator for your Dart projects. Stagehand helps you get set
up!
Expand All @@ -13,16 +13,19 @@ authors:
- Seth Ladd <[email protected]>
- Devon Carew <[email protected]>

environment:
sdk: '>=1.9.0 <2.0.0'

# Add the bin/stagehand.dart script to the scripts pub installs.
executables:
stagehand:

dependencies:
args: '>=0.12.0+1 <0.14.0'
crypto: '>=0.9.0 <0.10.0'
http: '>=0.11.0 <0.12.0'
path: '>=1.3.0 <2.0.0'
usage: '>=1.0.0 <2.0.0'
crypto: ^0.9.0
http: ^0.11.0
path: ^1.3.0
usage: ^1.0.0

dev_dependencies:
browser: ^0.10.0
Expand Down
1 change: 0 additions & 1 deletion templates/console-simple/bin/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

main(List<String> args) {
print('Hello world!');
}
11 changes: 6 additions & 5 deletions templates/server-appengine/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ void requestHandler(HttpRequest request) {
..close();
}
}).catchError((_) => request.response
..write('Failed handling request: ${request.toString()}.')
..close());
..write('Failed handling request: ${request.toString()}.')
..close());
}

/// GET request handler.
Expand Down Expand Up @@ -65,9 +65,10 @@ handleGetRequest(HttpRequest request) {
cache.read(response, queryMap.keys);
} else if (request.uri.path == '/clear_cache') {
// Reintialize the cache. This clears all values and resets the default.
cache.clear()
.then((_) => response.writeln('Cleared cache!'))
.whenComplete(response.close);
cache
.clear()
.then((_) => response.writeln('Cleared cache!'))
.whenComplete(response.close);
} else {
// Serve some static content. This must be located in 'build/web' or some
// subdirectory of 'build/web'.
Expand Down
2 changes: 1 addition & 1 deletion templates/server-shelf/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:shelf/shelf_io.dart' as io;

void main(List<String> args) {
var parser = new ArgParser()
..addOption('port', abbr: 'p', defaultsTo: '8080');
..addOption('port', abbr: 'p', defaultsTo: '8080');

var result = parser.parse(args);

Expand Down
3 changes: 2 additions & 1 deletion test/common_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void main() {
});

test('convertToYamlMultiLine', () {
expect(convertToYamlMultiLine(
expect(
convertToYamlMultiLine(
'one two three four five size seven eight nine '
'ten eleven twelve thirteen fourteen fifteen'),
' one two three four five size seven eight nine ten eleven twelve '
Expand Down
7 changes: 4 additions & 3 deletions test/validate_templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void _testGenerator(stagehand.Generator generator, Directory tempDir) {
!FileSystemEntity.isFileSync(filePath)) {
var parent = new Directory(path.dirname(filePath));

var file = _listSync(parent).firstWhere((f) => f.path.endsWith('.dart'),
orElse: () => null);
var file = _listSync(parent)
.firstWhere((f) => f.path.endsWith('.dart'), orElse: () => null);

if (file == null) {
filePath = null;
Expand All @@ -78,7 +78,8 @@ void _testGenerator(stagehand.Generator generator, Directory tempDir) {
var devDeps = pubspecContent['dev_dependencies'];
if (devDeps != null) {
if (devDeps.containsKey('test')) {
Pub.run('test', runOptions: new RunOptions(workingDirectory: tempDir.path));
Pub.run('test',
runOptions: new RunOptions(workingDirectory: tempDir.path));
}
}
}
Expand Down
25 changes: 11 additions & 14 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ import 'package:path/path.dart' as path;
import 'package:stagehand/stagehand.dart' as stagehand;

final RegExp _binaryFileTypes = new RegExp(
r'\.(jpe?g|png|gif|ico|svg|ttf|eot|woff|woff2)$', caseSensitive: false);
r'\.(jpe?g|png|gif|ico|svg|ttf|eot|woff|woff2)$',
caseSensitive: false);

main(List<String> args) => grind(args);

@Task('Concatenate the template files into data files that the generators can consume')
@Task('Concatenate the template files into data files'
' that the generators can consume')
void build() {
stagehand.generators.forEach((generator) {
_concatenateFiles(
getDir('templates/${generator.id}'),
getFile('lib/generators/${generator.id.replaceAll('-', '_')}_data.dart'));
getFile(
'lib/generators/${generator.id.replaceAll('-', '_')}_data.dart'));
});

// Update the readme.md file.
Expand All @@ -30,10 +33,7 @@ void build() {
return '* `${g.id}` - ${g.description}';
}).join('\n');
String newSource = _replaceInString(
source,
'## Stagehand templates',
'## Installation',
fragment + '\n');
source, '## Stagehand templates', '## Installation', fragment + '\n');
f.writeAsStringSync(newSource);

// Update the site/index.html file.
Expand All @@ -42,11 +42,8 @@ void build() {
fragment = stagehand.generators.map((g) {
return ' <li>${g.id} - <em>${g.description}</em></li>';
}).join('\n');
newSource = _replaceInString(
source,
'<ul id="template-list">',
'</ul>',
fragment);
newSource =
_replaceInString(source, '<ul id="template-list">', '</ul>', fragment);
f.writeAsStringSync(newSource);
}

Expand Down Expand Up @@ -134,8 +131,8 @@ List<FileSystemEntity> _listSync(Directory dir,

/// Look for [start] and [end] in [source]; replace the current contents with
/// [replacement], and return the result.
String _replaceInString(String source, String start,
String end, String replacement) {
String _replaceInString(
String source, String start, String end, String replacement) {
int startIndex = source.indexOf(start);
int endIndex = source.indexOf(end, startIndex + 1);

Expand Down

0 comments on commit eaf7111

Please sign in to comment.