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

generate-build-info

v0.0.3

Published

Generates a `buildinfo.json` file in the designated folder

Downloads

34

Readme

Generate Build Info

Command line utility for npm-based packages that generates a simple buildinfo.json file in a specified folder with the expectation that the application in the project folder reads the file and displays the contents somehow within the application.

Here's a link to the NPM project: https://www.npmjs.com/package/generate-build-info

For example, if the project is a web application (like React or Vue.js), the application code can read the generated file and display the build version and build date on the web application's footer.

The contents of the file look like this:

{
  "buildVersion": "1.0.0",
  "buildDateMs": 1678724886957,
  "buildDateStr": "3/13/2023, 12:28:06 PM"
}

Usage

To install the module as a dependency in the application project, open a terminal window or command prompt and execute the following command:

npm install generate-build-info --save-dev 

This approach allows you to easily execute the module in the standard npm run build process.

To install the module globally, open a terminal window or command prompt and execute the following command:

npm install generate-build-info -g

With this approach, you can execute the module in a terminal window or command prompt from any folder on your development system.

When you execute the module, it reads the local project's package.json file, and, using the file's version property and the current date/time, creates the buildinfo.json file in a folder location specified on the command line.

After installation, execute the module using the gen-build-info command passing in the destination location for the generated file:

gen-build-info <target_folder>

For example, to create the file in the current folder, use the following:

gen-build-info .

for npm-based web applications, you'll likely put the file in the project's src folder:

gen-build-info src

For npm-based Static Site Generators that use a data folder, you might use:

gen-build-info src/_data

Note: The module will not create the target folder for you.

To use the module during an npm-driven build process, you can open the project's package.json file and update the project's existing build script:

"build": "npm version patch && gen-build-info && <your_project_build_command>",

For example, for a React.js project it would look like this:

"build": "npm version patch && gen-build-info && react-scripts build",

The npm version patch part of the build step increments the patch version in the package.json file before calling gen-build-info.

With this in place, when you execute npm run build to build a production version of the app, npm will update the version number in the project's package.json file, generate an updated version of the buildinfo.js file, then generate the production build of the app.

The next step is to read the file in you app and use it whatever way makes the most sense for your app.

Background

This module is a generic version of my react-build-info and ionic-build-info projects. In these earlier projects, the target folder is standard, so the modules put the generated file where the project expects it to be and simplifies the command line.

I created this version when I started working with Eleventy and wanted an easy way to create a data file in the project that I could use to display an Eleventy site's build version and date on the site. Eleventy already has a way to display the build date in the site since it's a static site generator and all files are generated at build time, but I wanted a way to display the site's platform version (changes to the site, not the site's articles).


You can find information on many different topics on my personal blog. Learn about all of my publications at John Wargo Books.

If you find this code useful and feel like thanking me for providing it, please consider Buying Me a Coffee, or making a purchase from my Amazon Wish List.