Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

add-dist-header

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

add-dist-header - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

11

bin/cli.js

@@ -39,3 +39,2 @@ #!/usr/bin/env node

};
const exit = (message) => (console.error('[add-dist-header]', message), process.exit(1));
const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^[-]*/, '').split('=')));

@@ -50,6 +49,8 @@ const delimiter = flagMap.delimiter ?? '~~';

const logResult = (result) => log(name, chalk.blue.bold(result.file), chalk.magenta(result.size));
if (files.length > 2)
exit('Unknown extraneous parameter: ' + files[2]);
if (!filenames.length)
exit('File not found: ' + param.filename);
const error =
files.length > 2 ? 'Unknown extraneous parameter: ' + files[2] :
!filenames.length ? 'File not found: ' + param.filename :
null;
if (error)
throw Error('[add-dist-header] ' + error);
const prepend = (file) => addDistHeader.prepend({

@@ -56,0 +57,0 @@ filename: file,

@@ -1,2 +0,2 @@

//! add-dist-header v0.2.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v0.2.1 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

@@ -3,0 +3,0 @@ export declare type Options = {

@@ -1,2 +0,2 @@

//! add-dist-header v0.2.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v0.2.1 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

@@ -3,0 +3,0 @@ import { format, parse } from 'path';

{
"name": "add-dist-header",
"version": "0.2.0",
"description": "Adds a header comment to a file and saves it to your distribution folder (written in functional TypeScript)",
"version": "0.2.1",
"description": "Prepend a one-line header comment (with license notice) to distribution files",
"license": "MIT",

@@ -69,8 +69,8 @@ "type": "module",

"step:01": "rimraf build dist spec/fixtures/dist **/.DS_Store",
"step:02": "jshint . --exclude node_modules,build,dist",
"step:02": "jshint . --exclude-path .gitignore",
"step:03": "eslint --max-warnings 0 . --ext .ts",
"step:04": "tsc",
"step:05": "tsc --module UMD --outDir build/umd",
"step:06": "cpy build/umd/add-dist-header.js build --rename=add-dist-header.umd.cjs --flat=true",
"step:07": "cpy build/add-dist-header.* dist --flat=true",
"step:06": "copy-file build/umd/add-dist-header.js build/add-dist-header.umd.cjs",
"step:07": "copy-file build/add-dist-header.js --folder dist",
"step:08": "node bin/cli.js --version=false build dist",

@@ -91,7 +91,8 @@ "pretest": "npm-run-all step:*",

"@types/node": "~18.7",
"@typescript-eslint/eslint-plugin": "~5.37",
"@typescript-eslint/parser": "~5.37",
"@typescript-eslint/eslint-plugin": "~5.38",
"@typescript-eslint/parser": "~5.38",
"assert-deep-strict-equal": "~1.0",
"cpy-cli": "~4.2",
"eslint": "~8.23",
"copy-file-util": "~0.1",
"copy-folder-cli": "~0.1",
"eslint": "~8.24",
"jshint": "~2.13",

@@ -98,0 +99,0 @@ "mocha": "~10.0",

# Add Dist Header
<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>
_Adds a header comment to a file and saves it to your distribution folder_
_Prepend a one-line header comment (with license notice) to distribution files_

@@ -29,5 +29,3 @@ [![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/add-dist-header/blob/main/LICENSE.txt)

## 1) Setup
### Install
## A) Setup
Install package for node:

@@ -38,4 +36,5 @@ ```shell

## 2) Usage
Call `add-dist-header` from the `"scripts"` section of your **package.json** file.
## B) Usage
### 1. npm scripts
Run `add-dist-header` from the `"scripts"` section of your **package.json** file.

@@ -51,11 +50,11 @@ The **first** parameter is the *source* file (defaults to `"build/*"`).

```
Try out the first script with the command: `npm run make-dist`
Alternatively, you can run **add-dist-header** directly from the terminal in your project home
folder.
### 2. Global
You can install **add-dist-header** globally and then run it anywhere directly from the terminal.
Example terminal command:
Example terminal commands:
```shell
$ ls package.json
package.json
$ npx add-dist-header "build" "dist"
$ npm install --global add-dist-header
$ add-dist-header "build" "dist"
[17:13:50] add-dist-header dist/my-app.d.ts 413.11 kB

@@ -67,27 +66,45 @@ [17:13:51] add-dist-header dist/my-app.js 1,569.70 kB

```shell
$ npx add-dist-header #same as above since "build/*" "dist" are the default parameter values
$ add-dist-header #same as above since "build/*" "dist" are the default parameter values
[17:13:50] add-dist-header dist/my-app.d.ts 413.11 kB
[17:13:51] add-dist-header dist/my-app.js 1,569.70 kB
$ npx add-dist-header "meta/config.js" #creates "dist/config.js" prepended with header
$ add-dist-header "meta/config.js" #creates "dist/config.js" prepended with header
[17:15:03] add-dist-header dist/config.js 3.91 kB
```
## 3) Version Number Substitution
### 3. CLI Flags
Command-line flags:
| Flag | Description | Values | Default |
| ------------- | -------------------------------------------------------------------------------------- | --------------- | ------- |
| `--delimiter` | Characters separating the parts<br>of the header comment. | **string** | `~~` |
| `--replace` | Delete the original first line<br>comment (if not marked `!` important). | `true`, `false` | `true` |
| `--version` | Substitute occurrences of `~~~version~~~`<br>with the **package.json** version number. | `true`, `false` | `true` |
#### Version Number Substitution:
In addition to prepending the header comment, **add-dist-header** also replaces all occurrences of
`~~~version~~~` with the version number found in the **package.json** file.
`~~~version~~~` in each file with the version number found in **package.json**.
This enables inserting the current package version number into your distribution files.
The substitution feature is disabled by setting `--version` flag to `false`:
```json
"scripts": {
"add-headers": "add-dist-header --version=false build dist"
},
Examples:
- `add-dist-header temp dist --delimiter=🔥` &nbsp; Use "🔥" instead of "~~~" in the header.
- `add-dist-header --version=false build dist` &nbsp; Add headers but do not subsitute the version number.
## C) Application Code
Even though **add-dist-header** is primarily intended for build scripts, the package can easily be used in ESM and TypeScript projects.
Example:
``` typescript
import { addDistHeader } from 'add-dist-header';
const options = {
filename: 'build/rocket.js',
dist: 'dist',
delimiter: '🚀🚀🚀',
};
const result = addDistHeader.prepend(options);
console.log('The size of the new file is:', result.size);
```
## 4) CLI Flags
| Flag | Description | Values | Default |
| ------------- | -------------------------------------------------------------------------------------- | --------------- | ------- |
| `--delimiter` | Characters separating the parts<br>of the header comment. | **string** | `~~` |
| `--replace` | Delete the original first line<br>comment (if not marked `!` important). | `true`, `false` | `true` |
| `--version` | Substitute occurrences of `~~~version~~~`<br>with the **package.json** version number. | `true`, `false` | `true` |
See the **TypeScript Declarations** at the top of [add-dist-header.ts](add-dist-header.ts) for documentation.

@@ -97,2 +114,11 @@ <br>

---
**Build Tools**
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):&nbsp; _Prepend a one-line header comment (with license notice) to distribution files_
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util):&nbsp; _Copy or rename a file (CLI tool designed for use in npm scripts)_
- 📂 [copy-folder-cli](https://github.com/center-key/copy-folder-cli):&nbsp; _Recursively copy a folder (CLI tool designed for use in npm scripts)_
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):&nbsp; _Check the markup validity of HTML files using the W3C validator_
Feel free to submit questions at:<br>
[github.com/center-key/add-dist-header/issues](https://github.com/center-key/add-dist-header/issues)
[MIT License](LICENSE.txt)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc