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

hs list command to check contents of directories #354

Merged
merged 14 commits into from
Oct 19, 2020
Merged

Conversation

miketalley
Copy link
Contributor

@miketalley miketalley commented Oct 9, 2020

Description and Context

New command hs list [path] allows listing directory contents by path. Default path is root. Aliased as hs ls [path].

Screenshots

image

image

image

Questions

Do we want to group folders/files and output folders first(perhaps with / prefix)? Done
Any other changes to the output(I made this as MVP as possible for now)?
Do we want to look at the BE endpoint to increase speed(it's a bit slow ATM)?

TODO

Filed issue with fileMapper to include @hubspot folder in list of contents returned from endpoint.

Who to Notify

/cc @TheWebTech

@miketalley miketalley marked this pull request as ready for review October 9, 2020 18:53
@anthmatic
Copy link
Contributor

Nice! Re: grouping, I do think something there would be beneficial. Maybe some way to differentiate between folders and files?

@miketalley
Copy link
Contributor Author

miketalley commented Oct 9, 2020

Nice! Re: grouping, I do think something there would be beneficial. Maybe some way to differentiate between folders and files?

I was thinking of changing the output to look for a file extension and then assume that if one exists(minus special case of .functions) we can assume those are files. Any others would tack on a slash to denote a folder -- `/${name}`. Then we can place the folders above the files in the sort order.

image

@miketalley miketalley linked an issue Oct 9, 2020 that may be closed by this pull request
@miketalley miketalley changed the title Added basic ls command to check contents of directories hs ls command to check contents of directories Oct 13, 2020
@anthmatic
Copy link
Contributor

2 things I noticed, neither of which are deal breakers:

  • the @hubspot folder doesn't show up. I'm not sure if we NEED to support that, but it might be nice
  • /Coded files and /Custom aren't in alphabetical order (which is a departure from DM)

@anthmatic anthmatic closed this Oct 14, 2020
@anthmatic anthmatic reopened this Oct 14, 2020
@miketalley
Copy link
Contributor Author

miketalley commented Oct 14, 2020

  • the @hubspot folder doesn't show up. I'm not sure if we NEED to support that, but it might be nice
    Good catch -- @mattcoley any idea why the @hubspot folder would not show up in the results from content/filemapper/v1/meta/${path}?
  • /Coded files and /Custom aren't in alphabetical order (which is a departure from DM)
    I'm not sure that I follow, they appear in the same order for me in the CLI and DM.
    image
    image

@anthmatic
Copy link
Contributor

Re: the order, this is what I see (with other folders that start with "c")
image

vs

image

@miketalley
Copy link
Contributor Author

Fixed the incorrect sorting and pinned @HubSpot and @marketplace folders to top of the list
image

@miketalley
Copy link
Contributor Author

@anthmatic I filed an issue for the filemapper endpoint to include the @hubspot folder and it should be pinned to the top when included in the results from the endpoint response.

return fileOrFolder;
}

return `/${fileOrFolder}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason for prepending / to some items but not others? If we decide to keep this logic, one thing to keep in mind is that modules also have a postfix (e.g. .module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was done to make it clearer which items are folders(prepended with /) and which are files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it works properly with modules
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't mymodule.module a folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to mimic the display of the finder in DM where modules are listed more like files, but that is a good point -- it should be listed like a folder.

image

packages/cms-cli/commands/ls.js Outdated Show resolved Hide resolved
packages/cms-cli/commands/ls.js Outdated Show resolved Hide resolved
packages/cms-cli/commands/ls.js Outdated Show resolved Hide resolved
@miketalley miketalley changed the title hs ls command to check contents of directories hs list command to check contents of directories Oct 14, 2020
@gcorne
Copy link
Contributor

gcorne commented Oct 15, 2020

I wonder if we should borrow from ls and colorize folders instead of using /. I say that because I think prepending with / is confusing especially when listing folders deeper in the directory structure because the path to the file in HubSpot is different from what is presented in the output. The path separator also applies to both files and folders, so I don't think the purpose is obvious.

mappedContents
.sort(function(a, b) {
// Pin @hubspot folder to top
if (a === hubspotFolder) {
Copy link
Contributor

Choose a reason for hiding this comment

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

With the other changes, does this still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it looks to be pinning these folders to the top.

Note: The BE is not currently returning the @hubspot folder(I've filed an issue for this in the filemapper repo).

I tested with the following code...

contentsResp = await getDirectoryContentsByPath(portalId, directoryPath);
  const randomIndex = Math.floor(
    Math.random() * contentsResp.children.length
  );
contentsResp.children.splice(randomIndex, 0, '@hubspot');

Copy link
Contributor

Choose a reason for hiding this comment

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

Were you testing with a root directory that had folders starting with numbers such as 1folder?

packages/cms-cli/commands/list.js Outdated Show resolved Hide resolved
@miketalley
Copy link
Contributor Author

miketalley commented Oct 16, 2020

Updated output to use chalk to colorize folders instead of prepending /. This mimics the ls -G command.

Another potential that I looked into was using sprintf to create columns and having a column after the folder name indicating <dir> similar to the dir output within Windows.

image

I believe that using color to distinguish folders is the simplest and clearest solution and is less confusing than /.

image

@miketalley miketalley merged commit bee439f into master Oct 19, 2020
@miketalley miketalley deleted the issue/309-hs-ls branch October 19, 2020 15:13
@drewjenkins
Copy link
Contributor

We are using table in a couple places, such as hs open, you could probably use that to pretty easily achieve what you are looking for with the columns

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.

Add hs ls command to get asset listing
4 participants