Skip to content

Commit

Permalink
Add installModuleIfMissing method
Browse files Browse the repository at this point in the history
Toon324 committed Jul 17, 2020
1 parent 693443b commit e9b5827
Showing 3 changed files with 61 additions and 6 deletions.
42 changes: 41 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -14,6 +14,22 @@ https://raw.githubusercontent.com/cswendrowski/foundryget/master/module.json

## Module API

### Install Module if Missing

Checks if module with id `name` exists. If so, checks if `version` is older or equal to the installed version. If either of these is not true, installs the module from `moduleManifest` and returns false.

```js
async installModuleIfMissing(moduleName, version, moduleManifest)
```

### Restart After Install

Returns the game to the Setup screen so that the user may relaunch the world. Required for a module installation to take place.

```js
restartAfterInstall()
```

### Require Module

Checks if module with id `name` exists. If so, checks if `version` is older or equal to the installed version. If either of these is not true, returns false and displays a UI warning.
@@ -34,7 +50,7 @@ requireSystemVersion(yourPackageName, yourPackageManifest, version)

Once the API is ready, a `foundryget-ready` hook is fired

### Example
### Examples

```js
Hooks.once('foundryget-ready', async function() {
@@ -53,6 +69,30 @@ Hooks.once('foundryget-ready', async function() {
});
```


```js
Hooks.once('foundryget-ready', async function() {

var systemRequirement = game.foundryGet.requireSystemVersion("npc-chatter", "https://raw.githubusercontent.com/cswendrowski/FoundryVtt-Npc-Chatter/master/module.json", "2.0.0");

if (!systemRequirement) {
// Cancel module initialization
return;
}

var compendiumWasAlreadyInstalled = game.foundryGet.installModuleIfMissing("13a-dark-alleys-compendium", "1.0.0", "https://github.com/mk572/FoundryVTT-Dark-Alleys-Compendium/releases/download/latest/module.json");

if (!compendiumWasAlreadyInstalled) {
game.foundryGet.restartAfterInstall();
return;
}

game.npcChatter = new NpcChatter();
console.log("Npc Chatter is now ready");

});
```

# The FoundryGet CLI

## Warning!!
10 changes: 5 additions & 5 deletions module.json
Original file line number Diff line number Diff line change
@@ -2,11 +2,11 @@
"name": "foundryget",
"title": "FoundryGet Package Manager",
"description": "The unofficial package manager CLI for FoundryVTT ",
"semanticVersion": "1.0.0",
"version": "1.0.0",
"semanticVersion": "1.2.0",
"version": "1.2.0",
"dependencies": [],
"minimumCoreVersion": "0.6.0",
"compatibleCoreVersion": "0.6.4",
"minimumCoreVersion": "0.7.0",
"compatibleCoreVersion": "0.7.0",
"author": "Cody Swendrowski <cody@swendrowski.us>",
"scripts": [
"/scripts/foundryget.js"
@@ -16,5 +16,5 @@
"packs": [],
"url": "https://github.com/cswendrowski/FoundryVTT-13th-Age-Expanded",
"manifest": "https://raw.githubusercontent.com/cswendrowski/foundryget/master/module.json",
"download": "https://github.com/cswendrowski/foundryget/releases/download/1.0.0/module.zip"
"download": "https://github.com/cswendrowski/foundryget/releases/download/1.2.0/module.zip"
}
15 changes: 15 additions & 0 deletions scripts/foundryget.js
Original file line number Diff line number Diff line change
@@ -2,6 +2,17 @@ class FoundryGet {

// Thanks to Atropos for inspiration: https://gitlab.com/foundrynet/foundryvtt/-/issues/1461#note_365038655

async installModuleIfMissing(moduleName, version, moduleManifest) {
const dependency = game.data.modules.find(x => x.id == moduleName);
if (!dependency || isNewerVersion(version, dependency.data.version)) {
var message = `Installing module ${moduleName} version ${version}. A restart will be required to activate.`;
ui.notifications.info(message);
await SetupConfiguration.installPackage({manifest: moduleManifest});
return false;
}
return true;
}

requireModule(yourPackageName, yourPackageManifest, name, version) {
const dependency = game.data.modules.find(x => x.id == name);
if (!dependency || isNewerVersion(version, dependency.data.version)) {
@@ -20,6 +31,10 @@ class FoundryGet {
}
return true;
}

restartAfterInstall() {
game.shutDown();
}
}

Hooks.once('ready', async function() {

0 comments on commit e9b5827

Please sign in to comment.