diff --git a/go-cli/pubspec.yaml b/go-cli/pubspec.yaml index f2725f4a..dfc961c2 100644 --- a/go-cli/pubspec.yaml +++ b/go-cli/pubspec.yaml @@ -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: diff --git a/go-cli/src/build/build_page_list.dart b/go-cli/src/build/build_page_list.dart index 212acffd..1b89413a 100644 --- a/go-cli/src/build/build_page_list.dart +++ b/go-cli/src/build/build_page_list.dart @@ -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 buildPageListJson() async { List childList = await readeDirChildren(TARGET_PAGE_DIC, false); List pagePathList = []; @@ -55,36 +67,49 @@ Future buildPageListJson() async { } String renderPagesDart(List> 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 standardPages; Map getPages() { return { -"""; - - for (int i = 0; i < data.length; i++) { - Map 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> 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 formatData = { + "pages": data + }; + + var output = template.renderString(formatData); + print(output); + + +// } +return output; - return head + foot; } Future checkPage(String path) async { List files = [ diff --git a/go-cli/src/cli_command_runder.dart b/go-cli/src/cli_command_runder.dart index b27b85f7..76105449 100644 --- a/go-cli/src/cli_command_runder.dart +++ b/go-cli/src/cli_command_runder.dart @@ -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 { negatable: false, help: 'Prints the version of goCi.'); addCommand(CreateDemoCommand()); addCommand(CreatePageCommand()); - addCommand(WatchCommand()); + addCommand(Build()); } diff --git a/go-cli/src/command/build.dart b/go-cli/src/command/build.dart new file mode 100644 index 00000000..5502cc33 --- /dev/null +++ b/go-cli/src/command/build.dart @@ -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 { + @override + final name = 'build'; + @override + final description = '生成索引等'; + + + @override + Future run() async { + buildPageListJson(); + buildDemoListJson(); + return 0; + } +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 38f89897..d1cc0eb2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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()); diff --git a/lib/model/widget.dart b/lib/model/widget.dart index 25e0a9af..59605e86 100644 --- a/lib/model/widget.dart +++ b/lib/model/widget.dart @@ -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); diff --git a/lib/standard_pages/.pages.json b/lib/standard_pages/.pages.json index e5fdc536..ee0bce1f 100644 --- a/lib/standard_pages/.pages.json +++ b/lib/standard_pages/.pages.json @@ -1,11 +1 @@ -[ - { - "name": "standard", - "screenShot": "", - "author": "sanfan", - "title": "介绍页", - "email": "hanxu317@qq.com", - "desc": "desc", - "id": "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096" - } -] \ No newline at end of file +[{"name":"standard","screenShot":"","author":"sanfan","title":"介绍页","email":"hanxu317@qq.com","desc":"desc","id":"ee4feb8e_32ae_4241_9c8a_5c9e1f92b096"}] \ No newline at end of file diff --git a/lib/standard_pages/index.dart b/lib/standard_pages/index.dart index 9d537fdd..bf6a71bd 100644 --- a/lib/standard_pages/index.dart +++ b/lib/standard_pages/index.dart @@ -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 standardPages; Map 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> getLocalList() { + return [ + {}, + { "id": "ee4feb8e_32ae_4241_9c8a_5c9e1f92b096", "name": "standard", "email": "hanxu317@qq.com", "author": "sanfan"} + ]; + } - \ No newline at end of file +} + + \ No newline at end of file