src/utility/find-module.js
function findModule(host, generateDir) {
    let dir = host.getDir('/' + generateDir);
    const moduleRe = /\.module\.ts$/;
    const routingModuleRe = /-routing\.module\.ts/;
    while (dir) {
        const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
        if (matches.length == 1) {
            return core_1.join(dir.path, matches[0]);
        }
        else if (matches.length > 1) {
            throw new Error('More than one module matches. Use skip-import option to skip importing '
                + 'the component into the closest module.');
        }
        dir = dir.parent;
    }
    throw new Error('Could not find an NgModule for the new component. Use the skip-import '
        + 'option to skip importing components in NgModule.');
}
function findModule(host, generateDir) {
    let dir = host.getDir('/' + generateDir);
    const moduleRe = /\.module\.ts$/;
    const routingModuleRe = /-routing\.module\.ts/;
    while (dir) {
        const matches = dir.subfiles.filter(p => moduleRe.test(p) && !routingModuleRe.test(p));
        if (matches.length == 1) {
            return core_1.join(dir.path, matches[0]);
        }
        else if (matches.length > 1) {
            throw new Error('More than one module matches. Use skip-import option to skip importing '
                + 'the component into the closest module.');
        }
        dir = dir.parent;
    }
    throw new Error('Could not find an NgModule for the new component. Use the skip-import '
        + 'option to skip importing components in NgModule.');
}
function findModule ( host , generateDir ) { let dir = host . getDir ( '/' + generateDir ) ; const moduleRe = / \.module\.ts$ / ; const routingModuleRe = / -routing\.module\.ts / ; while ( dir ) { const matches = dir . subfiles . filter ( p => moduleRe . test ( p ) && ! routingModuleRe . test ( p ) ) ; if ( matches . length == 1 ) { return core_1 . join ( dir . path , matches [ 0 ] ) ; } else if ( matches . length > 1 ) { throw new Error ( 'More than one module matches. Use skip-import option to skip importing ' + 'the component into the closest module.' ) ; } dir = dir . parent ; } throw new Error ( 'Could not find an NgModule for the new component. Use the skip-import ' + 'option to skip importing components in NgModule.' ) ; }
Function to find the "closest" module to a generated file's path.
Function to find the closest module to a generated file s path .