From 1e4ec5e4b79fb9f9fa8de078ae73475e5531b6ae Mon Sep 17 00:00:00 2001 From: Taranveer Virk Date: Mon, 11 Sep 2017 09:47:14 -0400 Subject: [PATCH] Add initial project infrastructure. --- .gitignore | 3 ++ .npmrc | 1 + .prettierrc | 7 ++++ .vscode/settings.json | 22 ++++++++++++ .vscode/tasks.json | 46 ++++++++++++++++++++++++ DEVELOPING.md | 21 +++++++++++ README.md | 3 +- index.d.ts | 6 ++++ index.js | 9 +++++ package.json | 46 ++++++++++++++++++++++++ src/controllers/README.md | 3 ++ src/index.ts | 4 +++ src/providers/README.md | 4 +++ src/repositories/README.md | 3 ++ test/mocha.opts | 3 ++ test/smoke.test.ts | 12 +++++++ tsconfig.json | 21 +++++++++++ tslint.full.json | 21 +++++++++++ tslint.json | 72 ++++++++++++++++++++++++++++++++++++++ 19 files changed, 305 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 .npmrc create mode 100644 .prettierrc create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 DEVELOPING.md create mode 100644 index.d.ts create mode 100644 index.js create mode 100644 package.json create mode 100644 src/controllers/README.md create mode 100644 src/index.ts create mode 100644 src/providers/README.md create mode 100644 src/repositories/README.md create mode 100644 test/mocha.opts create mode 100644 test/smoke.test.ts create mode 100644 tsconfig.json create mode 100644 tslint.full.json create mode 100644 tslint.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2945331 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +dist +dist6 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/.prettierrc b/.prettierrc new file mode 100644 index 0000000..a866396 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "eslintIntegration": true, + "bracketSpacing": false, + "singleQuote": true, + "printWidth": 80, + "trailingComma": "all" +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..114ad6d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,22 @@ +{ + "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, + "dist6": true + }, + "files.insertFinalNewline": true, + "files.trimTrailingWhitespace": true, + + "tslint.ignoreDefinitionFiles": true, + "typescript.tsdk": "./node_modules/typescript/lib" +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..f957137 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,46 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "taskName": "Watch and compile TypeScript", + "command": "tsc", + "args": ["--watch"], + "type": "process", + "isBackground": true, + "problemMatcher": "$tsc-watch", + "group": { + "kind": "build", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "never", + "focus": false, + "panel": "dedicated" + } + }, + { + "taskName": "Test and lint", + "command": "npm", + "args": [ + "--silent", + "run", + "vscode-test" + ], + "type": "process", + "group": { + "kind": "test", + "isDefault": true + }, + "presentation": { + "echo": true, + "reveal": "always", + "focus": false, + "panel": "dedicated" + }, + "problemMatcher": "$tslint5" + } + ] +} diff --git a/DEVELOPING.md b/DEVELOPING.md new file mode 100644 index 0000000..dae0095 --- /dev/null +++ b/DEVELOPING.md @@ -0,0 +1,21 @@ +# Developer's Guide + +We use Visual Studio Code for developing LoopBack and recommend the same to our contributors. + +While this package supports both Node.js 6.x and 8.x versions, you will need Node.js 8.x (or newer) for the best development experience in VS Code. + +## 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 + +1. Start the build task (Cmd+Shift+B), it will run TypeScript compiler in backround, watching and recompiling files as you change them. Compilation errors will be shown in the VSCode's "PROBLEMS" window. + + +2. Execute "Test and lint" task (Cmd+Shift+T) 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. + +3. Run "npm test" explicitly before committing your changes. This will execute the same sequence as our CI server does. diff --git a/README.md b/README.md index 99e4e0e..20447b5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,3 @@ # loopback-next-extension-starter -A starter project to create extensions for loopback-next -Starting point to create a variety of extensions for loopback-next. +A starter project to create extensions for loopback-next. diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..ed500a3 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,6 @@ +// Copyright IBM Corp. 2017. All Rights Reserved. +// Node module: @loopback/core +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +export * from './dist/lib'; diff --git a/index.js b/index.js new file mode 100644 index 0000000..33cf0d8 --- /dev/null +++ b/index.js @@ -0,0 +1,9 @@ +// Copyright IBM Corp. 2017. All Rights Reserved. +// Node module: @loopback/core +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +const nodeMajorVersion = +process.versions.node.split('.')[0]; +module.exports = nodeMajorVersion >= 7 ? + require('./dist/lib') : + require('./dist6/lib'); diff --git a/package.json b/package.json new file mode 100644 index 0000000..f042959 --- /dev/null +++ b/package.json @@ -0,0 +1,46 @@ +{ + "name": "loopback-next-extension-starter", + "version": "1.0.0", + "description": "A starter project for LoopBack Next Extensions", + "main": "index.js", + "scripts": { + "build": "npm run build:lib && npm run build:lib6", + "build:lib": "tsc --target es2017 --outDir dist", + "build:lib6": "tsc --target es2015 --outDir dist6", + "lint": "tslint -c tslint.full.json --project tsconfig.json --type-check", + "lint:fix": "npm run lint -- --fix", + "prepublish": "npm run build", + "pretest": "npm run build", + "test": "mocha", + "posttest": "npm run lint", + "vscode-test": "mocha && npm run lint" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/strongloop/loopback-next-extension-starter.git" + }, + "author": "", + "license": "MIT", + "bugs": { + "url": "https://github.com/strongloop/loopback-next-extension-starter/issues" + }, + "homepage": "https://github.com/strongloop/loopback-next-extension-starter#readme", + "files": [ + "README.md", + "index.js", + "index.d.ts", + "dist", + "dist6" + ], + "dependencies": { + "@loopback/core": "^4.0.0-alpha.14", + "@loopback/repository": "^4.0.0-alpha.8" + }, + "devDependencies": { + "@loopback/testlab": "^4.0.0-alpha.7", + "@types/mocha": "^2.2.43", + "mocha": "^3.5.3", + "tslint": "^5.7.0", + "typescript": "^2.5.2" + } +} diff --git a/src/controllers/README.md b/src/controllers/README.md new file mode 100644 index 0000000..91e5545 --- /dev/null +++ b/src/controllers/README.md @@ -0,0 +1,3 @@ +# Controllers + +This directory contains source files for the controllers exported by this extension. diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..0c8fd35 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,4 @@ +// Copyright IBM Corp. 2013,2017. All Rights Reserved. +// Node module: loopback-next-extension-starter +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT diff --git a/src/providers/README.md b/src/providers/README.md new file mode 100644 index 0000000..a5b27ae --- /dev/null +++ b/src/providers/README.md @@ -0,0 +1,4 @@ +# Providers + +This directory contains providers contributing additional bindings, for example +custom sequence actions. diff --git a/src/repositories/README.md b/src/repositories/README.md new file mode 100644 index 0000000..7594752 --- /dev/null +++ b/src/repositories/README.md @@ -0,0 +1,3 @@ +# Repositories + +This directory contains code for repositories provided by this extension. diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..3b2b30f --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,3 @@ +--recursive +--reporter dot +dist/test diff --git a/test/smoke.test.ts b/test/smoke.test.ts new file mode 100644 index 0000000..c688a2a --- /dev/null +++ b/test/smoke.test.ts @@ -0,0 +1,12 @@ +// Copyright IBM Corp. 2017. All Rights Reserved. +// Node module: loopback-next-extension-starter +// This file is licensed under the MIT License. +// License text available at https://opensource.org/licenses/MIT + +import {expect} from '@loopback/testlab'; + +describe('Smoke test to verify project setup - remove me later', () => { + it('works', () => { + expect(true).to.equal(true); + }); +}); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..c5279e0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": true, + "strictNullChecks": true, + "noUnusedLocals": true, + + "lib": ["es2017", "dom"], + "module": "commonjs", + "moduleResolution": "node", + "target": "es2017", + "outDir": "dist", + "sourceMap": true, + "declaration": true + }, + "include": [ + "src", + "test" + ] +} diff --git a/tslint.full.json b/tslint.full.json new file mode 100644 index 0000000..8af98a7 --- /dev/null +++ b/tslint.full.json @@ -0,0 +1,21 @@ +{ + "$schema": "http://json.schemastore.org/tslint", + "extends": [ + "./tslint.json" + ], + // This configuration files enabled rules which require type checking + // and therefore cannot be run by Visual Studio Code TSLint extension + // See https://github.com/Microsoft/vscode-tslint/issues/70 + "rules": { + // These rules find errors related to TypeScript features. + + + // These rules catch common errors in JS programming or otherwise + // confusing constructs that are prone to producing bugs. + + "await-promise": true, + "no-floating-promises": true, + "no-void-expression": [true, "ignore-arrow-function-shorthand"] + } + } + \ No newline at end of file diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..dfc1d8b --- /dev/null +++ b/tslint.json @@ -0,0 +1,72 @@ +{ + // See https://palantir.github.io/tslint/rules/ + "rules": { + // These rules find errors related to TypeScript features. + "adjacent-overload-signatures": true, + "prefer-for-of": true, + "unified-signatures": true, + "no-any": true, + + // These rules catch common errors in JS programming or otherwise + // confusing constructs that are prone to producing bugs. + + "label-position": true, + "no-arg": true, + "no-construct": true, + "no-duplicate-variable": true, + + "no-invalid-this": true, + "no-misused-new": true, + "no-shadowed-variable": true, + "no-string-throw": true, + "no-unused-expression": true, + "no-var-keyword": true, + "triple-equals": [ + true, + "allow-null-check", + "allow-undefined-check" + ], + "typeof-compare": true, + + // These rules make code maintenance easier + "eofline": true, + "indent": [true, "spaces"], + "no-default-export": true, + "no-trailing-whitespace": true, + "prefer-const": true, + "trailing-comma": [true, { + "multiline": "always", + "singleline": "never" + }], + + // These rules enforce consistent style across your codebase: + "arrow-return-shorthand": [true], + "class-name": true, + "comment-format": [true, "check-space"], + "file-header": [true, "Copyright IBM"], + "max-line-length": [true, 80], + "no-consecutive-blank-lines": [true, 2], + "no-unnecessary-callback-wrapper": true, + "one-variable-per-declaration": [true, "ignore-for-loop"], + "prefer-method-signature": true, + "quotemark": [true, "single", "avoid-escape"], + "semicolon": [true, "always"], + "space-before-function-paren": [true, { + "anonymous": "never", + "named": "never", + "asyncArrow": "always", + "method": "never", + "constructor": "never" + }], + "variable-name": [true, "allow-leading-underscore", "ban-keywords", "check-format"], + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-separator", + "check-type", + "check-typecast", + "check-preblock" + ] + } +}