{"id":22897282,"url":"https://github.com/center-key/add-dist-header","last_synced_at":"2025-05-07T22:06:54.092Z","repository":{"id":57173170,"uuid":"411087483","full_name":"center-key/add-dist-header","owner":"center-key","description":"🎋 Prepend a one-line banner comment with license notice to distribution files (CLI for package.json scripts)","archived":false,"fork":false,"pushed_at":"2025-05-04T02:16:20.000Z","size":638,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T22:06:42.519Z","etag":null,"topics":["banner","cli","directory","dist","distribution","file","folder","header","npm","prepend"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/center-key.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-28T00:45:13.000Z","updated_at":"2025-05-04T02:15:43.000Z","dependencies_parsed_at":"2023-12-27T13:31:54.643Z","dependency_job_id":"638be45b-363f-422b-99e9-4dc1f641f714","html_url":"https://github.com/center-key/add-dist-header","commit_stats":{"total_commits":89,"total_committers":1,"mean_commits":89.0,"dds":0.0,"last_synced_commit":"5a1d1a89cd7ea7594761a2606e03394d92731340"},"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/center-key%2Fadd-dist-header","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/center-key%2Fadd-dist-header/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/center-key%2Fadd-dist-header/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/center-key%2Fadd-dist-header/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/center-key","download_url":"https://codeload.github.com/center-key/add-dist-header/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252961837,"owners_count":21832196,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["banner","cli","directory","dist","distribution","file","folder","header","npm","prepend"],"created_at":"2024-12-14T00:16:25.010Z","updated_at":"2025-05-07T22:06:54.083Z","avatar_url":"https://github.com/center-key.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Add Dist Header\n\u003cimg src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo\u003e\n\n_Prepend a one-line banner comment (with license notice) to distribution files_\n\n[![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/add-dist-header/blob/main/LICENSE.txt)\n[![npm](https://img.shields.io/npm/v/add-dist-header.svg)](https://www.npmjs.com/package/add-dist-header)\n[![Build](https://github.com/center-key/add-dist-header/actions/workflows/run-spec-on-push.yaml/badge.svg)](https://github.com/center-key/add-dist-header/actions/workflows/run-spec-on-push.yaml)\n\n**add-dist-header** uses the `name`, `homepage`, and `license` from your project's **package.json**\nfile to create a header comment and prepend it to a build file.\n\n\u003cimg src=https://raw.githubusercontent.com/center-key/add-dist-header/main/screenshot.png\nwidth=800 alt=screenshot\u003e\n\nExample header comment for a **.js** file:\n```javascript\n//! my-app v3.1.4 ~~ https://github.com/my-org/my-app ~~ MIT License\n```\nExample header comment for a **.css** file:\n```css\n/*! my-app v3.1.4 ~~ https://github.com/my-org/my-app ~~ MIT License */\n```\nExample header comment for a **.xml** file:\n```xml\n\u003c!-- my-app v3.1.4 ~~ https://github.com/my-org/my-app ~~ MIT License --\u003e\n```\n\nHeader comments are only prepended to text files.\u0026nbsp;\nBinary files are ignored (unless the `--all-files` flag is specified).\n\nAutomatically prepending headers to distribution files is particularly handy when your build\ntools are configured to remove comments (such as if `\"removeComments\": true` in set\nin **tsconfig.json**).\nFor a real-world example, see the files in the **dist** folder at\n[w3c-html-validator](https://github.com/center-key/w3c-html-validator/tree/main/dist)\n\n## A) Setup\nInstall package for node:\n```shell\n$ npm install --save-dev add-dist-header\n```\n\n## B) Usage\n### 1. npm package.json scripts\nRun `dist-header` from the `\"scripts\"` section of your **package.json** file.\n\nParameters:\n* The **first** parameter is the *source* file (defaults to `\"build/*\"`).\n* The **second** parameter is the *output* folder (defaults to `\"dist\"`).\n\nExample **package.json** script:\n```json\n   \"scripts\": {\n      \"add-headers\": \"add-dist-header build dist\"\n   },\n```\n\n### 2. Command-line npx\nExample terminal commands:\n```shell\n$ npm install --save-dev add-dist-header\n$ npx add-dist-header \"build\" \"dist\"\n[17:13:50] add-dist-header build/my-app.d.ts --\u003e dist/my-app.d.ts (413.11 KB)\n[17:13:51] add-dist-header build/my-app.js --\u003e dist/my-app.js (1,569.70 KB)\n```\nThe parameters are optional:\n```shell\n$ add-dist-header  #same as above since \"build/*\" \"dist\" are the default parameter values\n[17:13:50] add-dist-header build/my-app.d.ts --\u003e dist/my-app.d.ts (413.11 KB)\n[17:13:51] add-dist-header build/my-app.js --\u003e dist/my-app.js (1,569.70 KB)\n$ add-dist-header \"meta/config.js\"  #creates \"dist/config.js\" prepended with header\n[17:15:03] add-dist-header meta/config.js --\u003e dist/config.js (3.91 KB)\n```\nYou can also install **add-dist-header** globally (`--global`) and then run it anywhere directly from the terminal.\n\n### 3. CLI flags\nCommand-line flags:\n| Flag           | Description                                            | Values     | Default |\n| -------------- | ------------------------------------------------------ | ---------- | ------- |\n| `--all-files`  | Add headers to text files and just copy binary files.  | N/A        | N/A     |\n| `--delimiter`  | Characters separating the parts of the header comment. | **string** | `~~`    |\n| `--ext`        | Filter files by file extension, such as `.js`.\u003cbr\u003eUse a comma to specify multiple extensions. | **string** | N/A |\n| `--keep-first` | Do not delete the original first line comment.         | N/A        | N/A     |\n| `--no-version` | Do not substitute occurrences of `{{package.version}}`\u003cbr\u003ewith the **package.json** version number. | N/A | N/A |\n| `--note`       | Place to add a comment only for humans.                | **string** | N/A     |\n| `--quiet`      | Suppress informational messages.                       | N/A        | N/A     |\n| `--recursive`  | Include subfolders of the source folder.               | N/A        | N/A     |\n\n#### Version number substitution:\nIn addition to prepending the header comment, **add-dist-header** also replaces all occurrences of\n`{{package.version}}` in each file with the version number found in **package.json**.\nThis enables inserting the current package version number into your distribution files.\n\nThe substitution feature is disabled with the `--no-version` flag.\n\nExamples:\n   - `add-dist-header build/minimized dist`\u003cbr\u003e\n   Copy the files in the **build/minimized** folder to the **dist** folder and add comment headers.\n\n   - `add-dist-header build/minimized dist --all-files`\u003cbr\u003e\n   Same as above command except that binary files, such as .png files, will also be copied over unmodified.\n\n   - `add-dist-header build dist --no-version --delimiter=🔥`\u003cbr\u003e\n   Add comment headers but do not substitute the version number and use \"🔥\" as the separator in the header comment instead of \"~~\".\n\n   - `add-dist-header build dist --no-version '--delimiter= --- '`\u003cbr\u003e\n   Specify a delimiter with a leading and trailing space.\n\n   - `add-dist-header build dist --ext=.js,.css --recursive`\u003cbr\u003e\n   Process only JavaScript and CSS files in the **build** folder and its subfolders.\n\n_**Note:** Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._\n\n## C) Application Code\nEven though **add-dist-header** is primarily intended for build scripts, the package can be used programmatically in ESM and TypeScript projects.\n\nExample:\n``` typescript\nimport { addDistHeader } from 'add-dist-header';\n\nconst options = {\n   dist:      'dist',\n   delimiter: '🚀🚀🚀',\n   };\nconst result = addDistHeader.prepend('build/rocket.js', options);\nconsole.log('The size of the new file is:', result.size);\n```\n\nSee the **TypeScript Declarations** at the top of [add-dist-header.ts](src/add-dist-header.ts) for documentation.\n\n\u003cbr\u003e\n\n---\n**CLI Build Tools for package.json**\n   - 🎋 [add-dist-header](https://github.com/center-key/add-dist-header):\u0026nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_\n   - 📄 [copy-file-util](https://github.com/center-key/copy-file-util):\u0026nbsp; _Copy or rename a file with optional package version number_\n   - 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util):\u0026nbsp; _Recursively copy files from one folder to another folder_\n   - 🪺 [recursive-exec](https://github.com/center-key/recursive-exec):\u0026nbsp; _Run a command on each file in a folder and its subfolders_\n   - 🔍 [replacer-util](https://github.com/center-key/replacer-util):\u0026nbsp; _Find and replace strings or template outputs in text files_\n   - 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets):\u0026nbsp; _Revision web asset filenames with cache busting content hash fingerprints_\n   - 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util):\u0026nbsp; _Organize npm package.json scripts into groups of easy to manage commands_\n   - 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator):\u0026nbsp; _Check the markup validity of HTML files using the W3C validator_\n\nFeel free to submit questions at:\u003cbr\u003e\n[github.com/center-key/add-dist-header/issues](https://github.com/center-key/add-dist-header/issues)\n\n[MIT License](LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenter-key%2Fadd-dist-header","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcenter-key%2Fadd-dist-header","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcenter-key%2Fadd-dist-header/lists"}