add-dist-header
Advanced tools
Comparing version 0.3.5 to 0.3.6
@@ -26,2 +26,3 @@ #!/usr/bin/env node | ||
import { addDistHeader } from '../dist/add-dist-header.js'; | ||
import { cliArgvUtil } from 'cli-argv-util'; | ||
import chalk from 'chalk'; | ||
@@ -32,14 +33,11 @@ import fs from 'fs'; | ||
// Parameters | ||
const validFlags = ['delimiter', 'keep', 'no-version', 'note', 'quiet']; | ||
const args = process.argv.slice(2); | ||
const flags = args.filter(arg => /^--/.test(arg)); | ||
const flagMap = Object.fromEntries(flags.map(flag => flag.replace(/^--/, '').split('='))); | ||
const flagOn = Object.fromEntries(validFlags.map(flag => [flag, flag in flagMap])); | ||
const invalidFlag = Object.keys(flagMap).find(key => !validFlags.includes(key)); | ||
const params = args.filter(arg => !/^--/.test(arg)); | ||
// Parameters and flags | ||
const validFlags = ['delimiter', 'keep-first', 'keep', 'no-version', 'note', 'quiet']; | ||
const cli = cliArgvUtil.parse(validFlags); | ||
const source = cli.params[0] ?? 'build/*'; | ||
const target = cli.params[1] ?? 'dist'; | ||
// Data | ||
const source = params[0] ?? 'build/*'; | ||
const target = params[1] ?? 'dist'; | ||
// Deprecated | ||
if (cli.flagOn.keepFirst) console.log('DEPRECATED: Replace --keep flag with --keep-first'); | ||
cli.flagOn.keep = cli.flagOn.keep || cli.flagOn.keepFirst; | ||
@@ -53,3 +51,3 @@ // Reporting | ||
const size = chalk.white('(' + result.size + ')'); | ||
if (!flagOn.quiet && result.valid) | ||
if (!cli.flagOn.quiet && result.valid) | ||
log(name, source, arrow, target, size); | ||
@@ -63,5 +61,5 @@ }; | ||
const error = | ||
invalidFlag ? 'Invalid flag: ' + invalidFlag : | ||
params.length > 2 ? 'Unknown extraneous parameter: ' + 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 : | ||
null; | ||
@@ -72,6 +70,6 @@ if (error) | ||
dist: target, | ||
delimiter: flagMap.delimiter ?? '~~', | ||
replaceComment: !flagOn.keep, | ||
setVersion: !flagOn['no-version'], | ||
delimiter: cli.flagMap.delimiter ?? '~~', | ||
replaceComment: !cli.flagOn.keep, | ||
setVersion: !cli.flagOn.noVersion, | ||
}; | ||
filenames.forEach(filename => logResult(addDistHeader.prepend(filename, options))); |
@@ -1,4 +0,4 @@ | ||
//! add-dist-header v0.3.5 ~~ https://github.com/center-key/add-dist-header ~~ MIT License | ||
//! add-dist-header v0.3.6 ~~ https://github.com/center-key/add-dist-header ~~ MIT License | ||
export declare type Settings = { | ||
export type Settings = { | ||
dist: string; | ||
@@ -10,4 +10,4 @@ extension: string | null; | ||
}; | ||
export declare type Options = Partial<Settings>; | ||
export declare type Result = { | ||
export type Options = Partial<Settings>; | ||
export type Result = { | ||
valid: boolean; | ||
@@ -14,0 +14,0 @@ dist: string; |
@@ -1,2 +0,2 @@ | ||
//! add-dist-header v0.3.5 ~~ https://github.com/center-key/add-dist-header ~~ MIT License | ||
//! add-dist-header v0.3.6 ~~ https://github.com/center-key/add-dist-header ~~ MIT License | ||
@@ -3,0 +3,0 @@ import { isBinary } from 'istextorbinary'; |
{ | ||
"name": "add-dist-header", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"description": "Prepend a one-line banner comment (with license notice) to distribution files", | ||
@@ -86,2 +86,3 @@ "license": "MIT", | ||
"chalk": "~5.1", | ||
"cli-argv-util": "~0.1", | ||
"fancy-log": "~2.0", | ||
@@ -97,8 +98,8 @@ "glob": "~8.0", | ||
"@types/node": "~18.11", | ||
"@typescript-eslint/eslint-plugin": "~5.40", | ||
"@typescript-eslint/parser": "~5.40", | ||
"@typescript-eslint/eslint-plugin": "~5.43", | ||
"@typescript-eslint/parser": "~5.43", | ||
"assert-deep-strict-equal": "~1.0", | ||
"copy-file-util": "~0.1", | ||
"copy-folder-util": "~0.2", | ||
"eslint": "~8.26", | ||
"eslint": "~8.27", | ||
"jshint": "~2.13", | ||
@@ -108,5 +109,5 @@ "mocha": "~10.1", | ||
"run-scripts-util": "~0.1", | ||
"typescript": "~4.8", | ||
"typescript": "~4.9", | ||
"w3c-html-validator": "~1.2" | ||
} | ||
} |
@@ -77,5 +77,5 @@ # Add Dist Header | ||
| -------------- | --------------------------------------------------------- | ---------- | ------- | | ||
| `--delimiter` | Characters separating the parts<br>of the header comment. | **string** | `~~` | | ||
| `--keep` | Do not delete the original first line<br>comment. | N/A | N/A | | ||
| `--no-version` | Do not substitute occurrences of `{{pkg.version}}` with<br>the **package.json** version number. | N/A | N/A | | ||
| `--delimiter` | Characters separating the parts of the header<br>comment. | **string** | `~~` | | ||
| `--keep-first` | Do not delete the original first line comment. | N/A | N/A | | ||
| `--no-version` | Do not substitute occurrences of `{{pkg.version}}`<br>with the **package.json** version number. | N/A | N/A | | ||
| `--note` | Place to add a comment only for humans. | **string** | N/A | | ||
@@ -82,0 +82,0 @@ | `--quiet` | Suppress informational messages. | N/A | N/A | |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21443
7
244
+ Addedcli-argv-util@~0.1
+ Addedcli-argv-util@0.1.1(transitive)