aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xcli.js39
-rw-r--r--index.js20
-rw-r--r--models.js5
-rw-r--r--package-lock.json20
-rw-r--r--package.json7
5 files changed, 77 insertions, 14 deletions
diff --git a/cli.js b/cli.js
index 04fca98..348c092 100755
--- a/cli.js
+++ b/cli.js
@@ -236,8 +236,8 @@ vorpal
}
if (!args.key || !args.value) {
- this.log('Please provide both "key" and "value" arguments.');
- return callback();
+ this.log('Please provide both "key" and "value" arguments.');
+ return callback();
}
try {
@@ -248,7 +248,7 @@ vorpal
this.log(chalk.green(`Secret "${args.key}" set successfully.`));
} catch (err) {
this.log(chalk.red(`Failed to set secret ${args.key}!`));
- this.log(chalk.red(String(err)));
+ this.log(chalk.red(String(err)));
}
callback();
});
@@ -264,8 +264,8 @@ vorpal
}
if (!args.key) {
- this.log('Please provide the "key" argument.');
- return callback();
+ this.log('Please provide the "key" argument.');
+ return callback();
}
try {
@@ -273,7 +273,34 @@ vorpal
this.log(chalk.green(`Secret "${args.key}" removed successfully.`));
} catch (err) {
this.log(chalk.red(`Failed to remove secret ${args.key}!`));
- this.log(chalk.red(String(err)));
+ this.log(chalk.red(String(err)));
+ }
+ callback();
+ });
+
+vorpal
+ .command('package install <package>', `Install an NPM package on the host.`)
+ .action(async function (args, callback) {
+ try {
+ await checkConnection(mongoURL, this);
+ } catch (err) {
+ showMongoNotSetError(vorpal);
+ return callback();
+ }
+
+ if (!args.package) {
+ this.log('Please provide the "package" argument.');
+ return callback();
+ }
+
+ try {
+ await models.packages.insert({
+ name: args.package
+ });
+ this.log(chalk.green(`Package "${args.package}" added successfully to list of packages to install.`));
+ } catch (err) {
+ this.log(chalk.red(`Failed to add package ${args.package} to list of packages to install!`));
+ this.log(chalk.red(String(err)));
}
callback();
});
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}`)}`));
diff --git a/models.js b/models.js
index 50ee3b8..e0b4abb 100644
--- a/models.js
+++ b/models.js
@@ -5,8 +5,11 @@ module.exports = db => {
const secrets = db.get('secrets');
secrets.createIndex({key: 1}, {unique: true});
+ const packages = db.get('packages');
+
return {
endpoints,
- secrets
+ secrets,
+ packages
};
};
diff --git a/package-lock.json b/package-lock.json
index bc6aed9..b0246d4 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
- "name": "faas",
- "version": "1.0.0",
+ "name": "faaslift",
+ "version": "1.0.4",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@@ -328,6 +328,11 @@
"integrity": "sha1-RqoXUftqL5PuXmibsQh9SxTGwgU=",
"dev": true
},
+ "bluebird": {
+ "version": "3.5.1",
+ "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz",
+ "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA=="
+ },
"body-parser": {
"version": "1.18.2",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz",
@@ -982,8 +987,7 @@
"dotenv": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.0.0.tgz",
- "integrity": "sha512-FlWbnhgjtwD+uNLUGHbMykMOYQaTivdHEmYwAKFjn6GKe/CqY0fNae93ZHTd20snh9ZLr8mTzIL9m0APQ1pjQg==",
- "dev": true
+ "integrity": "sha512-FlWbnhgjtwD+uNLUGHbMykMOYQaTivdHEmYwAKFjn6GKe/CqY0fNae93ZHTd20snh9ZLr8mTzIL9m0APQ1pjQg=="
},
"duplexer": {
"version": "0.1.1",
@@ -3593,6 +3597,14 @@
"remove-trailing-separator": "^1.0.1"
}
},
+ "npm-programmatic": {
+ "version": "0.0.10",
+ "resolved": "https://registry.npmjs.org/npm-programmatic/-/npm-programmatic-0.0.10.tgz",
+ "integrity": "sha512-SklCZ26RRGi7hLIz/oaSnHy8ZT0gh8r6N3FMuKRye3ZcRo4HI/saldc8b7OqlY/Ov8FXnA1+I+Od+WtesWEp2Q==",
+ "requires": {
+ "bluebird": "^3.4.1"
+ }
+ },
"npm-run-path": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-2.0.2.tgz",
diff --git a/package.json b/package.json
index 897c5d5..078b8be 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "faaslift",
- "version": "1.0.4",
+ "version": "1.0.5",
"description": "",
"main": "index.js",
"scripts": {
@@ -12,11 +12,12 @@
"license": "MIT",
"dependencies": {
"chalk": "^2.4.1",
+ "dotenv": "^6.0.0",
"express": "^4.16.3",
"monk": "^6.0.6",
+ "npm-programmatic": "0.0.10",
"require-from-string": "^2.0.2",
- "vorpal": "^1.12.0",
- "dotenv": "^6.0.0"
+ "vorpal": "^1.12.0"
},
"devDependencies": {
"nodemon": "^1.18.1",