npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

github-pages

v3.0.2

Published

Publishes your github pages using the github API

Downloads

241

Readme

NPM

Build Status Code Climate Test Coverage Dependencies devDependencies Status

Github Pages

Tool for publishing gh-pages the pro way. WIP

Install

  npm install --save-dev github-pages

Usage

CLI Usage

Publishes your github pages using the github API

Usage
  $ github-pages [options] [src]

  Options
  -r, --repo
  -t, --token
  -m  --commit-message
  -a  --commit-author
      --remote-ref
      --api-version
      --api-protocol
      --api-host
      --api-path
      --api-timeout

Examples
  $ github-pages -r user/repo -t $GH_TOKEN ./data
    > github-pages commit
    > github-pages push to user/repo

Not that the CLI arguments will always overwrite your github-pages configuration in your package.json file.

You only need to provide the repository, the token data and the src. The other arguments are optional.

WARNING The GithubPages will replace all the content of the given ref (heads/gh-pages by default) with the provided content. EVERYTHING that is not present in the src folder will be deleted in your branch. Have you made any mistake? Don't panic, GithubPages does not mess up with you git story. Just revert the commit. ;)

Configuration

All of the CLI options can be configured in the GithubPages section of your package.json. This allows you to modify the default behavior of the GithubPages command.

{
  "github-pages": {
    "api": {
      "version": "3.0.0",
      "protocol": "https",
      "host": "api.github.com",
      "pathPrefix": "",
      "timeout": 5000
    },
    "auth": {
      "type": "token",
      "token": "GH_TOKEN"
    },
    "remote": {
      "user": "user",
      "repo": "repo",
      "ref": "heads/gh-pages"
    },
    "commit": {
      "message": "commit made by me",
      "author": {
        "name": "author-name",
        "email": "author-email"
      }
    },
    "src": "./data"
  }
}

Arguments passed to the CLI will always take precedence over the configuration in package.json.

$GH_TOKEN: By default the token value is read from the environment var $GH_TOKEN. So if you don't want to set it in the configurations/cli, it will be read from $GH_TOKEN.

API Usage

  const GithubPages = require('github-pages');
  const config = require('package.json')['github-pages'];

  const pages = new GithubPages(config);
  pages.publish().then((res)=> {
    console.log('published');
    console.log(JSON.stringify(res, null, 2));
  }).catch((err)=> {
    console.error('error while publishing');
    console.error(JSON.stringify(err, null, 2));
  });

The GithubPages needs the complete configuration to be used (same file structure as described in package.json). If you don't want to provide all the configuration you can use the support file parse-config, passing the same arguments as the cli (using camelCase).

  const GithubPages = require('github-pages');
  const parseConfig = require('github-pages').parseConfig;
  const config = parseConfig({
    repo: 'user/repo',
    token: 'GH-TOKEN',
    remoteRef: 'heads/gh-pages',
    commitMessage: 'publishing from API.',
    commitAuthor: 'author-name <author-email>',
    apiVersion: '3.0.0',
    apiProtocol: 'https',
    apiHost: 'api.github.com',
    apiPath: '',
    apiTimeout: 5000
  }, './dist');

  const pages = new GithubPages(config);

The parseConfig method receives as a input the same structure used in the cli, which is a plain object with the cli params using camelCase, different from the one used in the package.json. Besides that, parseConfig method will try to preload the configuration from your package.json.

The parseConfig function will return null if the final configuration is invalid.

If you want to get the default configuration and change it yourself, then use if directly:

  const config = require('github-pages').parseConfig.default;
  /* => {
    api: {
      version: '3.0.0',
      protocol: 'https',
      host: 'api.github.com',
      pathPrefix: '',
      timeout: 5000
    },
    auth: { type: 'token', token: 'GH_TOKEN' },
    remote: { ref: 'heads/gh-pages' },
    commit: { message: 'github-pages publish.' }
  } */

If you want to validate your config object, you can use the helper function from parseConfig called isValid:

  const isValid = require('github-pages').parseConfig.isValid;
  isValid(config);
  // true|false

Integrating with Travis CI

To use GithubPages on your CI server, just install your lib and set your configuration. For a less intrusive aproach, just create a script in your package.json for GithubPages:

{
  "script": {
    "gh-pages": "github-pages -r user/repo ./dist"
  }
}

add the following to your .travis.yml:

after_success: npm run gh-pages

Remember that you need to provide the environment var GH_TOKEN. To learn how to provide this var in a secure and safe way, look at travis-encrypted-environment-variables or travis-repository-variables (recommended).

stack