@angular-devkit/schematics#externalSchematic TypeScript Examples

The following examples show how to use @angular-devkit/schematics#externalSchematic. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: schematic.ts    From nx-plugins with MIT License 5 votes vote down vote up
export default function (): Rule {
  return async (host: Tree, context: SchematicContext): Promise<Rule> => {
    const workspace = await getWorkspace(host);
    const applications = getApplications(workspace, host);
    const questions: any[] = [];

    if (applications.length === 0) {
      context.logger.log('info', 'no applications found');
      return chain([]);
    }

    context.logger.log(
      'info',
      `We found ${applications.length} supported applications.`
    );

    const choosenApplications = await prompt<{
      setupApplications: {
        projectName: string;
        applicationType: ApplicationType;
      }[];
    }>({
      ...QUESTIONS.setupApplications,
      choices: applications.map((app) => ({
        name: `${app.projectName} (${app.applicationType})`,
        value: app,
      })),
      result: function (result: string) {
        return Object.values(this.map(result));
      },
    } as any);

    if (choosenApplications.setupApplications.length === 0) {
      context.logger.log('info', 'No applications selected. Skipping setup');
      return chain([]);
    }

    const { provider } = await prompt<{ provider: PROVIDER }>([
      QUESTIONS.whichProvider,
    ]);

    switch (provider) {
      case PROVIDER.AWS:
        questions.push(QUESTIONS.awsProfile, QUESTIONS.awsRegion);
        break;

      case PROVIDER.AZURE:
        questions.push(QUESTIONS.azureLocation);
        break;

      case PROVIDER.GOOGLE_CLOUD_PLATFORM:
        questions.push(QUESTIONS.gcpProjectId);
        break;

      default:
        break;
    }

    const options = await prompt(questions);

    return chain(
      choosenApplications.setupApplications.map((application) => {
        return externalSchematic('@dev-thought/nx-deploy-it', 'init', {
          ...options,
          provider,
          project: application.projectName,
        });
      })
    );
  };
}
Example #2
Source File: dependencies.ts    From cli with Apache License 2.0 5 votes vote down vote up
export function addMaterialAngular(_options: CoveoSchema): Rule {
  console.log('\nConfigure your Material Project');
  // For more information about @angular/material schema options:
  // https://github.com/angular/components/blob/e99ca0ac9b0088d20d5d680092cd7ea5624934c0/src/material/schematics/ng-add/schema.json
  return externalSchematic('@angular/material', 'install', _options);
}