diff --git a/.analysis_options b/.analysis_options index e243eaf..ae7799e 100644 --- a/.analysis_options +++ b/.analysis_options @@ -1,4 +1,4 @@ analyzer: strong-mode: true exclude: - - bin/template \ No newline at end of file + - bin/template/** \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index c69216b..5ab1922 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +## 0.2.0 +* Add `init` command to create a config file inside an existing project +* Update `Angular2` +* move all libraries export to `lib/` +* simplify generated file name (no '_component.dart', '_service.dart'...) +* `sass` support +* `less` support +* refactor `Route` defintion +* bugfix + + ## 0.1.0 ### Add full application generation with `new` command diff --git a/README.md b/README.md index 6133636..424ef77 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ pub global run ng2gen:new app - `ng2gen service my_service` - `ng2gen pipe my_pipe` - `ng2gen route home /home_path` +- `ng2gen init` ## Create an Application diff --git a/bin/app.dart b/bin/app.dart index 85cffc8..8e78623 100644 --- a/bin/app.dart +++ b/bin/app.dart @@ -6,11 +6,11 @@ import "dart:io"; import 'dart:async'; import "package:dev_string_converter/dev_string_converter.dart"; -import "utils.dart"; import "package:stagehand/stagehand.dart"; import "package:stagehand/src/common.dart"; -import "app_template_data.dart" as template; import 'package:path/path.dart' as path; +import "app_template_data.dart" as template; +import "utils.dart"; class _DirectoryGeneratorTarget extends GeneratorTarget { final Directory dir; diff --git a/bin/app_template_data.dart b/bin/app_template_data.dart index 71b8fc1..5883b8e 100644 --- a/bin/app_template_data.dart +++ b/bin/app_template_data.dart @@ -1,68 +1,47 @@ -// 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. const List data = const [ ".gitignore", "text", "LnBhY2thZ2VzCnB1YnNwZWMubG9jawoucHViCnBhY2thZ2VzCmJ1aWxkCi5pZGVh", "angular.config.yaml", "text", - "cHJvamVjdDoKICBuYW1lOiAiX19wcm9qZWN0TmFtZV9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GVtcGxhdGVVcmw6ICJfX3Byb2plY3ROYW1lX18uaHRtbCIsCiAgICBkaXJlY3RpdmVzOiBjb25zdCBbUk9VVEVSX0RJUkVDVElWRVNdKQpAUm91dGVDb25maWcoY29uc3QgWwogIGNvbnN0IFJvdXRlKAogICAgICB1c2VBc0RlZmF1bHQ6IGZhbHNlLCBwYXRoOiAnL2hvbWUnLCBuYW1lOiAnSG9tZScsIGNvbXBvbmVudDogSG9tZVJvdXRlKQpdKQpjbGFzcyBBcHBDb21wb25lbnQge30K", - "lib/__projectName__.html", + "bGlicmFyeSBfX3Byb2plY3ROYW1lX187CgppbXBvcnQgJ3BhY2thZ2U6YW5ndWxhcjIvY29yZS5kYXJ0JzsKaW1wb3J0ICJwYWNrYWdlOmFuZ3VsYXIyL3JvdXRlci5kYXJ0IjsKaW1wb3J0ICJyb3V0ZXMuZGFydCI7CgpAQ29tcG9uZW50KAogICAgc2VsZWN0b3I6ICdteS1hcHAnLAogICAgdGVtcGxhdGVVcmw6ICJhcHAuaHRtbCIsCiAgICBkaXJlY3RpdmVzOiBjb25zdCA8ZHluYW1pYz5bUk9VVEVSX0RJUkVDVElWRVNdKQpAUm91dGVDb25maWcoY29uc3QgPGR5bmFtaWM+WwogIC8qSW5zZXJ0IFJvdXRlcyBoZXJlKi8KXSkKY2xhc3MgQXBwQ29tcG9uZW50IHt9Cg==", + "lib/app.html", "text", - "PGgxPk15IEZpcnN0IEFuZ3VsYXIgMiBBcHA8L2gxPgo8bmF2PgogICAgPGEgW3JvdXRlckxpbmtdPSJbJ0hvbWUnXSI+SG9tZTwvYT4KPC9uYXY+Cjxyb3V0ZXItb3V0bGV0Pjwvcm91dGVyLW91dGxldD4K", - "lib/components/components.dart", + "PGgxPk15IEZpcnN0IEFuZ3VsYXIgMiBBcHA8L2gxPgo8cm91dGVyLW91dGxldD48L3JvdXRlci1vdXRsZXQ+Cg==", + "lib/components.dart", "text", - "bGlicmFyeSBfX3Byb2plY3ROYW1lX18uY29tcG9uZW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ZXIgZXh0ZW5kcyBDb252ZXJ0ZXI8RGF0YSwgTWFwPiBpbXBsZW1lbnRzIE1vZGVsRW5jb2RlcjxEYXRhPiB7CiAgQG92ZXJyaWRlCiAgTWFwIGNvbnZlcnQoRGF0YSBpbnB1dCkgewogICAgdmFyIG1vZGVsID0ge307CgogICAgbW9kZWxbJ2ZvbyddID0gaW5wdXQuZm9vOwoKICAgIHJldHVybiBtb2RlbDsKICB9Cn0K", - "lib/directives/directives.dart", - "text", - "bGlicmFyeSBfX3Byb2plY3ROYW1lX18uZGlyZWN0aXZlczsK", - "lib/models/data.dart", + "", + "lib/directives.dart", "text", - "LyoqCiAqIENyZWF0ZWQgYnkgbGVqYXJkX2ggb24gMDYvMDUvMTYuCiAqLwoKY2xhc3MgRGF0YSB7CgogICAgU3RyaW5nIGZvbyA9ICJiYXIiOwoKfQ==", + "", "lib/models.dart", "text", - "bGlicmFyeSBfX3Byb2plY3ROYW1lX18ubW9kZWxzOwoKZXhwb3J0ICdtb2RlbHMvZGF0YS5kYXJ0Jzs=", - "lib/pipes/pipes.dart", - "text", - "bGlicmFyeSBfX3Byb2plY3ROYW1lX18ucGlwZXM7Cg==", - "lib/routes/home_route/home_route.css", - "text", "", - "lib/routes/home_route/home_route.dart", + "lib/pipes.dart", + "text", + "Cg==", + "lib/routes.dart", "text", - "Ly8gQ29weXJpZ2h0IChjKSAyMDE2LCA8eW91ciBuYW1lPi4gQWxsIHJpZ2h0cyByZXNlcnZlZC4gVXNlIG9mIHRoaXMgc291cmNlIGNvZGUKLy8gaXMgZ292ZXJuZWQgYnkgYSBCU0Qtc3R5bGUgbGljZW5zZSB0aGF0IGNhbiBiZSBmb3VuZCBpbiB0aGUgTElDRU5TRSBmaWxlLgoKaW1wb3J0ICdwYWNrYWdlOmFuZ3VsYXIyL2NvcmUuZGFydCc7CgpAQ29tcG9uZW50KAogIHNlbGVjdG9yOiAnaG9tZS1yb3V0ZScsCiAgdGVtcGxhdGU6ICcnJwogICAgICAgIDxwPgogICAgICAgICAgaG9tZS1yb3V0ZSB3b3JrcyEKICAgICAgICA8L3A+CiAgICAgICAgJycnLAogIHN0eWxlVXJsczogY29uc3QgWydob21lX3JvdXRlLmNzcyddKQpjbGFzcyBIb21lUm91dGUgaW1wbGVtZW50cyBPbkluaXQgewoKICBIb21lUm91dGUoKTsKCiAgbmdPbkluaXQoKSB7fQoKfQo=", - "lib/routes/routes.dart", + "Cg==", + "lib/services.dart", "text", - "bGlicmFyeSBfX3Byb2plY3ROYW1lX18ucm91dGVzOwoKZXhwb3J0ICJob21lX3JvdXRlL2hvbWVfcm91dGUuZGFydCI7Cg==", - "lib/services/services.dart", + "Cg==", + "lib/styles/styles.css", "text", - "bGlicmFyeSBfX3Byb2plY3ROYW1lX18uc2VydmljZXM7Cg==", + "Cg==", "pubspec.yaml", "text", - "bmFtZTogX19wcm9qZWN0TmFtZV9fCnZlcnNpb246IDAuMC4xCmRlc2NyaXB0aW9uOgphdXRob3I6CmhvbWVwYWdlOgoKZGVwZW5kZW5jaWVzOgogICAgYW5ndWxhcjI6IDIuMC4wLWJldGEuMTcKICAgIGJyb3dzZXI6IF4wLjEwLjAKICAgIGRhcnRfdG9fanNfc2NyaXB0X3Jld3JpdGVyOiBeMS4wLjEKCmRldl9kZXBlbmRlbmNpZXM6CiAgICBncmluZGVyOiAiXjAuOC4wKzIiCiAgICB0ZXN0OiAiXjAuMTIuMTMrMSIKICAgIHdhdGNoZXI6ICJeMC45LjcrMiIKICAgIHlhbWw6ICJeMi4xLjkiCiAgICBkb2dtYV9jb2RlZ2VuOiAnPj0wLjAuMiA8MC4xLjAnCgp0cmFuc2Zvcm1lcnM6CiAgICAtIGFuZ3VsYXIyOgogICAgICAgIGVudHJ5X3BvaW50czogd2ViL21haW4uZGFydAogICAgLSBkYXJ0X3RvX2pzX3NjcmlwdF9yZXdyaXRlcgogICAgLSAkZGFydDJqczoKICAgICAgICBtaW5pZnk6IHRydWUKICAgICAgICBjb21tYW5kTGluZU9wdGlvbn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jb25maWcgIT0gbnVsbCAgJiYgX2NvbmZpZy5jb250YWluc0tleSgic2VydmVyIikpIHsKICAgICAgcmV0dXJuIF9jb25maWdbInNlcnZlciJdWyJwb3J0Il07CiAgICB9CiAgICByZXR1cm4gbnVsbDsKICB9CgogIFN0cmluZyBnZXQgc2VydmVySG9zdG5hbWUgewogICAgaWYgKF9jb25maWcgIT0gbnVsbCAgJiYgX2NvbmZpZy5jb250YWluc0tleSgic2VydmVyIikpIHsKICAgICAgcmV0dXJuIF9jb25maWdbInNlcnZlciJdWyJob3N0bmFtZSJdOwogICAgfQogICAgcmV0dXJuIG51bGw7CiAgfQoKICBTdHJpbmcgZ2V0IGNvbXBvbmVudHNQYXRoIHsKICAgIGlmIChfY29uZmlnICE9IG51bGwgICYmIF9jb25maWcuY29udGFpbnNLZXkoInByb2plY3QiKSkgewogICAgICByZXR1cm4gX2NvbmZpZ1sicHJvamVjdCJdWyJjb21wb25lbnRzIl07CiAgICB9CiAgICByZXR1cm4gbnVsbDsKICB9CgogIFN0cmluZyBnZXQgc2VydmljZXNQYXRoIHsKICAgIGlmIChfY29uZmlnICE9IG51bGwgICYmIF9jb25maWcuY29udGFpbnNLZXkoInByb2plY3QiKSkgewogICAgICByZXR1cm4gX2NvbmZpZ1sicHJvamVjdCJdWyJzZXJ2aWNlcyJdOwogICAgfQogICAgcmV0dXJuIG51bGw7CiAgfQoKICBTdHJpbmcgZ2V0IHBpcGVzUGF0aCB7CiAgICBpZiAoX2NvbmZpZyAhPSBudWxsICAmJiBfY29uZmlnLmNvbnRhaW5zS2V5KCJwcm9qZWN0IikpIHsKICAgICAgcmV0dXJuIF9jb25maWdbInByb2plY3QiXVsicGlwZXMiXTsKICAgIH0KICAgIHJldHVybiBudWxsOwogIH0KCiAgU3RyaW5nIGdldCByb3V0ZXNQYXRoIHsKICAgIGlmIChfY29uZmlnICE9IG51bGwgICYmIF9jb25maWcuY29udGFpbnNLZXkoInByb2plY3QiKSkgewogICAgICByZXR1cm4gX2N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ndWxhcjIvcm91dGVyLmRhcnQiOwppbXBvcnQgInBhY2thZ2U6YW5ndWxhcjIvc3JjL3BsYXRmb3JtL2Jyb3dzZXIvbG9jYXRpb24vaGFzaF9sb2NhdGlvbl9zdHJhdGVneS5kYXJ0IjsKaW1wb3J0ICJwYWNrYWdlOmFuZ3VsYXIyL3BsYXRmb3JtL2NvbW1vbi5kYXJ0IjsKCmltcG9ydCAicGFja2FnZTpfX3Byb2plY3ROYW1lX18vYXBwLmRhcnQiOwoKYm9vbCBnZXQgaXNEZWJ1ZyA9PiAoY29uc3QgU3RyaW5nLmZyb21FbnZpcm9ubWVudCgiUFJPRFVDVElPTiIsIGRlZmF1bHRWYWx1ZTogImZhbHNlIikpICE9ICJ0cnVlIjsKCm1haW4oKSBhc3luYyB7CiAgaWYgKGlzRGVidWcpIHsKICAgIHJlZmxlY3Rvci50cmFja1VzYWdlKCk7CiAgfQogIENvbXBvbmVudFJlZiByZWYgPSBhd2FpdCBib290c3RyYXAoCiAgICAgIEFwcENvbXBvbmVudCwgW1JPVVRFUl9QUk9WSURFUlMsIGNvbnN0IFByb3ZpZGVyKExvY2F0aW9uU3RyYXRlZ3ksIHVzZUNsYXNzOiBIYXNoTG9jYXRpb25TdHJhdGVneSldKTsKCiAgaWYgKGlzRGVidWcpIHsKICAgIHByaW50KCJBcHBsaWNhdGlvbiBpbiBEZWJ1Z01vZGUiKTsKICAgIGVuYWJsZURlYnVnVG9vbHMocmVmKTsKICAgIHByaW50KCdVbnVzZWQga2V5czogJHtyZWZsZWN0b3IubGlzdFVudXNlZEtleXMoKX0nKTsKICB9Cn0K" ]; diff --git a/bin/component.dart b/bin/component.dart index 6f0698d..aa91e14 100644 --- a/bin/component.dart +++ b/bin/component.dart @@ -11,38 +11,39 @@ main(List args) async { if (config?.componentsPath != null) { path = "${config.componentsPath}/${toTableName(name)}"; - lib = "${config.componentsPath}/components.dart"; + lib = "lib/components.dart"; } - String dartPath = '$path/${toTableName(name)}_component.dart'; - String htmlPath = '$path/${toTableName(name)}_component.html'; - String cssPath = '$path/${toTableName(name)}_component.css'; + String prefix = config?.componentsPath != null ? "lib/" : ""; + String filePath = '$prefix$path/${toTableName(name)}'; + + String dartPath = '$filePath.dart'; + String htmlPath = '$filePath.html'; + String cssPath = '$filePath.${config.styleFileType}'; await writeInFile(dartPath, componentTemplateDart(name)); await writeInFile(htmlPath, componentTemplateHtml(name)); await createFile(cssPath); if (lib != null) { - addToLibrary("${toTableName(name)}/${toTableName(name)}_component.dart", lib); + addToLibrary("$path/${toTableName(name)}.dart", lib); } } String componentTemplateDart(String name) => - '''// Copyright (c) 2016, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - -import 'package:angular2/core.dart'; + '''import 'package:angular2/core.dart'; @Component( selector: '${toPolyName(name)}', - templateUrl: '${toTableName(name)}_component.html', - styleUrls: const ['${toTableName(name)}_component.css']) + templateUrl: '${toTableName(name)}.html', + styleUrls: const ['${toTableName(name)}.css']) class ${toUpperCamelCase(name)} implements OnInit { ${toUpperCamelCase(name)}(); - ngOnInit() {} + @override + void ngOnInit() {} } '''; diff --git a/bin/component_inline.dart b/bin/component_inline.dart index 210cb1c..d9fdd76 100644 --- a/bin/component_inline.dart +++ b/bin/component_inline.dart @@ -11,26 +11,26 @@ main(List args) async { if (config?.componentsPath != null) { path = "${config.componentsPath}/${toTableName(name)}"; - lib = "${config.componentsPath}/components.dart"; + lib = "lib/components.dart"; } - String dartPath = '$path/${toTableName(name)}_component.dart'; - String cssPath = '$path/${toTableName(name)}_component.css'; + String prefix = config?.componentsPath != null ? "lib/" : ""; + String filePath = '$prefix$path/${toTableName(name)}'; + + String dartPath = '$filePath.dart'; + String cssPath = '$filePath.${config.styleFileType}'; await writeInFile(dartPath, componentTemplateDart(name)); await createFile(cssPath); if (lib != null) { - addToLibrary("${toTableName(name)}/${toTableName(name)}_component.dart", lib); + addToLibrary("$path/${toTableName(name)}.dart", lib); } } String componentTemplateDart(String name) => - '''// Copyright (c) 2016, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - -import 'package:angular2/core.dart'; + '''import 'package:angular2/core.dart'; @Component( selector: '${toPolyName(name)}', @@ -39,12 +39,13 @@ import 'package:angular2/core.dart'; ${toPolyName(name)} works!

\'\'\', - styleUrls: const ['${toTableName(name)}_component.css']) + styleUrls: const ['${toTableName(name)}.css']) class ${toUpperCamelCase(name)} implements OnInit { ${toUpperCamelCase(name)}(); - ngOnInit() {} + @override + void ngOnInit() {} } '''; \ No newline at end of file diff --git a/bin/directive.dart b/bin/directive.dart index 2c28718..006ef48 100644 --- a/bin/directive.dart +++ b/bin/directive.dart @@ -11,23 +11,22 @@ main(List args) async { if (config?.directivesPath != null) { path = "${config.directivesPath}"; - lib = "${config.directivesPath}/directives.dart"; + lib = "lib/directives.dart"; } - String dartPath = '$path/${toTableName(name)}_directive.dart'; + String prefix = config?.directivesPath != null ? "lib/" : ""; + + String dartPath = '$prefix$path/${toTableName(name)}.dart'; await writeInFile(dartPath, directiveTemplate(name)); if (lib != null) { - addToLibrary("${toTableName(name)}_directive.dart", lib); + addToLibrary("$path/${toTableName(name)}.dart", lib); } } String directiveTemplate(String name) => ''' -// Copyright (c) 2016, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - import "package:angular2/core.dart"; @Directive( diff --git a/bin/init.dart b/bin/init.dart new file mode 100644 index 0000000..0b44a61 --- /dev/null +++ b/bin/init.dart @@ -0,0 +1,29 @@ +import 'dart:io'; +import 'package:yaml/yaml.dart'; +import "utils.dart"; + +main(List _) async { + File pubspec = new File("pubspec.yaml"); + if (!(await pubspec.exists())) { + output("'pubspec.yaml' not found.", Color.red); + } else { + File config = new File(config_file_name); + if (config.existsSync()) { + output("'$config_file_name' already exist.", Color.red); + } else { + config.writeAsString(configYaml); + } + } +} + +String get configYaml => +'''project: + root: "app.dart" + components: "lib/components" + directives: "lib/directives" + services: "lib/services" + routes: "lib/routes" + pipes: "lib/pipes" + sass: false + less: false + '''; diff --git a/bin/main.dart b/bin/main.dart index e16542c..5b8bd90 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -7,11 +7,16 @@ import 'pipe.dart' as pipe; import 'app.dart' as app; import 'component_inline.dart' as component_inline; import 'route.dart' as route; +import 'init.dart' as init; /// Creates a main(List args) { _showHelp(args, 0); switch(args[0]) { + case 'init': + _showHelp(args, 0); + init.main(args.getRange(1, args.length).toList()); + break; case 'component': _showHelp(args, 1); component.main(args.getRange(1, args.length).toList()); @@ -59,6 +64,7 @@ USAGE: service : create a new service. pipe : create a new pipe. route : create a new route. + init : init an existing project with ng2gen '''); exit(0); } diff --git a/bin/pipe.dart b/bin/pipe.dart index c314eb1..8818dcd 100644 --- a/bin/pipe.dart +++ b/bin/pipe.dart @@ -11,33 +11,33 @@ main(List args) async { if (config?.pipesPath != null) { path = "${config.pipesPath}"; - lib = "${config.pipesPath}/pipes.dart"; + lib = "lib/pipes.dart"; } - String dartPath = '$path/${toTableName(name)}_pipe.dart'; + String prefix = config?.pipesPath != null ? "lib/" : ""; + + String dartPath = '$prefix$path/${toTableName(name)}.dart'; await writeInFile(dartPath, pipeTemplate(name)); if (lib != null) { - addToLibrary("${toTableName(name)}_pipe.dart", lib); + addToLibrary("$path/${toTableName(name)}.dart", lib); } } String pipeTemplate(String name) => ''' -// Copyright (c) 2016, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - import "package:angular2/core.dart"; @Pipe( - name: '${toUpperCamelCase(name)}' + name: '${toLowerCamelCase(name)}' ) @Injectable() class ${toUpperCamelCase(name)} implements PipeTransform { const ${toUpperCamelCase(name)}(); + @override dynamic transform(dynamic value, [List args = null]) { return value; } diff --git a/bin/route.dart b/bin/route.dart index 93431dd..5449a07 100644 --- a/bin/route.dart +++ b/bin/route.dart @@ -8,41 +8,69 @@ import "component.dart"; ConfigFile config = new ConfigFile(); main(List args) async { + String name = args[0]; + String routePath = args[1]; + String lib; + String path = "${toTableName(name)}"; - String name = "${args[0]}-route"; - String lib; - String path = "${toTableName(name)}"; + if (config?.routesPath != null) { + path = "${config.routesPath}/${toTableName(name)}"; + lib = "lib/routes.dart"; + } - if (config?.routesPath != null) { - path = "${config.routesPath}/${toTableName(name)}"; - lib = "${config.routesPath}/routes.dart"; - } + String prefix = config?.routesPath != null ? "lib/" : ""; + String filePath = '$prefix$path/${toTableName(name)}'; - String dartPath = '$path/${toTableName(name)}_component.dart'; - String htmlPath = '$path/${toTableName(name)}_component.html'; - String cssPath = '$path/${toTableName(name)}_component.css'; + String dartPath = '$filePath.dart'; + String htmlPath = '$filePath.html'; + String cssPath = '$filePath.${config.styleFileType}'; - await writeInFile(dartPath, componentTemplateDart(name)); - await writeInFile(htmlPath, componentTemplateHtml(name)); - await createFile(cssPath); + await writeInFile(dartPath, componentRouteTemplateDart(name, routePath)); + await writeInFile(htmlPath, componentTemplateHtml(name)); + await createFile(cssPath); - if (lib != null) { - addToLibrary("${toTableName(name)}/${toTableName(name)}_component.dart", lib); - addToRouteConfig(toUpperCamelCase(name), toUpperCamelCase(args[0]), args[1]); - } + if (lib != null) { + addToLibrary("$path/${toTableName(name)}.dart", lib); + addToRouteConfig(toUpperCamelCase(name), config?.rootPath); + } +} + +String componentRouteTemplateDart(String name, String path) => '''import 'package:angular2/core.dart'; +import 'package:angular2/router.dart'; + +@Component( + selector: '${name.replaceAll("_", "-")}', + templateUrl: '${toTableName(name)}.html', + styleUrls: const ['${toTableName(name)}.css']) +class ${toUpperCamelCase(name)} implements OnInit { + + static const String route_name = "${toUpperCamelCase(name)}"; + static const String route_path = "$path"; + static const Route route = const Route(path: ${toUpperCamelCase(name)}.route_path, + component: ${toUpperCamelCase(name)}, + name: ${toUpperCamelCase(name)}.route_name); + + ${toUpperCamelCase(name)}(); + + @override + void ngOnInit() {} } +'''; -addToRouteConfig(String className, String name, String path) { - File rootComponent = new File("lib/${config.projectName}.dart"); +addToRouteConfig(String className, String rootPath) { + File rootComponent = new File("lib/$rootPath"); - if (rootComponent.existsSync()) { - String content = rootComponent.readAsStringSync(); - content = formatter.format(content); - content = content.replaceFirst("@RouteConfig(const [", ''' - @RouteConfig(const [ - const Route(useAsDefault: false, path: '$path', name: '$name', component: $className), + if (rootComponent.existsSync()) { + String content = rootComponent.readAsStringSync(); + content = formatter.format(content); + content = content.replaceFirst( + "/*Insert Routes here*/", + ''' + /*Insert Routes here*/ + $className.route, '''); - rootComponent.writeAsStringSync(formatter.format(content)); - } -} \ No newline at end of file + rootComponent.writeAsStringSync(formatter.format(content)); + output("Route Inserted into root component.\n", Color.yellow); + } +} diff --git a/bin/service.dart b/bin/service.dart index cca99eb..b85e732 100644 --- a/bin/service.dart +++ b/bin/service.dart @@ -11,23 +11,23 @@ main(List args) async { if (config?.servicesPath != null) { path = "${config.servicesPath}"; - lib = "${config.servicesPath}/services.dart"; + lib = "lib/services.dart"; } - String dartPath = '$path/${toTableName(name)}_service.dart'; + String prefix = config?.servicesPath != null ? "lib/" : ""; + + String dartPath = '$prefix$path/${toTableName(name)}.dart'; await writeInFile(dartPath, serviceTemplate(name)); if (lib != null) { - addToLibrary("${toTableName(name)}_service.dart", lib); + addToLibrary("$path/${toTableName(name)}", lib); } } String serviceTemplate(String name) => - '''// Copyright (c) 2016, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - + ''' import "package:angular2/core.dart"; @Injectable() diff --git a/bin/template/.analysis_options b/bin/template/.analysis_options index 09fde6e..b1c49b9 100644 --- a/bin/template/.analysis_options +++ b/bin/template/.analysis_options @@ -1,7 +1,5 @@ analyzer: strong-mode: true - exclude: - - lib/convert linter: rules: diff --git a/bin/template/angular.config.yaml b/bin/template/angular.config.yaml index 5a4a8ca..6e9cca5 100644 --- a/bin/template/angular.config.yaml +++ b/bin/template/angular.config.yaml @@ -1,10 +1,12 @@ project: - name: "__projectName__" - components: "lib/components" - directives: "lib/directives" - services: "lib/services" - routes: "lib/routes" - pipes: "lib/pipes" + root: "app.dart" + components: "components" + directives: "directives" + services: "services" + routes: "routes" + pipes: "pipes" + sass: false + less: false server: hostname: "0.0.0.0" diff --git a/bin/template/lib/__projectName__.dart b/bin/template/lib/__projectName__.dart deleted file mode 100644 index d70d210..0000000 --- a/bin/template/lib/__projectName__.dart +++ /dev/null @@ -1,24 +0,0 @@ -library __projectName__; - -import 'package:angular2/core.dart'; -import "package:angular2/router.dart"; - -export "models.dart"; -export "convert/convert.dart"; -export "services/services.dart"; -export "pipes/pipes.dart"; -export "directives/directives.dart"; -export "routes/routes.dart"; -export "components/components.dart"; - -import "routes/routes.dart"; - -@Component( - selector: 'my-app', - templateUrl: "__projectName__.html", - directives: const [ROUTER_DIRECTIVES]) -@RouteConfig(const [ - const Route( - useAsDefault: false, path: '/home', name: 'Home', component: HomeRoute) -]) -class AppComponent {} diff --git a/bin/template/lib/app.dart b/bin/template/lib/app.dart new file mode 100644 index 0000000..2258297 --- /dev/null +++ b/bin/template/lib/app.dart @@ -0,0 +1,14 @@ +library __projectName__; + +import 'package:angular2/core.dart'; +import "package:angular2/router.dart"; +import "routes.dart"; + +@Component( + selector: 'my-app', + templateUrl: "app.html", + directives: const [ROUTER_DIRECTIVES]) +@RouteConfig(const [ + /*Insert Routes here*/ +]) +class AppComponent {} diff --git a/bin/template/lib/__projectName__.html b/bin/template/lib/app.html similarity index 54% rename from bin/template/lib/__projectName__.html rename to bin/template/lib/app.html index 7928ea2..953fbf0 100644 --- a/bin/template/lib/__projectName__.html +++ b/bin/template/lib/app.html @@ -1,5 +1,2 @@

My First Angular 2 App

- diff --git a/bin/template/lib/routes/home_route/home_route.css b/bin/template/lib/components.dart similarity index 100% rename from bin/template/lib/routes/home_route/home_route.css rename to bin/template/lib/components.dart diff --git a/bin/template/lib/components/components.dart b/bin/template/lib/components/components.dart deleted file mode 100644 index 37eb8aa..0000000 --- a/bin/template/lib/components/components.dart +++ /dev/null @@ -1 +0,0 @@ -library __projectName__.components; diff --git a/bin/template/lib/convert/convert.dart b/bin/template/lib/convert/convert.dart deleted file mode 100644 index b195ded..0000000 --- a/bin/template/lib/convert/convert.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Generated by Dogma Dart. DO NOT MODIFY! -// 2016-05-06 21:32:36.052430 - -library __projectName__.convert.convert; - -//--------------------------------------------------------------------- -// Exports -//--------------------------------------------------------------------- - -export 'data_convert.dart'; - -//--------------------------------------------------------------------- -// Library contents -//--------------------------------------------------------------------- diff --git a/bin/template/lib/convert/data_convert.dart b/bin/template/lib/convert/data_convert.dart deleted file mode 100644 index 3938b92..0000000 --- a/bin/template/lib/convert/data_convert.dart +++ /dev/null @@ -1,46 +0,0 @@ -// Generated by Dogma Dart. DO NOT MODIFY! -// 2016-05-06 21:32:36.052430 - -library __projectName__.convert.data_convert; - -//--------------------------------------------------------------------- -// Standard libraries -//--------------------------------------------------------------------- - -import 'dart:convert'; - -//--------------------------------------------------------------------- -// Imports -//--------------------------------------------------------------------- - -import 'package:__projectName__/models.dart'; -import 'package:dogma_convert/convert.dart'; - -//--------------------------------------------------------------------- -// Library contents -//--------------------------------------------------------------------- - -/// A [ModelDecoder] for [Data]. -class DataDecoder extends Converter implements ModelDecoder { - @override - Data create() => new Data(); - @override - Data convert(Map input, [Data model]) { - model ??= create(); - - model.foo = input['foo']; - return model; - } -} - -/// A [ModelEncoder] for [Data]. -class DataEncoder extends Converter implements ModelEncoder { - @override - Map convert(Data input) { - var model = {}; - - model['foo'] = input.foo; - - return model; - } -} diff --git a/bin/template/lib/directives.dart b/bin/template/lib/directives.dart new file mode 100644 index 0000000..e69de29 diff --git a/bin/template/lib/directives/directives.dart b/bin/template/lib/directives/directives.dart deleted file mode 100644 index 37a08d4..0000000 --- a/bin/template/lib/directives/directives.dart +++ /dev/null @@ -1 +0,0 @@ -library __projectName__.directives; diff --git a/bin/template/lib/models.dart b/bin/template/lib/models.dart index 5accbe3..e69de29 100644 --- a/bin/template/lib/models.dart +++ b/bin/template/lib/models.dart @@ -1,3 +0,0 @@ -library __projectName__.models; - -export 'models/data.dart'; \ No newline at end of file diff --git a/bin/template/lib/models/data.dart b/bin/template/lib/models/data.dart deleted file mode 100644 index e372f7b..0000000 --- a/bin/template/lib/models/data.dart +++ /dev/null @@ -1,9 +0,0 @@ -/** - * Created by lejard_h on 06/05/16. - */ - -class Data { - - String foo = "bar"; - -} \ No newline at end of file diff --git a/bin/template/web/styles.css b/bin/template/lib/pipes.dart similarity index 100% rename from bin/template/web/styles.css rename to bin/template/lib/pipes.dart diff --git a/bin/template/lib/pipes/pipes.dart b/bin/template/lib/pipes/pipes.dart deleted file mode 100644 index 8b73016..0000000 --- a/bin/template/lib/pipes/pipes.dart +++ /dev/null @@ -1 +0,0 @@ -library __projectName__.pipes; diff --git a/bin/template/lib/routes.dart b/bin/template/lib/routes.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/bin/template/lib/routes.dart @@ -0,0 +1 @@ + diff --git a/bin/template/lib/routes/home_route/home_route.dart b/bin/template/lib/routes/home_route/home_route.dart deleted file mode 100644 index 171bc79..0000000 --- a/bin/template/lib/routes/home_route/home_route.dart +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) 2016, . All rights reserved. Use of this source code -// is governed by a BSD-style license that can be found in the LICENSE file. - -import 'package:angular2/core.dart'; - -@Component( - selector: 'home-route', - template: ''' -

- home-route works! -

- ''', - styleUrls: const ['home_route.css']) -class HomeRoute implements OnInit { - - HomeRoute(); - - ngOnInit() {} - -} diff --git a/bin/template/lib/routes/routes.dart b/bin/template/lib/routes/routes.dart deleted file mode 100644 index 3c444ae..0000000 --- a/bin/template/lib/routes/routes.dart +++ /dev/null @@ -1,3 +0,0 @@ -library __projectName__.routes; - -export "home_route/home_route.dart"; diff --git a/bin/template/lib/services.dart b/bin/template/lib/services.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/bin/template/lib/services.dart @@ -0,0 +1 @@ + diff --git a/bin/template/lib/services/services.dart b/bin/template/lib/services/services.dart deleted file mode 100644 index c9a8176..0000000 --- a/bin/template/lib/services/services.dart +++ /dev/null @@ -1 +0,0 @@ -library __projectName__.services; diff --git a/bin/template/lib/styles/styles.css b/bin/template/lib/styles/styles.css new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/bin/template/lib/styles/styles.css @@ -0,0 +1 @@ + diff --git a/bin/template/pubspec.yaml b/bin/template/pubspec.yaml index d0ea03c..bcfab31 100644 --- a/bin/template/pubspec.yaml +++ b/bin/template/pubspec.yaml @@ -5,19 +5,24 @@ author: homepage: dependencies: - angular2: 2.0.0-beta.17 + angular2: ^2.0.0-beta.22 browser: ^0.10.0 dart_to_js_script_rewriter: ^1.0.1 + # sass_transformer: ^0.1.0 ## if you use sass + # less_dart: ^0.3.4 ## if you use less dev_dependencies: - grinder: "^0.8.0+2" test: "^0.12.13+1" - watcher: "^0.9.7+2" yaml: "^2.1.9" - dogma_codegen: '>=0.0.2 <0.1.0' transformers: + #- sass_transformer ## if you use sass + #- less_dart ## if you use less - angular2: + platform_directives: + - 'package:angular2/common.dart#COMMON_DIRECTIVES' + platform_pipes: + - 'package:angular2/common.dart#COMMON_PIPES' entry_points: web/main.dart - dart_to_js_script_rewriter - $dart2js: diff --git a/bin/template/tool/grind.dart b/bin/template/tool/grind.dart deleted file mode 100644 index 0c51a83..0000000 --- a/bin/template/tool/grind.dart +++ /dev/null @@ -1,164 +0,0 @@ -import "dart:io"; -import "package:grinder/grinder.dart"; -import "package:yaml/yaml.dart"; -import "package:dogma_codegen/build.dart" as dogma_build; -import "package:watcher/watcher.dart"; - -class ConfigFile { - static Map _config; - - ConfigFile() { - if (_config == null) { - File _configFile = new File("angular.config.yaml"); - if (_configFile.existsSync()) { - _config = loadYaml(_configFile.readAsStringSync()) as Map; - } - } - } - - String get projectName { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["name"]; - } - return null; - } - - int get serverPort { - if (_config != null && _config.containsKey("server")) { - return _config["server"]["port"]; - } - return null; - } - - String get serverHostname { - if (_config != null && _config.containsKey("server")) { - return _config["server"]["hostname"]; - } - return null; - } - - String get componentsPath { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["components"]; - } - return null; - } - - String get servicesPath { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["services"]; - } - return null; - } - - String get pipesPath { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["pipes"]; - } - return null; - } - - String get routesPath { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["routes"]; - } - return null; - } - - String get directivesPath { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["directives"]; - } - return null; - } - - String get modelsPath { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["models"]; - } - return null; - } -} - -ConfigFile config = new ConfigFile(); - -main(List args) async => await grind(args); - -@Task("models") -codegen() async { - await dogma_build.build([], - modelLibrary: "lib/models.dart", - modelPath: "lib/models/", - convertPath: "lib/convert", - convertLibrary: "lib/convert/convert.dart", - mapper: false, - unmodifiable: false); -} - -@Task("watchModels") -watchModels() { - new Watcher("lib/models").events.listen((WatchEvent _) { - print("[codegen]"); - codegen(); - }); -} - -@Task("serve") -@Depends(codegen, watchModels) -serve() async { - Process _server = await Process.start( - "pub", - [ - "serve", - "--hostname=${config.serverHostname}", - "--port=${config.serverPort}" - ], - runInShell: true); - print("Serving http://${config.serverHostname}:${config.serverPort}"); - - Process dartium; - - _server.stdout.listen((List data) async { - String message = new String.fromCharCodes(data); - stdout.write(message); - if (message == "Build completed successfully\n" && dartium == null) { - dartium = await Process.start( - "dartium", ["http://${config.serverHostname}:${config.serverPort}"], - runInShell: true); - } - }); - - _server.stderr.listen((List data) { - stderr.write(new String.fromCharCodes(data)); - }); - await _server.exitCode; -} - -@Task("doc") -doc() { - DartDoc.doc(); -} - -@Task("build") -build() async { - Process p = await Process.start("pub", ["build", "--mode=release", "-DPRODUCTION=true"]); - p.stdout.listen((List data) async { - stdout.write(new String.fromCharCodes(data)); - }); - p.stderr.listen((List data) { - stderr.write(new String.fromCharCodes(data)); - }); - await p.exitCode; -} - -@Task("test") -test() { - new PubApp.local('test').run([]); -} - -@Task("deploy") -@Depends(test, doc, codegen, build) -deploy() async {} - -@Task("clean") -void clean() => defaultClean(); \ No newline at end of file diff --git a/bin/template/web/index.html b/bin/template/web/index.html index 9ab9ddb..56ac296 100644 --- a/bin/template/web/index.html +++ b/bin/template/web/index.html @@ -3,7 +3,7 @@ Angular 2 - + diff --git a/bin/template/web/main.dart b/bin/template/web/main.dart index f3aa42a..049f462 100644 --- a/bin/template/web/main.dart +++ b/bin/template/web/main.dart @@ -7,7 +7,7 @@ import "package:angular2/router.dart"; import "package:angular2/src/platform/browser/location/hash_location_strategy.dart"; import "package:angular2/platform/common.dart"; -import "package:__projectName__/__projectName__.dart"; +import "package:__projectName__/app.dart"; bool get isDebug => (const String.fromEnvironment("PRODUCTION", defaultValue: "false")) != "true"; diff --git a/bin/utils.dart b/bin/utils.dart index 9ba37a8..f7013e5 100644 --- a/bin/utils.dart +++ b/bin/utils.dart @@ -3,6 +3,8 @@ import "dart:async"; import "package:dart_style/dart_style.dart"; import "package:yaml/yaml.dart"; +const String config_file_name = "angular.config.yaml"; + Future createFile(String path) async { File file = new File(path); if (!file.existsSync()) { @@ -51,7 +53,7 @@ void output(String input, Color color) { addToLibrary(String name, String libPath) { File lib = new File(libPath); if (!lib.existsSync()) { - throw "Library at $libPath does not exist"; + output("Creating library '$libPath'.\n", Color.gray); } lib.writeAsStringSync( @@ -73,12 +75,6 @@ class ConfigFile { } } - String get projectName { - if (_config != null && _config.containsKey("project")) { - return _config["project"]["name"]; - } - return null; - } int get serverPort { if (_config != null && _config.containsKey("server")) { @@ -94,6 +90,20 @@ class ConfigFile { return null; } + bool get useSass { + if (_config != null &&_config.containsKey("project")) { + return _config["project"]["sass"]; + } + return null; + } + + bool get useLess { + if (_config != null &&_config.containsKey("project")) { + return _config["project"]["less"]; + } + return null; + } + String get componentsPath { if (_config != null &&_config.containsKey("project")) { return _config["project"]["components"]; @@ -136,6 +146,22 @@ class ConfigFile { return null; } + String get rootPath { + if (_config != null && _config.containsKey("project")) { + return _config["project"]["root"]; + } + return null; + } + + String get styleFileType { + if (useSass == true) { + return "scss"; + } else if (useLess == true) { + return "less"; + } + return "css"; + } + } StreamSubscription _progressSubscription; diff --git a/tool/grind.dart b/tool/grind.dart index 2e1aa44..b355a5a 100644 --- a/tool/grind.dart +++ b/tool/grind.dart @@ -26,9 +26,6 @@ void _concatenateFiles(Directory src, File target) { 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. const List data = const [ ${str} ];