Skip to content

Init APIs

The auto init command provides an easy way to create an .autorc without reading too many docs. It exposes hooks to get the basic information auto needs to function (getRepo and getAuthor). It also provides hooks the set up your plugin quicker (configurePlugin and createEnv).

writeRcFile

Override where/how the rc file is written.

class MyPlugin implements IPlugin {
  init(initializer: InteractiveInit) {
    initializer.hooks.writeRcFile.tapPromise("Example", async (rc) => {
      // write the file somewhere other than .autorc
      return filename;
    });
  }
}
class MyPlugin implements IPlugin {
  init(initializer: InteractiveInit) {
    initializer.hooks.writeRcFile.tapPromise("Example", async (rc) => {
      // write the file somewhere other than .autorc
      return filename;
    });
  }
}

Other examples:

  • In Core: Defaults to writing rc file to root of project
  • npm - Writes RC file to package.json

getRepo

Get or verify the repo information.

Examples:

  • npm - Gets repo info from package.json

getAuthor

Get or verify the author information.

Examples:

  • npm - Gets author info from package.json

configurePlugin

Run extra configuration for a plugin. Here is where to display prompts to the user.

class MyPlugin implements IPlugin {
  init(initializer: InteractiveInit) {
    initializer.hooks.configurePlugin.tapPromise("Example", async (name) => {
      if (name === "my-plugins") {
        return [
          name,
          {
            // extra config options
          },
        ];
      }
    });
  }
}
class MyPlugin implements IPlugin {
  init(initializer: InteractiveInit) {
    initializer.hooks.configurePlugin.tapPromise("Example", async (name) => {
      if (name === "my-plugins") {
        return [
          name,
          {
            // extra config options
          },
        ];
      }
    });
  }
}

Other examples:

  • jira - Query the user for their JIRA url

createEnv

Add environment variables to get from the user. These values are stored in a local .env file.

class MyPlugin implements IPlugin {
  init(initializer: InteractiveInit) {
    initializer.hooks.createEnv.tap("Example", (vars) => [
      ...vars,
      {
        variable: "MY_TOKEN",
        message: `This is a very important secret`,
      },
    ]);
  }
}
class MyPlugin implements IPlugin {
  init(initializer: InteractiveInit) {
    initializer.hooks.createEnv.tap("Example", (vars) => [
      ...vars,
      {
        variable: "MY_TOKEN",
        message: `This is a very important secret`,
      },
    ]);
  }
}

Other examples:

  • npm - Query the user for their npm token
  • slack - Query the user for their slack url