How to use the @microsoft/api-extractor-model.ApiModel function in @microsoft/api-extractor-model

To help you get started, we’ve selected a few @microsoft/api-extractor-model 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 OfficeDev / office-ui-fabric-react / packages / api-docs / src / generatePageJsonFiles.ts View on Github external
export function generatePageJsonFiles(options: IPageJsonOptions): void {
  const { pageGroups = {}, fallbackGroup, outputRoot, apiJsonPaths, min } = options;

  // Create and/or empty output folders
  fse.emptyDirSync(outputRoot);
  for (const group of Object.keys(pageGroups)) {
    fse.emptyDirSync(path.join(outputRoot, group));
  }
  if (fallbackGroup) {
    fse.emptyDirSync(path.join(outputRoot, fallbackGroup));
  }

  // Load api-extractor output from packages into a model
  const apiModel = new ApiModel();
  for (const apiJsonPath of apiJsonPaths) {
    console.log('Loading ' + apiJsonPath);
    apiModel.loadPackage(apiJsonPath);
  }

  // Generate the page data
  const pageJsonByName = generatePageJson(apiModel, pageGroups, fallbackGroup);

  // Warn if any requested page names didn't correspond to a docCategory found in the API info
  const requestedPages = ([] as string[]).concat(...Object.values(pageGroups));
  for (const pageName of requestedPages) {
    if (!pageJsonByName.has(pageName)) {
      console.warn('Warning: no API items found for expected @docCategory ' + pageName);
    }
  }
github OfficeDev / office-ui-fabric-react / packages / api-docs / src / PageJsonGenerator.tsx View on Github external
// collect page data
    // Create the folder if it doesn't already exist
    FileSystem.ensureFolder(option.pageJsonFolderPath);

    console.log('Deleting contents of ' + option.pageJsonFolderPath);
    FileSystem.ensureEmptyFolder(option.pageJsonFolderPath);

    // Store the data for each page in a map
    for (const pageName of option.pageNames) {
      collectedData.pageDataByPageName.set(pageName, new PageData(pageName, option.kind));
    }

    for (const apiJsonPath of option.apiJsonPaths) {
      console.log('Loading ' + apiJsonPath);

      const apiModel: ApiModel = new ApiModel();
      // NOTE: later you can load other packages into the model and process them together
      const apiPackage: ApiPackage = apiModel.loadPackage(apiJsonPath);

      console.log('Successfully loaded ' + apiJsonPath);

      const apiEntryPoint: ApiEntryPoint = apiPackage.entryPoints[0]; // assume there is only one entry point

      collectPageData(collectedData, apiEntryPoint, option.kind);
    }
  }

  // create files
  for (const option of options) {
    createPageJsonFiles(collectedData, option);
  }
}
github microsoft / rushstack / apps / api-documenter / src / cli / BaseAction.ts View on Github external
protected buildApiModel(): ApiModel {
    const apiModel: ApiModel = new ApiModel();

    this.inputFolder = this._inputFolderParameter.value || './input';
    if (!FileSystem.exists(this.inputFolder)) {
      throw new Error('The input folder does not exist: ' + this.inputFolder);
    }

    this.outputFolder = this._outputFolderParameter.value || `./${this.actionName}`;
    FileSystem.ensureFolder(this.outputFolder);

    for (const filename of FileSystem.readFolder(this.inputFolder)) {
      if (filename.match(/\.api\.json$/i)) {
        console.log(`Reading ${filename}`);
        const filenamePath: string = path.join(this.inputFolder, filename);
        apiModel.loadPackage(filenamePath);
      }
    }
github esfx / esfx / scripts / docs.js View on Github external
async function apiDocumenter(projectFolders, apiDir = "/.docs/api", yamlDir = ".docs/yml") {
    const outputDirs = [...new Set(projectFolders.map(projectFolder => path.resolve(replaceVars(yamlDir, { projectFolder }))))];
    await del(outputDirs);

    /** @type {Map} */
    const apiModels = new Map();

    for (const projectFolder of projectFolders) {
        const inputDir = path.resolve(replaceVars(apiDir, { projectFolder }));
        const outputDir = path.resolve(replaceVars(yamlDir, { projectFolder }));
        let apiModel = apiModels.get(outputDir);
        if (!apiModel) apiModels.set(outputDir, apiModel = new ApiModel());
        for (const entry of await fs.promises.readdir(inputDir)) {
            if (!entry.endsWith(".api.json")) continue;
            apiModel.loadPackage(path.resolve(inputDir, entry));
        }
        fixupModel(apiModel, apiModel);
    }

    for (const [outputDir, apiModel] of apiModels) {
        const documenter = new CustomYamlDocumenter(apiModel);
        documenter.generateFiles(outputDir);
    }
}
exports.apiDocumenter = apiDocumenter;
github microsoft / rushstack / apps / api-extractor / src / generators / ApiModelGenerator.ts View on Github external
public constructor(collector: Collector) {
    this._collector = collector;
    this._apiModel = new ApiModel();
    this._referenceGenerator = new DeclarationReferenceGenerator(
      collector.packageJsonLookup,
      collector.workingPackage.name,
      collector.program,
      collector.typeChecker);
  }
github microsoft / rushstack / apps / api-extractor / src / generators / ApiModelGenerator.ts View on Github external
public constructor(collector: Collector) {
    this._collector = collector;
    this._cachedOverloadIndexesByDeclaration = new Map();
    this._apiModel = new ApiModel();
  }