fix (sourcemap-uploader): logs to show the map-realted files & readme info

This commit is contained in:
ShiKhu 2021-05-10 12:34:49 +02:00
parent d187636d8e
commit 0cc5f37b0a
4 changed files with 24 additions and 12 deletions

View file

@ -13,15 +13,18 @@ npm i @openreplay/sourcemap-uploader -D
Upload sourcemap for one file Upload sourcemap for one file
``` ```
sourcemap-uploader -k API_KEY -p PROJECT_KEY file -m ./dist/index.js.map -u https://openreplay.com/index.js sourcemap-uploader -k API_KEY -p PROJECT_KEY file -m ./dist/index.js.map -u https://myapp.com/index.js
``` ```
Upload all sourcemaps in the directory. The path will be appended to the base url Upload all sourcemaps in the directory. The url must correspond to the root where you upload JS files from the directory.
Thus, if you have your `app-42.js` along with the `app-42.js.map` in the `./build` folder and then want to upload it to you server (you might want to avoid uploading soursemaps) so it can be reachable through the link `https://myapp.com/static/app-42.js`, the command would be the next:
``` ```
sourcemap-uploader -k API_KEY -p PROJECT_KEY dir -m ./dist -u https://openreplay.com/ sourcemap-uploader -k API_KEY -p PROJECT_KEY dir -m ./build -u https://myapp.com/static
``` ```
## NPM ## NPM
There are two functions inside `index.js` of the package There are two functions inside `index.js` of the package

View file

@ -48,6 +48,8 @@ dir.addArgument(['-u', '--js-dir-url'], {
required: true, required: true,
}); });
// TODO: exclude in dir
const { command, api_key, project_key, server, ...args } = parser.parseArgs(); const { command, api_key, project_key, server, ...args } = parser.parseArgs();
try { try {
@ -60,9 +62,11 @@ try {
? uploadFile(api_key, project_key, args.sourcemap_file_path, args.js_file_url) ? uploadFile(api_key, project_key, args.sourcemap_file_path, args.js_file_url)
: uploadDir(api_key, project_key, args.sourcemap_dir_path, args.js_dir_url) : uploadDir(api_key, project_key, args.sourcemap_dir_path, args.js_dir_url)
) )
.then((uploadedFiles) => .then((sourceFiles) =>
console.log(`Sourcemap${uploadedFiles.length > 1 ? "s" : ""} successfully uploaded! (${uploadedFiles.length} files)\n` sourceFiles.length > 0
+ uploadedFiles.join("\t\n") ? console.log(`Successfully uploaded ${sourceFiles.length} sourcemap file${sourceFiles.length > 1 ? "s" : ""} for: \n`
+ sourceFiles.join("\t\n")
) )
: console.log(`No sourcemaps found in ${ args.js_dir_url }`)
) )
.catch(e => console.error(`Sourcemap Uploader: ${e}`)); .catch(e => console.error(`Sourcemap Uploader: ${e}`));

View file

@ -2,6 +2,10 @@ const https = require('https');
const getUploadURLs = (api_key, project_key, js_file_urls) => const getUploadURLs = (api_key, project_key, js_file_urls) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
if (js_file_urls.length === 0) {
resolve([]);
}
const pathPrefix = (global.SERVER.pathname + "/").replace(/\/+/g, '/'); const pathPrefix = (global.SERVER.pathname + "/").replace(/\/+/g, '/');
const req = https.request( const req = https.request(
{ {
@ -28,9 +32,9 @@ const getUploadURLs = (api_key, project_key, js_file_urls) =>
req.end(); req.end();
}); });
const uploadSourcemap = (upload_url, sourcemap) => const uploadSourcemap = (upload_url, body) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
body = Buffer.from(JSON.stringify(sourcemap.body)); body = Buffer.from(JSON.stringify(body));
const req = https.request( const req = https.request(
upload_url, upload_url,
{ {
@ -45,7 +49,7 @@ const uploadSourcemap = (upload_url, sourcemap) =>
reject("Unable to upload. Please, contact OpenReplay support."); reject("Unable to upload. Please, contact OpenReplay support.");
return; return;
} }
resolve(sourcemap.sourcemap_file_path) resolve();
//res.on('end', resolve); //res.on('end', resolve);
}, },
); );
@ -62,7 +66,8 @@ module.exports = (api_key, project_key, sourcemaps) =>
).then(upload_urls => ).then(upload_urls =>
Promise.all( Promise.all(
upload_urls.map((upload_url, i) => upload_urls.map((upload_url, i) =>
uploadSourcemap(upload_url, sourcemaps[i]) uploadSourcemap(upload_url, sourcemaps[i].body)
.then(() => sourcemaps[i].js_file_url)
), ),
), ),
); );

View file

@ -1,6 +1,6 @@
{ {
"name": "@asayerio/sourcemaps-uploader", "name": "@openreplay/sourcemap-uploader",
"version": "1.0.0", "version": "3.0.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {