adding packages
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// Copyright 2017 Google Inc.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import '../file_reader.dart';
|
||||
import '../generator.dart';
|
||||
import '../page_object_data.dart';
|
||||
import 'package:ngflutter/src/visitors/component_info.dart';
|
||||
|
||||
/// Generator for page object.
|
||||
class PoGenerator extends Generator {
|
||||
static const _templateFolder = 'pageobject';
|
||||
static const _templateFileName = 'po.dart.mustache';
|
||||
|
||||
final String componentPath;
|
||||
final String poClassName;
|
||||
final String poFileName;
|
||||
final PageObjectData pageObjectData;
|
||||
|
||||
PoGenerator._(this.componentPath, this.poClassName, this.poFileName,
|
||||
this.pageObjectData, String destinationFolder)
|
||||
: super(destinationFolder);
|
||||
|
||||
factory PoGenerator(ComponentInfo componentInfo, String componentPath,
|
||||
String poClassName, String destinationFolder) {
|
||||
PageObjectData pageObjectData;
|
||||
|
||||
if (componentInfo.inlineTemplate == null) {
|
||||
// componentInfo.templatePath is not null here
|
||||
|
||||
var componentTemplateFilePath =
|
||||
path.join(path.dirname(componentPath), componentInfo.templatePath);
|
||||
|
||||
pageObjectData = new PageObjectData(
|
||||
FileReader.reader.readAsString(componentTemplateFilePath));
|
||||
} else {
|
||||
pageObjectData = new PageObjectData(componentInfo.inlineTemplate);
|
||||
}
|
||||
|
||||
return new PoGenerator._(
|
||||
componentPath,
|
||||
poClassName,
|
||||
'${path.basenameWithoutExtension(componentPath)}_po.dart',
|
||||
pageObjectData,
|
||||
destinationFolder);
|
||||
}
|
||||
|
||||
// Gets a map from template file name to target file name.
|
||||
Map<String, String> _getTemplateTargetPaths() {
|
||||
var results = <String, String>{};
|
||||
|
||||
results[path.join(_templateFolder, _templateFileName)] = poFileName;
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@override
|
||||
Future generate() async {
|
||||
await renderAndWriteTemplates(_getTemplateTargetPaths());
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> toMap() {
|
||||
return {
|
||||
"componentPath": componentPath,
|
||||
"poClassName": poClassName,
|
||||
"poFileName": poFileName
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2017 Google Inc.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
import '../generator.dart';
|
||||
import 'widget.dart';
|
||||
|
||||
/// Generator for sample Flutter project.
|
||||
class ProjectGenerator extends Generator {
|
||||
static const _templateFolder = 'project';
|
||||
static final List<String> _templateFilePaths = [
|
||||
path.join('web', 'index.html.mustache'),
|
||||
path.join('lib', 'main.dart.mustache'),
|
||||
'analysis_options.yaml',
|
||||
'.gitignore',
|
||||
'pubspec.yaml.mustache',
|
||||
];
|
||||
|
||||
/// Project name in format abc_bcd.
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
/// Root component of this project.
|
||||
final WidgetGenerator component;
|
||||
|
||||
ProjectGenerator._(
|
||||
this.name, this.description, this.component, String destinationFolder)
|
||||
: super(destinationFolder);
|
||||
|
||||
factory ProjectGenerator(ReCase projectEntityName, String destinationFolder,
|
||||
ReCase componentClassEntityName) {
|
||||
destinationFolder =
|
||||
path.join(destinationFolder, projectEntityName.snakeCase);
|
||||
var component = new WidgetGenerator(
|
||||
componentClassEntityName, path.join(destinationFolder, 'lib/ui/home'));
|
||||
|
||||
return new ProjectGenerator._(projectEntityName.snakeCase,
|
||||
projectEntityName.titleCase, component, destinationFolder);
|
||||
}
|
||||
|
||||
// Gets a map from template file name to target file name.
|
||||
Map<String, String> _getTemplateTargetPaths() {
|
||||
var results = <String, String>{};
|
||||
for (final templatePath in _templateFilePaths) {
|
||||
results[path.join(_templateFolder, templatePath)] =
|
||||
templatePath.replaceAll('.mustache', '');
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@override
|
||||
Future generate() async {
|
||||
await renderAndWriteTemplates(_getTemplateTargetPaths());
|
||||
await component.generate();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> toMap() {
|
||||
return {
|
||||
"name": name,
|
||||
"description": description,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
// Copyright 2017 Google Inc.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:ngflutter/src/project_model.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import '../generator.dart';
|
||||
import 'po.dart';
|
||||
|
||||
/// Generator for component test.
|
||||
class TestGenerator extends Generator {
|
||||
static const _templateFolder = 'test';
|
||||
static const _templateFileName = 'test.dart.mustache';
|
||||
|
||||
static final _suffixPattern = new RegExp(r'(Component|View|PO|UnitTestPO)*$');
|
||||
|
||||
final String tag;
|
||||
final String componentPath;
|
||||
final ProjectModel projectModel;
|
||||
|
||||
final PoGenerator poGenerator;
|
||||
|
||||
TestGenerator._(this.tag, this.componentPath, this.projectModel,
|
||||
this.poGenerator, String destinationFolder)
|
||||
: super(destinationFolder);
|
||||
|
||||
factory TestGenerator(String tag, String componentPath, String className,
|
||||
String destinationFolder) {
|
||||
var projectModel =
|
||||
new ProjectModel('.packages', 'pubspec.yaml', componentPath, className);
|
||||
var poClassName =
|
||||
projectModel.componentClassName.replaceAll(_suffixPattern, '') + 'PO';
|
||||
var poGenerator = new PoGenerator(
|
||||
projectModel.components[projectModel.componentClassName],
|
||||
componentPath,
|
||||
poClassName,
|
||||
destinationFolder);
|
||||
|
||||
return new TestGenerator._(
|
||||
tag, componentPath, projectModel, poGenerator, destinationFolder);
|
||||
}
|
||||
|
||||
// Gets a map from template file name to target file name.
|
||||
Map<String, String> _getTemplateTargetPaths() {
|
||||
var results = <String, String>{};
|
||||
|
||||
results[path.join(_templateFolder, _templateFileName)] =
|
||||
'${path.basenameWithoutExtension(componentPath)}_test.dart';
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@override
|
||||
Future generate() async {
|
||||
await renderAndWriteTemplates(_getTemplateTargetPaths());
|
||||
await poGenerator.generate();
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> toMap() {
|
||||
return {
|
||||
"tag": tag,
|
||||
"componentPath": componentPath,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2017 Google Inc.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:recase/recase.dart';
|
||||
|
||||
import '../generator.dart';
|
||||
|
||||
/// Generator for Flutter Widget.
|
||||
class WidgetGenerator extends Generator {
|
||||
static const _templateFolder = 'widgets';
|
||||
static const List<String> _templateFileNames = const [
|
||||
'widget.dart.mustache',
|
||||
];
|
||||
|
||||
/// Class name of this Widget.
|
||||
final String className;
|
||||
|
||||
final String selector;
|
||||
|
||||
/// Widget file name without extension.
|
||||
final String targetName;
|
||||
|
||||
WidgetGenerator._(
|
||||
this.className, this.selector, this.targetName, String destinationFolder)
|
||||
: super(destinationFolder);
|
||||
|
||||
factory WidgetGenerator(
|
||||
ReCase classEntityName,
|
||||
String destinationFolder,
|
||||
) {
|
||||
return new WidgetGenerator._(
|
||||
classEntityName.pascalCase,
|
||||
classEntityName.paramCase,
|
||||
classEntityName.snakeCase,
|
||||
destinationFolder);
|
||||
}
|
||||
|
||||
// Gets a map from template file name to target file name.
|
||||
Map<String, String> _getTemplateTargetPaths() {
|
||||
var results = <String, String>{};
|
||||
for (String templateFileName in _templateFileNames) {
|
||||
final _template = path.join(_templateFolder, templateFileName);
|
||||
final _path = '$targetName.${templateFileName.split('.')[1]}';
|
||||
print('Path: $_template -> $_path');
|
||||
results[_template] = _path;
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@override
|
||||
Future generate() async {
|
||||
await renderAndWriteTemplates(_getTemplateTargetPaths());
|
||||
}
|
||||
|
||||
@override
|
||||
Map<String, String> toMap() {
|
||||
return {
|
||||
"className": className,
|
||||
"selector": selector,
|
||||
"targetName": targetName,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user