This commit is contained in:
sanfan.hx
2019-07-31 17:36:56 +08:00
parent c9a9a991b0
commit a75269d383
8 changed files with 98 additions and 38 deletions

View File

@ -17,6 +17,7 @@ dependencies:
args: '^1.5.1'
dart_inquirer: '^1.0.0'
watcher: ^0.9.7+10
mustache: ^1.1.1
dev_dependencies:

View File

@ -1,11 +1,23 @@
import 'dart:io';
import 'dart:convert';
import 'package:mustache/mustache.dart';
import 'package:path/path.dart' as p;
import '../../utils/util.dart';
import '../config.dart';
import '../exception/demo.dart';
String prettyJson(Map json) {
String res = "{";
json.forEach((k, v) {
res += (
"\t'$k': '$v'");
});
res +='}';
return res;
}
Future<List> buildPageListJson() async {
List<FileSystemEntity> childList = await readeDirChildren(TARGET_PAGE_DIC, false);
List<String> pagePathList = [];
@ -55,36 +67,49 @@ Future<List> buildPageListJson() async {
}
String renderPagesDart(List<Map<String, dynamic>> data) {
// 自定义前缀 避免出现数字非法字符等
String pre = "StandardPage";
String head = '';
String foot = """
print('data>>> $data');
var source = '''
{{# pages }}
import '{{ name }}_{{ author }}_{{ id }}/index.dart' as StandardPage_{{ name }}_{{ id }};
{{/ pages }}
class StandardPages {
Map<String, String> standardPages;
Map<String, String> getPages() {
return {
""";
for (int i = 0; i < data.length; i++) {
Map<String, dynamic> item = data[i];
String demoImportName = '${item['name']}_${item['id']}';
head += "import '${item['name']}_${item['author']}_${item['id']}/index.dart' as ${pre}_$demoImportName;\r\n";
foot += "\t\t\t'${item['id']}': ${pre}_${demoImportName}.getMd()";
if (i != data.length - 1) {
foot += ',\r\n';
}
}
foot += """\r
"0": "0" {{# pages }},
"{{ id }}" : StandardPage_{{ name }}_{{ id }}.getMd()
{{/ pages }}
};
}
}
List<Map<String, String>> getLocalList() {
return [
{}{{# pages }},
{ "id": "{{ id }}", "name": "{{ name }}", "email": "{{ email }}", "author": "{{ author }}"}
{{/ pages }}
];
}
""";
}
''';
var template = new Template(source, name: 'template-filename.html');
// print(prettyJson(data[0]));
// 自定义前缀 避免出现数字非法字符等
String pre = "StandardPage";
Map<String, List> formatData = {
"pages": data
};
var output = template.renderString(formatData);
print(output);
// }
return output;
return head + foot;
}
Future<bool> checkPage(String path) async {
List files = [

View File

@ -6,6 +6,7 @@ import './version.dart';
import './command/create_demo.dart';
import './command/create_page.dart';
import './command/watch_md.dart';
import './command/build.dart';
@ -17,7 +18,7 @@ class _CommandRunner extends CommandRunner<int> {
negatable: false, help: 'Prints the version of goCi.');
addCommand(CreateDemoCommand());
addCommand(CreatePageCommand());
addCommand(WatchCommand());
addCommand(Build());
}

View File

@ -0,0 +1,32 @@
//
// Created with Android Studio.
// User: 三帆
// Date: 30/07/2019
// Time: 16:51
// email: sanfan.hx@alibaba-inc.com
// target: build
//
import 'package:args/command_runner.dart';
import '../build/build_demo_list.dart';
import '../build/build_page_list.dart';
import 'dart:async';
class Build extends Command<int> {
@override
final name = 'build';
@override
final description = '生成索引等';
@override
Future<int> run() async {
buildPageListJson();
buildDemoListJson();
return 0;
}
}

View File

@ -191,7 +191,10 @@ void main() async {
new SearchHistoryList(sp);
await DataUtils.getWidgetTreeList().then((List json) {
Application.widgetTree = WidgetTree.buildWidgetTree(json);
if (Application.env == ENV.DEV) {
}
print("Application.widgetTree>>>> ${Application.widgetTree}");
});
db = Provider.db;
runApp(new MyApp());

View File

@ -297,7 +297,6 @@ class WidgetTree {
current = CategoryComponent(id: 0, name: 'root', parentId: null, children: []);
}
json.forEach((item) {
// 归属分类级别
if (['root', 'category'].indexOf(item['type']) != -1) {
CategoryComponent cate = CategoryComponent.fromJson(item);

View File

@ -1,11 +1 @@
[
{
"name": "standard",
"screenShot": "",
"author": "sanfan",
"title": "介绍页",
"email": "hanxu317@qq.com",
"desc": "desc",
"id": "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096"
}
]
[{"name":"standard","screenShot":"","author":"sanfan","title":"介绍页","email":"hanxu317@qq.com","desc":"desc","id":"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096"}]

View File

@ -1,11 +1,20 @@
import 'standard_sanfan_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096/index.dart' as StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096;
class StandardPages {
Map<String, String> standardPages;
Map<String, String> getPages() {
return {
'ee4feb8e_32ae_4241_9c8a_5c9e1f92b096': StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096.getMd()
"0": "0" ,
"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096" : StandardPage_standard_ee4feb8e_32ae_4241_9c8a_5c9e1f92b096.getMd()
};
}
}
List<Map<String, String>> getLocalList() {
return [
{},
{ "id": "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096", "name": "standard", "email": "hanxu317@qq.com", "author": "sanfan"}
];
}
}