Skip to content

Commit

Permalink
Update examples to version 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
betula committed Apr 16, 2020
1 parent 9debbf6 commit 31eaa71
Show file tree
Hide file tree
Showing 23 changed files with 46 additions and 96 deletions.
1 change: 1 addition & 0 deletions examples/api-server-with-jest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dist
1 change: 1 addition & 0 deletions examples/api-server-with-jest/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion examples/api-server-with-jest/AccountApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { provide } from "node-provide";
import { Db } from "@services/Db";

export class AccountApi {
@provide db: Db;
db = provide(Db);

public async createToken() {
const token = nanoid();
Expand Down
4 changes: 2 additions & 2 deletions examples/api-server-with-jest/AccountRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { Server } from "@services/Server";
import { AccountApi } from "./AccountApi";

export class AccountRouter {
@provide server: Server;
@provide accountApi: AccountApi;
server = provide(Server);
accountApi = provide(AccountApi);

public init() {
this.server.route("GET", "/account/token", this.createToken);
Expand Down
6 changes: 3 additions & 3 deletions examples/api-server-with-jest/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Server } from "@services/Server";
import { AccountRouter } from "./AccountRouter";

export class App {
@provide db: Db;
@provide server: Server;
@provide accountRouter: AccountRouter;
db = provide(Db);
server = provide(Server);
accountRouter = provide(AccountRouter);

public async start(config: any) {
this.configure(config);
Expand Down
9 changes: 9 additions & 0 deletions examples/api-server-with-jest/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
presets: [
["@babel/preset-env", {targets: {node: "current"}}],
"@babel/preset-typescript",
],
plugins: [
[ "@babel/plugin-proposal-class-properties", { "loose": true } ]
]
};
4 changes: 2 additions & 2 deletions examples/api-server-with-jest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { App } from "./App";
import { Logger } from "@services/Logger";

class AppRunner {
@provide app: App;
@provide logger: Logger;
app = provide(App);
logger = provide(Logger);

public start() {
this.app.start({
Expand Down
8 changes: 0 additions & 8 deletions examples/api-server-with-jest/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module.exports = {
globals: {
"ts-jest": {
tsConfig: "tsconfig.json"
}
},
setupFilesAfterEnv: [ "node-provide/jest-cleanup-after-each" ],
transform: {
"^.+\\.ts$": "ts-jest"
},
testMatch: [ "**/*.test.ts" ],
moduleNameMapper: {
"@(services/.*)$": "<rootDir>/$1"
Expand Down
4 changes: 3 additions & 1 deletion examples/api-server-with-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"module-alias": "^2.2.0"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.5",
"@babel/preset-typescript": "^7.9.0",
"@types/express": "^4.17.0",
"@types/cors": "^2.8.5",
"@types/nanoid": "^2.0.0",
Expand All @@ -26,7 +29,6 @@
"tslint": "^5.17.0",
"tslint-config-airbnb": "^5.11.1",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"@types/jest": "^24.0.13"
},
"_moduleAliases": {
Expand Down
2 changes: 1 addition & 1 deletion examples/api-server-with-jest/services/Db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { provide } from "node-provide";
import { Logger } from "@services/Logger";

export class Db {
@provide logger: Logger;
logger = provide(Logger);

configure({ url }: any) {
this.logger.log("Configure Db service with url", url);
Expand Down
6 changes: 3 additions & 3 deletions examples/api-server-with-jest/services/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { Logger } from "@services/Logger";
export type RequestHandler = (req: Express.Request, res: Express.Response) => Promise<any>;

export class Server {
@provide logger: Logger;
logger = provide(Logger);

public express: Express.Express;
public port: number;
public hostname: string;
public port!: number;
public hostname!: string;

constructor() {
this.express = Express();
Expand Down
3 changes: 0 additions & 3 deletions examples/api-server-with-jest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"strict": true,
"outDir": ".dist",
"baseUrl": ".",
Expand Down
1 change: 1 addition & 0 deletions examples/modules/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dist
1 change: 1 addition & 0 deletions examples/modules/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion examples/modules/common/Hello.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { provide } from "node-provide";
import { Logger } from "./Logger";

export class Hello {
@provide logger: Logger;
logger = provide(Logger);

public world() {
this.logger.log("Hello world!");
Expand Down
2 changes: 1 addition & 1 deletion examples/modules/main/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { provide } from "node-provide";
import { Hello } from "@modules/common";

export class App {
@provide hello: Hello;
hello = provide(Hello);

public start() {
this.hello.world();
Expand Down
3 changes: 0 additions & 3 deletions examples/modules/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
"target": "es6",
"noImplicitAny": true,
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
"strict": true,
"outDir": ".dist",
"baseUrl": ".",
Expand Down
1 change: 0 additions & 1 deletion examples/with-javascript/.babelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
[ "@babel/plugin-proposal-decorators", { "legacy": true } ],
[ "@babel/plugin-proposal-class-properties", { "loose": true } ]
]
}
1 change: 1 addition & 0 deletions examples/with-javascript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.dist
1 change: 1 addition & 0 deletions examples/with-javascript/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 1 addition & 1 deletion examples/with-javascript/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { provide } from "node-provide";
import { Logger } from "./Logger";

export class App {
@provide(Logger) logger;
logger = provide(Logger);

start() {
this.logger.log("App ready");
Expand Down
11 changes: 5 additions & 6 deletions examples/with-javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,17 @@
"description": "Example with javascript",
"private": true,
"scripts": {
"start": "npx babel *.js -d .dist >/dev/null && node .dist/index.js"
"start": "babel *.js -d .dist >/dev/null && node .dist/index.js"
},
"author": "betula <mail@betula.co>",
"license": "ISC",
"dependencies": {
"node-provide": "latest"
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"@babel/plugin-proposal-decorators": "^7.4.4",
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/preset-env": "^7.4.5"
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"@babel/plugin-proposal-class-properties": "^7.8.3"
}
}
67 changes: 8 additions & 59 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,13 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "lib": [], /* Specify library files to be included in the compilation. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
"declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./release", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
"strictPropertyInitialization": false, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */

/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

/* Experimental Options */
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */
"target": "es2017",
"module": "commonjs",
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "./release",
"strict": true,
"esModuleInterop": true
},
"exclude": [
"release/*",
Expand Down

0 comments on commit 31eaa71

Please sign in to comment.