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 #276 from google/kevmoo_fixes
Browse files Browse the repository at this point in the history
Kevmoo fixes
  • Loading branch information
devoncarew committed Oct 16, 2015
2 parents 8489307 + 1d1fb0c commit c43b37c
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 75 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## 0.2.4
- Improved layout of `server-appengine`.

## 0.2.3+1
- fixed an issue with the Polymer template

Expand Down
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,32 @@ Requirements:

To install:

$> pub global activate stagehand
```console
> pub global activate stagehand
```

To update:
To update, run activate again:

# activate stagehand again
$> pub global activate stagehand
```console
> pub global activate stagehand
```

## Usage

Stagehand will generate a project skeleton into the current directory. As an
example, here is how you create a package with Stagehand:

$> mkdir fancy_project
$> cd fancy_project
$> stagehand package-simple
```console
> mkdir fancy_project
> cd fancy_project
> stagehand package-simple
```

And to list all of the project templates:

$> stagehand
```console
> stagehand
```

## Goals

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/console_full_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
".gitignore",
"text",
"""LmJ1aWxkbG9nCi5EU19TdG9yZQouaWRlYQoucGFja2FnZXMKLnB1Yi8KYnVpbGQvCnBhY2thZ2Vz
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/console_simple_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
"bin/main.dart",
"text",
"bWFpbihMaXN0PFN0cmluZz4gYXJncykgewogIHByaW50KCdIZWxsbyB3b3JsZCEnKTsKfQo=",
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/package_simple_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
".gitignore",
"text",
"""LmJ1aWxkbG9nCi5EU19TdG9yZQouaWRlYQoucGFja2FnZXMKLnB1Yi8KYnVpbGQvCnBhY2thZ2Vz
Expand Down
55 changes: 28 additions & 27 deletions lib/generators/server_appengine_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
".gitignore",
"text",
"""LmJ1aWxkbG9nCi5EU19TdG9yZQouaWRlYQoucGFja2FnZXMKLnB1Yi8KYnVpbGQvCnBhY2thZ2Vz
Expand Down Expand Up @@ -129,36 +129,37 @@ bGljZW5zZSB0aGF0IGNhbiBiZSBmb3VuZCBpbiB0aGUgTElDRU5TRSBmaWxlLgoKbGlicmFyeSB7
e3Byb2plY3ROYW1lfX0ubWVtY2FjaGU7CgppbXBvcnQgJ2RhcnQ6YXN5bmMnOwppbXBvcnQgJ2Rh
cnQ6aW8nOwoKaW1wb3J0ICdwYWNrYWdlOmFwcGVuZ2luZS9hcHBlbmdpbmUuZGFydCc7Cgpjb25z
dCBTdHJpbmcgREVGQVVMVF9LRVkgPSAnaGVsbG8nOwpib29sIGNhY2hlSW5pdGlhbGl6ZWQgPSBm
YWxzZTsKCi8vLyBJbml0aWFsaXplIHRoZSBjYWNoZS4KRnV0dXJlIGluaXRpYWxpemUoKSB7CiAg
Ly8gSWYgdGhlIGNhY2hlIGlzIGFscmVhZHkgaW5pdGlhbGl6ZWQsIGp1c3QgcmV0dXJuLgogIGlm
IChjYWNoZUluaXRpYWxpemVkKSB7CiAgICByZXR1cm4gbmV3IEZ1dHVyZS52YWx1ZSgpOwogIH0K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250ZXh0LnNl
cnZpY2VzLm1lbWNhY2hlOwogIEZ1dHVyZQogICAgICAuZm9yRWFjaCgKICAgICAgICAgIGtleXMs
CiAgICAgICAgICAoa2V5KSA9PiBtZW1jYWNoZQogICAgICAgICAgICAgIC5nZXQoa2V5KQogICAg
ICAgICAgICAgIC50aGVuKCh2YWx1ZSkgPT4gcmVzcG9uc2Uud3JpdGVsbignIiR7a2V5fSI6ICIk
e3ZhbHVlfSInKSkKICAgICAgICAgICAgICAuY2F0Y2hFcnJvcigKICAgICAgICAgICAgICAgICAg
KF8pID0+IHJlc3BvbnNlLndyaXRlbG4oJyIke2tleX0iOiB2YWx1ZSBub3QgZm91bmQhJykpKQog
ICAgICAud2hlbkNvbXBsZXRlKHJlc3BvbnNlLmNsb3NlKTsKfQo=""",
"pubspec.yaml",
"text",
"""bmFtZToge3twcm9qZWN0TmFtZX19CnZlcnNpb246IDAuMC4xCmRlc2NyaXB0aW9uOiBBIHNpbXBs
ZSBBcHAgRW5naW5lIGFwcGxpY2F0aW9uLgojYXV0aG9yOiB7e2F1dGhvcn19IDxlbWFpbEBleGFt
cGxlLmNvbT4KI2hvbWVwYWdlOiBodHRwczovL3d3dy5leGFtcGxlLmNvbQoKZW52aXJvbm1lbnQ6
CiAgc2RrOiAnPj0xLjUuMCA8Mi4wLjAnCgpkZXBlbmRlbmNpZXM6CiAgYXBwZW5naW5lOiAnPj0w
CiAgc2RrOiAnPj0xLjkuMCA8Mi4wLjAnCgpkZXBlbmRlbmNpZXM6CiAgYXBwZW5naW5lOiAnPj0w
LjMuMCA8MC40LjAnCg=="""
];
2 changes: 1 addition & 1 deletion lib/generators/server_shelf_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
".gitignore",
"text",
"""LmJ1aWxkbG9nCi5EU19TdG9yZQouaWRlYQoucGFja2FnZXMKLnB1Yi8KYnVpbGQvCnBhY2thZ2Vz
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/web_polymer_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
".gitignore",
"text",
"""LmJ1aWxkbG9nCi5EU19TdG9yZQouaWRlYQoucGFja2FnZXMKLnB1Yi8KYnVpbGQvCnBhY2thZ2Vz
Expand Down
2 changes: 1 addition & 1 deletion lib/generators/web_simple_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

List<String> data = [
const List<String> data = const <String>[
".gitignore",
"text",
"""LmJ1aWxkbG9nCi5EU19TdG9yZQouaWRlYQoucGFja2FnZXMKLnB1Yi8KYnVpbGQvCnBhY2thZ2Vz
Expand Down
32 changes: 18 additions & 14 deletions templates/server-appengine/lib/memcache.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,47 @@ const String DEFAULT_KEY = 'hello';
bool cacheInitialized = false;

/// Initialize the cache.
Future initialize() {
Future initialize() async {
// If the cache is already initialized, just return.
if (cacheInitialized) {
return new Future.value();
}
if (cacheInitialized) return;

// The AppEngine environment has a preconfigured 'context' which provides
// authorized access to the default api services.
var memcache = context.services.memcache;

// Initialize the cache and set the default value.
return memcache.clear()
.then((_) => memcache.set(DEFAULT_KEY, 'there!'))
.then((_) => cacheInitialized = true);
await memcache.clear();
await memcache.set(DEFAULT_KEY, 'there!');
cacheInitialized = true;
}

/// Clears the cache and resets the default.
Future clear() {
Future clear() async {
cacheInitialized = false;
return initialize();
await initialize();
}

/// Helper method to write a set of key/value pairs to the memcache.
void write(HttpResponse response, Map<String, String> valueMap) {
var memcache = context.services.memcache;
Future.forEach(valueMap.keys, (key) {
var value = valueMap[key];
return memcache.set(key, value)
return memcache
.set(key, value)
.then((_) => response.writeln('"${key}": "${value}"'));
}).whenComplete(response.close);
}

/// Helper method to read a set of values from the memcache.
void read(HttpResponse response, Iterable<String> keys) {
var memcache = context.services.memcache;
Future.forEach(keys, (key) => memcache.get(key)
.then((value) => response.writeln('"${key}": "${value}"'))
.catchError((_) => response.writeln('"${key}": value not found!')))
.whenComplete(response.close);
Future
.forEach(
keys,
(key) => memcache
.get(key)
.then((value) => response.writeln('"${key}": "${value}"'))
.catchError(
(_) => response.writeln('"${key}": value not found!')))
.whenComplete(response.close);
}
2 changes: 1 addition & 1 deletion templates/server-appengine/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: A simple App Engine application.
#homepage: https://www.example.com

environment:
sdk: '>=1.5.0 <2.0.0'
sdk: '>=1.9.0 <2.0.0'

dependencies:
appengine: '>=0.3.0 <0.4.0'
4 changes: 2 additions & 2 deletions test/validate_templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ library stagehand.test.validate_templates;

import 'dart:io';

import 'package:grinder/grinder.dart';
import 'package:grinder/grinder.dart' hide fail;
import 'package:path/path.dart' as path;
import 'package:stagehand/stagehand.dart' as stagehand;
import 'package:test/test.dart';
Expand Down Expand Up @@ -44,7 +44,7 @@ void _testGenerator(stagehand.Generator generator, Directory tempDir) {
var pubspecFile = new File(pubspecPath);

if (!pubspecFile.existsSync()) {
throw 'A pubspec much be defined!';
fail('A pubspec much be defined!');
}

Pub.get(runOptions: new RunOptions(workingDirectory: tempDir.path));
Expand Down
25 changes: 8 additions & 17 deletions tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,14 @@ test() => new TestRunner().testAsync(files: 'test/validate_templates.dart');
void _concatenateFiles(Directory src, File target) {
log('Creating ${target.path}');

List<String> results = [];

_traverse(src, '', results);

String str = results.map((s) => ' ${_toStr(s)}').join(',\n');
String str = _traverse(src, '').map((s) => ' ${_toStr(s)}').join(',\n');

target.writeAsStringSync("""
// Copyright (c) 2014, Google Inc. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
List<String> data = [
const List<String> data = const <String>[
${str}
];
""");
Expand All @@ -85,27 +81,22 @@ String _toStr(String s) {
}
}

void _traverse(Directory dir, String root, List<String> results) {
Iterable<String> _traverse(Directory dir, String root) sync* {
var files = _listSync(dir, recursive: false, followLinks: false);
for (FileSystemEntity entity in files) {
String name = path.basename(entity.path);

if (entity is Link) continue;

String name = path.basename(entity.path);
if (name == 'pubspec.lock') continue;
if (name.startsWith('.') && name != '.gitignore') continue;

if (entity is Directory) {
_traverse(entity, '${root}${name}/', results);
yield* _traverse(entity, '${root}${name}/');
} else {
File file = entity;
String fileType = _isBinaryFile(name) ? 'binary' : 'text';
String data = CryptoUtils.bytesToBase64(file.readAsBytesSync(),
yield '${root}${name}';
yield _isBinaryFile(name) ? 'binary' : 'text';
yield BASE64.encode((entity as File).readAsBytesSync(),
addLineSeparator: true);

results.add('${root}${name}');
results.add(fileType);
results.add(data);
}
}
}
Expand Down

0 comments on commit c43b37c

Please sign in to comment.