Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular route subgenerator and test added #162

Closed
wants to merge 2 commits into from
Closed

Angular route subgenerator and test added #162

wants to merge 2 commits into from

Conversation

UndeadBaneGitHub
Copy link
Contributor

No description provided.

state('<%= slugifiedName %>', {
url: '/<%= slugifiedRoutePath %>',
templateUrl: 'modules/<%= slugifiedModuleName %>/views/<%= slugifiedViewName %>.client.view.html'
}).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New Line

@codydaig
Copy link
Member

Left some line comments.
Don't forget to squash commit.
Otherwise, LGTM.

@codydaig codydaig self-assigned this Dec 19, 2015
@UndeadBaneGitHub
Copy link
Contributor Author

@codydaig Regarding new line in the end of angular-route/templates/_.client.route.js - there should be none, as this template is inserted during the generation into an existing file, and newline will break the code.
Also, I found a bug in template, fixing.

state('<%= slugifiedName %>', {
url: '/<%= slugifiedRoutePath %>',
templateUrl: 'modules/<%= slugifiedModuleName %>/client/views/<%= slugifiedViewName %>.client.view.html'
}).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, why newline in a partial, that is used to replace a
$stateProvider. string in original file?
Newline in the end would just ruin the idea.

2015-12-21 1:38 GMT+03:00 Ilan Biala [email protected]:

In angular-route/templates/_.client.route.js
#162 (comment)
:

@@ -0,0 +1,5 @@
+$stateProvider.

  • state('<%= slugifiedName %>', {
  • url: '/<%= slugifiedRoutePath %>',
  • templateUrl: 'modules/<%= slugifiedModuleName %>/client/views/<%= slugifiedViewName %>.client.view.html'
  • }).

newline


Reply to this email directly or view it on GitHub
https://github.com/meanjs/generator-meanjs/pull/162/files#r48109358.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do this get pulled into that makes it a partial? Also, why does it end with a .?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilanbiala It ends with a . exactly because it's a partial. Look up _.client.routes.js - that's a template for routes file, which should contain many of them. If the file already exists, this partial is taken instead, and inserted into an already existing routes file. See index.js, line 89 and below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this implemented? How does it work? What is the goal and the end result?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, see angular-route/index.js, renderRoute function:

  renderRoute: function () {
    var routesFilePath = process.cwd() + '/modules/' + this.slugifiedModuleName + '/client/config/' + this.slugifiedModuleName + '.client.routes.js';

    // If routes file exists we add a new state otherwise we render a new one
    if (fs.existsSync(routesFilePath)) {
      // Read the source routes file content
      var routesFileContent = this.readFileAsString(routesFilePath);

      // Append the new state
      routesFileContent = routesFileContent.replace('$stateProvider.', this.engine(this.read('_.client.route.js'), this));

      // Save route file
      this.writeFileFromString(routesFileContent, routesFilePath);
    } else {
      this.template('_.client.routes.js', 'modules/' + this.slugifiedModuleName + '/client/config/' + this.slugifiedModuleName + '.client.routes.js')
    }
  }

The code is quite well commented, but I will repeat the idea here:

  1. For module name foo check, that foo.client.routes.js already exists
    2a. If it does, render the partial _.client.route.js and insert the rendered contents with new route description into an existing foo.client.routes.js
    2b. If it does not exist, render template _.client.routes.js and save rendered result as foo.client.routes.js

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@UndeadBaneGitHub @codydaig shouldn't any code be based on our using ui-router and not ng-route? I don't think we are using ng-route at all...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilanbiala Ehm... But it is based on ui-router, hence $stateProvider. Old ngRoute uses $routeProvider.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh sorry, I thought you were actually referring to angular-route code..my mistake. Can you briefly detail all the possible scenarios and what happens? I just want to make sure we didn't miss one and there is nothing better for each scenario.

@codydaig
Copy link
Member

@ilanbiala LGTY?

@ilanbiala
Copy link
Member

Only thing I'm worried about is some sort of scenario not working? @UndeadBaneGitHub can you maybe add a test for each scenario? For example, for the one where a file already exists, maybe create a file in the test that has xyz code, and then expect abc code after? That will ensure it works properly even in those cases.

@UndeadBaneGitHub
Copy link
Contributor Author

Fixed! Although, need help with squashing: if I do it, then conflicts emerge, because pull requests have been merged, which is kinda strange.

@@ -34,4 +34,4 @@ gulp.task('mocha', function () {
gulp.task('test', gulp.series('mocha', 'lint'));

// The default task (called when you run `gulp` from cli)
gulp.task('default');
gulp.task('default');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline

@ilanbiala
Copy link
Member

@UndeadBaneGitHub how are you doing the squash?

@UndeadBaneGitHub
Copy link
Contributor Author

Normally, like this: git reset --soft HEAD~2 && git commit, but it is unapplicable because of the merge

@ilanbiala
Copy link
Member

Oh right, you need to get rid of those couple files. I usually do git rebase -i HEAD~<<number of commits back>> and then change all commits after the top one to fixup and the top one to reword and that usually works for me. However, that won't get rid of the files, it just does the squash for you.

@UndeadBaneGitHub
Copy link
Contributor Author

@ilanbiala ok, I managed to squash the commits into one now. Waiting for the merge to fix timeout(0) and temp folder!

@@ -1,68 +0,0 @@
'use strict';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these files being deleted?

@ilanbiala
Copy link
Member

LGTM other than all the deleted files? Those don't look relevant to this PR, are they a result of rebasing/squashing/merging?

@UndeadBaneGitHub
Copy link
Contributor Author

@ilanbiala actually, let me check about the deleted files.

@UndeadBaneGitHub
Copy link
Contributor Author

@ilanbiala Ok, I just forgot to merge master into this branch. Now it's fixed and the files are back

@ilanbiala
Copy link
Member

@UndeadBaneGitHub The comment is still there and there are a bunch of wholly deleted files, did you forget to push or finish the merge or something?

@UndeadBaneGitHub
Copy link
Contributor Author

Created a new PR #183, closing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants