Skip to content

Commit

Permalink
Release v1.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilafian committed Sep 29, 2023
1 parent bcdfee7 commit 781d71e
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 29 deletions.
3 changes: 1 addition & 2 deletions dist/replacer.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! replacer-util v1.2.1 ~~ https://github.com/center-key/replacer-util ~~ MIT License
//! replacer-util v1.2.2 ~~ https://github.com/center-key/replacer-util ~~ MIT License

export type Settings = {
cd: string | null;
Expand All @@ -10,7 +10,6 @@ export type Settings = {
find: string | null;
header: string | null;
noSourceMap: boolean;
pkg: boolean;
regex: RegExp | null;
rename: string | null;
replacement: string | null;
Expand Down
30 changes: 17 additions & 13 deletions dist/replacer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! replacer-util v1.2.1 ~~ https://github.com/center-key/replacer-util ~~ MIT License
//! replacer-util v1.2.2 ~~ https://github.com/center-key/replacer-util ~~ MIT License

import { globSync } from 'glob';
import { isBinary } from 'istextorbinary';
Expand Down Expand Up @@ -41,7 +41,6 @@ const replacer = {
extensions: [],
find: null,
noSourceMap: false,
pkg: false,
regex: null,
replacement: null,
};
Expand Down Expand Up @@ -76,12 +75,7 @@ const replacer = {
const filesRaw = settings.filename ? [source + '/' + settings.filename] : globFiles();
const filtered = filesRaw.filter(task.isTextFile).filter(keep);
const fileRoutes = filtered.map(file => slash(file)).map(getFileRoute);
const pkg = settings.pkg ? task.readPackageJson() : null;
const engine = new Liquid({ globals: { pkg } });
const versionFormatter = (numIds) => (str) => str.replace(/[^0-9]*/, '').split('.').slice(0, numIds).join('.');
engine.registerFilter('version', versionFormatter(3));
engine.registerFilter('minor-version', versionFormatter(2));
engine.registerFilter('major-version', versionFormatter(1));
const pkg = task.readPackageJson();
const normalizeEol = /\r/g;
const normalizeEof = /\s*$(?!\n)/;
const sourceMapLine = /^\/.#\ssourceMappingURL=.*\n/gm;
Expand All @@ -91,16 +85,26 @@ const replacer = {
const parsedPath = path.parse(origin);
const dir = slash(parsedPath.dir);
const filePath = dir + '/' + slash(parsedPath.base);
return { file: { ...parsedPath, dir: dir, path: filePath } };
return { ...parsedPath, dir: dir, path: filePath };
};
const createEngine = (file) => {
const globals = { package: pkg, file: getFileInfo(file.origin) };
globals['pkg'] = pkg;
const engine = new Liquid({ globals });
const versionFormatter = (numIds) => (str) => str.replace(/[^0-9]*/, '').split('.').slice(0, numIds).join('.');
engine.registerFilter('version', versionFormatter(3));
engine.registerFilter('minor-version', versionFormatter(2));
engine.registerFilter('major-version', versionFormatter(1));
return engine;
};
const processFile = (file, index) => {
const fileInfo = getFileInfo(file.origin);
const render = (text) => engine.parseAndRenderSync(text, fileInfo);
const engine = createEngine(file);
const render = (text) => engine.parseAndRenderSync(text);
const append = settings.concat && index > 0;
const altText = settings.content ? render(settings.content) : null;
const content = render(header) + (altText ?? fs.readFileSync(file.origin, 'utf-8'));
const newStr = settings.pkg ? render(rep) : rep;
const out1 = settings.pkg ? render(content) : content;
const newStr = render(rep);
const out1 = render(content);
const out2 = out1.replace(normalizeEol, '').replace(normalizeEof, '\n');
const out3 = settings.find ? out2.replaceAll(settings.find, newStr) : out2;
const out4 = settings.regex ? out3.replace(settings.regex, newStr) : out3;
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "replacer-util",
"version": "1.2.1",
"version": "1.2.2",
"description": "Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)",
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -91,7 +91,7 @@
"chalk": "~5.3",
"cli-argv-util": "~1.2",
"fancy-log": "~2.0",
"glob": "10.3.6",
"glob": "~10.3",
"istextorbinary": "~6.0",
"liquidjs": "~10.9",
"slash": "~5.1"
Expand All @@ -100,7 +100,7 @@
"@fortawesome/fontawesome-free": "~6.4",
"@types/fancy-log": "~2.0",
"@types/glob": "~8.1",
"@types/node": "~20.6",
"@types/node": "~20.7",
"@typescript-eslint/eslint-plugin": "~6.7",
"@typescript-eslint/parser": "~6.7",
"add-dist-header": "~1.3",
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/target/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions spec/fixtures/target/mock1.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>🔍🔍🔍 replacer-util 🔍🔍🔍</h1>
<h2>Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)</h2>
<p>I, for one, welcome our new A.I. module overlords.</p>
<ul>
<li>Release: v1.2.1</li>
<li>Release: v1.2.2</li>
<li>Minor: v1.2</li>
<li>Major: v1</li>
</ul>
Expand All @@ -25,7 +25,7 @@ <h2>Find and replace strings or template outputs in text files (CLI tool designe
let τ2 = 2 * π2;

const info2 = {
banner: '🔍🔍🔍 replacer-util v1.2.1 🔍🔍🔍',
banner: '🔍🔍🔍 replacer-util v1.2.2 🔍🔍🔍',
description: 'Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)',
code: 'mock1',
file: '{"root":"","dir":"spec/fixtures/source","base":"mock1.html","ext":".html","name":"mock1","path":"spec/fixtures/source/mock1.html"}',
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/mock1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let π1 = 3.14;
let τ1 = 2 * π1;

const info1 = {
banner: '🔍🔍🔍 replacer-util v1.2.1 🔍🔍🔍',
banner: '🔍🔍🔍 replacer-util v1.2.2 🔍🔍🔍',
description: 'Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)',
list1: 'A.I. module, A.I. module, A.I. module',
list2: 'A.I. module, iNsEcT, INSECT, A.I. module',
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/subfolder-a/mock2.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>🔍🔍🔍 replacer-util 🔍🔍🔍</h1>
<h2>Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)</h2>
<p>I, for one, welcome our new A.I. module overlords.</p>
<ul>
<li>Release: v1.2.1</li>
<li>Release: v1.2.2</li>
<li>Minor: v1.2</li>
<li>Major: v1</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/subfolder-a/mock2.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let π2 = 3.14;
let τ2 = 2 * π2;

const info2 = {
banner: '🔍🔍🔍 replacer-util v1.2.1 🔍🔍🔍',
banner: '🔍🔍🔍 replacer-util v1.2.2 🔍🔍🔍',
description: 'Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)',
code: 'mock2',
file: '{"root":"","dir":"spec/fixtures/source/subfolder-a","base":"mock2.js","ext":".js","name":"mock2","path":"spec/fixtures/source/subfolder-a/mock2.js"}',
Expand Down
4 changes: 2 additions & 2 deletions spec/fixtures/target/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h1>🔍🔍🔍 replacer-util 🔍🔍🔍</h1>
<h2>Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)</h2>
<p>I, for one, welcome our new insect overlords.</p>
<ul>
<li>Release: v1.2.1</li>
<li>Release: v1.2.2</li>
<li>Minor: v1.2</li>
<li>Major: v1</li>
</ul>
Expand All @@ -25,7 +25,7 @@ <h2>Find and replace strings or template outputs in text files (CLI tool designe
let τ2 = 2 * π2;

const info2 = {
banner: '🔍🔍🔍 replacer-util v1.2.1 🔍🔍🔍',
banner: '🔍🔍🔍 replacer-util v1.2.2 🔍🔍🔍',
description: 'Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)',
code: 'mock1',
file: '{"root":"","dir":"spec/fixtures/source","base":"mock1.html","ext":".html","name":"mock1","path":"spec/fixtures/source/mock1.html"}',
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/web/subfolder-a/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>🔍🔍🔍 replacer-util 🔍🔍🔍</h1>
<h2>Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)</h2>
<p>I, for one, welcome our new insect overlords.</p>
<ul>
<li>Release: v1.2.1</li>
<li>Release: v1.2.2</li>
<li>Minor: v1.2</li>
<li>Major: v1</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/target/web/subfolder-b/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>🔍🔍🔍 replacer-util 🔍🔍🔍</h1>
<h2>Find and replace strings or template outputs in text files (CLI tool designed for use in npm scripts)</h2>
<p>I, for one, welcome our new insect overlords.</p>
<ul>
<li>Release: v1.2.1</li>
<li>Release: v1.2.2</li>
<li>Minor: v1.2</li>
<li>Major: v1</li>
</ul>
Expand Down

0 comments on commit 781d71e

Please sign in to comment.