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-fullstack 5.0.0-rc.3 route subgenerator does not work #2743

Open
soccer-coder opened this issue Jul 9, 2018 · 5 comments
Open

Angular-fullstack 5.0.0-rc.3 route subgenerator does not work #2743

soccer-coder opened this issue Jul 9, 2018 · 5 comments

Comments

@soccer-coder
Copy link

  • [x ] I understand that GitHub issues are not for tech support, but for questions specific to this generator, bug reports, and feature requests.
Item Version
generator-angular-fullstack 5.0.0-rc.3
Node 8.11.2
npm 6.1.0
Operating System MacOs
Item Answer
Transpiler TypeScript
Markup HTML
CSS SCSS / Stylus
Router ngRoute
DB MongoDB

I tried to generate the "route" as below, I ran into an issue:

yo angular-fullstack:route sidenav
? Where would you like to create this route? client/app/
? What will the url of your route be? sidenav
events.js:183
throw er; // Unhandled 'error' event
^

TypeError: Cannot read property 'name' of undefined

I could run "endpoint" without any issue.

@Awk34
Copy link
Member

Awk34 commented Jul 15, 2018

This was a bug in https://github.com/angular-fullstack/generator-angular-fullstack-component. See angular-fullstack/generator-angular-fullstack-component@b854fda. This fix was released in 1.0.2. You should be able to reinstall the generator's dependencies or the generator itself for it to get the fixed version.

@Awk34 Awk34 removed the investigate label Jul 15, 2018
@fcristel
Copy link

Is this still not working? I am running on Windows, on a freshly installed version of the generator (yesterday).

First of all, the generator comes with generator-angular-fullstack-component 1.0.1

And I get this error:

events.js:167
      throw er; // Unhandled 'error' event
      ^

TypeError: Cannot read property 'name' of undefined

If I update the generator-angular-fullstack-component to the 1.0.2, then the error is this one:

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find module 'generator-angular-fullstack-component/generators/route'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.resolve (internal/modules/cjs/helpers.js:32:19)
    at RouteGenerator.compose (C:\Users\crist\AppData\Roaming\npm\node_modules\generator-angular-fullstack\generators\route\index.js:13:30)
    at Object.<anonymous> (C:\Users\crist\AppData\Roaming\npm\node_modules\generator-angular-fullstack\node_modules\yeoman-generator\lib\index.js:399:25)
    at C:\Users\crist\AppData\Roaming\npm\node_modules\generator-angular-fullstack\node_modules\run-async\index.js:25:25
    at new Promise (<anonymous>)
    at C:\Users\crist\AppData\Roaming\npm\node_modules\generator-angular-fullstack\node_modules\run-async\index.js:24:19
    at self.env.runLoop.add.completed (C:\Users\crist\AppData\Roaming\npm\node_modules\generator-angular-fullstack\node_modules\yeoman-generator\lib\index.js:400:11)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
Emitted 'error' event at:
    at Immediate.setImmediate (C:\Users\crist\AppData\Roaming\npm\node_modules\generator-angular-fullstack\node_modules\yeoman-generator\lib\index.js:406:18)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)

@pschoro
Copy link

pschoro commented Nov 19, 2019

Hey guys,

I fixed it with this code :

'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.addModule = addModule;

var _jscodeshift = require('jscodeshift');

var _jscodeshift2 = _interopRequireDefault(_jscodeshift);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const moduleName = 'Test1Module';
const modulePath = './test0/test1.module';

class NoModulesError extends Error {
    constructor() {
        super(`No NgModules found in app module.
  Are you sure you have the correct path registered in 'appModulePath'?`);
    }
}
class TooManyModulesError extends Error {
    constructor() {
        super(`More than one NgModule found in app module.
  There should be only one.`);
    }
}

/**
 * @param {string} source
 * @param {string} moduleName - ex 'MyModule'
 * @param {string} modulePath - module path relative to appModulePath, ex './thing/my.module'
 */
function addModule(sourceText, moduleName, modulePath) {
    const source = _jscodeshift.withParser('flow')(sourceText);

    // const ngModules = source.find(_jscodeshift2.default.ClassDeclaration, path => path.decorators.some(decorator => decorator.callee.name === 'NgModule'));
    const ngModules = source
        .find(_jscodeshift.ClassDeclaration, path => path.decorators.some(decorator => decorator.expression.callee.name === 'NgModule'));

        if (ngModules.size() === 0) {
        throw new NoModulesError();
    }
    if (ngModules.size() > 1) {
        throw new TooManyModulesError();
    }

    const ngModuleClass = ngModules.get();
    // const ngModule = ngModuleClass.value.decorators.find(decorator => decorator.callee.name === 'NgModule');
    // const imports = ngModule.arguments[0].properties.find(prop => prop.key.name === 'imports');
    const ngModule = ngModuleClass.value.decorators.find(decorator => decorator.expression.callee.name === 'NgModule');
    const imports = ngModule.expression.arguments[0].properties.find(prop => prop.key.name === 'imports');

    if (!imports) {
        console.info('No \'imports\' property? Strange..');
        // TODO: create
    }

    // Push module to `imports` array
    const MyModuleIdentifier = _jscodeshift2.default.identifier(moduleName);
    imports.value.elements.push(MyModuleIdentifier);

    const existingImports = source.find(_jscodeshift.ImportSpecifier);
    if (existingImports.size() === 0) {
        // TODO: Must be using some other module format
    }

    const MyModuleImport = _jscodeshift2.default.importDeclaration([_jscodeshift2.default.importSpecifier(_jscodeshift2.default.identifier(moduleName))], _jscodeshift2.default.literal(modulePath));

    // Insert after last `import {...} from '...'` statement
    (0, _jscodeshift2.default)(existingImports.at(-1).get().parent.insertAfter(MyModuleImport));

    return source.toSource({ quote: 'single' });
}

@Awk34
Copy link
Member

Awk34 commented Nov 19, 2019

@pschoro would you be willing to make a pull request?

@Awk34 Awk34 reopened this Nov 19, 2019
@pschoro
Copy link

pschoro commented Nov 20, 2019

No need ...it was simply a typo in the variable _jscodeshift...I did not change anything else ^^

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

No branches or pull requests

4 participants