aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@eficode.com>2018-07-12 16:56:26 +0300
committerJan Tuomi <jan.tuomi@eficode.com>2018-07-12 16:56:59 +0300
commit8b07446f67a5e68d00725fef37061bc87643beb6 (patch)
treeb5350b11840b808d663e877046e34916c99c81b5 /index.js
parent0b4ebb81270f016bb7e5ed0e95e5e07146c03f0f (diff)
Implement installation of NPM packages on host
Diffstat (limited to 'index.js')
-rw-r--r--index.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/index.js b/index.js
index 7ae392d..c1d4121 100644
--- a/index.js
+++ b/index.js
@@ -1,6 +1,7 @@
require('dotenv').config();
const path = require('path');
const chalk = require('chalk');
+const npm = require('npm-programmatic');
if (!process.env.MONGO_URL) {
throw new Error('No MONGO_URL set in .env!');
@@ -54,5 +55,24 @@ app.all('/:path*', async (req, res) => {
}
});
+(async function () {
+ try {
+ const packagesToInstall = await models.packages.find({});
+ const packages = packagesToInstall.map(obj => obj.name);
+
+ packages.forEach(async pkg => {
+ console.info(`Installing package "${pkg}"...`);
+ await npm.install([pkg], {
+ cwd: __dirname,
+ save: false
+ });
+ });
+ console.info(`Successfully installed ${packages.length} NPM packages programmatically.`);
+ } catch (err) {
+ console.error(`Failed to install NPM packages programmatically.`);
+ console.error(err);
+ }
+})();
+
const port = process.env.PORT || 3000;
app.listen(port, () => console.log(`${chalk.blue('faas')} listening on port ${port}! URL: ${chalk.yellow(`http://localhost:${port}`)}`));