feat (sourcemaps-uploader): v.3.0.2 filename fix + logging arg
This commit is contained in:
parent
cc35c64047
commit
a71612cddb
4 changed files with 35 additions and 12 deletions
|
|
@ -18,10 +18,13 @@ parser.addArgument(['-p', '-i', '--project-key'], { // -i is depricated
|
|||
help: 'Project Key',
|
||||
required: true,
|
||||
});
|
||||
|
||||
parser.addArgument(['-s', '--server'], {
|
||||
help: 'OpenReplay API server URL for upload',
|
||||
});
|
||||
parser.addArgument(['-l', '--log'], {
|
||||
help: 'Log requests information',
|
||||
action: 'storeTrue',
|
||||
});
|
||||
|
||||
const subparsers = parser.addSubparsers({
|
||||
title: 'commands',
|
||||
|
|
@ -50,7 +53,9 @@ dir.addArgument(['-u', '--js-dir-url'], {
|
|||
|
||||
// TODO: exclude in dir
|
||||
|
||||
const { command, api_key, project_key, server, ...args } = parser.parseArgs();
|
||||
const { command, api_key, project_key, server, log, ...args } = parser.parseArgs();
|
||||
|
||||
global.LOG = !!log;
|
||||
|
||||
try {
|
||||
global.SERVER = new URL(server || "https://api.openreplay.com");
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ const readFile = require('./readFile');
|
|||
|
||||
module.exports = (sourcemap_dir_path, js_dir_url) => {
|
||||
sourcemap_dir_path = (sourcemap_dir_path + '/').replace(/\/+/g, '/');
|
||||
js_dir_url = (js_dir_url + '/').replace(/\/+/g, '/');
|
||||
if (js_dir_url[ js_dir_url.length - 1 ] !== '/') { // replace will break schema
|
||||
js_dir_url += '/';
|
||||
}
|
||||
return glob(sourcemap_dir_path + '**/*.map').then(sourcemap_file_paths =>
|
||||
Promise.all(
|
||||
sourcemap_file_paths.map(sourcemap_file_path =>
|
||||
|
|
|
|||
|
|
@ -7,14 +7,21 @@ const getUploadURLs = (api_key, project_key, js_file_urls) =>
|
|||
}
|
||||
|
||||
const pathPrefix = (global.SERVER.pathname + "/").replace(/\/+/g, '/');
|
||||
const options = {
|
||||
method: 'PUT',
|
||||
hostname: global.SERVER.host,
|
||||
path: pathPrefix + `${project_key}/sourcemaps/`,
|
||||
headers: { Authorization: api_key, 'Content-Type': 'application/json' },
|
||||
}
|
||||
if (global.LOG) {
|
||||
console.log("Request: ", options, "\nFiles: ", js_file_urls);
|
||||
}
|
||||
const req = https.request(
|
||||
{
|
||||
method: 'PUT',
|
||||
hostname: global.SERVER.host,
|
||||
path: pathPrefix + `${project_key}/sourcemaps/`,
|
||||
headers: { Authorization: api_key, 'Content-Type': 'application/json' },
|
||||
},
|
||||
options,
|
||||
res => {
|
||||
if (global.LOG) {
|
||||
console.log("Response Code: ", res.statusCode, "\nMessage: ", res.statusMessage);
|
||||
}
|
||||
if (res.statusCode === 403) {
|
||||
reject("Authorisation rejected. Please, check your API_KEY and/or PROJECT_KEY.")
|
||||
return
|
||||
|
|
@ -24,7 +31,12 @@ const getUploadURLs = (api_key, project_key, js_file_urls) =>
|
|||
}
|
||||
let data = '';
|
||||
res.on('data', s => (data += s));
|
||||
res.on('end', () => resolve(JSON.parse(data).data));
|
||||
res.on('end', () => {
|
||||
if (global.LOG) {
|
||||
console.log("Server Response: ", data)
|
||||
}
|
||||
resolve(JSON.parse(data).data)
|
||||
});
|
||||
},
|
||||
);
|
||||
req.on('error', reject);
|
||||
|
|
@ -46,8 +58,12 @@ const uploadSourcemap = (upload_url, body) =>
|
|||
},
|
||||
res => {
|
||||
if (res.statusCode !== 200) {
|
||||
if (global.LOG) {
|
||||
console.log("Response Code: ", res.statusCode, "\nMessage: ", res.statusMessage);
|
||||
}
|
||||
|
||||
reject("Unable to upload. Please, contact OpenReplay support.");
|
||||
return;
|
||||
return; // TODO: report per-file errors.
|
||||
}
|
||||
resolve();
|
||||
//res.on('end', resolve);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@openreplay/sourcemap-uploader",
|
||||
"version": "3.0.1",
|
||||
"version": "3.0.2",
|
||||
"description": "NPM module to upload your JS sourcemaps files to OpenReplay",
|
||||
"bin": "cli.js",
|
||||
"main": "index.js",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue