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

feat: Add experimental CLI for LoopBack 4 #693

Merged
merged 1 commit into from
Nov 6, 2017
Merged

feat: Add experimental CLI for LoopBack 4 #693

merged 1 commit into from
Nov 6, 2017

Conversation

raymondfeng
Copy link
Contributor

@raymondfeng raymondfeng commented Nov 1, 2017

Description

Usage:

npm i -g @loopback/cli
lb4 app <name>
lb4 extension <name>

For reviewers, you can check out the branch and run node packages/cli/bin/cli app <my-app> or node packages/cli/bin/cli extension <my-ext>.

Related issues

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style guide

--skip-cache # Do not remember prompt answers Default: false
--skip-install # Do not automatically install dependencies Default: false
--applicationName # Application name
--description # Description for theapplication
Copy link
Contributor

Choose a reason for hiding this comment

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

the application

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.


it('creates files', () => {
assert.noFile(['tslint.json', 'tslint.build.json']);
assert.jsonFileContent('package.json', props);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder how assert.jsonFileContent works. Below we are checking for prettier here, but not in this particular test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See https://github.com/yeoman/yeoman-assert#api. The assertions here focus on verifying the omission of tslint related artifacts.

@b-admike
Copy link
Contributor

b-admike commented Nov 2, 2017

Trial run result (for app):

___________________    | ~/loopback/loopback-next @ biniams-mbp (badmike)
| => node packages/cli/bin/cli app
? Project name: foobar
? Project description: my first lbnext app!
? Project root directory: foobar
? Application class name: FoobarApplication
? Select project build settings:  Enable tslint, Enable prettier, Enable mocha, Enable loopb
ackBuild
   create .gitignore
   create .npmrc
   create .prettierignore
   create .prettierrc
   create index.d.ts
   create index.js
   create index.ts
   create LICENSE
   create package.json
   create README.md
   create src/application.ts
   create src/controllers/ping-controller.ts
   create src/controllers/README.md
   create src/index.ts
   create src/repositories/README.md
   create test/mocha.opts
   create test/ping-controller.test.ts
   create test/README.md
   create tsconfig.json
   create tslint.build.json
   create tslint.json

> [email protected] prepare /Users/badmike/loopback/loopback-next/foobar
> npm run build


> [email protected] build /Users/badmike/loopback/loopback-next/foobar
> lb-tsc

added 570 packages in 31.853s

Application foobar is now created in foobar.

Next steps:

$ cd foobar
$ npm start

___________________    | ~/loopback/loopback-next @ biniams-mbp (badmike)
| => cd foobar/
___________________    | ~/loopback/loopback-next/foobar @ biniams-mbp (badmike)
| => npm start

> [email protected] start /Users/badmike/loopback/loopback-next/foobar
> npm run build && node .


> [email protected] build /Users/badmike/loopback/loopback-next/foobar
> lb-tsc

Server is running at http://127.0.0.1:3000
Try http://127.0.0.1:3000/ping
Unhandled error in GET /favicon.ico: 404 Error: Endpoint "GET /favicon.ico" not found.
    at RoutingTable.find (/Users/badmike/loopback/loopback-next/foobar/node_modules/@loopback/rest/dist/src/router/routing-table.js:75:15)
    at HttpHandler.findRoute (/Users/badmike/loopback/loopback-next/foobar/node_modules/@loopback/rest/dist/src/http-handler.js:26:29)
    at DefaultSequence.request [as findRoute] (/Users/badmike/loopback/loopback-next/foobar/node_modules/@loopback/rest/dist/src/providers/find-route.js:29:40)
    at DefaultSequence.handle (/Users/badmike/loopback/loopback-next/foobar/node_modules/@loopback/rest/dist/src/sequence.js:83:32)
    at HttpHandler._handleRequest (/Users/badmike/loopback/loopback-next/foobar/node_modules/@loopback/rest/dist/src/http-handler.js:32:24)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

ping page:

{"greeting":"Hello from LoopBack","date":"2017-11-02T23:19:24.416Z","url":"/ping","headers":{"host":"localhost:3000","connection":"keep-alive","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36","upgrade-insecure-requests":"1","accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.8"}}

greeting: 'Hello from LoopBack',
date: new Date(),
url: this.req.url,
headers: Object.assign({}, this.req.headers),
Copy link
Contributor

@b-admike b-admike Nov 2, 2017

Choose a reason for hiding this comment

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

I found including the headers to be a bit ugly for UX, but feel free to keep it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Haha, I have a json viewer extension installed for my browser and it looks fine :-). Surprisingly, most browsers don't render json response nicely by default.

@@ -0,0 +1,3 @@
# Repositories
Copy link
Contributor

Choose a reason for hiding this comment

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

The Mixin, Providers, etc.. pages have a great deal of description. Can we add some links to our docs or brief explanations here as well?

Copy link
Contributor Author

@raymondfeng raymondfeng Nov 2, 2017

Choose a reason for hiding this comment

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

The READMEs are copied from https://github.com/strongloop/loopback4-extension-starter.

@virkt25 Do you make the docs for Mixin/Provider/Decorator available to http://loopback.io/doc/en/lb4/Concepts.html?

We should only keep links in the README.md to be scaffolded into user projects.

@@ -0,0 +1,3 @@
# Controllers
Copy link
Contributor

Choose a reason for hiding this comment

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

The Mixin, Providers, etc.. pages have a great deal of description. Can we add some links to our docs or brief explanations here as well?

@@ -0,0 +1,3 @@
# Repositories
Copy link
Contributor

Choose a reason for hiding this comment

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

The Mixin, Providers, etc.. pages have a great deal of description. Can we add some links to our docs or brief explanations here as well?

@@ -0,0 +1 @@
# Acceptance tests
Copy link
Contributor

Choose a reason for hiding this comment

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

The Mixin, Providers, etc.. pages have a great deal of description. Can we add some links to our docs or brief explanations here as well?

@@ -0,0 +1 @@
# Integration tests
Copy link
Contributor

Choose a reason for hiding this comment

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

The Mixin, Providers, etc.. pages have a great deal of description. Can we add some links to our docs or brief explanations here as well?

@@ -0,0 +1 @@
# Unit tests
Copy link
Contributor

Choose a reason for hiding this comment

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

The Mixin, Providers, etc.. pages have a great deal of description. Can we add some links to our docs or brief explanations here as well?

@raymondfeng
Copy link
Contributor Author

Unhandled error in GET /favicon.ico: 404 Error: Endpoint "GET /favicon.ico" not found.

This is expected as the browser will send GET /favicon.ico to the server and it's not available. In LoopBack 3.x, we ship a default LoopBack logo as the icon. The runtime should have not dump 404 errors by default, IMO. It should be configured and toggled somehow.

@bajtos
Copy link
Member

bajtos commented Nov 3, 2017

Considering our past experience with yeoman, I think we should not be basing any new tooling on yeoman. We should use inquirer and ejs templating directly.

Having said that, I am happy to use yeoman for this initial experimental implementation, as it makes it easier for us to get something up and running 👍

I don't have bandwidth to review this pull request in details, I'll leave that up to @strongloop/sq-lb-apex

@kjdelisle kjdelisle mentioned this pull request Nov 3, 2017
4 tasks
Usage:
npm i -g @loopback/cli
lb4 app <name>
lb4 extension <name>
@raymondfeng
Copy link
Contributor Author

raymondfeng commented Nov 3, 2017

Considering our past experience with yeoman, I think we should not be basing any new tooling on yeoman. We should use inquirer and ejs templating directly.

Do we have a list of pain points with Yeoman somewhere? The latest version seems to be working out pretty well. I was able to register generators with yeoman-environment explicitly without the magic and the module name doesn't have to be generator-*.

@eddiemonge As a maintainer of Yeoman, do you have any insights?

@kjdelisle
Copy link
Contributor

I'm not well-versed enough in templating and generators to have an informed opinion. I'd probably have to take a few days to play around with it and see what I think. If we're concerned about blocking this PR for that long, then I won't stand in the way.

@raymondfeng
Copy link
Contributor Author

@kjdelisle I would like to have it merged as soon as possible so that we can start to use it to scaffold new extensions/apps. Maybe we can move forward as follows:

  1. I'll merge the PR and make a new release
  2. Some of us can start to use it after npm i -g @loopback/cli.
  3. We'll refine the templates as they are being improved over time.

Copy link
Contributor

@kjdelisle kjdelisle left a comment

Choose a reason for hiding this comment

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

To recap, it looks good to me, but I admit that I don't really know what would be best.

@raymondfeng raymondfeng merged commit 707f692 into master Nov 6, 2017
@kjdelisle kjdelisle deleted the add-cli branch November 6, 2017 18:17
@jonathan-casarrubias
Copy link

When can we expect this experimental cli to be published?

@raymondfeng
Copy link
Contributor Author

@jonathan-casarrubias It's published under @loopback/cli. You can install it now - npm i -g @loopback/cli. Feedback is welcome.

@jonathan-casarrubias
Copy link

Ok cool, installing....

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.

5 participants