@tertium/hlpr 0.3.4 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/commands/file/rename/rename.js +23 -12
- package/bin/index.js +11 -2
- package/package.json +2 -1
|
@@ -8,30 +8,36 @@ function splitWords(s) {
|
|
|
8
8
|
function transformBasename(basename, style) {
|
|
9
9
|
if (!basename)
|
|
10
10
|
return basename;
|
|
11
|
-
if (basename.includes(".") && !basename.startsWith("."))
|
|
12
|
-
return basename;
|
|
13
11
|
const leadingDot = basename.startsWith(".") ? "." : "";
|
|
14
|
-
|
|
12
|
+
let core = leadingDot ? basename.slice(1) : basename;
|
|
13
|
+
let ext = "";
|
|
14
|
+
const firstDot = core.indexOf(".");
|
|
15
|
+
if (firstDot !== -1) {
|
|
16
|
+
ext = core.slice(firstDot);
|
|
17
|
+
core = core.slice(0, firstDot);
|
|
18
|
+
}
|
|
15
19
|
const words = splitWords(core);
|
|
16
20
|
if (words.length === 0)
|
|
17
21
|
return basename;
|
|
18
22
|
switch (style) {
|
|
19
23
|
case "title_underscore":
|
|
20
|
-
return leadingDot + words.map(cap).join("_");
|
|
24
|
+
return leadingDot + words.map(cap).join("_") + ext;
|
|
21
25
|
case "snake":
|
|
22
|
-
return leadingDot + words.map((w) => w.toLowerCase()).join("_");
|
|
26
|
+
return leadingDot + words.map((w) => w.toLowerCase()).join("_") + ext;
|
|
23
27
|
case "kebab":
|
|
24
|
-
return leadingDot + words.map((w) => w.toLowerCase()).join("-");
|
|
28
|
+
return leadingDot + words.map((w) => w.toLowerCase()).join("-") + ext;
|
|
25
29
|
case "camel":
|
|
26
|
-
return leadingDot + words.map((w, i) => i === 0 ? w.toLowerCase() : cap(w)).join("");
|
|
30
|
+
return leadingDot + words.map((w, i) => i === 0 ? w.toLowerCase() : cap(w)).join("") + ext;
|
|
27
31
|
case "pascal":
|
|
28
|
-
return leadingDot + words.map(cap).join("");
|
|
32
|
+
return leadingDot + words.map(cap).join("") + ext;
|
|
33
|
+
case "pascal_underscore":
|
|
34
|
+
return leadingDot + words.map(cap).join("_") + ext;
|
|
29
35
|
case "upper":
|
|
30
|
-
return leadingDot + words.join("_").toUpperCase();
|
|
36
|
+
return leadingDot + words.join("_").toUpperCase() + ext;
|
|
31
37
|
case "lower":
|
|
32
|
-
return leadingDot + words.join("_").toLowerCase();
|
|
38
|
+
return leadingDot + words.join("_").toLowerCase() + ext;
|
|
33
39
|
default:
|
|
34
|
-
return
|
|
40
|
+
return leadingDot + core + ext;
|
|
35
41
|
}
|
|
36
42
|
}
|
|
37
43
|
function cap(s) {
|
|
@@ -126,10 +132,15 @@ if (import.meta.url.endsWith(process.argv[1]?.replace(/\\/g, "/"))) {
|
|
|
126
132
|
const args = process.argv.slice(2);
|
|
127
133
|
const rootArg = args[0];
|
|
128
134
|
const styleArg = args[1];
|
|
135
|
+
if (args.includes("--help") || args.includes("-h") || args.includes("/help") || args.includes("/h") || args.includes("/?")) {
|
|
136
|
+
console.log("Usage: rename <root> <style> [--dry|-n]");
|
|
137
|
+
console.log("Styles: title_underscore, pascal_underscore, snake, kebab, camel, pascal, upper, lower");
|
|
138
|
+
process.exit(0);
|
|
139
|
+
}
|
|
129
140
|
const dryRun = args.includes("--dry") || args.includes("-n");
|
|
130
141
|
if (!rootArg || !styleArg) {
|
|
131
142
|
console.error("Usage: rename <root> <style> [--dry|-n]");
|
|
132
|
-
console.error("Styles: title_underscore, snake, kebab, camel, pascal, upper, lower");
|
|
143
|
+
console.error("Styles: title_underscore, pascal_underscore, snake, kebab, camel, pascal, upper, lower");
|
|
133
144
|
process.exit(1);
|
|
134
145
|
}
|
|
135
146
|
renameRecursive(rootArg, styleArg, { dryRun }).then((performed) => {
|
package/bin/index.js
CHANGED
|
@@ -262,11 +262,20 @@ async function main() {
|
|
|
262
262
|
process.exit(1);
|
|
263
263
|
}
|
|
264
264
|
if (isTypeScriptCommand) {
|
|
265
|
-
|
|
265
|
+
let tsArgs;
|
|
266
|
+
if (restArgs.length > 0 && restArgs[0] && scriptPath) {
|
|
267
|
+
const subcategory = restArgs[0];
|
|
268
|
+
const isNested = path.basename(scriptPath) === `${subcategory}.js` && path.basename(path.dirname(scriptPath)) === subcategory;
|
|
269
|
+
tsArgs = isNested ? process.argv.slice(4) : process.argv.slice(3);
|
|
270
|
+
} else {
|
|
271
|
+
tsArgs = process.argv.slice(3);
|
|
272
|
+
}
|
|
266
273
|
const finalCommand = `node "${scriptPath}" ${tsArgs.join(" ")}`;
|
|
267
274
|
console.log(`Executing command: ${finalCommand}`);
|
|
268
275
|
const success2 = await executeCommand(finalCommand, {});
|
|
269
|
-
|
|
276
|
+
const helpFlags = ["-h", "--help", "help", "/h", "/help", "/?"];
|
|
277
|
+
const isHelpInvocation = tsArgs.some((arg) => helpFlags.includes(arg));
|
|
278
|
+
if (!success2 && !forceFlag && !isHelpInvocation) {
|
|
270
279
|
console.error("Command failed, stopping execution.");
|
|
271
280
|
process.exit(1);
|
|
272
281
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tertium/hlpr",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Windows and *Nix utility for typical programming activity",
|
|
5
5
|
"author": "Vitalii Balabanov",
|
|
6
6
|
"email": "tertiumnon@gmail.com",
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"build:commands": "node build-commands.js",
|
|
12
12
|
"build": "bun run build:main && bun run build:commands",
|
|
13
13
|
"test": "bun test",
|
|
14
|
+
"test:e2e": "node scripts/test-rename-e2e.cjs",
|
|
14
15
|
"prepublishOnly": "npm run build",
|
|
15
16
|
"release:minor": "node node_modules/@tertium/js/scripts/release.js minor",
|
|
16
17
|
"release:patch": "node node_modules/@tertium/js/scripts/release.js patch",
|