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

Create api samples #421

Merged
merged 7 commits into from
Jan 22, 2021
Merged

Create api samples #421

merged 7 commits into from
Jan 22, 2021

Conversation

asalauyeu-hubspot
Copy link
Contributor

@asalauyeu-hubspot asalauyeu-hubspot commented Jan 20, 2021

Description and Context

This is the first PR about integration with SDK sample-apps.
Currently initial flow is the following:

  1. The following repo includes samples.json config, which will be downloaded each time user runs hs create api-sample to check, which samples are currently available on which languages.
  2. After that we have a prompt with several questions to the user, which sample type on which language they want to download (using samples config for selection choices)
  3. Then download repo with sample app and put it to destination folder the same way, as it's done for react-app / vue-app / webpack-serverless / website-theme.

We've added one repo with first oauth sample app on node language to test .

Screenshots

image
image
image
image

Copy link
Contributor

@gcorne gcorne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to see this. Are we planning to add additional API sample projects before merging this? If not, I think we should remove the prompt flow.

I also think we should add some info to the README on the need to create a developer account and an app in order to obtain a client id and secret.

packages/cli-lib/projects.js Outdated Show resolved Hide resolved
const { logErrorInstance } = require('@hubspot/cli-lib/errorHandlers');

// https://developer.github.com/v3/#user-agent-required
const USER_AGENT_HEADERS = { 'User-Agent': 'HubSpot/hubspot-cms-tools' };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should create a constant in packages/cli-lib/http/requestOptions for the constant and share it between here and getRequestOptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice point. Created DEFAULT_USER_AGENT_HEADERS constant, and shared it to projects and github.js

packages/cli/lib/configs.js Outdated Show resolved Hide resolved
packages/cli/lib/configs.js Outdated Show resolved Hide resolved
* @param {String} repoName - name of the github repository
* @returns {Buffer|Null} Zip data buffer
*/
async function downloadConfig(repoName, filePath) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works, it does seem like a pretty indirect way to get a JSON file with information on the different samples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the logic of getting configs to 1 method, and made it more abstract for getting json files.

if (fs.existsSync(filePath)) {
const { overwrite } = await overwriteSamplePrompt(filePath);
if (overwrite) {
const removingSpinner = ora(`Removing existing ${filePath} folder`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're dealing with a local file system operation, is this necessary?

case TYPES['api-sample']: {
const filePath = path.join(dest, name);
if (fs.existsSync(filePath)) {
const { overwrite } = await overwriteSamplePrompt(filePath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a neat idea! We should consider using it in other hs create flows.

if (!sampleType || !sampleLanguage) {
logger.error(
`Currently there are no samples available, please, try again later.`
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the message here be different?

packages/cli/commands/create.js Outdated Show resolved Hide resolved
packages/cli/commands/create.js Show resolved Hide resolved
@asalauyeu-hubspot asalauyeu-hubspot merged commit 8ac3415 into master Jan 22, 2021
@asalauyeu-hubspot asalauyeu-hubspot deleted the create-api-samples branch January 22, 2021 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants