diff options
| author | Jan Tuomi <jan.tuomi@eficode.com> | 2018-07-12 16:56:26 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@eficode.com> | 2018-07-12 16:56:59 +0300 |
| commit | 8b07446f67a5e68d00725fef37061bc87643beb6 (patch) | |
| tree | b5350b11840b808d663e877046e34916c99c81b5 | |
| parent | 0b4ebb81270f016bb7e5ed0e95e5e07146c03f0f (diff) | |
Implement installation of NPM packages on host
| -rwxr-xr-x | cli.js | 39 | ||||
| -rw-r--r-- | index.js | 20 | ||||
| -rw-r--r-- | models.js | 5 | ||||
| -rw-r--r-- | package-lock.json | 20 | ||||
| -rw-r--r-- | package.json | 7 |
5 files changed, 77 insertions, 14 deletions
@@ -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(); }); @@ -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}`)}`)); @@ -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", |
