Socket
Socket
Sign inDemoInstall

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 1.1.3 to 1.2.0

31

bin/cli.js

@@ -31,5 +31,6 @@ #!/usr/bin/env node

import log from 'fancy-log';
import path from 'path';
// Parameters and flags
const validFlags = ['delimiter', 'keep-first', 'keep', 'no-version', 'note', 'quiet'];
const validFlags = ['delimiter', 'keep-first', 'keep', 'no-version', 'note', 'quiet', 'recursive'];
const cli = cliArgvUtil.parse(validFlags);

@@ -44,3 +45,3 @@ const source = cli.params[0] ?? 'build/*';

// Reporting
const logResult = (result) => {
const logResult = (result) => {
const name = chalk.gray('add-dist-header');

@@ -56,18 +57,24 @@ const arrow = chalk.gray.bold('→');

// Prepend
const isFolder = fs.existsSync(source) && fs.statSync(source).isDirectory();
const pattern = isFolder ? source + '/*' : source;
const filenames = globSync(pattern, { nodir: true }).sort();
const normalize = (name) => path.normalize(name.endsWith(path.sep) ? name.slice(0, -1) : name);
const origin = normalize(source);
const targetRoot = normalize(target);
const isFolder = fs.existsSync(origin) && fs.statSync(origin).isDirectory();
const wildcard = cli.flagOn.recursive ? '/**/*' : '/*';
const pattern = isFolder ? origin + wildcard : origin;
const filenames = globSync(pattern, { nodir: true }).sort();
const error =
cli.invalidFlag ? cli.invalidFlagMsg :
cli.paramsCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
!filenames.length ? 'File not found: ' + source :
cli.invalidFlag ? cli.invalidFlagMsg :
cli.paramsCount > 2 ? 'Extraneous parameter: ' + cli.params[2] :
!filenames.length ? 'File not found: ' + source :
source.includes('*') ? 'Wildcards not supported in source: ' + source :
null;
if (error)
throw Error('[add-dist-header] ' + error);
const options = {
dist: target,
const clacOptions = (sourceFilename) => ({
dist: targetRoot + path.dirname(sourceFilename).substring(origin.length),
delimiter: cli.flagMap.delimiter ?? '~~',
replaceComment: !cli.flagOn.keep,
setVersion: !cli.flagOn.noVersion,
};
filenames.forEach(filename => logResult(addDistHeader.prepend(filename, options)));
});
filenames.forEach(filename =>
logResult(addDistHeader.prepend(filename, clacOptions(filename))));

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

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

@@ -3,0 +3,0 @@ export type Settings = {

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

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

@@ -10,3 +10,2 @@ import { isBinary } from 'istextorbinary';

prepend(filename, options) {
var _a, _b, _c, _d;
const defaults = {

@@ -19,3 +18,3 @@ dist: 'dist',

};
const settings = Object.assign(Object.assign({}, defaults), options);
const settings = { ...defaults, ...options };
if (!filename)

@@ -36,3 +35,3 @@ throw Error('[add-dist-header] Must specify the "filename" option.');

const inputFile = path.parse(filename);
const fileExt = (_a = settings.extension) !== null && _a !== void 0 ? _a : inputFile.ext;
const fileExt = settings.extension ?? inputFile.ext;
const jsStyle = /\.(js|ts|cjs|mjs)$/.test(fileExt);

@@ -47,7 +46,7 @@ const mlStyle = /\.(html|htm|sgml|xml|php)$/.test(fileExt);

const out2 = settings.replaceComment ? out1.replace(firstLine[type], '') : out1;
const doctype = mlStyle && ((_b = out2.match(doctypeLine)) === null || _b === void 0 ? void 0 : _b[0]) || '';
const doctype = mlStyle && out2.match(doctypeLine)?.[0] || '';
const out3 = mlStyle && doctype ? out2.replace(doctype, '') : out2;
const versionPattern = /{{pkg[.]version}}/g;
const out4 = settings.setVersion ? out3.replace(versionPattern, pkg.version) : out3;
const info = (_d = (_c = pkg.homepage) !== null && _c !== void 0 ? _c : pkg.docs) !== null && _d !== void 0 ? _d : pkg.repository;
const info = pkg.homepage ?? pkg.docs ?? pkg.repository;
const unlicensed = !pkg.license || pkg.license === 'UNLICENSED';

@@ -54,0 +53,0 @@ const license = unlicensed ? 'All Rights Reserved' : pkg.license + ' License';

{
"name": "add-dist-header",
"version": "1.1.3",
"version": "1.2.0",
"description": "Prepend a one-line banner comment (with license notice) to distribution files",

@@ -96,8 +96,8 @@ "license": "MIT",

"@types/node": "~20.4",
"@typescript-eslint/eslint-plugin": "~6.0",
"@typescript-eslint/parser": "~6.0",
"@typescript-eslint/eslint-plugin": "~6.2",
"@typescript-eslint/parser": "~6.2",
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"copy-folder-util": "~1.1",
"eslint": "~8.44",
"eslint": "~8.46",
"jshint": "~2.13",

@@ -104,0 +104,0 @@ "mocha": "~10.2",

@@ -18,7 +18,7 @@ # Add Dist Header

```javascript
//! my-app v0.3.7 ~~ https://github.com/my-org/my-app ~~ MIT License
//! my-app v3.1.4 ~~ https://github.com/my-org/my-app ~~ MIT License
```
Example header comment for a **.css** file:
```javascript
/*! my-app v0.3.7 ~~ https://github.com/my-org/my-app ~~ MIT License */
/*! my-app v3.1.4 ~~ https://github.com/my-org/my-app ~~ MIT License */
```

@@ -82,2 +82,3 @@

| `--quiet` | Suppress informational messages. | N/A | N/A |
| `--recursive` | Include subfolders for the source folder. | N/A | N/A |

@@ -89,11 +90,14 @@ #### Version number substitution:

The substitution feature is disabled by setting `--version` flag to `false`:
The substitution feature is disabled with the `--no-version` flag.
Examples:
- `add-dist-header temp dist --delimiter=🔥`<br>
Use "🔥" as the separator instead of "~~".
- `add-dist-header build/minimized dist`<br>
Copy the files in the **build/minimized** folder to the **dist** folder and add comment headers.
- `add-dist-header --no-version build dist`<br>
Add headers but do not substitute the version number.
- `add-dist-header build dist --no-version --delimiter=🔥`<br>
Add comment headers but do not substitute the version number and use "🔥" as the separator in the header comment instead of "~~".
- `add-dist-header build dist --recursive`<br>
Include the subfolders of **build**.
## C) Application Code

@@ -100,0 +104,0 @@ Even though **add-dist-header** is primarily intended for build scripts, the package can easily be used programmatically in ESM and TypeScript projects.

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