A CLI tool to manage your CDN script tags in files. Automatically generate a sub-resource integrity from a file, then add it to the matching script tag.
npm install paopuA CLI tool to manage your CDN script tags in files. Automatically generate a sub-resource integrity from a file, then add it to the matching script tag.
Read the Why section for more details.
Paopu was created to work with Node 14 and newer.
Feel free to submit an issue or pull request. :)
TODO:
- More hashing options (currently only SHA256 is supported).
1. Install it in your project:
``sh`
$ npm i -D paopu
2. Create a configuration.
3. Run it:
`sh`
$ paopu
Scenario: Let's say you want to tell the world that your package's bundle can be accessed on a public CDN. You might include an example script in your README, like so:
`html`
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/my-package@0.3.2/dist/my-cool-package.min.js"
integrity="sha256-waCWKicYMCJic4tBKdkV54qhuGsq8J9JWQY+QmFVjj8="
crossorigin="anonymous"
>
Problem: Every time you release a new package version, you need to update that integrity hash. Sometimes in multiple files.
Solution: Install Paopu, add a config, then run the CLI tool. Done. ✨
Create a paopu.config.json at the root of your project. Optional properties below have default values displayed.
`
// paopu.config.json
{
// Each entry uses a package name as the key
"package-name": {
// Specifies the file paths used in your script tags. These paths must
// partially match your path in the src attribute.
//
// REQUIRED
"resources": ["some/path/bundle-name.min.js", "some-path/bundle-name.js"],
// Specifies which files to search for script tags in.
//
// REQUIRED
"targets": ["README.md", "test/index.html"],
// Specifies if the resources are located in a modules folder.
// Automatically prepends node_modules/ to pathsresources
// defined in , where is the keyresourceBasePath
// of the given paopu config entry.
// This also causes the tool to ignore
//
// OPTIONAL
"module": false,
// Specifies a common base path for paths in resourcesmodule
// Should resolve to a package root in all cases.
// This is ignored if is true.
//
// OPTIONAL
"resourceBasePath": ".",
// Specifies a common base path for paths in targets
//
// OPTIONAL
"targetBasePath": ".",
// A url matcher for your script tag. If its src contains
// this pattern AND the matching resource path, then the
// script tag will be updated.
// E.g., 'unpkg.com'
//
// OPTIONAL
"urlPattern": 'cdn.jsdelivr.net'
}
}
`
Any CLI options given will override the defaults used by the tool.
Flags: --config, -c
Default: paopu.config.json
Example usage: paopu -c path/to/paopu.config.json
Override the default configuration filename.
Flags: --debug, -d
Default: false
Example usage: paopu -d
If given, Paopu will spit out a .paopu-cache` file so you can inspect the resolved paths, options, etc., being used by the tool.