Skip to content

Commit 9f54d95

Browse files
committed
Make runnable, swap to using appdata
1 parent 34e6f81 commit 9f54d95

File tree

7 files changed

+65
-14
lines changed

7 files changed

+65
-14
lines changed

commands/configuration.mjs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function getCommand() {
88
yargs.positional("action", {
99
describe: "The action to perform",
1010
type: "string",
11-
choices: ["get", "set"]
11+
choices: ["get", "set", "path"]
1212
})
1313
.positional("key", {
1414
describe: "The configuration key",
@@ -20,7 +20,6 @@ export function getCommand() {
2020
});
2121
},
2222
handler: async (argv) => {
23-
console.log("configure handler", argv);
2423

2524
// Handle actions
2625
switch ( argv.action ) {
@@ -33,11 +32,33 @@ export function getCommand() {
3332
console.log(`Set ${argv.key} to ${argv.value}`);
3433
break;
3534
}
36-
default: {
35+
case "view": {
3736
// Output the current configuration
38-
console.log(Config.instance.getAll());
37+
console.log("Current Configuration:", Config.instance.getAll());
38+
break;
39+
}
40+
case "path": {
41+
// Output the current configuration file path
42+
console.log("Current Configuration File:", Config.instance.configPath);
3943
break;
4044
}
45+
default: {
46+
// Determine if the dataPath and installPath are set
47+
const installPath = Config.instance.get("installPath");
48+
if ( !installPath ) {
49+
console.error("The installation path is not set. Use `configure set installPath <path>` to set it. Install paths look like `C:/Program Files/Foundry Virtual Tabletop`");
50+
}
51+
52+
const dataPath = Config.instance.get("dataPath");
53+
if ( !dataPath ) {
54+
console.error("The data path is not set. Use `configure set dataPath <path>` to set it. Data paths look like `C:/Users/Example/AppData/Local/FoundryVTT/Data`");
55+
}
56+
57+
// If both are set, configuration is complete
58+
if ( installPath && dataPath ) {
59+
console.log("Configuration complete!");
60+
}
61+
}
4162
}
4263
}
4364
}

commands/package.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ export function getCommand() {
4646
});
4747
},
4848
handler: async (argv) => {
49-
console.log("package handler", argv);
50-
5149
if ( argv.id ) {
5250
currentPackageId = argv.id;
5351
}
@@ -190,7 +188,7 @@ export function getCommand() {
190188
return;
191189
}
192190
const packDir = normalizePath(`${dataPath}/${typeDir}/${currentPackageId}/data/${documentDir}`);
193-
const inputDir = normalizePath(`${argv.directory ?? `./${typeDir}/${currentPackageId}`}/${documentDir}`);
191+
const inputDir = normalizePath(`${argv.directory ? argv.directory : `./${typeDir}/${currentPackageId}`}/${documentDir}`);
194192
console.log(`Packing "${inputDir}" into pack "${packDir}"`);
195193

196194
try {

config.example.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
installPath: C:\Program Files\Foundry Virtual Tabletop
12
dataPath: C:\Users\Example\AppData\Local\FoundryVTT\Data
23
currentPackageId: example-id
34
currentPackageType: World

config.mjs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from "fs";
22
import yaml from "js-yaml";
3+
import path from "path";
34

45
/**
56
* Manages the configuration of the CLI. Stored as config.yml
@@ -20,13 +21,23 @@ export default class Config {
2021
/* -------------------------------------------- */
2122

2223
constructor() {
23-
this.#config = yaml.load(fs.readFileSync("./config.yml", "utf8"));
24+
25+
// Set the config file path to the appData directory
26+
this.configPath = path.join(process.env.APPDATA ?? process.env.HOME, "config.yml");
27+
28+
// Ensure the config file exists
29+
if (!fs.existsSync(this.configPath)) {
30+
fs.writeFileSync(this.configPath, yaml.dump({}));
31+
}
32+
this.#config = yaml.load(fs.readFileSync(this.configPath, "utf8"));
2433
}
2534

2635
/* -------------------------------------------- */
2736

2837
#config = {};
2938

39+
configPath = "";
40+
3041
/* -------------------------------------------- */
3142

3243
getAll() {
@@ -52,6 +63,6 @@ export default class Config {
5263

5364
#writeConfig() {
5465
// Write to disk
55-
fs.writeFileSync("./config.yml", yaml.dump(this.#config));
66+
fs.writeFileSync(this.configPath, yaml.dump(this.#config));
5667
}
5768
}

fvtt.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#!/usr/bin/env node
2+
13
import yargs from "yargs";
24
import {hideBin} from "yargs/helpers";
35
import {getCommand as configureCommand} from "./commands/configuration.mjs";

package-lock.json

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@foundryvtt/fvtt",
33
"productName": "Foundry VTT CLI",
44
"description": "The Official CLI for Foundry VTT",
5-
"version": "0.0.2",
5+
"version": "0.0.3",
66
"author": {
77
"name": "Foundry Gaming LLC",
88
"email": "admin@foundryvtt.com",
@@ -17,6 +17,7 @@
1717
"private": false,
1818
"dependencies": {
1919
"classic-level": "^1.2.0",
20+
"esm": "^3.2.25",
2021
"js-yaml": "^4.1.0",
2122
"yargs": "^17.7.1"
2223
}

0 commit comments

Comments
 (0)