How to use the @microsoft/api-extractor.ExtractorConfig.loadFileAndPrepare function in @microsoft/api-extractor

To help you get started, we’ve selected a few @microsoft/api-extractor 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 microsoft / rushstack / build-tests / api-extractor-scenarios / src / runScenarios.ts View on Github external
const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;

    JsonFile.save(apiExtractorJson, apiExtractorJsonPath, { ensureFolderExists: true });
  }

  let compilerState: CompilerState | undefined = undefined;
  let anyErrors: boolean = false;
  process.exitCode = 1;

  for (const scenarioFolderName of buildConfig.scenarioFolderNames) {
    const apiExtractorJsonPath: string = `./temp/configs/api-extractor-${scenarioFolderName}.json`;

    console.log('Scenario: ' + scenarioFolderName);

    // Run the API Extractor command-line
    const extractorConfig: ExtractorConfig = ExtractorConfig.loadFileAndPrepare(apiExtractorJsonPath);

    if (!compilerState) {
      compilerState = CompilerState.create(extractorConfig, {
        additionalEntryPoints: entryPoints
      });
    }

    const extractorResult: ExtractorResult = Extractor.invoke(extractorConfig, {
      localBuild: true,
      showVerboseMessages: true,
      messageCallback: (message: ExtractorMessage) => {
        if (message.messageId === ConsoleMessageId.ApiReportCreated) {
          // This script deletes the outputs for a clean build, so don't issue a warning if the file gets created
          message.logLevel = ExtractorLogLevel.None;
        }
      },
github algolia / algoliasearch-client-javascript / scripts / build.js View on Github external
async function buildDefinition(target, config = '') {
  const pkgDir = path.resolve(`packages/${target}`);
  const pkg = require(`${pkgDir}/package.json`);

  console.log();
  console.log(chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`)));

  // build types
  const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor');

  const extractorConfigPath = path.resolve(
    pkgDir,
    `api-extractor${config ? `-${config}` : ''}.json`
  );
  const extractorConfig = ExtractorConfig.loadFileAndPrepare(extractorConfigPath);
  const result = Extractor.invoke(extractorConfig, {
    localBuild: true,
    showVerboseMessages: true,
  });

  if (result.succeeded) {
    if (pkg.buildOptions && pkg.buildOptions.dts) {
      const dtsPath = path.resolve(pkgDir, pkg.types);
      const existing = await fs.readFile(dtsPath, 'utf-8');
      const toAdd = await Promise.all(
        pkg.buildOptions.dts.map(file => {
          return fs.readFile(path.resolve(pkgDir, file), 'utf-8');
        })
      );
      await fs.writeFile(dtsPath, `${existing}\n${toAdd.join('\n')}`);
    }
github vuejs / vue-next / scripts / build.js View on Github external
.join(',')
    ],
    { stdio: 'inherit' }
  )

  if (buildTypes && pkg.types) {
    console.log()
    console.log(
      chalk.bold(chalk.yellow(`Rolling up type definitions for ${target}...`))
    )

    // build types
    const { Extractor, ExtractorConfig } = require('@microsoft/api-extractor')

    const extractorConfigPath = path.resolve(pkgDir, `api-extractor.json`)
    const extractorConfig = ExtractorConfig.loadFileAndPrepare(
      extractorConfigPath
    )
    const result = Extractor.invoke(extractorConfig, {
      localBuild: true,
      showVerboseMessages: true
    })

    if (result.succeeded) {
      // concat additional d.ts to rolled-up dts (mostly for JSX)
      if (pkg.buildOptions && pkg.buildOptions.dts) {
        const dtsPath = path.resolve(pkgDir, pkg.types)
        const existing = await fs.readFile(dtsPath, 'utf-8')
        const toAdd = await Promise.all(
          pkg.buildOptions.dts.map(file => {
            return fs.readFile(path.resolve(pkgDir, file), 'utf-8')
          })
github ifiokjr / remirror / support / scripts / generate-api-docs.js View on Github external
packages.forEach(json => {
    const relativePath = getRelativePathFromJson(json);
    const path = baseDir(relativePath, 'api-extractor.json');

    const config = ExtractorConfig.loadFileAndPrepare(path);
    const result = Extractor.invoke(config, {
      localBuild: true,
      showVerboseMessages: true,
      typescriptCompilerFolder: baseDir('node_modules', 'typescript'),
    });

    if (result.succeeded) {
      console.info(
        `API Extractor completed successfully with ${result.warningCount} warnings: ${json.name}`,
      );
    } else {
      console.error(
        `API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings: ${json.name}`,
      );
      process.exitCode = 1;
    }
github FontoXML / fontoxpath / build.js View on Github external
function outputDeclarations() {
	console.log('Starting generation of typings');
	const apiExtractorConfig = ExtractorConfig.loadFileAndPrepare('./api-extractor.json');
	const extractorResult = Extractor.invoke(apiExtractorConfig, {});
	if (!extractorResult.succeeded) {
		throw new Error('Typing extraction failed');
	}
	console.log('Typings generated');
}