Skip to content

Commit 59110c5

Browse files
committed
Cleanup pass and add Readme
1 parent 72f9ad8 commit 59110c5

File tree

6 files changed

+160
-12
lines changed

6 files changed

+160
-12
lines changed

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,110 @@
11
# foundryvtt-cli
22
The official Foundry VTT CLI
3+
4+
## Installation
5+
```bash
6+
npm install -g foundryvtt-cli
7+
```
8+
9+
## Usage
10+
### Help
11+
```bash
12+
fvtt --help
13+
```
14+
15+
### Current CLI Version
16+
```bash
17+
fvtt --version
18+
```
19+
20+
### Configuration
21+
```bash
22+
fvtt configure
23+
```
24+
Determines if your configuration is correct and if not, prompts you to fix it.
25+
26+
#### View
27+
```bash
28+
fvtt configure view
29+
```
30+
31+
View your current configuration.
32+
33+
34+
#### Set
35+
```bash
36+
fvtt configure set "key" "value"
37+
```
38+
39+
Set a configuration value.
40+
41+
#### Get
42+
```bash
43+
fvtt configure get "key"
44+
```
45+
46+
Get a configuration value.
47+
48+
#### Path
49+
```bash
50+
fvtt configure path
51+
```
52+
Outputs the path to your configuration file.
53+
54+
### Launch
55+
56+
```bash
57+
fvtt launch
58+
```
59+
Launches Foundry VTT. Available options are:
60+
* `--demo` - Launches Foundry VTT in demo mode.
61+
* `--port 30000` - Launches Foundry VTT on a specific port.
62+
* `--world my-world` - Launches Foundry VTT straight into a specific world.
63+
* `--noupnp` - Disable UPnP port forwarding.
64+
* `--noupdate` - Disable automatic update checking.
65+
* `--adminKey "ABC123"` - The admin key to secure Foundry VTT's Setup screen with.
66+
67+
### Package
68+
69+
```bash
70+
fvtt package
71+
```
72+
Output the current working package, if any.
73+
74+
#### Workon
75+
```bash
76+
fvtt package workon "1001-fish" --type "module"
77+
```
78+
Swaps to working on a specific package, eliminating the need to pass `--type` and `--id` to other package commands.
79+
80+
#### Clear
81+
```bash
82+
fvtt package clear
83+
```
84+
Clears the current working package.
85+
86+
#### Unpack
87+
```bash
88+
fvtt package unpack "compendiumName"
89+
```
90+
Reads a LevelDB database from the current Package /packs/ directory and writes each document as a serialized Object to its own file.
91+
There are a number of options available to customize the output, check out `fvtt package unpack --help` for more information.
92+
93+
#### Pack
94+
```bash
95+
fvtt package pack "compendiumName"
96+
```
97+
98+
Reads a directory of serialized Objects and writes them to a LevelDB database in the current Package /packs/ directory. There are a number of options available to customize the operation, check out `fvtt package pack --help` for more information.
99+
100+
## Development
101+
```bash
102+
git clone
103+
cd foundryvtt-cli
104+
npm install
105+
npm run build
106+
npm link
107+
```
108+
109+
## Contributing
110+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

commands/configuration.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import Config from "../config.mjs";
22

3+
/**
4+
* Get the command object for the configuration command
5+
* @returns {{handler: ((function(*): Promise<void>)|*), builder: builder, describe: string, command: string}}
6+
*/
37
export function getCommand() {
48
return {
59
command: "configure [action] [key] [value]",

commands/launch.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import Config from "../config.mjs";
22
import {spawn} from "child_process";
33
import path from "path";
44

5+
/**
6+
* Get the command object for the launch command
7+
* @returns {{handler: ((function(*): Promise<void>)|*), builder: builder, describe: string, command: string}}
8+
*/
59
export function getCommand() {
610
return {
711
command: "launch",

commands/package.mjs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import yaml from "js-yaml";
44
import path from "path";
55
import fs from "fs";
66

7+
/**
8+
* Get the command object for the package command
9+
* @returns {{handler: ((function(*): Promise<void>)|*), builder: builder, describe: string, command: string}}
10+
*/
711
export function getCommand() {
812
let currentPackageId = Config.instance.get("currentPackageId");
913
let currentPackageType = Config.instance.get("currentPackageType");
@@ -90,6 +94,10 @@ export function getCommand() {
9094
}
9195

9296
default: {
97+
if ( !currentPackageId ) {
98+
console.error("No package ID is currently set. Use `package workon <id>` to set it.");
99+
return;
100+
}
93101
console.log(`Currently in ${currentPackageType} ${currentPackageId}`);
94102
break;
95103
}
@@ -101,6 +109,7 @@ export function getCommand() {
101109

102110
/**
103111
* Set the current package ID and type
112+
* @param {Object} argv The command line arguments
104113
* @private
105114
*/
106115
function _handleWorkon(argv) {
@@ -144,6 +153,11 @@ export function getCommand() {
144153

145154
/* -------------------------------------------- */
146155

156+
/**
157+
* Normalize a path to use POSIX separators
158+
* @param {string} pathToNormalize The path to normalize
159+
* @returns {string}
160+
*/
147161
function normalizePath(pathToNormalize) {
148162
return path.normalize(pathToNormalize).split(path.sep).join(path.posix.sep);
149163
}
@@ -152,6 +166,7 @@ export function getCommand() {
152166

153167
/**
154168
* Discover the list of all Packages in the dataPath
169+
* @param {Object} argv The command line arguments
155170
* @returns {*}
156171
*/
157172
function discoverPackageDirectory(argv) {
@@ -228,7 +243,7 @@ export function getCommand() {
228243

229244
/**
230245
* Load a pack from a directory and serialize the DB entries, each to their own file
231-
* @param argv
246+
* @param {Object} argv The command line arguments
232247
* @returns {Promise<void>}
233248
* @private
234249
*/
@@ -258,14 +273,8 @@ export function getCommand() {
258273
if (!fs.existsSync(outputDir)) {
259274
fs.mkdirSync(outputDir, {recursive: true});
260275
}
261-
const entries = new Map();
262276
for await (const [key, value] of db.iterator()) {
263277
const name = value.name ? `${value.name.toLowerCase().replaceAll(" ", "_")}_${value._id}` : key;
264-
entries.set(name, value);
265-
}
266-
await db.close();
267-
268-
for (const [name, value] of entries) {
269278
let fileName;
270279
if ( argv.yaml ) {
271280
fileName = `${outputDir}/${name}.yml`;
@@ -277,6 +286,7 @@ export function getCommand() {
277286
}
278287
console.log(`Wrote ${fileName}`);
279288
}
289+
await db.close();
280290
}
281291
catch (err) {
282292
console.error(err);
@@ -287,7 +297,7 @@ export function getCommand() {
287297

288298
/**
289299
* Read serialized files from a directory and write them to a pack db
290-
* @param argv
300+
* @param {Object} argv The command line arguments
291301
* @returns {Promise<void>}
292302
* @private
293303
*/
@@ -312,18 +322,20 @@ export function getCommand() {
312322
try {
313323
// Load the directory as a ClassicLevel db
314324
const db = new ClassicLevel(packDir, {keyEncoding: "utf8", valueEncoding: "json"});
325+
const batch = db.batch();
315326

316327
// Iterate over all YAML files in the input directory, writing them to the db
317328
const files = fs.readdirSync(inputDir);
318329
for ( const file of files ) {
319330
const fileContents = fs.readFileSync(path.join(inputDir, file));
320331
const value = file.endsWith(".yml") ? yaml.load(fileContents) : JSON.parse(fileContents);
321-
await db.put(value._id, value);
332+
batch.put(value._id, value);
322333
console.log(`Packed ${value._id}${value.name ? ` (${value.name})` : ""}`);
323334
}
335+
await batch.write();
324336
}
325337
catch (err) {
326338
console.error(err);
327339
}
328340
}
329-
}
341+
}

config.mjs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export default class Config {
1111

1212
/* -------------------------------------------- */
1313

14+
/**
15+
* Get the singleton instance of the Config class
16+
* @returns {Config}
17+
*/
1418
static get instance() {
1519
if (!this.#instance) {
1620
this.#instance = new Config();
@@ -40,18 +44,32 @@ export default class Config {
4044

4145
/* -------------------------------------------- */
4246

47+
/**
48+
* Get the entire configuration object
49+
* @returns {Map<string, *>}
50+
*/
4351
getAll() {
4452
return this.#config;
4553
}
4654

4755
/* -------------------------------------------- */
4856

57+
/**
58+
* Get a specific configuration value
59+
* @param {string} key The configuration key
60+
* @returns {*}
61+
*/
4962
get(key) {
5063
return this.#config[key];
5164
}
5265

5366
/* -------------------------------------------- */
5467

68+
/**
69+
* Set a specific configuration value
70+
* @param {string} key The configuration key
71+
* @param {*} value The configuration value
72+
*/
5573
set(key, value) {
5674
this.#config[key] = value;
5775

@@ -61,8 +79,10 @@ export default class Config {
6179

6280
/* -------------------------------------------- */
6381

82+
/**
83+
* Write the configuration to disk
84+
*/
6485
#writeConfig() {
65-
// Write to disk
6686
fs.writeFileSync(this.configPath, yaml.dump(this.#config));
6787
}
6888
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@foundryvtt/fvtt",
2+
"name": "@foundryvtt/foundryvtt-cli",
33
"productName": "Foundry VTT CLI",
44
"description": "The Official CLI for Foundry VTT",
55
"version": "0.0.4",

0 commit comments

Comments
 (0)