diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index ccc915a..795176c 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,36 +1,37 @@ -### Bug or feature request +# Description/Steps to reproduce -- [ ] Bug -- [ ] Feature request - -### Description of feature (or steps to reproduce if bug) - - - -### Link to sample repo to reproduce issue (if bug) - - - -### Expected result +# Link to reproduction sandbox + -### Actual result (if bug) - - +# Expected result -### Additional information (Node.js version, LoopBack version, etc) + +# Additional information + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index d2b240f..368cb4c 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -6,17 +6,18 @@ -- None +- connect to ### Checklist - [ ] New tests added or existing tests modified to cover all changes diff --git a/.github/stale.yml b/.github/stale.yml new file mode 100644 index 0000000..bebe60a --- /dev/null +++ b/.github/stale.yml @@ -0,0 +1,23 @@ +# Number of days of inactivity before an issue becomes stale +daysUntilStale: 60 +# Number of days of inactivity before a stale issue is closed +daysUntilClose: 14 +# Issues with these labels will never be considered stale +exemptLabels: + - pinned + - security + - critical + - p1 + - major +# Label to use when marking an issue as stale +staleLabel: stale +# Comment to post when marking an issue as stale. Set to `false` to disable +markComment: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. +# Comment to post when closing a stale issue. Set to `false` to disable +closeComment: > + This issue has been closed due to continued inactivity. Thank you for your understanding. + If you believe this to be in error, please contact one of the code owners, + listed in the `CODEOWNERS` file at the top-level of this repository. diff --git a/.gitignore b/.gitignore index e525285..38add57 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ node_modules *xunit.xml test/sandbox/ test/fixtures/actual +.vscode/* diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index 01bff6f..a74acf2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,5 @@ sudo: false language: node_js node_js: - - "4" - - "6" - - "7" - + - "8" + - "10" diff --git a/CHANGES.md b/CHANGES.md index 0062a79..888e4e7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,177 @@ +2021-01-19, Version 5.2.0 +========================= + + * Reword end-of-life warning printed by CLI (Miroslav Bajtoš) + + * chore: update LTS status to End-of-Life (Rifa Achrinza) + + * fix: warning about LoopBack 3 in stderr (HugoPoi) + + +2020-03-05, Version 5.1.0 +========================= + + * Print a warning about Maintenance LTS at startup (Miroslav Bajtoš) + + * Update LTS status in README (Miroslav Bajtoš) + + * chore: update copyright year (Diana Lau) + + * chore: drop Node.js 6 support (Diana Lau) + + +2019-06-20, Version 5.0.3 +========================= + + * fix: a workaround to fix the hanging cmd (jannyHou) + + +2019-05-15, Version 5.0.2 +========================= + + * fix tests for prompts (Diana Lau) + + +2019-05-10, Version 5.0.1 +========================= + + * chore: update copyright years (Diana Lau) + + * chore: update LTS status (Diana Lau) + + * LTS (jannyHou) + + +2018-11-16, Version 5.0.0 +========================= + + * feat: switch to yeoman-env (jannyHou) + + * chore: add stalebot (Diana Lau) + + +2018-09-18, Version 4.2.1 +========================= + + * chore: upgrade dependencies (virkt25) + + * Fix tests on printing help (shimks) + + * Drop node 4 from CI (shimks) + + +2018-03-22, Version 4.2.0 +========================= + + * update generator-loopback version (Diana Lau) + + * update help-lb message (Diana Lau) + + +2017-12-14, Version 4.1.0 +========================= + + * Update for zosconnectee command (Andrew Smithson) + + * Update LICENSE (Diana Lau) + + +2017-09-07, Version 4.0.0 +========================= + + * Increment generator-loopback to 5.0.0 (#54) (Rashmi Hunt) + + * create pr template (Sakib Hasan) + + * create issue template (Sakib Hasan) + + * Update dev-dependencies (Miroslav Bajtoš) + + * travis: drop Node.js 7.x, add 8.x (Miroslav Bajtoš) + + +2017-07-28, Version 3.1.0 +========================= + + * Support `lb [command | appName]` (Hage Yaapa) + + * Add CODEOWNERS file (Diana Lau) + + +2017-07-15, Version 3.0.0 +========================= + + * deps: generator-loopback@4.0.0 (Hage Yaapa) + + +2017-06-28, Version 2.6.0 +========================= + + * Update generator-loopback to 3.9.0 (Hage Yaapa) + + * Separate service provisioning (Hage Yaapa) + + +2017-06-08, Version 2.5.1 +========================= + + * Switch from nopts to minimist for args parsing (Miroslav Bajtoš) + + +2017-05-06, Version 2.5.0 +========================= + + * bluemix login options (Hage Yaapa) + + +2017-04-28, Version 2.4.0 +========================= + + * Upgrade generator-loopback to 3.5.0 (Raymond Feng) + + * Add `lb:oracle` command (Raymond Feng) + + +2017-04-20, Version 2.3.0 +========================= + + * bluemix command (Hage Yaapa) + + +2017-04-16, Version 2.2.1 +========================= + + * Fix README review comments (rashmihunt) + + * README change for WSDL to datasource (rashmihunt) + + +2017-04-06, Version 2.2.0 +========================= + + * Include workspace version in --version log (Miroslav Bajtoš) + + * Remove reference to swagger (rashmihunt) + + * Add URL to SOAP and WSDL Spec (rashmihunt) + + * Point to README_Soap from REAME (rashmihunt) + + * Detail Readme for lb soap feature (rashmihunt) + + +2017-03-27, Version 2.1.0 +========================= + + * Fix soap help text (rashmihunt) + + * Rename oopback_soap_help.txt->help-lb-soap.txt (rashmihunt) + + * Add soap command in test/help.test.js (rashmihunt) + + * support for lb soap command (rashmihunt) + + 2017-03-07, Version 2.0.0 ========================= diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..ab41b34 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,6 @@ +# Lines starting with '#' are comments. +# Each line is a file pattern followed by one or more owners, +# the last matching pattern has the most precedence. + +# Core team members from IBM +* @bajtos @raymondfeng @rashmihunt @hacksparrow diff --git a/LICENSE b/LICENSE index 429a8f8..9e6ef73 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) IBM Corp. 2016. All Rights Reserved. +Copyright (c) IBM Corp. 2016,2017. All Rights Reserved. Node module: loopback-cli This project is licensed under the MIT License, full text below. diff --git a/README.md b/README.md index 188300c..c7d8e0e 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,16 @@ LoopBack CLI tool for creating projects, models and more. This package supersedes the older `slc` tool. +**⚠️ LoopBack 3 has reached end of life. We are no longer accepting pull requests or providing +support for community users. The only exception is fixes for critical bugs and security +vulnerabilities provided as part of support for IBM API Connect customers. (See +[Module Long Term Support Policy](#module-long-term-support-policy) below.)** + +We urge all LoopBack 3 users to migrate their applications to LoopBack 4 as +soon as possible. Refer to our +[Migration Guide](https://loopback.io/doc/en/lb4/migration-overview.html) +for more information on how to upgrade. + ## Installation To install the LoopBack CLI tool: @@ -15,7 +25,7 @@ $ npm install -g loopback-cli ### Getting started - 1. Run `lb` to create a new LoopBack application. + 1. Run `lb [appName]` to create a new LoopBack application. 2. Run `node .` to start the scaffolded server. ### What's next @@ -28,6 +38,7 @@ Available commands: lb acl lb app lb boot-script + lb bluemix lb datasource lb export-api-def lb middleware @@ -35,7 +46,9 @@ Available commands: lb property lb relation lb remote-method + lb soap lb swagger + lb zosconnectee ``` Run `lb --help` to learn more about each command. For example: @@ -66,6 +79,7 @@ Example: Refer to [Create a simple API](http://loopback.io/doc/en/lb3/Create-a-simple-API.html) for more information. +Refer to [README_Soap](./soap/README_Soap.md) for more information on 'lb soap' command. ## Contributing IBM/StrongLoop is an active supporter of open source and welcomes contributions @@ -81,3 +95,14 @@ Discuss features and ask questions on ## License MIT + +## Module Long Term Support Policy +This module adopts the [Module Long Term Support (LTS)](http://github.com/CloudNativeJS/ModuleLTS) policy, with the following End Of Life (EOL) dates: + +| Version | Status | Published | EOL | +| ------- | --------------- | --------- | -------- | +| 5.x | End-of-Life | Nov 2018 | Dec 2020 | +| 4.x | End-of-Life | Sep 2017 | Dec 2019 | +| 3.x | End-of-Life | Jul 2017 | Apr 2019 | + +Learn more about our LTS plan in the [docs](https://loopback.io/doc/en/contrib/Long-term-support.html). diff --git a/bin/loopback-cli.js b/bin/loopback-cli.js index 32c8e14..9b33bad 100755 --- a/bin/loopback-cli.js +++ b/bin/loopback-cli.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -// Copyright IBM Corp. 2016. All Rights Reserved. +// Copyright IBM Corp. 2016,2019. All Rights Reserved. // Node module: loopback-cli // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT @@ -8,24 +8,36 @@ const assert = require('assert'); const camelCaseKeys = require('camelcase-keys'); +const chalk = require('ansi-colors'); const debug = require('debug')('loopback:cli'); -const nopt = require('nopt'); +const minimist = require('minimist'); const path = require('path'); -const opts = nopt({ - help: Boolean, - version: Boolean, - commands: Boolean, -}, { - h: '--help', - v: '--version', - l: '--commands', +console.error(chalk.bold(chalk.red(` +LoopBack 3 has reached end of life. We are no longer accepting pull requests +or providing support for community users. The only exception is fixes for +critical bugs and security vulnerabilities provided as part of support for +IBM API Connect customers. + +We urge all LoopBack 3 users to migrate their applications to LoopBack 4 +as soon as possible. Refer to our Migration Guide for more information +on how to upgrade: https://loopback.io/doc/en/lb4/migration-overview.html +`))); + +const opts = minimist(process.argv.slice(2), { + alias: { + help: 'h', + version: 'v', + commands: 'l', + }, }); if (opts.version) { const ourVersion = require('../package.json').version; const generatorVersion = require('generator-loopback/package.json').version; - console.log('%s (generator-loopback@%s)', ourVersion, generatorVersion); + const workspaceVersion = require('generator-loopback').workspaceVersion; + console.log('%s (generator-loopback@%s loopback-workspace@%s)', + ourVersion, generatorVersion, workspaceVersion); return; } @@ -36,10 +48,10 @@ process.env.SLC_COMMAND = 'loopback-cli'; // therefore I am intentionally loading it only after we have // handled the "--version" case which becomes much faster as the result. const lbGenerator = require('generator-loopback'); -const yeoman = lbGenerator._yeoman; // generator-loopback should export _yeoman -assert(yeoman, 'generator-loopback should export _yeoman'); +const yeomanEnv = lbGenerator._yeomanEnv; +assert(yeomanEnv, 'generator-loopback should export _yeomanEnv'); -const env = yeoman(); +const env = yeomanEnv.createEnv(); // Change the working directory to the generator-loopback module so that // yeoman can discover the generators @@ -48,48 +60,39 @@ const cwd = process.cwd(); debug('changing directory to %s', root); process.chdir(root); -// lookup for every namespaces, within the environments.paths and lookups -env.lookup(); -debug('changing directory back to %s', cwd); -process.chdir(cwd); // Switch back - -// list generators -if (opts.commands) { - console.log('Available commands: '); - var list = Object.keys(env.getGeneratorsMeta()) - .filter(name => /^loopback:/.test(name)) - .map(name => name.replace(/^loopback:/, ' lb ')); - console.log(list.join('\n')); - return; -} +env.lookup(function() { + debug('changing directory back to %s', cwd); + process.chdir(cwd); // Switch back -const args = opts.argv.remain; -const originalCommand = args.shift(); -const command = 'loopback:' + (originalCommand || 'app'); -args.unshift(command); -debug('invoking generator', args); - -// `yo` is adding flags converted to CamelCase -const options = camelCaseKeys(opts, {exclude: ['--', /^\w$/, 'argv']}); -Object.assign(options, opts); - -// Handle unknown command (generator) -// This code overrides the error reported by yeoman: -// You don’t seem to have a generator with the name “' + n + '” installed. -// But help is on the way: -// (etc.) -try { - const generator = env.create(command, {args}); - if (generator instanceof Error) - throw generator; -} catch (err) { - debug('Cannot load generator %s: %s', command, err.stack); - console.error( - 'Unknown command %j\n' + - 'Run "%s --commands" to print the list of available commands.', - originalCommand, process.argv[1]); - process.exit(1); -} + // list generators + if (opts.commands) { + console.log('Available commands: '); + var list = Object.keys(env.getGeneratorsMeta()) + .filter(name => /^loopback:/.test(name)) + .map(name => name.replace(/^loopback:/, ' lb ')); + console.log(list.join('\n')); + return; + } -debug('env.run %j %j', args, options); -env.run(args, options); + const args = opts._; + const originalCommand = args.shift(); + let command = 'loopback:' + (originalCommand || 'app'); + const supportedCommands = env.getGeneratorsMeta(); + + if (!(command in supportedCommands)) { + command = 'loopback:app'; + args.unshift(originalCommand); + args.unshift(command); + } else { + args.unshift(command); + } + + debug('invoking generator', args); + + // `yo` is adding flags converted to CamelCase + const options = camelCaseKeys(opts, {exclude: ['--', /^\w$/, 'argv']}); + Object.assign(options, opts); + + debug('env.run %j %j', args, options); + env.run(args, options); +}); diff --git a/package.json b/package.json index 7dcd868..3bdb5b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "loopback-cli", - "version": "2.0.0", + "version": "5.2.0", "description": "LoopBack CLI tool for creating projects, models and more.", "license": "MIT", "homepage": "http://loopback.io", @@ -8,8 +8,9 @@ "LoopBack", "StrongLoop" ], + "author": "IBM Corp.", "engines": { - "node": ">=4.0.0" + "node": ">=8" }, "repository": { "type": "git", @@ -29,18 +30,20 @@ } }, "dependencies": { - "camelcase-keys": "^4.0.0", - "debug": "^2.6.1", - "generator-loopback": "^3.0.0", - "nopt": "^4.0.1" + "ansi-colors": "^4.1.1", + "camelcase-keys": "^4.2.0", + "debug": "^4.0.1", + "generator-loopback": "^6.0.0", + "inquirer": "~6.3.1", + "minimist": "^1.2.0" }, "devDependencies": { - "chai": "^3.5.0", - "dirty-chai": "^1.2.2", - "eslint": "^3.16.1", - "eslint-config-loopback": "^8.0.0", + "chai": "^4.1.2", + "dirty-chai": "^2.0.1", + "eslint": "^5.6.0", + "eslint-config-loopback": "^12.0.0", "mkdirp": "^0.5.1", - "mocha": "^3.2.0", - "rimraf": "^2.6.1" + "mocha": "^5.2.0", + "rimraf": "^2.6.2" } } diff --git a/soap/README_Soap.md b/soap/README_Soap.md new file mode 100644 index 0000000..808e163 --- /dev/null +++ b/soap/README_Soap.md @@ -0,0 +1,160 @@ +# API design first with LoopBack and SOAP Web Service + +## What is LoopBack? + +[LoopBack](http://loopback.io) is an open source Node.js API framework from [StrongLoop](http://www.strongloop.com). +It is built on top of Express optimized for mobile, web, and other devices. LoopBack makes +it really easy and productive for developers to define, build and consume APIs. Define data +models, connect to multiple data sources, write business logic in Node.js, glue on top of your +existing services and data, and consume using JS, iOS & Android SDKs. + +## What is Web Service/SOAP/WSDL? + +Web services is a technology which lets applications to talk to each other independent +of platform and language. A web service is a software interface which describes a collection +of operations that can be invoked over the network through standardized XML messaging using +[SOAP](https://www.w3.org/TR/soap/)(Simple Object Access Protocol). [WSDL](https://www.w3.org/TR/wsdl20/)(Web Services Description Language) is an +XML formatted document which describes the Web Service endpoint, bindings, operations +and schema. + +## LoopBack + SOAP = REST API + +![loopback soap](images/loopback-soap-integration.png) + +In many Enterprises, Web Services are still important and the way to access these +Web Services is still via SOAP. SOAP is fairly heavy weight, and working with XML-based SOAP +payloads in Node.js is not easy. It’s much easier to use JSON and to wrap or mediate a SOAP +service and expose it as a REST API. To support API design first approach, 'lb soap' feature +supports generation of JSON models and REST APIs for SOAP Web Services operations. These operations +can invoke Web Service without user writing any client code. + +## Scaffolding a LoopBack application from SOAP Web Services datasource + +Before we start, please make sure you have loopback-cli installed: + +```sh +npm install -g loopback-cli +``` +For more information, see https://github.com/strongloop/loopback-cli + +### Create a loopback application + +The first step is to create a blank loopback application. For e.g soap-demo + +```sh +lb app +``` +Select 3.x or 2.x Loopback version. When prompted 'What kind of application do you have in mind?', +select 'empty-server' for this demo purpose. + +![lb soap](images/loopback-app.png) + +### Create a SOAP Web Services datasource + +```sh +cd soap-demo +``` + +The next step is to create SOAP Web Services datasource. In this demo, we will create a SOAP datasource +for an externally available Periodic Table Web Service: http://www.webservicex.net/periodictable.asmx?WSDL + +```sh +lb datasource +``` +Here are the steps to create SOAP Web Services datasource for Periodic Table Web Service. + +- Enter the datasource name, e.g 'periodicSoapDS' +- Scroll through and select 'Soap Webservices(supported by StrongLoop)' from the list of connectors. +- Enter http://www.webservicex.net/periodictable.asmx for 'URL to the SOAP web service endpoint' prompt. +- Enter http://www.webservicex.net/periodictable.asmx?WSDL for 'HTTP URL or local fie system path to WSDL file' prompt. +- Enter 'Y' to Expose operations as REST APIs. +- Leave blank to 'Maps WSDL binding operations to node.js methods' +- Select 'Y' to 'Install 'loopback-connector-soap' prompt. 'lb soap' feature will not work if loopback-connector-soap + is not installed. + +Refer [SOAP data source properties](http://loopback.io/doc/en/lb3/SOAP-connector.html) for detail information on SOAP datasource properties. + +![lb soap](images/loopback-datasource.png) + +### Generate APIs from SOAP Web Services datasource + +Now let's try to generate models and APIs from SOAP Web Services datasource. + +```sh +lb soap +``` +This prompts list of SOAP Web Service datasources you have created for this app. For this demo it will just +show 'periodicSoapDS' since we created only this datasource so far. Select the datasource from the list. + +![lb soap:](images/loopback-datasource-select.png) + +The generator then discovers list of services defined in the WSDL for the selected datasource. +Select the service from a list of services. + +![lb soap:](images/loopback-soap-service.png) + +Once a 'service' is selected, it will discover and list bindings defined for the selected service. +Select a binding. + +![lb soap](images/loopback-soap-binding.png) + +Once a 'binding' is selected, it will then discover and list SOAP operations defined in the selected binding. +Select one or more SOAP operation/s. + +![lb soap](images/loopback-soap-operations.png) + +Once one or more operation/s are selected, the project will generate remote models and REST API which can +invoke the external Web Service which is running at (http://www.webservicex.net/periodictable.asmx). + +### Check the project + +The models and corresponding JS files are generated into the server/models folder: +![soap-demo project](images/soap-demo-project.png) + +- server/model-config.json: Config for all models + +- here are some of the server/models files: + + - soap-periodictable-soap.json: model to host all APIs + - soap-periodictable-soap.js: JS file containing all APIs which can invoke Web Service operations. + - get-atomic-number.json: GetAtomicNumber definition + - get-atomic-number.js: GetAtomicNumber extension + - get-atomic-weight.json: GetAtomicWeight model definition + - get-atomic-weight.js: GetAtomicWeight model extension + - etc + +### Run the application + +To run the application: +```sh +node . +``` + +Open your browser and points to http://localhost:3000/explorer. + +![explorer api](images/api-explorer.png) + +As you see, SOAP operations defined in the WSDL document is now available from LoopBack! + +Let's give a try: + +- Click on 'GetAtomicNumber' API. +- Under 'Parameters' click on 'Example Value' text box. This will fill in 'GetAtomicNumber' value text box. +- Fill in the 'ElementName' as 'Copper' or 'Iron' or any element name from the periodic table. +- Click on 'Try it out' button. + +![explorer api](images/invoke-api-webservice.png) + +This will invoke the REST API which is generated in soap-periodictable-soap.js. This REST API in turn +invokes the periodic table Web Service hosted at (http://www.webservicex.net/periodictable.asmx) returning SOAP result +back to the API explorer. + +![explorer api](images/api-webservice-result.png) + +## Summary + +With the 'lb soap' command, we now have the complete round trip: +- Start with a SOAP Web Service datasource. +- Generate corresponding models and APIs to invoke SOAP operations. +- Play with the live APIs served by LoopBack using the explorer. +- Invoke the Web Service through your REST API. diff --git a/soap/images/api-explorer.png b/soap/images/api-explorer.png new file mode 100644 index 0000000..eb70cc1 Binary files /dev/null and b/soap/images/api-explorer.png differ diff --git a/soap/images/api-webservice-result.png b/soap/images/api-webservice-result.png new file mode 100644 index 0000000..afd5a0a Binary files /dev/null and b/soap/images/api-webservice-result.png differ diff --git a/soap/images/invoke-api-webservice.png b/soap/images/invoke-api-webservice.png new file mode 100644 index 0000000..10cb65b Binary files /dev/null and b/soap/images/invoke-api-webservice.png differ diff --git a/soap/images/loopback-app.png b/soap/images/loopback-app.png new file mode 100644 index 0000000..1e7f0ab Binary files /dev/null and b/soap/images/loopback-app.png differ diff --git a/soap/images/loopback-datasource-select.png b/soap/images/loopback-datasource-select.png new file mode 100644 index 0000000..708fd24 Binary files /dev/null and b/soap/images/loopback-datasource-select.png differ diff --git a/soap/images/loopback-datasource.png b/soap/images/loopback-datasource.png new file mode 100644 index 0000000..f37bce3 Binary files /dev/null and b/soap/images/loopback-datasource.png differ diff --git a/soap/images/loopback-soap-binding.png b/soap/images/loopback-soap-binding.png new file mode 100644 index 0000000..e7e0c07 Binary files /dev/null and b/soap/images/loopback-soap-binding.png differ diff --git a/soap/images/loopback-soap-integration.png b/soap/images/loopback-soap-integration.png new file mode 100644 index 0000000..9d0f563 Binary files /dev/null and b/soap/images/loopback-soap-integration.png differ diff --git a/soap/images/loopback-soap-operations.png b/soap/images/loopback-soap-operations.png new file mode 100644 index 0000000..936a6c0 Binary files /dev/null and b/soap/images/loopback-soap-operations.png differ diff --git a/soap/images/loopback-soap-service.png b/soap/images/loopback-soap-service.png new file mode 100644 index 0000000..7642261 Binary files /dev/null and b/soap/images/loopback-soap-service.png differ diff --git a/soap/images/soap-demo-project.png b/soap/images/soap-demo-project.png new file mode 100644 index 0000000..34062c8 Binary files /dev/null and b/soap/images/soap-demo-project.png differ diff --git a/test/fixtures/help-lb-acl.txt b/test/fixtures/help-lb-acl.txt index 6304f55..59967ff 100644 --- a/test/fixtures/help-lb-acl.txt +++ b/test/fixtures/help-lb-acl.txt @@ -2,9 +2,10 @@ Usage: lb acl [options] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Description: Adds a new ACL entry to the LoopBack application. diff --git a/test/fixtures/help-lb-bluemix.txt b/test/fixtures/help-lb-bluemix.txt new file mode 100644 index 0000000..3ef108c --- /dev/null +++ b/test/fixtures/help-lb-bluemix.txt @@ -0,0 +1,22 @@ +Usage: + lb bluemix [options] + +Options: + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + --appName # Application name + --docker # Generate Dockerfile + --manifest # Generate Bluemix manifest file + --toolchain # Set up Bluemix toolchain + --login # Log into Bluemix Default: false + --sso # Log into Bluemix with SSO + --provision # Provision a Bluemix service Default: false + +Description: + `toolchain`, `manifest`, and `docker` are scaffold options. Not specifying any of them is interpreted as + specifying all of them. + + Specify `provision` to provision a LoopBack-supported Bluemix data service. + diff --git a/test/fixtures/help-lb-boot-script.txt b/test/fixtures/help-lb-boot-script.txt index 2586c7e..a20c545 100644 --- a/test/fixtures/help-lb-boot-script.txt +++ b/test/fixtures/help-lb-boot-script.txt @@ -2,9 +2,10 @@ Usage: lb boot-script [options] [] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Arguments: name # Name of the boot script to create. Type: String Required: false diff --git a/test/fixtures/help-lb-datasource.txt b/test/fixtures/help-lb-datasource.txt index 34dab3d..91782d4 100644 --- a/test/fixtures/help-lb-datasource.txt +++ b/test/fixtures/help-lb-datasource.txt @@ -2,12 +2,16 @@ Usage: lb datasource [options] [] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + --bluemix # Add a datasource from Bluemix + --login # Log into Bluemix Default: false + --sso # Log into Bluemix with SSO Arguments: - name # Name of the data-source to create. Type: String Required: false + name # Name of the datasource to create. Type: String Required: false Description: Creates a new DataSource in the LoopBack application. @@ -16,5 +20,5 @@ Example: lb datasource crm - This adds an entry to `datasources.json` defining the data-source "crm". + This adds an entry to `datasources.json` defining the datasource "crm". diff --git a/test/fixtures/help-lb-export-api-def.txt b/test/fixtures/help-lb-export-api-def.txt index 70839f1..4a4e00e 100644 --- a/test/fixtures/help-lb-export-api-def.txt +++ b/test/fixtures/help-lb-export-api-def.txt @@ -2,10 +2,11 @@ Usage: lb export-api-def [options] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false - -o, --output # Name/Full path to the output file. + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + -o, --output # Name/Full path to the output file. Description: Generate Swagger API definitions for LoopBack applications. diff --git a/test/fixtures/help-lb-middleware.txt b/test/fixtures/help-lb-middleware.txt index d5632b0..ec20305 100644 --- a/test/fixtures/help-lb-middleware.txt +++ b/test/fixtures/help-lb-middleware.txt @@ -2,9 +2,10 @@ Usage: lb middleware [options] [] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Arguments: name # Name of the middleware to create. Type: String Required: false diff --git a/test/fixtures/help-lb-model.txt b/test/fixtures/help-lb-model.txt index a70806a..5cde92a 100644 --- a/test/fixtures/help-lb-model.txt +++ b/test/fixtures/help-lb-model.txt @@ -2,9 +2,11 @@ Usage: lb model [options] [] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + --bluemix # Bind to a Bluemix datasource Arguments: name # Name of the model to create. Type: String Required: false diff --git a/test/fixtures/help-lb-oracle.txt b/test/fixtures/help-lb-oracle.txt new file mode 100644 index 0000000..48fa3bb --- /dev/null +++ b/test/fixtures/help-lb-oracle.txt @@ -0,0 +1,21 @@ +Usage: + lb oracle [options] + +Options: + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + --connector # Install loopback-connector-oracle module + --driver # Install oracledb module + --verbose # Print verbose information + +Description: + Utility to help install LoopBack Oracle connector. + +Example: + + lb oracle [--connector] [--driver] [--verbose] + +Without options, the command will try to detect the installation of Oracle Instant Client and check if `loopback-connector-oracle` can be loaded. + diff --git a/test/fixtures/help-lb-property.txt b/test/fixtures/help-lb-property.txt index 7521208..3677631 100644 --- a/test/fixtures/help-lb-property.txt +++ b/test/fixtures/help-lb-property.txt @@ -2,9 +2,10 @@ Usage: lb property [options] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Description: Creates a new model property in the LoopBack application. diff --git a/test/fixtures/help-lb-relation.txt b/test/fixtures/help-lb-relation.txt index 3b9fd78..dea57c6 100644 --- a/test/fixtures/help-lb-relation.txt +++ b/test/fixtures/help-lb-relation.txt @@ -2,9 +2,10 @@ Usage: lb relation [options] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Description: Creates a new model relation in the LoopBack application. diff --git a/test/fixtures/help-lb-remote-method.txt b/test/fixtures/help-lb-remote-method.txt index a7a7bae..b449f40 100644 --- a/test/fixtures/help-lb-remote-method.txt +++ b/test/fixtures/help-lb-remote-method.txt @@ -2,9 +2,10 @@ Usage: lb remote-method [options] [] [] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Arguments: modelName # Name of the model Type: String Required: false diff --git a/test/fixtures/help-lb-soap.txt b/test/fixtures/help-lb-soap.txt new file mode 100644 index 0000000..7db8540 --- /dev/null +++ b/test/fixtures/help-lb-soap.txt @@ -0,0 +1,12 @@ +Usage: + lb soap [options] [] + +Options: + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + +Arguments: + url # URL or file path of the WSDL Type: String Required: false + diff --git a/test/fixtures/help-lb-swagger.txt b/test/fixtures/help-lb-swagger.txt index eec6b3f..a4bccee 100644 --- a/test/fixtures/help-lb-swagger.txt +++ b/test/fixtures/help-lb-swagger.txt @@ -2,9 +2,10 @@ Usage: lb swagger [options] [] Options: - -h, --help # Print the generator's options and usage - --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false Arguments: url # URL of the swagger spec. Type: String Required: false diff --git a/test/fixtures/help-lb-zosconnectee.txt b/test/fixtures/help-lb-zosconnectee.txt new file mode 100644 index 0000000..1d2b617 --- /dev/null +++ b/test/fixtures/help-lb-zosconnectee.txt @@ -0,0 +1,16 @@ +Usage: + lb zosconnectee [options] + +Options: + -h, --help # Print the generator's options and usage + --skip-cache # Do not remember prompt answers Default: false + --skip-install # Do not automatically install dependencies Default: false + --force-install # Fail on install dependencies error Default: false + +Description: + Configures a z/OS Connect EE DataSource. + +Example: + + lb zosconnectee + diff --git a/test/fixtures/help-lb.txt b/test/fixtures/help-lb.txt index 7e6d736..37ad104 100644 --- a/test/fixtures/help-lb.txt +++ b/test/fixtures/help-lb.txt @@ -2,11 +2,15 @@ Usage: lb app [options] [] Options: - -h, --help # Print the generator's options and usage + -h, --help # Print the command's options and usage --skip-cache # Do not remember prompt answers Default: false - --skip-install # Do not automatically install dependencies Default: false + --skip-install # Do not install npm dependencies Default: false + --force-install # Fail on install dependencies error Default: false --skip-next-steps # Do not print "next steps" info --explorer # Add Loopback Explorer to the project (true by default) + --template # Set up the LoopBack application template + --bluemix # Set up as a Bluemix app + --version # Display version information Default: false Arguments: name # Name of the application to scaffold. Type: String Required: false @@ -34,13 +38,17 @@ Available commands: lb acl lb app + lb bluemix lb boot-script lb datasource lb export-api-def lb middleware lb model + lb oracle lb property lb relation lb remote-method + lb soap lb swagger + lb zosconnectee diff --git a/test/help.test.js b/test/help.test.js index 80e99bc..9a37d17 100644 --- a/test/help.test.js +++ b/test/help.test.js @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2016. All Rights Reserved. +// Copyright IBM Corp. 2016,2019. All Rights Reserved. // Node module: loopback-cli // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT @@ -15,15 +15,19 @@ const sandbox = require('./helpers/sandbox'); const COMMANDS = [ '', 'acl', + 'bluemix', 'boot-script', 'datasource', 'export-api-def', 'middleware', 'model', + 'oracle', 'property', 'relation', 'remote-method', + 'soap', 'swagger', + 'zosconnectee', ]; const FIXTURES = path.resolve(__dirname, 'fixtures'); @@ -50,7 +54,8 @@ describe('help', () => { const expected = fs.readFileSync( path.resolve(FIXTURES, helpFile), - 'utf-8'); + 'utf-8' + ); expect(actual).to.equal(expected); }); diff --git a/test/helpers/invoke.js b/test/helpers/invoke.js index 2c4ce77..7570fc8 100644 --- a/test/helpers/invoke.js +++ b/test/helpers/invoke.js @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2016. All Rights Reserved. +// Copyright IBM Corp. 2016,2019. All Rights Reserved. // Node module: loopback-cli // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT @@ -56,4 +56,4 @@ function invokeCli(args, prompts) { resolve({stdout, stderr, exitCode: code}); }); }); -}; +} diff --git a/test/helpers/responder.js b/test/helpers/responder.js index cf2046e..feb2d0b 100644 --- a/test/helpers/responder.js +++ b/test/helpers/responder.js @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2016. All Rights Reserved. +// Copyright IBM Corp. 2016,2019. All Rights Reserved. // Node module: loopback-cli // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT @@ -19,7 +19,7 @@ const PROMPTS = [ [/\? Custom plural form [^:]*:$/, enter('modelPlural')], [/\? .*property name:$/i, enter('propertyName')], [/\? default value[^:]*:$/i, enter('defaultValue')], - [/\? Enter the data-source name:$/, enter('dataSourceName')], + [/\? Enter the datasource name:$/, enter('dataSourceName')], [/\? Enter the script name[^:]*:$/, enter('scriptName')], [/\? Enter the remote method name:$/, enter('methodName')], [/\? Description for method:$/, enter('methodDescription')], @@ -41,7 +41,7 @@ const PROMPTS = [ [/\? Enter the swagger spec url or file path:$/, enter('url')], [/\? Select models to be generated:/, selectDefault()], - [/\? Select the data-source to attach models to:$/, selectDefault()], + [/\? Select the datasource to attach models to:$/, selectDefault()], ]; class Responder { diff --git a/test/mocha.opts b/test/mocha.opts index 0689afd..ef42e1d 100644 --- a/test/mocha.opts +++ b/test/mocha.opts @@ -1 +1 @@ ---timeout 20000 +--timeout 60000 diff --git a/test/smoke.test.js b/test/smoke.test.js index 59bb51b..b8bc4a1 100644 --- a/test/smoke.test.js +++ b/test/smoke.test.js @@ -1,4 +1,4 @@ -// Copyright IBM Corp. 2016. All Rights Reserved. +// Copyright IBM Corp. 2016,2019. All Rights Reserved. // Node module: loopback-cli // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT @@ -13,6 +13,7 @@ const sandbox = require('./helpers/sandbox'); const OUR_VERSION = require('../package.json').version; const GENERATOR_VERSION = require('generator-loopback/package.json').version; +const WORKSPACE_VERSION = require('generator-loopback').workspaceVersion; // These tests invoke `loopback-cli` in a sub-process and perform // a very minimal verification of invoked command's results. @@ -28,7 +29,8 @@ describe('smoke tests - lb', () => { return invoke(['--version']).then(result => { expect(result.exitCode).to.eql(0); expect(result.stdout).to.contain(OUR_VERSION) - .and.contain(GENERATOR_VERSION); + .and.contain(GENERATOR_VERSION) + .and.contain(WORKSPACE_VERSION); }); }); @@ -59,14 +61,6 @@ describe('smoke tests - lb', () => { }); }); - it('reports custom error instead of "generator not installed"', () => { - return invoke(['unknown']).then(result => { - expect(result.exitCode).to.eql(1); - expect(result.stderr).to.contain('Unknown command') - .and.not.contain('generator'); - }); - }); - it('creates a new loopback project via "lb"', () => { const prompts = {appName: 'test-app', appDir: '.'}; return invoke(['--skip-install'], prompts) @@ -92,6 +86,15 @@ describe('smoke tests - lb', () => { }); }); + it('accepts a name for the loopback project', () => { + const prompts = {appName: 'my-app', appDir: '.'}; + return invoke(['my-app', '--skip-install'], prompts) + .then(result => { + const pkg = require(sandbox.resolve('package.json')); + expect(pkg.name, 'package name').to.eql('my-app'); + }); + }); + it('honours "lb app" flag --skip-next-steps', () => { const prompts = {appName: 'test-app', appDir: '.'}; return invoke(['app', '--skip-install', '--skip-next-steps'], prompts) @@ -114,7 +117,8 @@ describe('smoke tests - lb', () => { }) .then(() => { const modelJson = require(sandbox.resolve( - 'common/models/test-model.json')); + 'common/models/test-model.json' + )); expect(modelJson.name, 'model name in JSON').to.equal('test-model'); }); }); @@ -255,8 +259,7 @@ describe('smoke tests - lb', () => { }; return givenProjectInSandbox() - .then(() => invoke(['swagger'], prompts) - ).then(() => { + .then(() => invoke(['swagger'], prompts)).then(() => { const pets = require(sandbox.resolve('common/models/pets.json')); expect(pets.name).to.eql('pets'); expect(pets.base).to.eql('Model');