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

@targetprocess/publish-frontend-assets

v1.0.0

Published

Script to publish assets of Targetprocess UI services (JS, CSS, images, etc.) to AWS S3

Downloads

69

Readme

Publish various front-end assets to AWS S3 before exposing them via CDN.

Usage

Expected to be used during build step of any Targetprocess service providing UI assets - JavaScript, CSS, images, fonts, etc.

Example Gitlab pipeline configuration (note that it implies configured AWS keys and secrets, please refer to Configuration section for details):

publish:
  stage: publish
  image: node:13.3-alpine
  # Run only when commit is explicitly tagged
  only:
    - tags
  variables:
    ASSETS_DIR: out
    SERVICE_NAME: your-service-name
    # Use commit tag as a published version
    SERVICE_VERSION: ${CI_COMMIT_TAG}
  script:
    - npx -p @targetprocess/publish-frontend-assets -c publish-frontend-assets

Configuration

Please refer to src/config.ts for the most recent actual list of configuration variables.

AWS_S3_ACCESS_KEY_ID and AWS_S3_ACCESS_KEY_SECRET

Required. AWS S3 credentials to upload assets. When package is used via Gitlab pipeline, it's recommended to set them as Runner Variables in your project configuration.

AWS_S3_BUCKET_NAME

Required. Name of AWS S3 bucket where assets should be uploaded to. It's expected that all UI services upload their assets to one single bucket (set as default value), but their assets are nested by %service_name%/%version% pattern.

SERVICE_NAME

Required. Name of your service, which will become a part of upload key for S3. Use simple but descriptive names with kebab-case, e.g. search-ui, rule-engine-ui, targetprocess-frontend.

SERVICE_VERSION

Required. Unique version describing this specific upload. Will become a part of upload key for S3. For example, 0.0.1, 0.0.1-rc.2.

ASSETS_DIR

Required. Path to the directory where assets which should be uploaded are located. Path is expected to be relative to the current working directory.

AWS_S3_CACHE_CONTROL

Optional. Cache-Control header which should be set for uploaded assets.

By default it is set to 1 year: public, max-age=31557600. Note the usage of public. Setting Cache-Control to private would not allow Cloudflare CDN to cache the asset.

AWS_S3_TAG

Optional. Allows to set object tags for uploaded assets.

By default sets TTL tag, which is later used by our custom S3 policies to automatically expire files.

MAX_NUMBER_OF_ASSET_FILES and MAX_TOTAL_ASSET_SIZE

Optional. To prevent accidental huge uploads due to misconfiguration (for example preventing upload of entire node_modules), this package enforces low limit of the total amount of assets and their total size (in bytes).

You can use these values to override defaults.

Dev notes

Because this package is run via npx, there's a dummy file bin/publish-frontend-assets with explicit hashbang header, which calls dist/app.js, which is build from src/app.ts.

Package version is automatically set via npm version from the current commit tag during pipeline build, so version in package.json is set to 0.0.0 in source code.

When running locally, use .env file to set AWS credentials and other env variables. Do not commit that file.