-
Notifications
You must be signed in to change notification settings - Fork 13
/
plugin_install
79 lines (74 loc) · 2.8 KB
/
plugin_install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env node
/*
* This module makes possible to install dependencies from plugins folder
* when they have a package.json inside any of the folders.
*/
let shelljs = require('shelljs');
let fs = require('fs');
let PJV = require('package-json-validator').PJV;
let glob = require("glob");
let async = require("async");
fs.readdir("./plugins", (err, files) => {
files.forEach(file => {
if(fs.lstatSync("./plugins/" + file).isDirectory()) {
if(fs.existsSync("./plugins/" + file + "/package.json")) {
console.log("Installing " + file);
let validation = PJV.validate(fs.readFileSync("./plugins/" + file + "/package.json", 'utf8'), "npm");
if (validation.valid) {
shelljs.exec("yarn add ./plugins/" + file).stdout;
}
}
} else {
// console.log(validation.errors);
}
});
});
/* GET JS LOCAL DEPENDENCIES AND CSS*/
async.series({
dependencies: function(call) {
glob("./plugins/*/package.json", function(err, files) {
let dependencies_array = [];
for(let f = 0; f < files.length; f++) {
var json = JSON.parse(fs.readFileSync(files[f], 'utf8'));
if(json.config && json.config.localDependencies) {
Object.keys(json.config.localDependencies).forEach(function(e) {
dependencies_array.push(json.config.localDependencies[e]);
});
}
}
call(null, dependencies_array);
});
},
css: function(call) {
glob("./plugins/*/package.json", function(err, files) {
let css_array = [];
for(let f = 0; f < files.length; f++) {
var json = JSON.parse(fs.readFileSync(files[f], 'utf8'));
if(json.config && json.config.css) {
Object.keys(json.config.css).forEach(function(e) {
css_array.push(json.config.css[e]);
});
}
}
call("css", css_array);
});
},
}, function(err, results) {
let loader_string = "module.exports = { requireAll: function() { ";
async.each(results.dependencies, function(file, call) {
let require_string = "require('!script-loader!./..";
let require_close = "');";
loader_string += require_string + file + require_close;
call();
}, function(err) {
async.each(results.css, function(file, call) {
let require_string = "require('./..";
let require_close = "');";
loader_string += require_string + file + require_close;
call();
}, function(err) {
loader_string += "} };\n";
fs.writeFile("./plugins/plugin_dependencies_loader.js", loader_string);
});
});
});