diff --git a/docs/site/Application-generator.md b/docs/site/Application-generator.md index e84979d89736..242db375d464 100644 --- a/docs/site/Application-generator.md +++ b/docs/site/Application-generator.md @@ -33,6 +33,8 @@ lb4 [app] [options] [] `--loopbackBuild` : Add @loopback/build module's script set to LoopBack4 application project. +`--vscode`: Add VSCode config files to LoopBack4 application project + {% include_relative includes/CLI-std-options.md %} ### Arguments @@ -66,6 +68,7 @@ The tool will prompt you for: - [`prettier`](https://www.npmjs.com/package/prettier) - [`mocha`](https://www.npmjs.com/package/mocha) - [`@loopback/build`](https://www.npmjs.com/package/@loopback/build) + - [`vscode`](https://code.visualstudio.com/) ### Output diff --git a/docs/site/Extension-generator.md b/docs/site/Extension-generator.md index 883730a86e2d..10d59ae06f3a 100644 --- a/docs/site/Extension-generator.md +++ b/docs/site/Extension-generator.md @@ -31,6 +31,8 @@ lb4 extension [options] [] `--loopbackBuild` : Add @loopback/build module's script set to LoopBack4 extension project. +`--vscode`: Add VSCode config files to LoopBack4 application project + {% include_relative includes/CLI-std-options.md %} ### Arguments @@ -60,3 +62,4 @@ The tool will prompt you for: - [`prettier`](https://www.npmjs.com/package/prettier) - [`mocha`](https://www.npmjs.com/package/mocha) - [`@loopback/build`](https://www.npmjs.com/package/@loopback/build) + - [`vscode`](https://code.visualstudio.com/) diff --git a/docs/site/Getting-started.md b/docs/site/Getting-started.md index f2eafc019a6e..ee89551c2e5a 100644 --- a/docs/site/Getting-started.md +++ b/docs/site/Getting-started.md @@ -42,7 +42,7 @@ Answer the prompts as follows: ? Project description: Getting started tutorial ? Project root directory: (getting-started) ? Application class name: StarterApplication -? Select project build settings: Enable tslint, Enable prettier, Enable mocha, Enable loopbackBuild +? Select project build settings: Enable tslint, Enable prettier, Enable mocha, Enable loopbackBuild, Enable vscode ``` ### Starting the project diff --git a/docs/site/todo-tutorial-scaffolding.md b/docs/site/todo-tutorial-scaffolding.md index c441ea364587..39003f5a4e84 100644 --- a/docs/site/todo-tutorial-scaffolding.md +++ b/docs/site/todo-tutorial-scaffolding.md @@ -28,6 +28,7 @@ $ lb4 app ◉ Enable prettier ◉ Enable mocha ◉ Enable loopbackBuild + ◉ Enable vscode # npm will install dependencies now Application todo-list is now created in todo-list. ``` @@ -72,27 +73,27 @@ tslint.build.json tslint.json ``` -| File | Purpose | -| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| index.ts | Allows importing contents of the `src` folder (for use elsewhere) | -| index.js | Top-level wireup for execution of the application. | -| package.json | Your application's package manifest. See [package.json](https://docs.npmjs.com/files/package.json) for details. | -| tsconfig.json | The TypeScript project configuration. See [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) for details. | -| tslint.json | [TSLint configuration](https://palantir.github.io/tslint/usage/tslint-json/) | -| tslint.build.json | [TSLint configuration (build only)](https://palantir.github.io/tslint/usage/tslint-json/) | -| README.md | The Markdown-based README generated for your application. | -| LICENSE | A copy of the MIT license. If you do not wish to use this license, please delete this file. | -| src/application.ts | The application class, which extends [`RestApplication`](http://apidocs.strongloop.com/@loopback%2frest/#RestApplication) by default. This is the root of your application, and is where your application will be configured. | -| src/index.ts | The starting point of your microservice. This file creates an instance of your application, runs the booter, then attempts to start the [`RestServer`](http://apidocs.strongloop.com/@loopback%2frest/#RestServer) instance bound to the application. | -| src/sequence.ts | An extension of the [Sequence](Sequence.md) class used to define the set of actions to take during a REST request/response. | -| src/controllers/README.md | Provides information about the controller directory, how to generate new controllers, and where to find more information. | -| src/controllers/ping.controller.ts | A basic controller that responds to GET requests at `/ping`. | -| src/datasources/README.md | Provides information about the datasources directory, how to generate new datasources, and where to find more information. | -| src/models/README.md | Provides information about the datasources directory, how to generate new datasources, and where to find more information. | -| src/repositories/README.md | Provides information about the repositories directory, how to generate new repositories, and where to find more information. | -| test/README.md | Please place your tests in this folder. | -| test/mocha.opts | [Mocha](https://mochajs.org/) configuration for running your application's tests. | -| test/acceptance/ping.controller.acceptance.ts | An example test to go with the ping controller in `src/controllers`. | +| File | Purpose | +| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| index.ts | Allows importing contents of the `src` folder (for use elsewhere) | +| index.js | Top-level wireup for execution of the application. | +| package.json | Your application's package manifest. See [package.json](https://docs.npmjs.com/files/package.json) for details. | +| tsconfig.json | The TypeScript project configuration. See [tsconfig.json](http://www.typescriptlang.org/docs/handbook/tsconfig-json.html) for details. | +| tslint.json | [TSLint configuration](https://palantir.github.io/tslint/usage/tslint-json/) | +| tslint.build.json | [TSLint configuration (build only)](https://palantir.github.io/tslint/usage/tslint-json/) | +| README.md | The Markdown-based README generated for your application. | +| LICENSE | A copy of the MIT license. If you do not wish to use this license, please delete this file. | +| src/application.ts | The application class, which extends [`RestApplication`](http://apidocs.strongloop.com/@loopback%2frest/#RestApplication) by default. This is the root of your application, and is where your application will be configured. | +| src/index.ts | The starting point of your microservice. This file creates an instance of your application, runs the booter, then attempts to start the [`RestServer`](http://apidocs.strongloop.com/@loopback%2frest/#RestServer) instance bound to the application. | +| src/sequence.ts | An extension of the [Sequence](Sequence.md) class used to define the set of actions to take during a REST request/response. | +| src/controllers/README.md | Provides information about the controller directory, how to generate new controllers, and where to find more information. | +| src/controllers/ping.controller.ts | A basic controller that responds to GET requests at `/ping`. | +| src/datasources/README.md | Provides information about the datasources directory, how to generate new datasources, and where to find more information. | +| src/models/README.md | Provides information about the datasources directory, how to generate new datasources, and where to find more information. | +| src/repositories/README.md | Provides information about the repositories directory, how to generate new repositories, and where to find more information. | +| test/README.md | Please place your tests in this folder. | +| test/mocha.opts | [Mocha](https://mochajs.org/) configuration for running your application's tests. | +| test/acceptance/ping.controller.acceptance.ts | An example test to go with the ping controller in `src/controllers`. | ### Navigation diff --git a/examples/hello-world/.prettierignore b/examples/hello-world/.prettierignore new file mode 100644 index 000000000000..bc1199efffac --- /dev/null +++ b/examples/hello-world/.prettierignore @@ -0,0 +1,2 @@ +dist* +*.json diff --git a/examples/hello-world/.prettierrc b/examples/hello-world/.prettierrc new file mode 100644 index 000000000000..f58b81dd7be2 --- /dev/null +++ b/examples/hello-world/.prettierrc @@ -0,0 +1,6 @@ +{ + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all" +} diff --git a/examples/hello-world/.vscode/settings.json b/examples/hello-world/.vscode/settings.json new file mode 100644 index 000000000000..0e1c0089f810 --- /dev/null +++ b/examples/hello-world/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "editor.rulers": [80], + "editor.tabCompletion": true, + "editor.tabSize": 2, + "editor.trimAutoWhitespace": true, + "editor.formatOnSave": true, + + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.hg": true, + "**/.svn": true, + "**/CVS": true, + "dist*": true, + }, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + + "tslint.ignoreDefinitionFiles": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} diff --git a/examples/hello-world/.vscode/tasks.json b/examples/hello-world/.vscode/tasks.json new file mode 100644 index 000000000000..c3003aa764e3 --- /dev/null +++ b/examples/hello-world/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Watch and Compile Project", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "build:watch"], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$tsc-watch" + }, + { + "label": "Build, Test and Lint", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "test:dev"], + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": ["$tsc", "$tslint5"] + } + ] +} diff --git a/examples/hello-world/package.json b/examples/hello-world/package.json index 212459403472..b083ddedd414 100644 --- a/examples/hello-world/package.json +++ b/examples/hello-world/package.json @@ -13,10 +13,23 @@ "build:current": "lb-tsc", "build:dist8": "lb-tsc es2017", "build:dist10": "lb-tsc es2018", + "build:watch": "lb-tsc --watch", "clean": "lb-clean *example-hello-world*.tgz dist* package api-docs", "verify": "npm pack && tar xf *example-hello-world*.tgz && tree package && npm run clean", + "lint": "npm run prettier:check && npm run tslint", + "lint:fix": "npm run prettier:fix && npm run tslint:fix", + "prettier:cli": "lb-prettier \"**/*.ts\" \"**/*.js\"", + "prettier:check": "npm run prettier:cli -- -l", + "prettier:fix": "npm run prettier:cli -- --write", + "tslint": "lb-tslint", + "tslint:fix": "npm run tslint -- --fix", + "pretest": "npm run clean && npm run build:current", + "test": "lb-mocha --allow-console-logs \"DIST/test\"", + "posttest": "npm run lint", + "test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js && npm run posttest", "prestart": "npm run build:current", - "start": "node ." + "start": "node .", + "prepublishOnly": "npm run test" }, "repository": { "type": "git", diff --git a/examples/hello-world/tslint.build.json b/examples/hello-world/tslint.build.json new file mode 100644 index 000000000000..0ace3417fa90 --- /dev/null +++ b/examples/hello-world/tslint.build.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.build.json"] +} diff --git a/examples/hello-world/tslint.json b/examples/hello-world/tslint.json new file mode 100644 index 000000000000..098c9615a68d --- /dev/null +++ b/examples/hello-world/tslint.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.common.json"] +} diff --git a/examples/log-extension/.prettierignore b/examples/log-extension/.prettierignore index 94427a0051ce..bc1199efffac 100644 --- a/examples/log-extension/.prettierignore +++ b/examples/log-extension/.prettierignore @@ -1,2 +1,2 @@ -dist -dist6 +dist* +*.json diff --git a/examples/log-extension/.prettierrc b/examples/log-extension/.prettierrc new file mode 100644 index 000000000000..f58b81dd7be2 --- /dev/null +++ b/examples/log-extension/.prettierrc @@ -0,0 +1,6 @@ +{ + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all" +} diff --git a/examples/log-extension/.vscode/settings.json b/examples/log-extension/.vscode/settings.json new file mode 100644 index 000000000000..0e1c0089f810 --- /dev/null +++ b/examples/log-extension/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "editor.rulers": [80], + "editor.tabCompletion": true, + "editor.tabSize": 2, + "editor.trimAutoWhitespace": true, + "editor.formatOnSave": true, + + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.hg": true, + "**/.svn": true, + "**/CVS": true, + "dist*": true, + }, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + + "tslint.ignoreDefinitionFiles": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} diff --git a/examples/log-extension/.vscode/tasks.json b/examples/log-extension/.vscode/tasks.json new file mode 100644 index 000000000000..c3003aa764e3 --- /dev/null +++ b/examples/log-extension/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Watch and Compile Project", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "build:watch"], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$tsc-watch" + }, + { + "label": "Build, Test and Lint", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "test:dev"], + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": ["$tsc", "$tslint5"] + } + ] +} diff --git a/examples/log-extension/package.json b/examples/log-extension/package.json index 5743a04efcad..28fd19a0718f 100644 --- a/examples/log-extension/package.json +++ b/examples/log-extension/package.json @@ -24,6 +24,7 @@ "pretest": "npm run clean && npm run build:current", "test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"", "posttest": "npm run lint", + "test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js && npm run posttest", "verify": "npm pack && tar xf *example-log-extension*.tgz && tree package && npm run clean" }, "repository": { diff --git a/examples/log-extension/tslint.build.json b/examples/log-extension/tslint.build.json new file mode 100644 index 000000000000..0ace3417fa90 --- /dev/null +++ b/examples/log-extension/tslint.build.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.build.json"] +} diff --git a/examples/log-extension/tslint.json b/examples/log-extension/tslint.json new file mode 100644 index 000000000000..098c9615a68d --- /dev/null +++ b/examples/log-extension/tslint.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.common.json"] +} diff --git a/examples/rpc-server/.prettierignore b/examples/rpc-server/.prettierignore index f84e220671a5..bc1199efffac 100644 --- a/examples/rpc-server/.prettierignore +++ b/examples/rpc-server/.prettierignore @@ -1,2 +1,2 @@ -*.js -*.d.ts +dist* +*.json diff --git a/examples/rpc-server/.prettierrc b/examples/rpc-server/.prettierrc new file mode 100644 index 000000000000..f58b81dd7be2 --- /dev/null +++ b/examples/rpc-server/.prettierrc @@ -0,0 +1,6 @@ +{ + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all" +} diff --git a/examples/rpc-server/.vscode/settings.json b/examples/rpc-server/.vscode/settings.json new file mode 100644 index 000000000000..0e1c0089f810 --- /dev/null +++ b/examples/rpc-server/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "editor.rulers": [80], + "editor.tabCompletion": true, + "editor.tabSize": 2, + "editor.trimAutoWhitespace": true, + "editor.formatOnSave": true, + + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.hg": true, + "**/.svn": true, + "**/CVS": true, + "dist*": true, + }, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + + "tslint.ignoreDefinitionFiles": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} diff --git a/examples/rpc-server/.vscode/tasks.json b/examples/rpc-server/.vscode/tasks.json new file mode 100644 index 000000000000..c3003aa764e3 --- /dev/null +++ b/examples/rpc-server/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Watch and Compile Project", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "build:watch"], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$tsc-watch" + }, + { + "label": "Build, Test and Lint", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "test:dev"], + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": ["$tsc", "$tslint5"] + } + ] +} diff --git a/examples/rpc-server/package.json b/examples/rpc-server/package.json index afd686744d33..d4d5cc421844 100644 --- a/examples/rpc-server/package.json +++ b/examples/rpc-server/package.json @@ -27,6 +27,7 @@ "pretest": "npm run clean && npm run build:current", "test": "lb-mocha DIST/test", "posttest": "npm run lint", + "test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js && npm run posttest", "prestart": "npm run build:current", "start": "node ." }, diff --git a/examples/rpc-server/tslint.build.json b/examples/rpc-server/tslint.build.json new file mode 100644 index 000000000000..0ace3417fa90 --- /dev/null +++ b/examples/rpc-server/tslint.build.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.build.json"] +} diff --git a/examples/rpc-server/tslint.json b/examples/rpc-server/tslint.json new file mode 100644 index 000000000000..098c9615a68d --- /dev/null +++ b/examples/rpc-server/tslint.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.common.json"] +} diff --git a/examples/todo/.prettierignore b/examples/todo/.prettierignore new file mode 100644 index 000000000000..bc1199efffac --- /dev/null +++ b/examples/todo/.prettierignore @@ -0,0 +1,2 @@ +dist* +*.json diff --git a/examples/todo/.prettierrc b/examples/todo/.prettierrc new file mode 100644 index 000000000000..f58b81dd7be2 --- /dev/null +++ b/examples/todo/.prettierrc @@ -0,0 +1,6 @@ +{ + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all" +} diff --git a/examples/todo/.vscode/settings.json b/examples/todo/.vscode/settings.json new file mode 100644 index 000000000000..0e1c0089f810 --- /dev/null +++ b/examples/todo/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "editor.rulers": [80], + "editor.tabCompletion": true, + "editor.tabSize": 2, + "editor.trimAutoWhitespace": true, + "editor.formatOnSave": true, + + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.hg": true, + "**/.svn": true, + "**/CVS": true, + "dist*": true, + }, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + + "tslint.ignoreDefinitionFiles": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} diff --git a/examples/todo/.vscode/tasks.json b/examples/todo/.vscode/tasks.json new file mode 100644 index 000000000000..c3003aa764e3 --- /dev/null +++ b/examples/todo/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Watch and Compile Project", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "build:watch"], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$tsc-watch" + }, + { + "label": "Build, Test and Lint", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "test:dev"], + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": ["$tsc", "$tslint5"] + } + ] +} diff --git a/examples/todo/package.json b/examples/todo/package.json index 693185a72407..817ccba32004 100644 --- a/examples/todo/package.json +++ b/examples/todo/package.json @@ -13,9 +13,18 @@ "build:current": "lb-tsc", "build:dist8": "lb-tsc es2017", "build:dist10": "lb-tsc es2018", + "build:watch": "lb-tsc --watch", "clean": "lb-clean *example-todo*.tgz dist* package api-docs", + "lint": "npm run prettier:check && npm run tslint", + "lint:fix": "npm run prettier:fix && npm run tslint:fix", + "prettier:cli": "lb-prettier \"**/*.ts\"", + "prettier:check": "npm run prettier:cli -- -l", + "prettier:fix": "npm run prettier:cli -- --write", + "tslint": "lb-tslint", + "tslint:fix": "npm run tslint -- --fix", "pretest": "npm run build:current", "test": "lb-mocha \"DIST/test/unit/**/*.js\" \"DIST/test/acceptance/**/*.js\"", + "test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js && npm run posttest", "unit": "lb-mocha \"DIST/test/unit/**/*.js\"", "verify": "npm pack && tar xf loopback-todo*.tgz && tree package && npm run clean", "prestart": "npm run build:current", diff --git a/examples/todo/tslint.build.json b/examples/todo/tslint.build.json new file mode 100644 index 000000000000..0ace3417fa90 --- /dev/null +++ b/examples/todo/tslint.build.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.build.json"] +} diff --git a/examples/todo/tslint.json b/examples/todo/tslint.json new file mode 100644 index 000000000000..098c9615a68d --- /dev/null +++ b/examples/todo/tslint.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": ["./node_modules/@loopback/build/config/tslint.common.json"] +} diff --git a/packages/cli/.prettierrc b/packages/cli/.prettierrc index fb1c07ce0f90..f58b81dd7be2 100644 --- a/packages/cli/.prettierrc +++ b/packages/cli/.prettierrc @@ -2,5 +2,5 @@ "bracketSpacing": false, "singleQuote": true, "printWidth": 80, - "trailingComma": "es5" + "trailingComma": "all" } diff --git a/packages/cli/generators/project/templates/.prettierignore b/packages/cli/generators/project/templates/.prettierignore index 98f6038900b4..bc1199efffac 100644 --- a/packages/cli/generators/project/templates/.prettierignore +++ b/packages/cli/generators/project/templates/.prettierignore @@ -1,3 +1,2 @@ dist* -api-docs *.json diff --git a/packages/cli/generators/project/templates/.vscode/settings.json b/packages/cli/generators/project/templates/.vscode/settings.json new file mode 100644 index 000000000000..0e1c0089f810 --- /dev/null +++ b/packages/cli/generators/project/templates/.vscode/settings.json @@ -0,0 +1,21 @@ +{ + "editor.rulers": [80], + "editor.tabCompletion": true, + "editor.tabSize": 2, + "editor.trimAutoWhitespace": true, + "editor.formatOnSave": true, + + "files.exclude": { + "**/.DS_Store": true, + "**/.git": true, + "**/.hg": true, + "**/.svn": true, + "**/CVS": true, + "dist*": true, + }, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + + "tslint.ignoreDefinitionFiles": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} diff --git a/packages/cli/generators/project/templates/.vscode/tasks.json b/packages/cli/generators/project/templates/.vscode/tasks.json new file mode 100644 index 000000000000..c3003aa764e3 --- /dev/null +++ b/packages/cli/generators/project/templates/.vscode/tasks.json @@ -0,0 +1,29 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Watch and Compile Project", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "build:watch"], + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$tsc-watch" + }, + { + "label": "Build, Test and Lint", + "type": "shell", + "command": "npm", + "args": ["--silent", "run", "test:dev"], + "group": { + "kind": "test", + "isDefault": true + }, + "problemMatcher": ["$tsc", "$tslint5"] + } + ] +} diff --git a/packages/cli/generators/project/templates/DEVELOPING.md b/packages/cli/generators/project/templates/DEVELOPING.md new file mode 100644 index 000000000000..cb323292391c --- /dev/null +++ b/packages/cli/generators/project/templates/DEVELOPING.md @@ -0,0 +1,36 @@ +# Developer's Guide + +We use Visual Studio Code for developing LoopBack and recommend the same to our +users. + +## VSCode setup + +Install the following extensions: + + - [tslint](https://marketplace.visualstudio.com/items?itemName=eg2.tslint) + - [prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) + +## Development workflow + +### Visual Studio Code + +1. Start the build task (Cmd+Shift+B) to run TypeScript compiler in the + background, watching and recompiling files as you change them. Compilation + errors will be shown in the VSCode's "PROBLEMS" window. + +2. Execute "Run Rest Task" from the Command Palette (Cmd+Shift+P) to re-run the + test suite and lint the code for both programming and style errors. Linting + errors will be shown in VSCode's "PROBLEMS" window. Failed tests are printed + to terminal output only. + +### Other editors/IDEs + +1. Open a new terminal window/tab and start the continous build process via + `npm run build:watch`. It will run TypeScript compiler in watch mode, + recompiling files as you change them. Any compilation errors will be printed + to the terminal. + +2. In your main terminal window/tab, run `npm run test:dev` to re-run the test + suite and lint the code for both programming and style errors. You should run + this command manually whenever you have new changes to test. Test failures + and linter errors will be printed to the terminal. diff --git a/packages/cli/generators/project/templates/package.json.ejs b/packages/cli/generators/project/templates/package.json.ejs index 3ed9bae2b8be..8c9ecacff675 100644 --- a/packages/cli/generators/project/templates/package.json.ejs +++ b/packages/cli/generators/project/templates/package.json.ejs @@ -44,6 +44,11 @@ <% if (project.prettier || project.tslint) { -%> "posttest": "npm run lint", <% } -%> +<% if (project.mocha && (project.prettier || project.tslint)) { -%> + "test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js && npm run posttest", +<% } else if (project.mocha) { -%> + "test:dev": "lb-mocha --allow-console-logs DIST/test/**/*.js", +<% } -%> <% if (project.projectType === 'application') { -%> "prestart": "npm run build:current", "start": "node .", diff --git a/packages/cli/generators/project/templates/package.plain.json.ejs b/packages/cli/generators/project/templates/package.plain.json.ejs index 67493469c945..fd6ba0409404 100644 --- a/packages/cli/generators/project/templates/package.plain.json.ejs +++ b/packages/cli/generators/project/templates/package.plain.json.ejs @@ -30,7 +30,7 @@ "prettier:fix": "npm run prettier:cli -- --write", <% } -%> <% if (project.tslint) { -%> - "tslint": "tslint", + "tslint": "tslint -p .", "tslint:fix": "npm run tslint -- --fix", <% } -%> "pretest": "npm run clean && npm run build", @@ -40,6 +40,11 @@ <% if (project.prettier || project.tslint) { -%> "posttest": "npm run lint", <% } -%> +<% if (project.mocha && (project.prettier || project.tslint)) { -%> + "test:dev": "mocha dist/test/**/*.js && npm run posttest", +<% } else if (project.mocha) { -%> + "test:dev": "mocha dist/test/**/*.js", +<% } -%> <% if (project.projectType === 'application') { -%> "start": "npm run build && node .", <% } -%> diff --git a/packages/cli/generators/project/templates/tslint.json.ejs b/packages/cli/generators/project/templates/tslint.json.ejs index 6a8445c727c3..174657df8c36 100644 --- a/packages/cli/generators/project/templates/tslint.json.ejs +++ b/packages/cli/generators/project/templates/tslint.json.ejs @@ -26,8 +26,7 @@ "no-unused-expression": true, "no-unused-variable": true, "no-var-keyword": true, - "triple-equals": [true, "allow-null-check", "allow-undefined-check"], - "typeof-compare": true + "triple-equals": [true, "allow-null-check", "allow-undefined-check"] } <% } -%> } diff --git a/packages/cli/lib/project-generator.js b/packages/cli/lib/project-generator.js index 5d99d3608e60..f095895a6035 100644 --- a/packages/cli/lib/project-generator.js +++ b/packages/cli/lib/project-generator.js @@ -14,7 +14,13 @@ module.exports = class ProjectGenerator extends BaseGenerator { // The default list of build options available for a project // This list gets shown to users to let them select the appropriate // build settings for their project. - this.buildOptions = ['tslint', 'prettier', 'mocha', 'loopbackBuild']; + this.buildOptions = [ + 'tslint', + 'prettier', + 'mocha', + 'loopbackBuild', + 'vscode', + ]; } _setupGenerator() { @@ -54,6 +60,11 @@ module.exports = class ProjectGenerator extends BaseGenerator { description: 'Use @loopback/build', }); + this.option('vscode', { + type: Boolean, + description: 'Use preconfigured VSCode settings', + }); + this.option('private', { type: Boolean, description: 'Mark the project private (excluded from npm publish)', @@ -228,6 +239,10 @@ module.exports = class ProjectGenerator extends BaseGenerator { if (!this.projectInfo.mocha) { this.fs.delete(this.destinationPath('test/mocha.opts')); } + + if (!this.projectInfo.vscode) { + this.fs.delete(this.destinationPath('.vscode')); + } } install() { diff --git a/packages/cli/test/integration/lib/project-generator.js b/packages/cli/test/integration/lib/project-generator.js index d485e266e790..99bccf835111 100644 --- a/packages/cli/test/integration/lib/project-generator.js +++ b/packages/cli/test/integration/lib/project-generator.js @@ -124,6 +124,13 @@ module.exports = function(projGenerator, props, projectType) { assert(helpText.match(/--loopbackBuild/)); assert(helpText.match(/# Use @loopback\/build/)); }); + + it('has vscode option set up', () => { + let gen = testUtils.testSetUpGen(projGenerator); + let helpText = gen.help(); + assert(helpText.match(/--vscode/)); + assert(helpText.match(/# Use preconfigured VSCode settings/)); + }); }); }); @@ -138,6 +145,7 @@ module.exports = function(projGenerator, props, projectType) { prettier: true, mocha: null, loopbackBuild: null, + vscode: null, }; gen.setOptions(); assert(gen.projectInfo.name === 'foobar'); @@ -202,6 +210,7 @@ module.exports = function(projGenerator, props, projectType) { 'Enable prettier', 'Enable mocha', 'Enable loopbackBuild', + 'Enable vscode', ], }, 'promptOptions', @@ -211,6 +220,7 @@ module.exports = function(projGenerator, props, projectType) { assert(gen.projectInfo.prettier === true); assert(gen.projectInfo.mocha === true); assert(gen.projectInfo.loopbackBuild === true); + assert(gen.projectInfo.vscode === true); }); }); }); @@ -229,6 +239,8 @@ module.exports = function(projGenerator, props, projectType) { '.npmrc', 'tslint.json', 'src/index.ts', + '.vscode/settings.json', + '.vscode/tasks.json', ]); assert.jsonFileContent('package.json', props); assert.fileContent([ @@ -296,6 +308,7 @@ module.exports = function(projGenerator, props, projectType) { 'Enable tslint', 'Enable prettier', 'Enable mocha', + 'Enable vscode', ], }, props, @@ -338,6 +351,7 @@ module.exports = function(projGenerator, props, projectType) { 'Enable tslint', 'Disable prettier', // Force Enable prettier to be unchecked 'Enable mocha', + 'Enable vscode', ], }, props, @@ -361,6 +375,7 @@ module.exports = function(projGenerator, props, projectType) { 'Disable tslint', // Force Enable tslint to be unchecked 'Enable prettier', 'Enable mocha', + 'Enable vscode', ], }, props, @@ -386,6 +401,7 @@ module.exports = function(projGenerator, props, projectType) { 'Disable tslint', 'Enable prettier', 'Enable mocha', + 'Enable vscode', ], }, props, @@ -409,6 +425,29 @@ module.exports = function(projGenerator, props, projectType) { }); }); + describe('with vscode disabled', () => { + before(() => { + return helpers.run(projGenerator).withPrompts( + Object.assign( + { + settings: [ + 'Enable loopbackBuild', + 'Enable tslint', + 'Enable prettier', + 'Enable mocha', + 'Disable vscode', // Force Enable vscode to be unchecked + ], + }, + props, + ), + ); + }); + + it('does not create .vscode files', () => { + assert.noFile('.vscode/'); + }); + }); + function testPrompt(gen, props, fnName) { gen.setOptions(); gen.prompt = sinon.stub(gen, 'prompt');