pf2e-sage-stats 0.1.1
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/README.md +143 -0
- package/dist/app.js +409 -0
- package/dist/index.js +199 -0
- package/eslint.config.mjs +11 -0
- package/jest.config.ts +11 -0
- package/package.json +40 -0
- package/src/app.ts +623 -0
- package/src/index.ts +198 -0
- package/src/types.d.ts +5 -0
- package/test/app.test.ts +67 -0
- package/tsconfig.json +14 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import fs from 'fs/promises';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
import pack from '../package.json';
|
|
8
|
+
|
|
9
|
+
import { formatCommand, formatJSON, formatTSV, fromatMap, valueNameMap, flatMap, parseJSON, parseStatblock, stub, valueMap, diceMap, diceNameMap, adjustmentMap, prediceateMap, formatTable, formatHP } from './app';
|
|
10
|
+
|
|
11
|
+
const program = new Command(pack.name);
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.name(pack.name)
|
|
15
|
+
.description(pack.description)
|
|
16
|
+
.version(pack.version);
|
|
17
|
+
|
|
18
|
+
program.command('stub')
|
|
19
|
+
.description('Generte a stat JSON template')
|
|
20
|
+
.option('-o, --output <file>', 'output json')
|
|
21
|
+
.action(async (option) => {
|
|
22
|
+
if (option.output) {
|
|
23
|
+
await fs.writeFile(option.output, formatJSON(stub), { encoding: 'utf-8' })
|
|
24
|
+
} else {
|
|
25
|
+
console.log(formatJSON(stub));
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
program.command('table')
|
|
30
|
+
.description('Generte a table configuration string')
|
|
31
|
+
.argument('<string>', 'table name')
|
|
32
|
+
.option('-o, --output <file>', 'output file')
|
|
33
|
+
.option('-t, --table <string>', 'table')
|
|
34
|
+
.option('-s, --season <string>', 'season')
|
|
35
|
+
.option('-c, --scenario <string>', 'scenario')
|
|
36
|
+
.option('-g, --gm <string>', 'gm')
|
|
37
|
+
.option('-p, --players <string>', 'players')
|
|
38
|
+
.action(async (argument, option) => {
|
|
39
|
+
if (option.output) {
|
|
40
|
+
await fs.writeFile(option.output, formatTable(Number(option.table ?? 1), Number(option.season ?? 1), Number(option.scenario ?? 1), argument, option.gm ?? '@lammonaaf', option.players ?? '<players>'), { encoding: 'utf-8' })
|
|
41
|
+
} else {
|
|
42
|
+
console.log(formatTable(Number(option.table ?? 1), Number(option.season ?? 1), Number(option.scenario ?? 1), argument, option.gm ?? '@lammonaaf', option.players ?? '<players>'));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
program.command('hp')
|
|
47
|
+
.description('Generte an hp bar')
|
|
48
|
+
.argument('<string>', 'hp/maxhp')
|
|
49
|
+
.action(async (argument) => {
|
|
50
|
+
console.log(formatHP(argument));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
program.command('flat')
|
|
54
|
+
.description('Generte a special flat npc tsv')
|
|
55
|
+
.option('-n, --name <string>', 'npc name')
|
|
56
|
+
.option('-o, --output <file>', 'output json')
|
|
57
|
+
.option('-s, --short', 'omit explosion')
|
|
58
|
+
.action(async (option) => {
|
|
59
|
+
if (option.output) {
|
|
60
|
+
await fs.writeFile(option.output, fromatMap(option.name ?? 'flat', option.short ? prediceateMap : flatMap), { encoding: 'utf-8' })
|
|
61
|
+
} else {
|
|
62
|
+
console.log(fromatMap(option.name ?? 'flat', option.short ? prediceateMap : flatMap));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
program.command('valuename')
|
|
67
|
+
.description('Generte a special value name npc tsv')
|
|
68
|
+
.option('-n, --name <string>', 'npc name')
|
|
69
|
+
.option('-t, --tag <string>', 'name tag')
|
|
70
|
+
.option('-o, --output <file>', 'output json')
|
|
71
|
+
.action(async (option) => {
|
|
72
|
+
if (option.output) {
|
|
73
|
+
await fs.writeFile(option.output, fromatMap(option.name ?? 'valuename', valueNameMap(option.tag ?? null)), { encoding: 'utf-8' })
|
|
74
|
+
} else {
|
|
75
|
+
console.log(fromatMap(option.name ?? 'valuename', valueNameMap(option.tag ?? null)));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
program.command('value')
|
|
80
|
+
.description('Generte a special value npc tsv')
|
|
81
|
+
.option('-n, --name <string>', 'npc name')
|
|
82
|
+
.option('-o, --output <file>', 'output json')
|
|
83
|
+
.action(async (option) => {
|
|
84
|
+
if (option.output) {
|
|
85
|
+
await fs.writeFile(option.output, fromatMap(option.name ?? 'value', valueMap()), { encoding: 'utf-8' })
|
|
86
|
+
} else {
|
|
87
|
+
console.log(fromatMap(option.name ?? 'value', valueMap()));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
program.command('dicename')
|
|
92
|
+
.description('Generte a special dice npc tsv')
|
|
93
|
+
.option('-n, --name <string>', 'npc name')
|
|
94
|
+
.option('-o, --output <file>', 'output json')
|
|
95
|
+
.action(async (option) => {
|
|
96
|
+
if (option.output) {
|
|
97
|
+
await fs.writeFile(option.output, fromatMap(option.name ?? 'dicename', diceNameMap()), { encoding: 'utf-8' })
|
|
98
|
+
} else {
|
|
99
|
+
console.log(fromatMap(option.name ?? 'dicename', valueMap()));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
program.command('dice')
|
|
104
|
+
.description('Generte a special dicemod npc tsv')
|
|
105
|
+
.option('-n, --name <string>', 'npc name')
|
|
106
|
+
.option('-o, --output <file>', 'output json')
|
|
107
|
+
.action(async (option) => {
|
|
108
|
+
if (option.output) {
|
|
109
|
+
await fs.writeFile(option.output, fromatMap(option.name ?? 'dice', diceMap()), { encoding: 'utf-8' })
|
|
110
|
+
} else {
|
|
111
|
+
console.log(fromatMap(option.name ?? 'dice', valueMap()));
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
program.command('adjustment')
|
|
116
|
+
.description('Generte a special adjustment npc tsv')
|
|
117
|
+
.option('-n, --name <string>', 'npc name')
|
|
118
|
+
.option('-o, --output <file>', 'output json')
|
|
119
|
+
.action(async (option) => {
|
|
120
|
+
if (option.output) {
|
|
121
|
+
await fs.writeFile(option.output, fromatMap(option.name ?? 'adjustment', adjustmentMap()), { encoding: 'utf-8' })
|
|
122
|
+
} else {
|
|
123
|
+
console.log(fromatMap(option.name ?? 'adjustment', adjustmentMap()));
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
program.command('statblock')
|
|
128
|
+
.description('Generte a stat JSON from Paizo creature statblock')
|
|
129
|
+
.argument('<file>', 'input text file')
|
|
130
|
+
.option('-n, --name <string>', 'creature name')
|
|
131
|
+
.option('-a, --alias <string>', 'creature alias')
|
|
132
|
+
.option('-b, --abbreviate', 'create alias from name')
|
|
133
|
+
.option('-t, --tsv', 'output directly to tsv')
|
|
134
|
+
.option('-c, --command', 'output directly to txt')
|
|
135
|
+
.option('-s, --secretDC', 'produce secret DCs (tsv only)')
|
|
136
|
+
.option('-d, --defaultSkills', 'produce values for untrained skills (tsv only)')
|
|
137
|
+
.option('-e, --desc', 'produce verbose desc fields (tsv only)')
|
|
138
|
+
.option('-o, --output <file>', 'output file name')
|
|
139
|
+
.action(async (argument, option) => {
|
|
140
|
+
const file = await fs.readFile(argument, { encoding: 'utf-8' });
|
|
141
|
+
|
|
142
|
+
const alias = option.alias ?? (option.abbreviate ? null : (option.output ? path.parse(option.output).name : path.parse(argument).name));
|
|
143
|
+
|
|
144
|
+
const stats = parseStatblock(option.name ?? null, file, alias);
|
|
145
|
+
|
|
146
|
+
if (option.tsv) {
|
|
147
|
+
const output = option.output ? option.output : path.join(path.parse(argument).dir, stats.alias + '.tsv');
|
|
148
|
+
|
|
149
|
+
await fs.writeFile(output, formatTSV(stats, option.secretDC, option.defaultSkills, option.desc), { encoding: 'utf-8' });
|
|
150
|
+
} else if (option.command) {
|
|
151
|
+
const output = option.output ? option.output : path.join(path.parse(argument).dir, stats.alias + '-command.txt');
|
|
152
|
+
|
|
153
|
+
await fs.writeFile(output, formatCommand(stats, option.secretDC, option.defaultSkills, option.desc), { encoding: 'utf-8' });
|
|
154
|
+
} else {
|
|
155
|
+
const output = option.output ? option.output : path.join(path.parse(argument).dir, stats.alias + '.json');
|
|
156
|
+
|
|
157
|
+
await fs.writeFile(output, formatJSON(stats), { encoding: 'utf-8' });
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
program.command('tsv')
|
|
162
|
+
.description('Generte a tsv file from JSON')
|
|
163
|
+
.argument('<file>', 'input json')
|
|
164
|
+
.option('-o, --output <file>', 'output tsv')
|
|
165
|
+
.option('-s, --secretDC', 'produce secret DCs')
|
|
166
|
+
.option('-r, --recallDC', 'produce recall DCs')
|
|
167
|
+
.option('-d, --defaultSkills', 'produce values for untrained skills')
|
|
168
|
+
.option('-e, --desc', 'produce verbose desc fields')
|
|
169
|
+
.action(async (argument, option) => {
|
|
170
|
+
const file = await fs.readFile(argument, { encoding: 'utf-8' });
|
|
171
|
+
|
|
172
|
+
const stats = parseJSON(file);
|
|
173
|
+
|
|
174
|
+
const output = option.output ? option.output : path.join(path.parse(argument).dir, path.parse(argument).name + '.tsv');
|
|
175
|
+
|
|
176
|
+
await fs.writeFile(output, formatTSV(stats, option.secretDC, option.defaultSkills, option.recallDC, option.desc), { encoding: 'utf-8' });
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
program.command('command')
|
|
180
|
+
.description('Generte a creation command file from JSON')
|
|
181
|
+
.argument('<file>', 'input json')
|
|
182
|
+
.option('-o, --output <file>', 'output txt')
|
|
183
|
+
.option('-s, --secretDC', 'produce secret DCs')
|
|
184
|
+
.option('-r, --recallDC', 'produce recall DCs')
|
|
185
|
+
.option('-d, --defaultSkills', 'produce values for untrained skills')
|
|
186
|
+
.option('-e, --desc', 'produce verbose desc fields')
|
|
187
|
+
.action(async (argument, option) => {
|
|
188
|
+
const file = await fs.readFile(argument, { encoding: 'utf-8' });
|
|
189
|
+
|
|
190
|
+
const stats = parseJSON(file);
|
|
191
|
+
|
|
192
|
+
const output = option.output ? option.output : path.join(path.parse(argument).dir, path.parse(argument).name + '-command.txt');
|
|
193
|
+
|
|
194
|
+
await fs.writeFile(output, formatCommand(stats, option.secretDC, option.defaultSkills, option.recallDC, option.desc), { encoding: 'utf-8' });
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
program.parse();
|
package/src/types.d.ts
ADDED
package/test/app.test.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parseJSON, stub } from '../src/app';
|
|
2
|
+
|
|
3
|
+
test('stats', () => {
|
|
4
|
+
expect(stub).toEqual({
|
|
5
|
+
name: 'name',
|
|
6
|
+
alias: 'nm',
|
|
7
|
+
level: 0,
|
|
8
|
+
maxhp: 0,
|
|
9
|
+
attributes: {
|
|
10
|
+
strength: 0,
|
|
11
|
+
dextrenity: 0,
|
|
12
|
+
constitution: 0,
|
|
13
|
+
intelligence: 0,
|
|
14
|
+
wisdom: 0,
|
|
15
|
+
charisma: 0,
|
|
16
|
+
},
|
|
17
|
+
saves: {
|
|
18
|
+
fortitude: 0,
|
|
19
|
+
reflex: 0,
|
|
20
|
+
will: 0,
|
|
21
|
+
},
|
|
22
|
+
ac: 10,
|
|
23
|
+
perception: 0,
|
|
24
|
+
skills: {
|
|
25
|
+
acrobatics: 0,
|
|
26
|
+
arcana: 0,
|
|
27
|
+
athletics: 0,
|
|
28
|
+
crafting: 0,
|
|
29
|
+
deception: 0,
|
|
30
|
+
diplomacy: 0,
|
|
31
|
+
intimidation: 0,
|
|
32
|
+
medicine: 0,
|
|
33
|
+
nature: 0,
|
|
34
|
+
occultism: 0,
|
|
35
|
+
perfomance: 0,
|
|
36
|
+
religion: 0,
|
|
37
|
+
society: 0,
|
|
38
|
+
stealth: 0,
|
|
39
|
+
survival: 0,
|
|
40
|
+
thievery: 0,
|
|
41
|
+
},
|
|
42
|
+
lores: {},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
expect(parseJSON('{"name":"Test"}')).toEqual({
|
|
46
|
+
name: 'Test',
|
|
47
|
+
level: 0,
|
|
48
|
+
maxhp: 0,
|
|
49
|
+
attributes: {
|
|
50
|
+
strength: 0,
|
|
51
|
+
dextrenity: 0,
|
|
52
|
+
constitution: 0,
|
|
53
|
+
intelligence: 0,
|
|
54
|
+
wisdom: 0,
|
|
55
|
+
charisma: 0,
|
|
56
|
+
},
|
|
57
|
+
saves: {
|
|
58
|
+
fortitude: 0,
|
|
59
|
+
reflex: 0,
|
|
60
|
+
will: 0,
|
|
61
|
+
},
|
|
62
|
+
ac: 10,
|
|
63
|
+
perception: 0,
|
|
64
|
+
skills: {},
|
|
65
|
+
lores: {},
|
|
66
|
+
});
|
|
67
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*.ts"]
|
|
14
|
+
}
|