Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial README #500

Merged
merged 10 commits into from
May 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/cli-lib/file-upload/MyProject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is purely for example on how to get a file uploaded to your Account
27 changes: 27 additions & 0 deletions examples/cli-lib/file-upload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## File Upload Example

** This example is for uploading a file to design-manager. To see an example on how to upload assets to File Manager, check out the filemanager-upload example **

### Overview

This example should you a simple file upload scenario. This would be used to upload a single file. To see how to upload a whole folder, check out the `slack` example.

### Running the Example

1. `npm install`
2. Open index.js, replace each ACCOUNT_ID with the account id of your HubSpot account. Note that in a production environment, data like this should be stored securely as an environment variable.
3. `node index.js`

You should see a success message in your terminal

### Real Life Usage

An example flow would be:

1. You make local changes to MyProject
2. You push the changes to GitHub
3. You use GitHub Actions to run tests on your code
4. If tests fail, abort. No upload happens
5. If all tests pass, have the Github action invoke this script. The LOCAL_PROJECT_PATH would be set to the path it is accessed from on the Github action. The mocked out environment variables we have in index.js would instead be securely stored on Github Actions and referenced through process.env.MY_VARIABLE
6. The folder at LOCAL_PROJECT_PATH is uploaded to your HubSpot DesignManager. Because we specified publish rather than draft, our changes are immediately published and available in your live HubSpot instance.
7. If the upload succeeds, log out a success message to the terminal
29 changes: 29 additions & 0 deletions examples/cli-lib/file-upload/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const { Mode, getAccountId, loadConfig } = require('@hubspot/cli-lib');
const { upload } = require('@hubspot/cli-lib/api/fileMapper');

// Mock out some environment variables
const LOCAL_FILE_PATH = './MyProject/README.md';
const REMOTE_FILE_PATH = '/MyProject/README.md';

// Loads the hubspot.config.yml file into memory for cli-lib usage
loadConfig();

/**
* getAccountId will get the default accountId specified in your hubspot.config.yml file
* You can alternatively pass in an account name if you don't want the default account
* to be used.
*/
const accountId = getAccountId();

(async function() {
try {
// Upload the contents of LOCAL_FILE_PATH to REMOTE_FILE_PATH in Design Manager
await upload(accountId, LOCAL_FILE_PATH, REMOTE_FILE_PATH, Mode.publish);
console.log(`${LOCAL_FILE_PATH} has been deployed to ${accountId}`);
} catch (e) {
console.error(
`Encountered an error uploading ${LOCAL_FILE_PATH} to your ${accountId} account\n${e.message}`
);
process.exit(1);
}
})();
Loading