mirror of
https://github.com/Kong/insomnia
synced 2024-11-07 22:30:15 +00:00
Download plugins as tar into own dirs (#388)
This commit is contained in:
parent
2fbb9dfe16
commit
bc54f269a8
@ -8,7 +8,7 @@ build: off
|
||||
shallow_clone: true
|
||||
platform: x64
|
||||
environment:
|
||||
NODEJS_VERSION: "7.4.0"
|
||||
NODEJS_VERSION: "8"
|
||||
CSC_LINK: '%WINDOWS_CSC_LINK%'
|
||||
CSC_KEY_PASSWORD: '%WINDOWS_CSC_KEY_PASSWORD%'
|
||||
|
||||
|
4
.babelrc
4
.babelrc
@ -17,10 +17,6 @@
|
||||
"presets": [
|
||||
"es2015",
|
||||
"flow" // We need to add this again because it has to run before es2015
|
||||
],
|
||||
"plugins": [
|
||||
"transform-regenerator",
|
||||
"transform-runtime"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ common text editors. Read more and download plugins at [editorconfig.org](http:/
|
||||
## Developing
|
||||
|
||||
Development on Insomnia can be done on Mac, Windows, or Linux as long as you have
|
||||
[NodeJS 7.4](https://nodejs.org) and [Git](https://git-scm.com/).
|
||||
[NodeJS 8](https://nodejs.org) and [Git](https://git-scm.com/).
|
||||
|
||||
<details>
|
||||
<summary>Initial Dev Setup</summary>
|
||||
|
@ -20,8 +20,9 @@
|
||||
"mkdirp": "^0.5.1",
|
||||
"nedb": "^1.8.0",
|
||||
"node-forge": "^0.7.0",
|
||||
"node-libcurl": "git://github.com/getinsomnia/node-libcurl.git#b3968130cbaeef6b432e617a5e835baf0f856880",
|
||||
"node-libcurl": "git://github.com/getinsomnia/node-libcurl.git#d3ee4d436a174c2bd5f2dc89b165257a5cac32ea",
|
||||
"srp-js": "^0.2.0",
|
||||
"tar": "^3.1.7",
|
||||
"tough-cookie": "^2.3.1",
|
||||
"vkbeautify": "^0.99.1"
|
||||
}
|
||||
|
@ -1,44 +1,106 @@
|
||||
// @flow
|
||||
import * as electron from 'electron';
|
||||
import childProcess from 'child_process';
|
||||
import {PLUGIN_PATH} from '../common/constants';
|
||||
import mkdirp from 'mkdirp';
|
||||
import path from 'path';
|
||||
import * as tar from 'tar';
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
export default async function (moduleName: string): Promise<void> {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
let info: Object = {};
|
||||
try {
|
||||
await _isInsomniaPlugin(moduleName);
|
||||
info = await _isInsomniaPlugin(moduleName);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
childProcess.exec(
|
||||
`npm install --prefix '${PLUGIN_PATH}' ${moduleName}`,
|
||||
(err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(new Error(stderr));
|
||||
} else {
|
||||
resolve();
|
||||
const pluginDir = path.join(PLUGIN_PATH, moduleName);
|
||||
|
||||
// Make plugin directory
|
||||
mkdirp.sync(pluginDir);
|
||||
|
||||
// Download the module
|
||||
const request = electron.remote.net.request(info.dist.tarball);
|
||||
request.on('response', response => {
|
||||
const bodyBuffers = [];
|
||||
|
||||
response.on('end', () => {
|
||||
const w = tar.extract({
|
||||
cwd: pluginDir, // Extract to plugin's directory
|
||||
strict: true, // Fail on anything
|
||||
strip: 1 // Skip the "package/*" parent folder
|
||||
});
|
||||
|
||||
w.on('error', err => {
|
||||
reject(new Error(`Failed to extract ${info.dist.tarball}: ${err.message}`));
|
||||
});
|
||||
|
||||
w.on('end', () => {
|
||||
childProcess.exec('npm install', {cwd: pluginDir}, (err, stdout, stderr) => {
|
||||
if (err) {
|
||||
reject(new Error(stderr));
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const body = Buffer.concat(bodyBuffers);
|
||||
|
||||
const shasum = crypto.createHash('sha1').update(body).digest('hex');
|
||||
if (shasum !== info.dist.shasum) {
|
||||
reject(new Error('Plugin shasum doesn\'t match npm'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
w.end(body);
|
||||
});
|
||||
|
||||
response.on('data', chunk => {
|
||||
bodyBuffers.push(chunk);
|
||||
});
|
||||
});
|
||||
|
||||
request.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function _isInsomniaPlugin (moduleName: string): Promise<void> {
|
||||
async function _isInsomniaPlugin (moduleName: string): Promise<Object> {
|
||||
return new Promise((resolve, reject) => {
|
||||
childProcess.exec(
|
||||
`npm show ${moduleName} insomnia`,
|
||||
`npm show ${moduleName} insomnia version name dist.shasum dist.tarball`,
|
||||
(err, stdout, stderr) => {
|
||||
if (err && stderr.includes('E404')) {
|
||||
reject(new Error(`${moduleName} not found on npm`));
|
||||
return;
|
||||
}
|
||||
|
||||
if (stdout) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`"insomnia" attribute missing in ${moduleName}'s package.json`));
|
||||
const lines = stdout.split('\n').filter(l => !!l);
|
||||
const info = {};
|
||||
for (const line of lines) {
|
||||
const match = line.match(/(.*) = '(.*)'/);
|
||||
|
||||
// Strip quotes off of the value
|
||||
info[match[1]] = match[2];
|
||||
}
|
||||
|
||||
if (!info.hasOwnProperty('insomnia')) {
|
||||
reject(new Error(`"${moduleName}" not a plugin! Package missing "insomnia" attribute`));
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
insomnia: info.insomnia,
|
||||
name: info.name,
|
||||
version: info.version,
|
||||
dist: {
|
||||
shasum: info['dist.shasum'],
|
||||
tarball: info['dist.tarball']
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
5
flow-typed/tar.js
vendored
Normal file
5
flow-typed/tar.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
declare module 'tar' {
|
||||
declare module.exports: {
|
||||
extract: Function
|
||||
}
|
||||
}
|
5406
package-lock.json
generated
5406
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -135,7 +135,7 @@
|
||||
"moment": "^2.18.1",
|
||||
"nedb": "^1.8.0",
|
||||
"node-forge": "^0.7.0",
|
||||
"node-libcurl": "git://github.com/getinsomnia/node-libcurl.git#b3968130cbaeef6b432e617a5e835baf0f856880",
|
||||
"node-libcurl": "git://github.com/getinsomnia/node-libcurl.git#d3ee4d436a174c2bd5f2dc89b165257a5cac32ea",
|
||||
"nunjucks": "^3.0.0",
|
||||
"react": "^15.4.2",
|
||||
"react-dnd": "^2.2.3",
|
||||
@ -148,6 +148,7 @@
|
||||
"reselect": "^2.5.4",
|
||||
"simple-react-pdf": "^1.0.8",
|
||||
"srp-js": "^0.2.0",
|
||||
"tar": "^3.1.7",
|
||||
"tough-cookie": "^2.3.1",
|
||||
"uuid": "^3.0.0",
|
||||
"vkbeautify": "^0.99.1",
|
||||
@ -201,9 +202,5 @@
|
||||
"webpack-dev-server": "^2.4.1",
|
||||
"webpack-hot-middleware": "^2.17.1",
|
||||
"webpack-target-electron-renderer": "^0.4.0"
|
||||
},
|
||||
"devEngines": {
|
||||
"node": "6.x",
|
||||
"npm": "2.x || 3.x"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user