# local-assets

> CLI tool to extract local\* stylesheets, images, scripts, fonts and other subresources (assets) from a HTML document, and optionally copy them into a directory.

Latest version **1.0.0** (published 2021-02-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install local-assets
pnpm add local-assets
yarn add local-assets
bun add local-assets
```

Provides the command `local-assets`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2021-02-05 |
| First published | 2021-02-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sid Vishnoi |
| Maintainers | sidvishnoi |

## Links

- npm: https://www.npmjs.com/package/local-assets
- Repository: git@github.com:sidvishnoi/local-assets
- npm.io page: https://npm.io/package/local-assets

## Dependencies (1)

- [subresources](https://npm.io/package/subresources.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2021-02-05

## README

# local-assets

CLI tool to extract local\* stylesheets, images, scripts, fonts and other subresources (assets) from a HTML document, and optionally copy them into a directory.

\*local here means resources under the same-origin and available in same directory as given HTML document.

## Motivation

While creating an auto-publish GitHub Action for W3C specifications (See [spec-prod](https://github.com/w3c/spec-prod/)), I wanted to find the minimal files needed by the specification. This ensures we do not deploy the specification when unrelated files (like metadata files, CI scripts etc.) get changed. We want to deploy only the main HTML file (the specification) and its dependencies (generally CSS files and images) to GitHub pages and/or https://w3.org.

Now, this works outside the W3C use-case also, so I created this tool as a CLI if other people also find it useful.

## Usage

This tool is meant to be used as a CLI, although you can also import it as a regular Node.js module.

You can install this tool as a CLI:

```bash
npm install --global local-assets
# Or, with yarn
yarn global add local-assets
```

Then, you can extract all local resources from `index.html` and copy them to `../all-the-files/` directory as:

```bash
local-assets index.html -o ../all-the-files/
```

If you do not wish to copy the assets and just list them out (on `stdout`):

```bash
local-assets index.html
```

For a more verbose output, set the `VERBOSE` environment variable. This will log additional information on `stderr`. The list of assets will be still be outputted to `stdout`.

```bash
VERBOSE=1 local-assets index.html
```

<details>
  <summary>Already got a Chromium based browser installed?</summary>

If you already have a Chromium based browser (Google Chrome, Microsoft Edge) installed, you can avoid re-downloading it by setting the `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` env variable before install. You would need to specify the location of your Chromium binary (`PUPPETEER_EXECUTABLE_PATH`) during CLI usage though. So:

```bash
# Install
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1
npm install --global local-assets

# Use
export PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome
# Or, export PUPPETEER_EXECUTABLE_PATH="$(which google-chrome)"
local-assets index.html
```

</details>

## How it works?

1. Use [puppeteer](https://github.com/puppeteer/puppeteer/) to open the HTML file/URL.
1. Use of the `document.querySelectorAll` APIs to find all subresources, and process them (this is done using the [subresource](https://github.com/sidvishnoi/subresources) package).
1. Filter out cross-origin subresources from above.
1. Filter out the resources not found in current directory.
1. Copy all other resources.

---
_Source: https://npm.io/package/local-assets · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
