Skip to content

Commit

Permalink
Merge pull request #40 from bugsnag/je/npm-fixes
Browse files Browse the repository at this point in the history
Add small fixes to the NPM package
  • Loading branch information
joshedney authored Jun 28, 2023
2 parents 8ae0787 + a2131c7 commit 5609480
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ bin/**/**
# NodeJS
node_modules/
package-lock.json


.idea/
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.2.0 (2023-06-13)

Add support for installing the CLI via NPM - [42](https://github.com/bugsnag/bugsnag-cli/pull/41)

## 1.1.1 (2023-05-25)

Fix how we check for the AndroidManifest.xml file for Android AAB - [37](https://github.com/bugsnag/bugsnag-cli/pull/37)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Simplify the process of creating releases on the BugSnag dashboard and uploading

The binaries are available on our [GitHub releases page](https://github.com/bugsnag/bugsnag-cli/releases) for macOS, Linux and Windows.

### cURL / Wget

To install or upgrade to the latest binary for your architecture, you can also run the following `cURL` or `Wget` commands:

```sh
Expand All @@ -29,6 +31,12 @@ wget -qO- https://raw.githubusercontent.com/bugsnag/bugsnag-cli/main/install.sh

The script downloads the appropriate binary and attempts to install it to `~/.local/bugsnag`.

### NPM

To install or upgrade the BugSnag CLI via `npm`, you can run the following command:

`npm install @bugsnag/cli`

## Supported commands

This tool is currently being developed. It currently supports the following commands:
Expand Down
49 changes: 35 additions & 14 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ const removeGitPrefixAndSuffix = (input) => {

const supportedPlatforms = [
{
TYPE: 'windows',
ARCHITECTURE: 'x86_64',
TYPE: 'Windows',
ARCHITECTURE: 'x64',
ARTIFACT_NAME: 'x86_64-windows-bugsnag-cli.exe',
BINARY_NAME: 'bugsnag-cli.exe'
},
{
TYPE: 'windows',
TYPE: 'Windows',
ARCHITECTURE: 'i386',
ARTIFACT_NAME: 'i386-windows-bugsnag-cli.exe',
BINARY_NAME: 'bugsnag-cli.exe'
},
{
TYPE: 'linux',
ARCHITECTURE: 'x86_64',
TYPE: 'Linux',
ARCHITECTURE: 'x64',
ARTIFACT_NAME: 'x86_64-linux-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
},
{
TYPE: 'linux',
TYPE: 'Linux',
ARCHITECTURE: 'i386',
ARTIFACT_NAME: 'i386-linux-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
},
{
TYPE: 'Darwin',
ARCHITECTURE: 'x86_64',
ARCHITECTURE: 'x64',
ARTIFACT_NAME: 'x86_64-macos-bugsnag-cli',
BINARY_NAME: 'bugsnag-cli'
},
Expand Down Expand Up @@ -85,7 +85,7 @@ const getPlatformMetadata = () => {

const downloadBinaryFromGitHub = async (downloadUrl, outputPath) => {
try {
const binDir = path.resolve(__dirname, '..', '.bin');
const binDir = path.resolve(process.cwd(),'..','..','.bin');
if (!fs.existsSync(binDir)) {
fs.mkdirSync(binDir, { recursive: true });
}
Expand All @@ -101,19 +101,40 @@ const downloadBinaryFromGitHub = async (downloadUrl, outputPath) => {
};

const writeToPackageJson = (packageJsonPath) => {
const packageJson = require(packageJsonPath);
fs.readFile(packageJsonPath, 'utf8', (err, data) => {
if (err) {
console.error(`Error reading package.json: ${err}`);
return;
}

try {
const packageJson = JSON.parse(data);

packageJson.scripts.bugsnagCreateBuild = './node_modules/.bin/bugsnag-cli create-build';
packageJson.scripts.bugsnagUpload = './node_modules/.bin/bugsnag-cli upload react-native-android';
packageJson.scripts = {
...packageJson.scripts,
"bugsnag:create-build": "./node_modules/.bin/bugsnag-cli create-build",
"bugsnag:upload-android": "./node_modules/.bin/bugsnag-cli upload react-native-android"
};

fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
const updatedPackageJson = JSON.stringify(packageJson, null, 2);

fs.writeFile(packageJsonPath, updatedPackageJson, 'utf8', (err) => {
if (err) {
console.error(`Error writing package.json: ${err}`);
return;
}
});
} catch (err) {
console.error(`Error parsing package.json: ${err}`);
}
})
}

const platformMetadata = getPlatformMetadata();
const repoUrl = removeGitPrefixAndSuffix(repository.url);
const binaryUrl = `${repoUrl}/releases/download/v${version}/${platformMetadata.ARTIFACT_NAME}`;
const binaryOutputPath = path.join(__dirname, '..', '.bin', platformMetadata.BINARY_NAME);
const projectPackageJsonPath = path.join(__dirname, '..', '..', 'package.json');
const binaryOutputPath = path.join(process.cwd(),'..','..','.bin', platformMetadata.BINARY_NAME);
const projectPackageJsonPath = path.join(process.cwd(),'..','..', '..','package.json');

downloadBinaryFromGitHub(binaryUrl, binaryOutputPath);
writeToPackageJson(projectPackageJsonPath)
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -o errexit
set -o pipefail
set -o nounset
#set -o nounset
#set -o xtrace

abort() {
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"name": "bugsnag-cli",
"version": "1.1.1",
"name": "@bugsnag/cli",
"version": "1.2.0",
"description": "BugSnag CLI",
"main": "install.js",
"repository": {
"type": "git",
"url": "https://github.com/bugsnag/bugsnag-cli"
"url": "git+https://github.com/bugsnag/bugsnag-cli.git"
},
"author": "BugSnag",
"license": "ISC",
"bugs": {
"url": "https://github.com/bugsnag/bugsnag-cli/issues"
},
"publishConfig": {
"access": "public"
},
"homepage": "https://github.com/bugsnag/bugsnag-cli#readme",
"dependencies": {
"axios": "^1.4.0",
Expand Down
21 changes: 20 additions & 1 deletion pkg/upload/react-native-android.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,20 @@ func ProcessReactNativeAndroid(apiKey string, appManifestPath string, bundlePath
}

if bundlePath == "" {
bundlePath = filepath.Join(buildDirPath, "ASSETS", "createBundleReleaseJsAndAssets", "index.android.bundle")
bundleDirPath := filepath.Join(buildDirPath, "generated", "assets", "react")

if utils.IsDir(bundleDirPath) {
if variant == "" {
variant, err = android.GetVariant(bundleDirPath)
if err != nil {
return err
}
}

bundlePath = filepath.Join(bundleDirPath, variant, "index.android.bundle")
} else {
bundlePath = filepath.Join(buildDirPath, "ASSETS", "createBundleReleaseJsAndAssets", "index.android.bundle")
}
}

if !utils.FileExists(bundlePath) {
Expand All @@ -63,6 +76,9 @@ func ProcessReactNativeAndroid(apiKey string, appManifestPath string, bundlePath

if variant == "" {
variant, err = android.GetVariant(sourceMapDirPath)
if err != nil {
return err
}
}

sourceMapPath = filepath.Join(sourceMapDirPath, variant, "index.android.bundle.map")
Expand All @@ -73,6 +89,9 @@ func ProcessReactNativeAndroid(apiKey string, appManifestPath string, bundlePath

if filepath.Base(sourceMapDirPath) == "react" {
variant, err = android.GetVariant(sourceMapDirPath)
if err != nil {
return err
}
}
}
}
Expand Down

0 comments on commit 5609480

Please sign in to comment.