Skip to content

Commit

Permalink
Merge pull request #103 from EllenFawkes/npm
Browse files Browse the repository at this point in the history
Npm dependencies for plugins
  • Loading branch information
Ellen Fawkes authored Sep 17, 2017
2 parents 7533e52 + ae4c9d4 commit c713781
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
node_modules
**/node_modules
npm-debug.log
.git
.gitignore
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
node_modules/*
node_modules
npm-debug.log
purrplingbot.log
package-lock.json
config/*.json
config/*.yaml
config/*.yml
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ RUN npm install
# Copy app bundle
COPY . .

# Install plugin dependencies
RUN npm run depmod

# Redirect configs to /data/config
RUN mv config/config.example.json extras/config.example.json && \
rm -rf config && \
Expand Down
69 changes: 69 additions & 0 deletions bin/plugdep.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var fs = require('fs'),
path = require('path');
function getDirectories(srcpath) {
return fs.readdirSync(srcpath).filter(function(file) {
return fs.statSync(path.join(srcpath, file)).isDirectory();
});
}

console.log("***********");

var plugin_folders;
var plugin_directory;
var exec_dir;
try { //try loading plugins from a non standalone install first
plugin_directory = "./plugins/";
plugin_folders = getDirectories(plugin_directory);
} catch(e){//load paths for an Electrify install
exec_dir = path.dirname(process.execPath) + "/resources/default_app/"; //need this to change node prefix for npm installs
plugin_directory = path.dirname(process.execPath) + "/resources/default_app/plugins/";
plugin_folders = getDirectories(plugin_directory);
}

function createNpmDependenciesArray (packageFilePath) {
var p = require(packageFilePath);
if (!p.dependencies) return [];
var deps = [];
for (var mod in p.dependencies) {
deps.push(mod + "@" + p.dependencies[mod]);
}

return deps;
}

function npm_install(){
var deps = [];
var npm = require("npm");
for (var i = 0; i < plugin_folders.length; i++) {
try{
require(plugin_directory + plugin_folders[i]);
} catch(e) {
deps = deps.concat(createNpmDependenciesArray(plugin_directory + plugin_folders[i] + "/package.json"));
}
}
if(deps.length > 0) {
npm.load({
loaded: false
}, function (err) {
// catch errors
if (plugin_directory != "./plugins/"){ //install plugin modules for Electrify builds
npm.prefix = exec_dir;
console.log(npm.prefix);
}
npm.commands.install(deps, function (er, data) {
if(er){
console.log(er);
}
console.log("Plugin NPM install complete!");
});

if (err) {
console.log("preload_plugins: " + err);
}
});
} else {
console.log("No dependencies to install");
}
}

npm_install();
15 changes: 15 additions & 0 deletions bin/plugdep.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

projectDir=$(pwd)
pluginDirs=$(find plugins -maxdepth 2 -name package.json | sed "s/package.json//")

echo "Found plugin dirs: $pluginDirs"

for pluginDir in $pluginDirs; do
cd $pluginDir
echo "Installing NPM dependencies for: $pluginDir"
npm install
#mv -f node_modules/* $projectDir/node_modules
done

echo "OK"
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"description": "A discordbot written primary for server PurrplingCat",
"main": "purrplingbot.js",
"scripts": {
"depmod": "./node_modules/recursive-install/recursive-install.js --skip-root",
"clean": "/bin/sh -c 'find . -name \"node_modules\" -type d -prune -exec rm -rf \"{}\" \\; ; find . -name \"package-lock.json\" -type f -exec rm \"{}\" \\;'",
"start": "nodemon --exitcrash --watch config/ purrplingbot.js 2>&1 3>&1 | tee -a purrplingbot.log",
"test": "ava --verbose"
},
Expand All @@ -28,17 +30,14 @@
"homepage": "https://github.com/EllenFawkes/PurrplingBot#readme",
"dependencies": {
"console-stamp": "^0.2.5",
"request": "^2.81.0",
"discord.js": "^11.2.0",
"duration-parser": "^1.0.2",
"js-yaml": "^3.10.0",
"merge": "^1.2.0",
"moment": "^2.18.1",
"npm": "",
"recursive-install": "^1.3.0"
"nodemon": "^1.12.0",
"request": "^2.81.0",
"stringbuilder": "0.0.11",
"tmi.js": "^1.2.1",
"twix": "^1.2.0",
"url-regex": "^4.1.1"
},
"devDependencies": {
"ava": "^0.22.0",
Expand Down
9 changes: 9 additions & 0 deletions plugins/Announcer/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pluginName": "Announcer",
"description": "Announce callouts to your Discord text channels",
"type": "plugin",
"main": "announcer.js",
"dependencies": {
"duration-parser": "^1.0.2"
}
}
9 changes: 9 additions & 0 deletions plugins/ChanInfo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pluginName": "ChanInfo",
"description": "Get a Discord channel informations",
"type": "plugin",
"main": "chaninfo.js",
"dependencies": {
"moment": "^2.18.1"
}
}
6 changes: 6 additions & 0 deletions plugins/Giphy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginName": "Giphy",
"description": "Find a gif and send it to a discord channel",
"type": "plugin",
"main": "giphy.js"
}
6 changes: 6 additions & 0 deletions plugins/Meowii/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginName": "Meowii",
"description": "Cat and Fox funny gifs",
"type": "plugin",
"main": "meowi.js"
}
10 changes: 10 additions & 0 deletions plugins/Misc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"pluginName": "Misc",
"description": "Core expansion plugin",
"type": "plugin",
"main": "misc.js",
"dependencies": {
"moment": "^2.18.1",
"twix": "^1.2.0"
}
}
9 changes: 9 additions & 0 deletions plugins/MumbleBox/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pluginName": "MumbleBox",
"description": "Mumbles and reactions to text messages on Discord channels",
"type": "plugin",
"main": "urbandictionary.js",
"dependencies": {
"url-regex": "^4.1.1"
}
}
9 changes: 9 additions & 0 deletions plugins/Nextstream/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pluginName": "Nextstream",
"description": "Is your stream live now? When is planned next stream?",
"type": "plugin",
"main": "nextstream.js",
"dependencies": {
"moment": "^2.18.1"
}
}
9 changes: 9 additions & 0 deletions plugins/Twitchcord/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"pluginName": "Twitchcord",
"description": "Chat messages bridge betwen Discord and Twitch worlds",
"type": "plugin",
"main": "twitchcord.js",
"dependencies": {
"tmi.js": "^1.2.1"
}
}
6 changes: 6 additions & 0 deletions plugins/UrbanDictionary/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pluginName": "UrbanDictionary",
"description": "Be smarter with Urbandictionary quotes!",
"type": "plugin",
"main": "urbandictionary.js"
}

0 comments on commit c713781

Please sign in to comment.