How to use the @schematics/angular/utility/find-module.findModuleFromOptions function in @schematics/angular

To help you get started, we’ve selected a few @schematics/angular 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 positive-js / mosaic / packages / cdk / schematics / utils / build-component.ts View on Github external
const schematicFilesUrl = './files';
        const schematicFilesPath = resolve(schematicPath, schematicFilesUrl);

        // Add the default component option values to the options if an option is not explicitly
        // specified but a default component option is available.
        Object.keys(options)
            .filter((optionName) => options[optionName] == null && defaultComponentOptions[optionName])
            .forEach((optionName) => options[optionName] = defaultComponentOptions[optionName]);

        if (options.path === undefined) {
            // TODO(jelbourn): figure out if the need for this `as any` is a bug due to two different
            // incompatible `WorkspaceProject` classes in @angular-devkit
            options.path = buildDefaultPath(project as any);
        }

        options.module = findModuleFromOptions(host, options);

        const parsedPath = parseName(options.path!, options.name);

        options.name = parsedPath.name;
        options.path = parsedPath.path;
        options.selector = options.selector || buildSelector(options, project.prefix);

        validateName(options.name);
        validateHtmlSelector(options.selector!);

        // In case the specified style extension is not part of the supported CSS supersets,
        // we generate the stylesheets with the "css" extension. This ensures that we don't
        // accidentally generate invalid stylesheets (e.g. drag-drop-comp.styl) which will
        // break the Angular CLI project. See: https://github.com/angular/components/issues/15164
        if (!supportedCssExtensions.includes(options.style!)) {
            // TODO: Cast is necessary as we can't use the Style enum which has been introduced
github ng-alain / delon / packages / schematics / utils / alain.ts View on Github external
// path
  if (schema.path === undefined) {
    const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
    schema.path = `/${project.sourceRoot}/${projectDirName}/routes`;
  }

  schema.path += `/${schema.module}`;

  const parsedPath = parseName(schema.path, schema.name!);
  schema.name = parsedPath.name;
  schema.path = parsedPath.path;
  const fullPath = path.join(process.cwd(), schema.path, schema.name);
  if (fs.existsSync(fullPath)) {
    throw new SchematicsException(`The directory (${fullPath}) already exists`);
  }
  schema.importModulePath = findModuleFromOptions(host, schema as any);

  if (!schema._filesPath) {
    // 若基础页尝试从 `_cli-tpl/_${schema.schematicName!}` 下查找该目录,若存在则优先使用
    if (['list', 'edit', 'view', 'empty'].includes(schema.schematicName!)) {
      const overrideDir = '/' + [project.root, `_cli-tpl/_${schema.schematicName}`].filter(i => !!i).join('/');
      const overridePath = `${overrideDir}/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts`;
      if (host.exists(overridePath)) {
        // 所在目录与命令目录同属一个目录结构,因此无须特殊处理
        schema._filesPath = path.relative(__dirname, process.cwd()) + overrideDir;
      }
    }
    schema._filesPath = schema._filesPath || './files';
  }
  // fill target
  if (schema.target) {
    schema.path += '/' + schema.target;
github DevExpress / devextreme-schematics / src / add-view / index.ts View on Github external
function getPathToFile(host: Tree, projectName: string, moduleName: string) {
  const rootPath = getApplicationPath(host, projectName);

  try {
    return findModuleFromOptions(host, { name: moduleName, path: rootPath, module: moduleName });
  } catch (error) {
    return;
  }
}
github mselerin / yang-schematics / src / module / index.ts View on Github external
return (host: Tree, context: SchematicContext) => {
    const rootPath = getRootPath(host, options);
    smartPath(rootPath, options);

    if (!options.path) {
      options.path = `${rootPath}/shared/modules`;
    }

    const parsedPath = parseName(options.path, options.name);
    options.path = parsedPath.path;

    options.module = findModuleFromOptions(host, options);

    const templateSource = apply(url('./files'), [
      options.routing ? noop() : filter(path => !path.endsWith('-routing.module.ts')),

      template({
        ...strings,
        'if-flat': (s: string) => options.flat ? '' : s,
        ...options
      }),
      move(options.path)
    ]);

    return chain([
      mergeWith(templateSource),
      addNgModule(options)
    ])(host, context);
github valor-software / ng2-charts / ng2-charts-schematics / src / ng2-charts-schematics / build-meta-config.ts View on Github external
return (tree: Tree, _context: SchematicContext) => {
    if (!_options.project) {
      throw new SchematicsException('Option (project) is required.');
    }
    const project = getProject(tree, _options.project);

    if (_options.path === undefined) {
      _options.path = buildDefaultPath(project);
    }

    _options.module = findModuleFromOptions(tree, _options);

    const parsedPath = parseName(dirname(normalize(_options.module)), 'not applicable');
    _options.metaname = parsedPath.name;
    _options.metapath = parsedPath.path;

    const metaConfigExists = tree.exists('/src/app/app-chart-config.ts');

    if (metaConfigExists) {
      return tree;
    }

    const templateSource = apply(url('./files'), [
      applyTemplates({
        ...strings,
        'if-flat': (s: string) => _options.flat ? '' : s,
        ..._options,
github mselerin / yang-schematics / src / pipe / index.ts View on Github external
return (host: Tree, context: SchematicContext) => {
    const rootPath = getRootPath(host, options);
    smartPath(rootPath, options);

    if (!options.path) {
      options.path = `${rootPath}/shared/pipes`;
    }

    const parsedPath = parseName(options.path, options.name);
    options.name = parsedPath.name;
    options.path = parsedPath.path;

    options.module = findModuleFromOptions(host, options);


    const ngOptions = {
      ...options,
      skipImport: true
    };

    return chain([
      externalSchematic('@schematics/angular', 'pipe', ngOptions),
      addNgModule(options)
    ])(host, context);
  };
}
github ng-alain / delon / packages / schematics / module / index.ts View on Github external
return (host: Tree, context: SchematicContext) => {
    const workspace = getWorkspace(host);
    if (!schema.project) {
      throw new SchematicsException('Option (project) is required.');
    }
    const project = workspace.projects[schema.project];

    if (schema.path === undefined) {
      const projectDirName = project.projectType === 'application' ? 'app' : 'lib';
      schema.path = `/${(project as any).sourceRoot}/${projectDirName}/routes`;
    }
    if (schema.module) {
      schema.module = findModuleFromOptions(host, schema);
    }

    const parsedPath = parseName(schema.path, schema.name);
    schema.name = parsedPath.name;
    schema.path = parsedPath.path;

    schema.routing = true;
    schema.flat = false;

    const templateSource = apply(url('./files'), [
      schema.routing ? noop() : filter(path => !path.endsWith('-routing.module.ts')),
      template({
        ...strings,
        'if-flat': (s: string) => (schema.flat ? '' : s),
        ...schema,
      }),
github DevExpress / devextreme-schematics / src / utility / ng-module-utils.ts View on Github external
function addImport(tree: Tree, options: ModuleOptions, widget: string) {
  const modulePath = findModuleFromOptions(tree, options) || '';
  const moduleContent = tree.read(modulePath);
  if (moduleContent === null) {
    throw new SchematicsException(`File ${modulePath} does not exist.`);
  }
  const sourceText = moduleContent.toString('utf-8');
  const source = ts.createSourceFile(modulePath, sourceText, ts.ScriptTarget.Latest, true);
  const componentPath = `/${options.path}/`
            + strings.dasherize(options.name) + '/'
            + strings.dasherize(options.name) + '.component';
  const relativePath = buildRelativePath(modulePath, componentPath);

  const declarationRecorder = tree.beginUpdate(modulePath);

  const classifiedComponent = 'Dx' + widget + 'Module';
  for (const change of addImportToModule(source, modulePath, classifiedComponent, 'devextreme-angular')) {
    if (change instanceof InsertChange) {