sl-train 1.0.0

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.
Files changed (4) hide show
  1. package/index.js +71 -0
  2. package/ls.js +14 -0
  3. package/package.json +13 -0
  4. package/sl.js +20 -0
package/index.js ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+
5
+ // Target how Windows / npm initiated the command thread execution
6
+ const npmLifecycle = process.env.npm_lifecycle_script || '';
7
+ const rawCommandString = (process.argv[0] + ' ' + process.argv[1] + ' ' + npmLifecycle).toLowerCase();
8
+
9
+ // Check if the caller specifically wanted the Train or the directory list
10
+ const isSlCommand = rawCommandString.includes('sl') && !rawCommandString.includes('ls');
11
+
12
+ if (isSlCommand) {
13
+ const trainFrame = [
14
+ " ==== ________ ___________ ",
15
+ " _D _| L_Y_B. | | _____ | |",
16
+ " [___________] |________| |_____| |___________|",
17
+ " | u o o o u | | | | | | |",
18
+ " |___________| |________| |_____| |___________|",
19
+ " OOOOO OOOOO O O O O O O"
20
+ ];
21
+
22
+ let position = process.stdout.columns || 80;
23
+
24
+ const interval = setInterval(() => {
25
+ console.clear();
26
+ if (position < -60) {
27
+ clearInterval(interval);
28
+ process.exit(0);
29
+ }
30
+
31
+ trainFrame.forEach(line => {
32
+ const spaces = Math.max(0, position);
33
+ const truncatedLine = position < 0 ? line.slice(Math.abs(position)) : line;
34
+ console.log(" ".repeat(spaces) + truncatedLine);
35
+ });
36
+
37
+ position -= 3;
38
+ }, 40);
39
+ return;
40
+ }
41
+
42
+ // EXACT LINUX LS OUTPUT MATCH ENGINE
43
+ const args = process.argv.slice(2);
44
+ const targetDir = args.filter(arg => !arg.startsWith('-'))[0] || process.cwd();
45
+
46
+ fs.readdir(targetDir, (err, files) => {
47
+ if (err) {
48
+ console.error(`ls: cannot access '${targetDir}': No such file or directory`);
49
+ process.exit(1);
50
+ }
51
+
52
+ // Linux lists items sorted alphabetically ignoring case, completely skipping hidden dotfiles by default
53
+ let sortedFiles = files
54
+ .filter(f => !f.startsWith('.'))
55
+ .sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
56
+
57
+ if (sortedFiles.length === 0) return;
58
+
59
+ // Map out the clean horizontal terminal inline chain matrix
60
+ const outputString = sortedFiles.map(file => {
61
+ try {
62
+ const isDirectory = fs.statSync(path.join(targetDir, file)).isDirectory();
63
+ // True Ubuntu/Fedora style: Bold blue text coloring accents for folders
64
+ return isDirectory ? `\x1b[1;\x1b[34m${file}\x1b[0m` : file;
65
+ } catch (e) {
66
+ return file;
67
+ }
68
+ }).join(' '); // Replicates the exact double-space column margins used by GNU coreutils
69
+
70
+ console.log(outputString);
71
+ });
package/ls.js ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const args = process.argv.slice(2);
5
+ const targetDir = args.filter(arg => !arg.startsWith('-'))[0] || process.cwd();
6
+ fs.readdir(targetDir, (err, files) => {
7
+ if (err) { console.error(`ls: cannot access '${targetDir}': No such file or directory`); process.exit(1); }
8
+ let sortedFiles = files.filter(f => !f.startsWith('.')).sort((a, b) => a.toLowerCase().localeCompare(b.toLowerCase()));
9
+ if (sortedFiles.length === 0) return;
10
+ const outputString = sortedFiles.map(file => {
11
+ try { return fs.statSync(path.join(targetDir, file)).isDirectory() ? `\x1b[1;\x1b[34m${file}\x1b[0m` : file; } catch (e) { return file; }
12
+ }).join(' ');
13
+ console.log(outputString);
14
+ });
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "sl-train",
3
+ "version": "1.0.0",
4
+ "description": "True Linux-style ls layout and the classic sl steam locomotive animation engine for Windows users.",
5
+ "main": "ls.js",
6
+ "bin": {
7
+ "ls": "ls.js",
8
+ "sl": "sl.js"
9
+ },
10
+ "keywords": ["ls", "sl", "linux", "ubuntu", "windows", "train"],
11
+ "author": "Kanika",
12
+ "license": "MIT"
13
+ }
package/sl.js ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ const trainFrame = [
3
+ " ==== ________ ___________ ",
4
+ " _D _| L_Y_B. | | _____ | |",
5
+ " [___________] |________| |_____| |___________|",
6
+ " | u o o o u | | | | | | |",
7
+ " |___________| |________| |_____| |___________|",
8
+ " OOOOO OOOOO O O O O O O"
9
+ ];
10
+ let position = process.stdout.columns || 80;
11
+ const interval = setInterval(() => {
12
+ console.clear();
13
+ if (position < -60) { clearInterval(interval); process.exit(0); }
14
+ trainFrame.forEach(line => {
15
+ const spaces = Math.max(0, position);
16
+ const truncatedLine = position < 0 ? line.slice(Math.abs(position)) : line;
17
+ console.log(" ".repeat(spaces) + truncatedLine);
18
+ });
19
+ position -= 3;
20
+ }, 40);