How to use the @angular-devkit/core.dirname function in @angular-devkit/core

To help you get started, we’ve selected a few @angular-devkit/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angular / angular-cli / packages / @angular / cli / models / workspace-loader.ts View on Github external
private _loadWorkspaceFromPath(workspacePath: Path) {
    if (!workspacePath) {
      return of(null);
    }

    if (this._workspaceCacheMap.has(workspacePath)) {
      return of(this._workspaceCacheMap.get(workspacePath));
    }

    const workspaceRoot = dirname(workspacePath);
    const workspaceFileName = basename(workspacePath);
    const workspace = new experimental.workspace.Workspace(workspaceRoot, this._host);

    return workspace.loadWorkspaceFromHost(workspaceFileName).pipe(
      tap(workspace => this._workspaceCacheMap.set(workspacePath, workspace)),
    );
  }
}
github akveo / nebular / schematics / playground-module / add-to-modules.ts View on Github external
function processFeatureModule(tree: Tree, context: SchematicContext, modulePath: Path): void {
  const moduleDeclarations = getClassWithDecorator(tree, modulePath, 'NgModule');
  if (!moduleDeclarations.length) {
    return;
  }

  multilineDeclarationsArray(tree, modulePath);

  const parentDir = dirname(dirname(modulePath));
  const routingModulePath = findRoutingModule(tree, parentDir);
  if (!routingModulePath) {
    return;
  }

  if (moduleDeclarations.length > 1) {
    context.logger.warn(`Found more than one module declaration in ${modulePath}. ` +
      'Route will be created only for the first one.');
  }
  addModuleRoute(tree, moduleDeclarations[0], modulePath, routingModulePath);
}
github akveo / nebular / schematics / playground-module / add-to-modules.ts View on Github external
function processComponent(tree: Tree, context: SchematicContext, componentPath: Path): void {
  const componentDir = tree.getDir(dirname(componentPath));
  const modulePath = findFeatureModule(tree, componentDir.path);
  if (!modulePath) {
    throw new SchematicsException(`Can't find module for component ${componentPath}.`);
  }

  const componentDeclarations = getClassWithDecorator(tree, componentPath, 'Component');
  if (!componentDeclarations.length) {
    return;
  }
  addComponentToModule(tree, componentDeclarations, componentPath, modulePath);

  if (hasRoutingModuleInDir(componentDir)) {
    addComponentRoute(tree, componentDeclarations, modulePath, context, componentPath);
  }
}
github akveo / nebular / schematics / utils / routing.ts View on Github external
export function routePredicatesFromPath(routingModulePath: Path, targetDirPath: Path): RoutePredicate[] {
  const routingModuleDir = dirname(routingModulePath);
  if (isRootPlaygroundModule(routingModuleDir)) {
    return [rootRoutePredicate(targetDirPath)];
  }

  const predicates: RoutePredicate[] = [];
  if (isBasePlaygroundModule(routingModuleDir)) {
    predicates.push(baseComponentPredicate(targetDirPath));
  }
  const relativeToRoutingModule = targetDirPath.replace(dirname(routingModulePath), '');
  const routePaths = dirsToRoutePaths(relativeToRoutingModule);
  for (const path of routePaths) {
    predicates.push((route: ts.ObjectLiteralExpression) => pathRoutePredicate(path, route));
  }

  return predicates;
}
github devonfw / devon4node / packages / schematics / src / lib / crud / crud.factory.ts View on Github external
export function crud(options: ICrudOptions): Rule {
  const name = strings.dasherize(basename(options.name as Path));
  const fullName = join(dirname(options.name as Path), pluralize.plural(name));
  const projectPath = options.path || '.';
  const path = normalize(join(projectPath as Path, 'src/app', options.name, '..'));
  return chain([
    schematic('entity', options),
    mergeWith(
      apply(url('./files'), [
        template({
          ...strings,
          name,
          fullName,
        }),
        formatTsFiles(),
        move(path),
      ]),
    ),
    updatePackageJson(projectPath),
github NativeScript / nativescript-schematics / src / migrate-module / index.ts View on Github external
const addCommonModuleFile = (options, modInfo) => {
  const { name } = options;
  const { modulePath } = modInfo;
  const moduleDirectory = dirname(modulePath);
  const commonModuleOptions = {
    name,
    path: moduleDirectory,
  };

  return schematic('common-module', commonModuleOptions);
};
github akveo / nebular / src / framework / theme / schematics / util / ast.ts View on Github external
export function getAppModulePath(host: Tree, mainPath: string): string {
  const moduleRelativePath = findBootstrapModulePath(host, mainPath);
  const mainDir = dirname(mainPath as Path);

  return normalize(`/${mainDir}/${moduleRelativePath}.ts`);
}
github ngrx / store-builds / schematics-core / utility / parse-name.js View on Github external
function parseName(path, name) {
        const nameWithoutPath = core_1.basename(name);
        const namePath = core_1.dirname((path + '/' + name));
        return {
            name: nameWithoutPath,
            path: core_1.normalize('/' + namePath),
        };
    }
    exports.parseName = parseName;
github fossasia / susper.com / node_modules / @angular-devkit / schematics / src / tree / filesystem.js View on Github external
get subdirs() {
        const result = new Set();
        try {
            this._host.listDirectory(this._systemPath)
                .filter(name => this._host.isDirectory(this._host.join(this._systemPath, name)))
                .forEach(name => result.add(core_1.fragment(name)));
        }
        catch (e) {
            if (e.code != 'ENOENT' && e.code != 'ENOTDIR') {
                throw e;
            }
        }
        for (const path of this._tree.staging.keys()) {
            if (path.startsWith(this._path) && core_1.dirname(path) != this._path) {
                result.add(core_1.basename(path));
            }
        }
        return [...result];
    }
    get subfiles() {
github rxweb / rxweb / rxweb.io / node_modules / @schematics / angular / module / index.js View on Github external
return (host) => {
        if (!options.module) {
            return host;
        }
        const modulePath = core_1.normalize('/' + options.module);
        const text = host.read(modulePath);
        if (text === null) {
            throw new schematics_1.SchematicsException(`File ${modulePath} does not exist.`);
        }
        const sourceText = text.toString('utf-8');
        const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
        const importModulePath = core_1.normalize(`/${options.path}/`
            + (options.flat ? '' : core_1.strings.dasherize(options.name) + '/')
            + core_1.strings.dasherize(options.name)
            + '.module');
        const relativeDir = core_1.relative(core_1.dirname(modulePath), core_1.dirname(importModulePath));
        const relativePath = (relativeDir.startsWith('.') ? relativeDir : './' + relativeDir)
            + '/' + core_1.basename(importModulePath);
        const changes = ast_utils_1.addImportToModule(source, modulePath, core_1.strings.classify(`${options.name}Module`), relativePath);
        const recorder = host.beginUpdate(modulePath);
        for (const change of changes) {
            if (change instanceof change_1.InsertChange) {
                recorder.insertLeft(change.pos, change.toAdd);
            }
        }
        host.commitUpdate(recorder);
        return host;
    };
}