-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #500 from HubSpot/cli-lib/readme
Initial README
- Loading branch information
Showing
11 changed files
with
9,640 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
})(); |
Oops, something went wrong.