-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(cli): lb4 example [<example-name>] #848
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
Conversation
|
Re-posting from our internal chat.
Well, I don't want to introduce dependency on Another reason why I prefer to download a ZIP bundle is that cloning a git repository downloads a full history with all revisions of all files, which is much more data than just the latest content in the |
|
|
||
| function extractEntry(entry, zipFile, next) { | ||
| // Skip optional directory entries | ||
| if (entry.fileName.endsWith('/')) return next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path.sep constant should be used for windows compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, zip entry file names always use /'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. According to yauzl's documentation, directory entries in ZIP end with / character - see https://www.npmjs.com/package/yauzl#usage:
if (/\/$/.test(entry.fileName)) {
// Directory file names end with '/'.
// Note that entires for directories themselves are optional.
// An entry's fileName implicitly requires its parent directories to exist.
zipfile.readEntry();
}See also ZIP format specification, section 4.4.17.1:
The name of the file, with optional relative path.
The path stored MUST not contain a drive or
device letter, or a leading slash. All slashes
MUST be forward slashes '/' as opposed to
backwards slashes '' for compatibility with Amiga
and UNIX file systems etc. If input came from standard
input, there is no file name field.
|
Can we avoid the temporary file by piping the http response into gunzip and extract? See an example at https://github.com/strongloop/loopback-oracle-installer/blob/master/lib/download.js#L103. |
| path.join(__dirname, '../generators/controller'), | ||
| 'loopback4:controller' | ||
| ); | ||
| env.register( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope for the PR, but we probably should refactor the list of generators into a separate file, such as:
generators.js
module.exports = {
app: path.join(__dirname, '../generators/app'), // Path
controller: path.join(__dirname, '../generators/controller'), // Path
another: AnotherGenerator, // Generator class
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, I'd like us to discover all generators automatically by scanning generators directory. I believe Yeoman is already doing that (or was doing that in earlier versions) for projects that are following prescribed project layout (see our generator-loopback for an example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we really want to use Yeoman discovery, which is one of areas that caused confusions in the past.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we probably don't want to use Yeoman discovery, I'd like us to write our own to follow the conventions we like most. But yeah, it's out of scope of this pull request.
Unfortunately not. See https://www.npmjs.com/package/yauzl#no-streaming-unzip-api
|
|
I think we should simply use tarball to enable streaming: https://codeload.github.com/strongloop/loopback-next/legacy.tar.gz/master (redirected from https://github.com/strongloop/loopback-next/tarball/master) |
|
I wonder if If git isn't an issue on windows still this approach might be simpler. |
Nice! I didn't know GitHub offers
Even if
The code to handle zip/tgz download and extraction may be slightly more complex to write. My expectation is that this will be "write once, never touch again" case and the extra complexity is more than worth the better user experience it gives us. |
|
Woot! I have reworked the code to download @virkt25 @raymondfeng LGTY now? |
52704fc to
b32271e
Compare
|
Rebased on top of the current master. |
Implement a new CLI command for cloning an example project
from our monorepo.
Usage:
lb4 example [options] [<example-name>]
Arguments:
example-name # Name of the example to clone Type: String Required: false
Available examples:
codehub: A GitHub-like application we used to use to model LB4 API.
The command downloads current master branch as a ZIP file from GitHub
to a temp file, creates a local directory called
`loopback4-example-${name}` and extracts all files from
`packages/example-${name}` to this new directory.
b32271e to
929af07
Compare
virkt25
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Implement a new CLI command for cloning an example project from our monorepo.
The command:
loopback4-example-${name},.tar.gzfile from GitHub in a streaming mode,packages/example-${name}to this new directory.See #836
Checklist
npm testpasses on your machinepackages/cliwere updatedpackages/example-*were updated (not applicable)