Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #40 from bugsnag/directory-mode
Browse files Browse the repository at this point in the history
Add --directory mode
  • Loading branch information
bengourley authored May 22, 2019
2 parents 3967849 + 5e20406 commit aca2088
Show file tree
Hide file tree
Showing 50 changed files with 3,675 additions and 675 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ $ npm install --global bugsnag-sourcemaps
`bugsnag-sourcemaps` provides a command-line interface for uploading source maps
directly. Run `bugsnag-sourcemaps --help` for a list of all options.

For a typical browser bundle, where your build generates a single minified file and accompanying source map:

```shell
$ bugsnag-sourcemaps upload --api-key YOUR_API_KEY_HERE \
--app-version 1.2.3 \
Expand All @@ -30,13 +32,29 @@ $ bugsnag-sourcemaps upload --api-key YOUR_API_KEY_HERE \
--upload-sources
```

For a typical Node.js project, where your build generates a source map per input file (e.g. Babel, TypeScript):

```shell
$ bugsnag-sourcemaps upload --api-key YOUR_API_KEY_HERE \
--app-version 1.2.3 \
--directory
```

### Options

```
-h, --help Prints this message
-k, --api-key KEY Your project API key
-v, --app-version VERSION The version number of your app
-c, --code-bundle-id ID The code bundle id (react native only)
-d, --directory [PATH] Enable directory mode. Searches for multiple source
maps in the directory and uploads them all. Only
supply a path if the directory you want to search is
not the same as your project root.
This option makes the following options redundant:
--source-map
--minified-url
--minified-file
-e, --endpoint URL The URL of the upload server
-m, --minified-url URL The URL your users will request your bundle
-s, --source-map PATH The path of the source map file (local)
Expand Down Expand Up @@ -74,9 +92,9 @@ upload({
});
```

### Bugsnag Enterprise
### Bugsnag On-premise

If you are using Bugsnag Enterprise (on premise installation) with a custom domain, you can pass an optional `endpoint` option to define a custom upload url.
If you are using Bugsnag On-premise, you should use the `endpoint` option to set the url of your upload server.

Example with endpoint option:

Expand Down
51 changes: 20 additions & 31 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env node

const meow = require('meow')
const Listr = require('listr')
const rc = require('rc')
const readPkgUp = require('read-pkg-up')
const logger = require('./lib/cli-logger')
const upload = require('./').upload

const cli = meow(`
Expand All @@ -15,6 +14,14 @@ const cli = meow(`
-k, --api-key KEY Your project API key
-v, --app-version VERSION The version number of your app
-c, --code-bundle-id ID The code bundle id (react-native only)
-d, --directory [PATH] Enable directory mode. Searches for multiple source
maps in the directory and uploads them all. Only
supply a path if the directory you want to search is
not the same as your project root.
This option makes the following options redundant:
--source-map
--minified-url
--minified-file
-e, --endpoint URL The URL of the upload server
-m, --minified-url URL The URL your users will request your bundle
-s, --source-map PATH The path of the source map file (local)
Expand All @@ -40,6 +47,11 @@ const cli = meow(`
--source-map dist/main.jsbundle.map \\
--minified-file dist/main.jsbundle \\
--upload-sources
OR
$ bugsnag-sourcemaps upload \\
--directory \\
--api-key f915102cdb8153ee934b8549c930aa1b \\
--app-version 1.0.0
`, {
alias: {
c: 'code-bundle-id',
Expand All @@ -54,7 +66,8 @@ const cli = meow(`
s: 'source-map',
u: 'upload-sources',
v: 'app-version',
w: 'add-wildcard-prefix'
w: 'add-wildcard-prefix',
d: 'directory'
},
string: [
'app-version',
Expand Down Expand Up @@ -86,31 +99,7 @@ for (const key in conf) {
}
}

const tasks = new Listr([
{
title: 'Uploading sourcemaps',
task: () => upload(conf)
}
])

Promise.resolve()
.then(() => {
if (!conf.appVersion && !conf.codeBundleId) {
return (
// If there was no appVersion specified, find the package.json within either
// the project root, or the current working directory, and use that version.
readPkgUp(conf.projectRoot || process.cwd())
.then(arg => {
const pkg = arg && arg.pkg ? arg.pkg : null
// only use pkg.version if it's truthy, because read-pkg-up will
// set it to "" (empty string) when it's missing
if (pkg && pkg.version) conf.appVersion = pkg.version
})
)
}
})
.then(() => {
return tasks.run().catch(() => {
process.exitCode = 1
})
})
upload(conf, logger).catch(err => {
logger.error(`Error uploding source maps: ${err.message}`)
process.exitCode = 1
})
1 change: 1 addition & 0 deletions example/babel/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
14 changes: 14 additions & 0 deletions example/babel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Example: Babel

This example contains a Node project which is transformed with Babel. The `upload-source-maps` command in `package.json` uses the `bugsnag-sourcemaps`' `--directory` mode to upload all of the generated source maps.

Be sure to replace the API key in `package.json` and `src/services/bugsnag.js` before you begin.

## Usage:

```
npm install
npm run build
npm run upload-source-maps
npm start
```
Loading

0 comments on commit aca2088

Please sign in to comment.