Skip to content

Commit

Permalink
Release v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Sep 6, 2023
1 parent b01db11 commit e928825
Show file tree
Hide file tree
Showing 19 changed files with 73 additions and 52 deletions.
4 changes: 0 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ const cli = cliArgvUtil.parse(validFlags);
const source = cli.params[0] ?? 'build/*';
const target = cli.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;

// Prepend
const normalize = (name) => path.normalize(name.endsWith(path.sep) ? name.slice(0, -1) : name);
const origin = normalize(source);
Expand Down
17 changes: 11 additions & 6 deletions dist/add-dist-header.d.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

export type Settings = {
allFiles: boolean;
dist: string;
extension: string | null;
delimiter: string;
replaceComment: boolean;
setVersion: boolean;
};
export type Options = Partial<Settings>;
export type Result = {
valid: boolean;
text: boolean;
dist: string;
header: string;
header: string | null;
source: string;
file: string;
length: number;
size: string;
length: number | null;
size: string | null;
};
export type ReporterSettings = {
quite: boolean;
};
declare const addDistHeader: {
prepend(filename: string, options?: Options): Result;
prepend(filename: string, options?: Partial<Settings>): Result;
reporter(result: Result, options?: ReporterSettings): Result;
};
export { addDistHeader };
36 changes: 28 additions & 8 deletions dist/add-dist-header.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

import { isBinary } from 'istextorbinary';
import path from 'path';
import chalk from 'chalk';
import fs from 'fs';
import log from 'fancy-log';
import makeDir from 'make-dir';
import path from 'path';
import slash from 'slash';
const addDistHeader = {
prepend(filename, options) {
const defaults = {
allFiles: false,
dist: 'dist',
extension: null,
delimiter: '~~',
Expand All @@ -34,7 +37,7 @@ const addDistHeader = {
const jsStyle = /\.(js|ts|cjs|mjs)$/.test(fileExt);
const mlStyle = /\.(html|htm|sgml|xml|php)$/.test(fileExt);
const type = jsStyle ? 'js' : mlStyle ? 'ml' : 'other';
const invalidContent = isBinary(filename);
const isTextFile = !isBinary(filename);
const input = fs.readFileSync(filename, 'utf-8').trimStart();
const normalizeEol = /\r/g;
const normalizeEof = /\s*$(?!\n)/;
Expand All @@ -58,17 +61,34 @@ const addDistHeader = {
const spacerLines = isMinified || mlStyle ? '\n' : '\n\n';
const leadingBlanks = /^\s*\n/;
const final = doctype + header + spacerLines + out4.replace(leadingBlanks, '');
if (!invalidContent)
if (isTextFile)
fs.writeFileSync(outputPath, final);
else if (settings.allFiles)
fs.copyFileSync(filename, outputPath);
return {
valid: !invalidContent,
valid: isTextFile || settings.allFiles,
text: isTextFile,
dist: distFolder,
header: header,
header: isTextFile ? header : null,
source: filename,
file: outputPath,
length: final.length,
size: (final.length / 1024).toLocaleString([], fixedDigits) + ' KB',
length: isTextFile ? final.length : null,
size: isTextFile ? (final.length / 1024).toLocaleString([], fixedDigits) + ' KB' : null,
};
},
reporter(result, options) {
const defaults = {
quiet: false,
};
const settings = { ...defaults, ...options };
const name = chalk.gray('add-dist-header');
const arrow = chalk.gray.bold('→');
const source = chalk.blue.bold(result.source);
const target = chalk.magenta(result.file);
const size = chalk.white('(' + result.size + ')');
if (!settings.quiet && result.valid)
log(name, source, arrow, target, size);
return result;
},
};
export { addDistHeader };
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "add-dist-header",
"version": "1.2.2",
"version": "1.3.0",
"description": "Prepend a one-line banner comment (with license notice) to distribution files",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -93,17 +93,17 @@
"@types/fancy-log": "~2.0",
"@types/glob": "~8.1",
"@types/node": "~20.5",
"@typescript-eslint/eslint-plugin": "~6.4",
"@typescript-eslint/parser": "~6.4",
"@typescript-eslint/eslint-plugin": "~6.6",
"@typescript-eslint/parser": "~6.6",
"assert-deep-strict-equal": "~1.1",
"copy-file-util": "~1.1",
"copy-folder-util": "~1.1",
"eslint": "~8.47",
"eslint": "~8.48",
"jshint": "~2.13",
"mocha": "~10.2",
"rimraf": "~5.0",
"run-scripts-util": "~1.2",
"typescript": "~5.1",
"typescript": "~5.2",
"w3c-html-validator": "~1.4"
}
}
4 changes: 2 additions & 2 deletions spec/fixtures/target/cli/all/kebab.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License */
/*! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License */

.kebab { /* v1.2.2 */
.kebab { /* v1.3.0 */
border: 2px solid firebrick;
border-radius: 3px;
}
4 changes: 2 additions & 2 deletions spec/fixtures/target/cli/all/kebab.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!doctype html>
<!-- add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License -->
<!-- add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License -->
<html lang=en>
<head>
<meta charset=utf-8>
<title>Kebab &bull; 🍢🍢🍢</title>
</head>
<body>
<h1>Kebab v1.2.2</h1>
<h1>Kebab v1.3.0</h1>
</body>
</html>
6 changes: 3 additions & 3 deletions spec/fixtures/target/cli/all/kebab.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

const toKebab = (camelStr) => { //v1.2.2
const toKebab = (camelStr) => { //v1.3.0
const dash = (word) => '-' + word.toLowerCase();
return ('' + camelStr).replace(/([A-Z]+)/g, dash).replace(/\s|^-/g, '');
};

export { toKebab }; //version: 1.2.2
export { toKebab }; //version: 1.3.0
2 changes: 1 addition & 1 deletion spec/fixtures/target/cli/all/kebab.min.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
const toKebab=(c)=>{const d=(w)=>'-'+ w.toLowerCase();return(''+c).replace(/([A-Z]+)/g,d).replace(/\s|^-/g,'');};module.exports=toKebab;
6 changes: 3 additions & 3 deletions spec/fixtures/target/cli/all/kebab.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

//! This comment is important!
const toKebab = (camelStr: string): string => { //v1.2.2
const toKebab = (camelStr: string): string => { //v1.3.0
const dash = (word: string) => '-' + word.toLowerCase();
return ('' + camelStr).replace(/([A-Z]+)/g, dash).replace(/\s|^-/g, '');
};

export { toKebab }; //version: 1.2.2
export { toKebab }; //version: 1.3.0
2 changes: 1 addition & 1 deletion spec/fixtures/target/cli/all/kebab.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!-- add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License -->
<!-- add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License -->
<styles>
<style region="Greece">souvlaki</style>
<style region="Türkiye">shish</style>
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/target/cli/all/subfolder/pita-bread.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

import { toKebab } from '../kebab';

const pitaBread = (str) => `🫓 ${toKebab(str)} 🫓`; //v1.2.2
const pitaBread = (str) => `🫓 ${toKebab(str)} 🫓`; //v1.3.0

export { pitaBread };
4 changes: 2 additions & 2 deletions spec/fixtures/target/cli/ext/kebab.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License */
/*! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License */

.kebab { /* v1.2.2 */
.kebab { /* v1.3.0 */
border: 2px solid firebrick;
border-radius: 3px;
}
6 changes: 3 additions & 3 deletions spec/fixtures/target/cli/ext/kebab.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

const toKebab = (camelStr) => { //v1.2.2
const toKebab = (camelStr) => { //v1.3.0
const dash = (word) => '-' + word.toLowerCase();
return ('' + camelStr).replace(/([A-Z]+)/g, dash).replace(/\s|^-/g, '');
};

export { toKebab }; //version: 1.2.2
export { toKebab }; //version: 1.3.0
2 changes: 1 addition & 1 deletion spec/fixtures/target/cli/ext/kebab.min.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
const toKebab=(c)=>{const d=(w)=>'-'+ w.toLowerCase();return(''+c).replace(/([A-Z]+)/g,d).replace(/\s|^-/g,'');};module.exports=toKebab;
4 changes: 2 additions & 2 deletions spec/fixtures/target/kebab.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License -->
<!-- add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License -->
<!-- Original header comment -->
<!doctype html>
<html lang=en>
Expand All @@ -7,6 +7,6 @@
<title>Kebab &bull; 🍢🍢🍢</title>
</head>
<body>
<h1>Kebab v1.2.2</h1>
<h1>Kebab v1.3.0</h1>
</body>
</html>
6 changes: 3 additions & 3 deletions spec/fixtures/target/kebab.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! add-dist-header v1.2.2 🫓🍢🫓 https://github.com/center-key/add-dist-header 🫓🍢🫓 MIT License
//! add-dist-header v1.3.0 🫓🍢🫓 https://github.com/center-key/add-dist-header 🫓🍢🫓 MIT License

const toKebab = (camelStr) => { //v1.2.2
const toKebab = (camelStr) => { //v1.3.0
const dash = (word) => '-' + word.toLowerCase();
return ('' + camelStr).replace(/([A-Z]+)/g, dash).replace(/\s|^-/g, '');
};

export { toKebab }; //version: 1.2.2
export { toKebab }; //version: 1.3.0
4 changes: 2 additions & 2 deletions spec/fixtures/target/kebab.min.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License */
.kebab { /* v1.2.2 */
/*! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License */
.kebab { /* v1.3.0 */
border: 2px solid firebrick;
border-radius: 3px;
}
2 changes: 1 addition & 1 deletion spec/fixtures/target/kebab.min.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
const toKebab=(c)=>{const d=(w)=>'-'+ w.toLowerCase();return(''+c).replace(/([A-Z]+)/g,d).replace(/\s|^-/g,'');};module.exports=toKebab;
2 changes: 1 addition & 1 deletion spec/fixtures/target/kebab.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! add-dist-header v1.2.2 ~~ https://github.com/center-key/add-dist-header ~~ MIT License
//! add-dist-header v1.3.0 ~~ https://github.com/center-key/add-dist-header ~~ MIT License

//! This comment is important!
const toKebab = (camelStr: string): string => { //v{{pkg.version}}
Expand Down

0 comments on commit e928825

Please sign in to comment.