@bitgenics/fab-upload-cli
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -1,9 +0,15 @@ | ||
import { Command } from '@oclif/command'; | ||
import { Command, flags } from '@oclif/command'; | ||
declare class LincFabUpload extends Command { | ||
static description: string; | ||
static examples: string[]; | ||
static flags: { | ||
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>; | ||
apiKey: flags.IOptionFlag<string | undefined>; | ||
}; | ||
static args: { | ||
name: string; | ||
required: boolean; | ||
}[]; | ||
run(): Promise<void>; | ||
} | ||
export = LincFabUpload; |
@@ -15,54 +15,81 @@ "use strict"; | ||
async run() { | ||
const { LINC_SITE_NAME, LINC_API_KEY } = process.env; | ||
if (LINC_SITE_NAME && LINC_API_KEY) { | ||
// generate FAB | ||
log_1.log("Executing build:fab script"); | ||
const buildInfo = await generateFab_1.default(); | ||
const buildPassed = buildInfo.status === enums_1.BuildStatus.SUCCESS; | ||
if (buildPassed) { | ||
log_1.log("FAB compile complete"); | ||
const fabExists = utils_1.doesFileExist(FAB_FILE_PATH); | ||
if (fabExists) { | ||
// Get signed url | ||
const bundle_id = utils_1.checksumFile(FAB_FILE_PATH); | ||
log_1.log("Validating FAB with Linc"); | ||
const srResponse = await getSignedRequest_1.default({ api_key: LINC_API_KEY, sitename: LINC_SITE_NAME, bundle_id }); | ||
if (srResponse.ok) { | ||
const { unique_bundle } = srResponse; | ||
const bundle_info = { | ||
bundle_id, | ||
unique_bundle | ||
}; | ||
if (unique_bundle === true) { | ||
log_1.log("Unique FAB detected!"); | ||
await handleUniqueBundle_1.default(srResponse.signed_request, LINC_SITE_NAME, LINC_API_KEY, bundle_info, buildInfo); | ||
const { args, flags } = this.parse(LincFabUpload); | ||
const LINC_SITE_NAME = args.sitename || process.env.LINC_SITE_NAME; | ||
const LINC_API_KEY = flags.apiKey || process.env.LINC_API_KEY; | ||
if (LINC_SITE_NAME) { | ||
if (LINC_API_KEY) { | ||
// generate FAB | ||
log_1.log("Executing build:fab script"); | ||
const buildInfo = await generateFab_1.default(); | ||
const buildPassed = buildInfo.status === enums_1.BuildStatus.SUCCESS; | ||
if (buildPassed) { | ||
log_1.log("FAB compile complete"); | ||
const fabExists = utils_1.doesFileExist(FAB_FILE_PATH); | ||
if (fabExists) { | ||
// Get signed url | ||
const bundle_id = utils_1.checksumFile(FAB_FILE_PATH); | ||
log_1.log("Validating FAB with Linc"); | ||
const srResponse = await getSignedRequest_1.default({ api_key: LINC_API_KEY, sitename: LINC_SITE_NAME, bundle_id }); | ||
if (srResponse.ok) { | ||
const { unique_bundle } = srResponse; | ||
const bundle_info = { | ||
bundle_id, | ||
unique_bundle | ||
}; | ||
if (unique_bundle === true) { | ||
log_1.log("Unique FAB detected!"); | ||
await handleUniqueBundle_1.default(srResponse.signed_request, LINC_SITE_NAME, LINC_API_KEY, bundle_info, buildInfo); | ||
} | ||
if (unique_bundle === false) { | ||
log_1.log("Duplicate FAB detected"); | ||
await handleDuplicateBundle_1.default(LINC_SITE_NAME, LINC_API_KEY, bundle_info, buildInfo); | ||
} | ||
} | ||
if (unique_bundle === false) { | ||
log_1.log("Duplicate FAB detected"); | ||
await handleDuplicateBundle_1.default(LINC_SITE_NAME, LINC_API_KEY, bundle_info, buildInfo); | ||
else { | ||
handleServerError_1.default(srResponse.error); | ||
} | ||
} | ||
else { | ||
handleServerError_1.default(srResponse.error); | ||
log_1.error(`Error: Unable to locate FAB at specified file path`); | ||
throw new Error('Environment vars errors.'); | ||
} | ||
} | ||
else { | ||
log_1.error(`Error: Unable to locate FAB at specified file path`); | ||
throw new Error('Environment vars errors.'); | ||
await handleBuildFailure_1.default(LINC_SITE_NAME, LINC_API_KEY, buildInfo); | ||
} | ||
} | ||
else { | ||
await handleBuildFailure_1.default(LINC_SITE_NAME, LINC_API_KEY, buildInfo); | ||
log_1.error(`Error: Missing API key. | ||
You can pass your API key to fab-upload by assigning it to the environment variable 'LINC_API_KEY' or via the flag '--apiKey' or '-a'. | ||
For information on generating a Linc API key, visit the fab-upload docs: https://github.com/bitgenics/fab-upload-cli/blob/master/README.md`); | ||
throw new Error('Missing sitename error.'); | ||
} | ||
} | ||
else { | ||
log_1.error(`Error: Missing LINC_SITE_NAME & LINC_API_KEY environment variables`); | ||
throw new Error('Environment vars errors.'); | ||
log_1.error(`Error: Missing [SITENAME]. | ||
You can pass your sitename to fab-upload as an argument or by assigning it to the environment variable 'LINC_SITE_NAME'.`); | ||
throw new Error('Missing sitename error.'); | ||
} | ||
} | ||
} | ||
LincFabUpload.description = 'describe the command here'; | ||
LincFabUpload.description = 'Builds and then uploads a FAB to Linc, along with some related build and git data.'; | ||
LincFabUpload.examples = [ | ||
`$ fab-upload my-site-name`, | ||
`$ fab-upload my-site-name -a my-api-key` | ||
]; | ||
LincFabUpload.flags = { | ||
help: command_1.flags.help({ char: 'h' }), | ||
apiKey: command_1.flags.string({ | ||
char: 'a', | ||
description: 'Your Linc site API key', | ||
env: "LINC_API_KEY", | ||
required: false, | ||
}), | ||
}; | ||
LincFabUpload.args = [ | ||
{ | ||
name: 'sitename', | ||
required: false, | ||
}, | ||
]; | ||
module.exports = LincFabUpload; |
@@ -1,5 +0,2 @@ | ||
import { CommitMetadata } from "../types"; | ||
export declare const getCurrentBranch: () => Promise<any>; | ||
export declare const getRepository: () => Promise<any>; | ||
export declare const getLastCommit: () => Promise<any>; | ||
export declare const getGitData: () => Promise<CommitMetadata>; |
@@ -5,11 +5,2 @@ "use strict"; | ||
const exec = util.promisify(require('child_process').exec); | ||
exports.getCurrentBranch = async () => { | ||
const { stdout, stderr } = await exec("git symbolic-ref --short HEAD"); | ||
if (stdout) { | ||
return stdout.replace(/(\r\n|\n|\r)/gm, ""); | ||
} | ||
else { | ||
throw new Error(stderr); | ||
} | ||
}; | ||
exports.getRepository = async () => { | ||
@@ -47,11 +38,1 @@ const { stdout, stderr } = await exec("git ls-remote --get-url"); | ||
}; | ||
exports.getGitData = async () => { | ||
const commit = await exports.getLastCommit(); | ||
// const branch = await getCurrentBranch() | ||
const branch = "unknown-branch"; | ||
// const repository = await getRepository() | ||
const repository = "plexey/fab-upload-test-app"; | ||
const CommitMetadata = Object.assign(Object.assign({}, commit), { branch, | ||
repository }); | ||
return CommitMetadata; | ||
}; |
@@ -30,5 +30,3 @@ "use strict"; | ||
const platform = environmentVariableUtils_1.getCI(); | ||
console.log({ platform }); | ||
const supportedPlatform = platform !== "unknown"; | ||
console.log({ supportedPlatform }); | ||
if (supportedPlatform) { | ||
@@ -42,3 +40,2 @@ // pull branch & repo from environment variables | ||
repository }); | ||
console.log({ commitMetadata }); | ||
return commitMetadata; | ||
@@ -45,0 +42,0 @@ } |
{ | ||
"name": "@bitgenics/fab-upload-cli", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "Tom Trinca @plexey", | ||
@@ -61,3 +61,3 @@ "bin": { | ||
"types": "lib/index.d.ts", | ||
"description": "linc-fab-upload ===============", | ||
"description": "CI tool for building and uploading a Frontend Application Bundle to Linc.", | ||
"directories": { | ||
@@ -64,0 +64,0 @@ "test": "test" |
@@ -1,15 +0,78 @@ | ||
linc-fab-upload | ||
=============== | ||
# fab-upload | ||
Builds and uploads a FAB to [Linc](https://linc.sh/). | ||
`fab-upload` let's you enjoy the benefits of Linc without having to give up your existing CI solution. | ||
[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io) | ||
[![Version](https://img.shields.io/npm/v/linc-fab-upload.svg)](https://npmjs.org/package/linc-fab-upload) | ||
[![Downloads/week](https://img.shields.io/npm/dw/linc-fab-upload.svg)](https://npmjs.org/package/linc-fab-upload) | ||
[![License](https://img.shields.io/npm/l/linc-fab-upload.svg)](https://github.com/bitgenics/linc-fab-upload/blob/master/package.json) | ||
[![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io) | ||
[![Version](https://img.shields.io/npm/v/@bitgenics/fab-upload-cli.svg)](https://npmjs.org/package/@bitgenics/fab-upload-cli) | ||
[![License](https://img.shields.io/npm/l/@bitgenics/fab-upload-cli.svg)](https://github.com/bitgenics/fab-upload-cli/blob/master/package.json) | ||
<!-- toc --> | ||
# Usage | ||
<!-- usage --> | ||
# Commands | ||
<!-- commands --> | ||
## Prerequisites | ||
1. An existing [Linc](https://linc.sh/) account. | ||
2. A frontend project configured to output a [FAB](https://fab.dev/). | ||
## Getting started | ||
Install `@bitgenics/fab-upload-cli` as a development dependency in your frontend project: | ||
```bash | ||
yarn add --dev @bitgenics/fab-upload-cli | ||
npm install --dev @bitgenics/fab-upload-cli | ||
``` | ||
Then add the following script to your `package.json`: | ||
```diff | ||
{ | ||
"scripts": { | ||
"build": "react-scripts build", | ||
"build:fab": "npm run fab-static build", | ||
+ "fab-upload": "fab-upload" | ||
} | ||
} | ||
``` | ||
## Usage | ||
`@bitgenics/fab-upload-cli` takes the following options: | ||
``` | ||
USAGE | ||
$ fab-upload [SITENAME] | ||
OPTIONS | ||
-a, --apiKey=apiKey Your Linc site API key | ||
-h, --help show CLI help | ||
EXAMPLES | ||
$ fab-upload my-site-name | ||
``` | ||
When `fab-upload` is run, it attempts to generate a FAB by running the `build:fab` script defined in your `package.json`. | ||
Running the `build:fab` script should compile a FAB by using a relevant [FAB](https://fab.dev/) package. | ||
If a FAB is successfully compiled, `fab-upload` will then upload the FAB to Linc along with a record of the build as well as some related git metadata. | ||
In order for `fab-upload` to operate, you will need to supply it with the name of your Linc site and an API key for that Linc site. | ||
You can supply these two values as environment variables: | ||
| Variable | Type | Value | | ||
| ---------------- | :----: | -------------------------: | | ||
| `LINC_API_KEY` | String | Your Linc site API key | | ||
| `LINC_SITE_NAME` | String | The name of your Linc site | | ||
Alternatively, you can pass these values to `fab-upload` via the `[SITENAME]` argument and `--apiKey` flag as follows: | ||
```bash | ||
fab-upload my-site-name --apiKey=abcd1234 | ||
``` | ||
Once `fab-upload` has successfully uploaded a FAB to Linc, it will return a list of preview URLs for the FAB, as well as a link to the build log in the Linc interface. | ||
## Obtaining an API key | ||
`fab-upload` is currently in beta. To obtain an API key and start using `fab-upload`, contact us at [support@linc.sh](mailto:support@linc.sh). |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
26074
581
78
4