@k03mad/dice 11.7.1 → 12.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.
- package/.github/workflows/lint.yml +1 -1
- package/.github/workflows/publish.yml +1 -1
- package/app/run.ts +43 -0
- package/app/utils/config.ts +29 -0
- package/app/utils/helpers.ts +9 -0
- package/package.json +9 -6
- package/pnpm-workspace.yaml +1 -41
- package/tsconfig.json +9 -0
- package/app/run.js +0 -43
- package/app/utils/config.js +0 -29
- package/app/utils/helpers.js +0 -2
package/app/run.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {emitKeypressEvents} from 'node:readline';
|
|
6
|
+
|
|
7
|
+
import image from 'terminal-image';
|
|
8
|
+
|
|
9
|
+
import config from './utils/config.ts';
|
|
10
|
+
import {getRandomArrElem} from './utils/helpers.ts';
|
|
11
|
+
|
|
12
|
+
const imgFolderAbs = path.join(import.meta.dirname, config.dice.picturesFolder);
|
|
13
|
+
|
|
14
|
+
const imgFiles: string[] = await fs.readdir(imgFolderAbs);
|
|
15
|
+
const imgFilesAbs = imgFiles.map(img => path.join(imgFolderAbs, img));
|
|
16
|
+
|
|
17
|
+
emitKeypressEvents(process.stdin);
|
|
18
|
+
process.stdin.setRawMode(true);
|
|
19
|
+
|
|
20
|
+
let diceCurrentCount: number = config.dice.defaultCount;
|
|
21
|
+
console.log(config.messages.welcome);
|
|
22
|
+
|
|
23
|
+
process.stdin.on('keypress', async (char: string, key: {ctrl: boolean; name: string}) => {
|
|
24
|
+
if (
|
|
25
|
+
(key.ctrl === true && key.name === config.exit.ctrlKeyModifier) ||
|
|
26
|
+
char === config.exit.extraKey
|
|
27
|
+
) {
|
|
28
|
+
process.exit();
|
|
29
|
+
} else {
|
|
30
|
+
console.log(config.dice.separator);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
diceCurrentCount = Number(char) || diceCurrentCount;
|
|
34
|
+
|
|
35
|
+
const output = await Promise.all(
|
|
36
|
+
Array.from({length: diceCurrentCount}, () => {
|
|
37
|
+
const diceImg = getRandomArrElem(imgFilesAbs);
|
|
38
|
+
return image.file(diceImg, {height: config.dice.height});
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
console.log(output.join('\n'));
|
|
43
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
|
|
3
|
+
const {green, dim, bold} = chalk;
|
|
4
|
+
|
|
5
|
+
const EXIT_EXTRA_KEY = 'q';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
dice: {
|
|
9
|
+
defaultCount: 1,
|
|
10
|
+
picturesFolder: 'png',
|
|
11
|
+
height: '30%',
|
|
12
|
+
separator: dim('>\n'),
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
exit: {
|
|
16
|
+
ctrlKeyModifier: 'c',
|
|
17
|
+
extraKey: EXIT_EXTRA_KEY,
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
messages: {
|
|
21
|
+
welcome: green(
|
|
22
|
+
[
|
|
23
|
+
'— type any digit to generate that number of dice',
|
|
24
|
+
'— press any key to reroll dice',
|
|
25
|
+
`— press ${bold('CTRL+C')} or type '${bold(EXIT_EXTRA_KEY)}' to exit`,
|
|
26
|
+
].join('\n'),
|
|
27
|
+
),
|
|
28
|
+
},
|
|
29
|
+
} as const;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@k03mad/dice",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "12.0.0",
|
|
4
4
|
"description": "Dice",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"maintainers": [
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"url": "git+https://github.com/k03mad/dice.git"
|
|
12
12
|
},
|
|
13
13
|
"bin": {
|
|
14
|
-
"dice": "app/run.
|
|
14
|
+
"dice": "app/run.ts"
|
|
15
15
|
},
|
|
16
16
|
"type": "module",
|
|
17
17
|
"scripts": {
|
|
18
|
-
"lint": "oxlint && oxfmt -c node_modules/@k03mad/oxlint-config/.oxfmtrc.json --check",
|
|
18
|
+
"lint": "oxlint && oxfmt -c node_modules/@k03mad/oxlint-config/.oxfmtrc.json --check && tsc --noEmit",
|
|
19
19
|
"prepare": "husky || true"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
@@ -23,10 +23,13 @@
|
|
|
23
23
|
"terminal-image": "4.3.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@k03mad/oxlint-config": "0.
|
|
26
|
+
"@k03mad/oxlint-config": "0.10.1",
|
|
27
|
+
"@tsconfig/strictest": "2.0.8",
|
|
28
|
+
"@types/node": "26.1.0",
|
|
27
29
|
"husky": "9.1.7",
|
|
28
|
-
"oxfmt": "0.
|
|
29
|
-
"oxlint": "1.
|
|
30
|
+
"oxfmt": "0.57.0",
|
|
31
|
+
"oxlint": "1.72.0",
|
|
32
|
+
"typescript": "6.0.3"
|
|
30
33
|
},
|
|
31
34
|
"engines": {
|
|
32
35
|
"node": ">=24"
|
package/pnpm-workspace.yaml
CHANGED
|
@@ -1,42 +1,2 @@
|
|
|
1
1
|
minimumReleaseAgeExclude:
|
|
2
|
-
- '@k03mad/oxlint-config@0.
|
|
3
|
-
- '@oxfmt/binding-android-arm-eabi@0.53.0'
|
|
4
|
-
- '@oxfmt/binding-android-arm64@0.53.0'
|
|
5
|
-
- '@oxfmt/binding-darwin-arm64@0.53.0'
|
|
6
|
-
- '@oxfmt/binding-darwin-x64@0.53.0'
|
|
7
|
-
- '@oxfmt/binding-freebsd-x64@0.53.0'
|
|
8
|
-
- '@oxfmt/binding-linux-arm-gnueabihf@0.53.0'
|
|
9
|
-
- '@oxfmt/binding-linux-arm-musleabihf@0.53.0'
|
|
10
|
-
- '@oxfmt/binding-linux-arm64-gnu@0.53.0'
|
|
11
|
-
- '@oxfmt/binding-linux-arm64-musl@0.53.0'
|
|
12
|
-
- '@oxfmt/binding-linux-ppc64-gnu@0.53.0'
|
|
13
|
-
- '@oxfmt/binding-linux-riscv64-gnu@0.53.0'
|
|
14
|
-
- '@oxfmt/binding-linux-riscv64-musl@0.53.0'
|
|
15
|
-
- '@oxfmt/binding-linux-s390x-gnu@0.53.0'
|
|
16
|
-
- '@oxfmt/binding-linux-x64-gnu@0.53.0'
|
|
17
|
-
- '@oxfmt/binding-linux-x64-musl@0.53.0'
|
|
18
|
-
- '@oxfmt/binding-openharmony-arm64@0.53.0'
|
|
19
|
-
- '@oxfmt/binding-win32-arm64-msvc@0.53.0'
|
|
20
|
-
- '@oxfmt/binding-win32-ia32-msvc@0.53.0'
|
|
21
|
-
- '@oxfmt/binding-win32-x64-msvc@0.53.0'
|
|
22
|
-
- '@oxlint/binding-android-arm-eabi@1.68.0'
|
|
23
|
-
- '@oxlint/binding-android-arm64@1.68.0'
|
|
24
|
-
- '@oxlint/binding-darwin-arm64@1.68.0'
|
|
25
|
-
- '@oxlint/binding-darwin-x64@1.68.0'
|
|
26
|
-
- '@oxlint/binding-freebsd-x64@1.68.0'
|
|
27
|
-
- '@oxlint/binding-linux-arm-gnueabihf@1.68.0'
|
|
28
|
-
- '@oxlint/binding-linux-arm-musleabihf@1.68.0'
|
|
29
|
-
- '@oxlint/binding-linux-arm64-gnu@1.68.0'
|
|
30
|
-
- '@oxlint/binding-linux-arm64-musl@1.68.0'
|
|
31
|
-
- '@oxlint/binding-linux-ppc64-gnu@1.68.0'
|
|
32
|
-
- '@oxlint/binding-linux-riscv64-gnu@1.68.0'
|
|
33
|
-
- '@oxlint/binding-linux-riscv64-musl@1.68.0'
|
|
34
|
-
- '@oxlint/binding-linux-s390x-gnu@1.68.0'
|
|
35
|
-
- '@oxlint/binding-linux-x64-gnu@1.68.0'
|
|
36
|
-
- '@oxlint/binding-linux-x64-musl@1.68.0'
|
|
37
|
-
- '@oxlint/binding-openharmony-arm64@1.68.0'
|
|
38
|
-
- '@oxlint/binding-win32-arm64-msvc@1.68.0'
|
|
39
|
-
- '@oxlint/binding-win32-ia32-msvc@1.68.0'
|
|
40
|
-
- '@oxlint/binding-win32-x64-msvc@1.68.0'
|
|
41
|
-
- oxfmt@0.53.0
|
|
42
|
-
- oxlint@1.68.0
|
|
2
|
+
- '@k03mad/oxlint-config@0.10.1'
|
package/tsconfig.json
ADDED
package/app/run.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import fs from 'node:fs/promises';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import {emitKeypressEvents} from 'node:readline';
|
|
6
|
-
|
|
7
|
-
import image from 'terminal-image';
|
|
8
|
-
|
|
9
|
-
import config from './utils/config.js';
|
|
10
|
-
import {getRandomArrElem} from './utils/helpers.js';
|
|
11
|
-
|
|
12
|
-
const imgFolderAbs = path.join(import.meta.dirname, config.dice.picturesFolder);
|
|
13
|
-
|
|
14
|
-
const imgFiles = await fs.readdir(imgFolderAbs);
|
|
15
|
-
const imgFilesAbs = imgFiles.map(img => path.join(imgFolderAbs, img));
|
|
16
|
-
|
|
17
|
-
emitKeypressEvents(process.stdin);
|
|
18
|
-
process.stdin.setRawMode(true);
|
|
19
|
-
|
|
20
|
-
let diceCurrentCount = config.dice.defaultCount;
|
|
21
|
-
console.log(config.messages.welcome);
|
|
22
|
-
|
|
23
|
-
process.stdin.on('keypress', async (char, key) => {
|
|
24
|
-
if (
|
|
25
|
-
(key.ctrl === true && key.name === config.exit.ctrlKeyModifier) ||
|
|
26
|
-
char === config.exit.extraKey
|
|
27
|
-
) {
|
|
28
|
-
process.exit();
|
|
29
|
-
} else {
|
|
30
|
-
console.log(config.dice.separator);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
diceCurrentCount = Number(char) || diceCurrentCount;
|
|
34
|
-
|
|
35
|
-
const output = await Promise.all(
|
|
36
|
-
Array.from({length: diceCurrentCount}, () => {
|
|
37
|
-
const diceImg = getRandomArrElem(imgFilesAbs);
|
|
38
|
-
return image.file(diceImg, {height: config.dice.height});
|
|
39
|
-
}),
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
console.log(output.join('\n'));
|
|
43
|
-
});
|
package/app/utils/config.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
|
|
3
|
-
const {green, dim, bold} = chalk;
|
|
4
|
-
|
|
5
|
-
const EXIT_EXTRA_KEY = 'q';
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
dice: {
|
|
9
|
-
defaultCount: 1,
|
|
10
|
-
picturesFolder: 'png',
|
|
11
|
-
height: '30%',
|
|
12
|
-
separator: dim('>\n'),
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
exit: {
|
|
16
|
-
ctrlKeyModifier: 'c',
|
|
17
|
-
extraKey: EXIT_EXTRA_KEY,
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
messages: {
|
|
21
|
-
welcome: green(
|
|
22
|
-
[
|
|
23
|
-
'— type any digit to generate that number of dice',
|
|
24
|
-
'— press any key to reroll dice',
|
|
25
|
-
`— press ${bold('CTRL+C')} or type '${bold(EXIT_EXTRA_KEY)}' to exit`,
|
|
26
|
-
].join('\n'),
|
|
27
|
-
),
|
|
28
|
-
},
|
|
29
|
-
};
|
package/app/utils/helpers.js
DELETED