From 1ebafbef49972693294fdc87bf10130f6bf04316 Mon Sep 17 00:00:00 2001 From: Filip Rojek Date: Wed, 1 Dec 2021 18:05:44 +0100 Subject: [PATCH] rewriting to oop and typescript --- .eslintrc.json | 39 +++++++ .mocharc.json | 4 + _old/LICENSE | 21 ++++ _old/README.md | 37 ++++++ _old/package.json | 32 ++++++ {src => _old/src}/app.js | 0 _old/src/make-files/express-js/controller.js | 8 ++ _old/src/make-files/express-js/middleware.js | 10 ++ _old/src/make-files/express-js/model.js | 17 +++ _old/src/make-files/express-js/route.js | 8 ++ .../src/make-files/express-js}/test.js | 0 _old/src/make-files/express-js/view.ejs | 15 +++ _old/src/make-files/express-ts/controller.js | 8 ++ _old/src/make-files/express-ts/controller.ts | 6 + _old/src/make-files/express-ts/interface.js | 2 + _old/src/make-files/express-ts/interface.ts | 4 + _old/src/make-files/express-ts/middleware.js | 9 ++ _old/src/make-files/express-ts/middleware.ts | 8 ++ _old/src/make-files/express-ts/model.js | 12 ++ _old/src/make-files/express-ts/model.ts | 15 +++ _old/src/make-files/express-ts/route.js | 26 +++++ _old/src/make-files/express-ts/route.ts | 6 + _old/src/make-files/express-ts/service.js | 7 ++ _old/src/make-files/express-ts/service.ts | 3 + _old/src/make-files/express-ts/test.js | 9 ++ _old/src/make-files/express-ts/view.ejs | 15 +++ _old/src/skeletons/express-js/.env.example | 2 + _old/src/skeletons/express-js/.gitignore | 107 ++++++++++++++++++ _old/src/skeletons/express-js/README.md | 0 _old/src/skeletons/express-js/norkconfig.json | 3 + _old/src/skeletons/express-js/package.json | 24 ++++ _old/src/skeletons/express-js/src/app.js | 41 +++++++ .../src/controllers/rootController.js | 8 ++ .../express-js/src/middlewares/index.js | 8 ++ .../src/middlewares/sayHiMiddleware.js | 10 ++ .../express-js/src/public/expressjs.png | Bin 0 -> 5032 bytes .../express-js/src/public/nodejs_logo.svg | 1 + .../skeletons/express-js/src/routes/index.js | 13 +++ .../express-js/src/routes/rootRoutes.js | 8 ++ .../express-js/src/tests/home.test.js | 9 ++ .../src/tests/modules/reqRes.module.js | 16 +++ .../skeletons/express-js/src/utils/REAME.md | 1 + .../skeletons/express-js/src/views/home.ejs | 69 +++++++++++ _old/src/skeletons/express-ts/.gitignore | 107 ++++++++++++++++++ _old/src/skeletons/express-ts/README.md | 1 + _old/src/skeletons/express-ts/jest.config.js | 5 + _old/src/skeletons/express-ts/norkconfig.json | 3 + _old/src/skeletons/express-ts/package.json | 62 ++++++++++ .../src/skeletons/express-ts/src/.env.example | 2 + _old/src/skeletons/express-ts/src/app.js | 39 +++++++ _old/src/skeletons/express-ts/src/app.ts | 36 ++++++ .../src/controllers/rootController.js | 8 ++ .../src/controllers/rootController.ts | 6 + .../src/interfaces/globalInterface.js | 2 + .../src/interfaces/globalInterface.ts | 4 + .../express-ts/src/middlewares/index.js | 7 ++ .../express-ts/src/middlewares/index.ts | 6 + .../src/middlewares/sayHiMiddleware.js | 9 ++ .../src/middlewares/sayHiMiddleware.ts | 9 ++ .../express-ts/src/public/expressjs.png | Bin 0 -> 5032 bytes .../express-ts/src/public/nodejs_logo.svg | 1 + .../skeletons/express-ts/src/routes/index.js | 11 ++ .../skeletons/express-ts/src/routes/index.ts | 11 ++ .../express-ts/src/routes/rootRoutes.js | 26 +++++ .../express-ts/src/routes/rootRoutes.ts | 6 + _old/src/skeletons/express-ts/src/server.js | 27 +++++ _old/src/skeletons/express-ts/src/server.ts | 24 ++++ .../express-ts/src/services/globalService.js | 37 ++++++ .../express-ts/src/services/globalService.ts | 40 +++++++ .../express-ts/src/services/rootService.js | 7 ++ .../express-ts/src/services/rootService.ts | 3 + .../express-ts/src/tests/home.test.js | 9 ++ .../src/tests/modules/reqRes.module.js | 16 +++ .../express-ts/src/utils/copyAssets.js | 27 +++++ .../express-ts/src/utils/copyAssets.ts | 7 ++ .../express-ts/src/utils/environment.js | 11 ++ .../express-ts/src/utils/environment.ts | 7 ++ .../skeletons/express-ts/src/views/home.ejs | 69 +++++++++++ _old/src/skeletons/express-ts/tsconfig.json | 85 ++++++++++++++ norkconfig.json | 1 + package.json | 28 ++++- progress-blog.md | 10 ++ src/app.ts | 9 ++ src/controllers/test.ts | 6 + src/controllers/undefined.ts | 6 + src/global.ts | 16 +++ src/help.ts | 66 +++++++++++ src/interfaces/GlobalInterface.ts | 3 + src/interfaces/SetupInterface.ts | 15 +++ src/interfaces/test.ts | 4 + src/interfaces/undefined.ts | 4 + src/make.ts | 76 +++++++++++++ src/middlewares/test.ts | 8 ++ src/middlewares/undefined.ts | 8 ++ src/models/test.ts | 15 +++ src/models/undefined.ts | 15 +++ src/routes.ts | 41 +++++++ src/routes/test.ts | 6 + src/routes/undefined.ts | 6 + src/services/test.ts | 3 + src/services/undefined.ts | 3 + src/setup.ts | 24 ++++ src/skeletons/express-ts/src/app.js | 39 +++++++ .../src/controllers/rootController.js | 8 ++ .../src/interfaces/globalInterface.js | 2 + .../express-ts/src/middlewares/index.js | 7 ++ .../src/middlewares/sayHiMiddleware.js | 9 ++ src/skeletons/express-ts/src/routes/index.js | 11 ++ .../express-ts/src/routes/rootRoutes.js | 26 +++++ src/skeletons/express-ts/src/server.js | 27 +++++ .../express-ts/src/services/globalService.js | 37 ++++++ .../express-ts/src/services/rootService.js | 7 ++ .../express-ts/src/utils/copyAssets.js | 27 +++++ .../express-ts/src/utils/environment.js | 11 ++ src/tests/help.test.ts | 23 ++++ src/tests/router.test.ts | 58 ++++++++++ src/tests/setup.test.ts | 11 ++ src/tests/test.test.ts.old | 20 ++++ src/tests/version.test.ts | 11 ++ src/version.ts | 10 ++ src/views/test.ejs | 15 +++ src/views/undefined.ejs | 15 +++ tsconfig.json | 16 +++ 123 files changed, 2129 insertions(+), 5 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .mocharc.json create mode 100644 _old/LICENSE create mode 100644 _old/README.md create mode 100644 _old/package.json rename {src => _old/src}/app.js (100%) create mode 100644 _old/src/make-files/express-js/controller.js create mode 100644 _old/src/make-files/express-js/middleware.js create mode 100644 _old/src/make-files/express-js/model.js create mode 100644 _old/src/make-files/express-js/route.js rename {src/make-files/express-ts => _old/src/make-files/express-js}/test.js (100%) create mode 100644 _old/src/make-files/express-js/view.ejs create mode 100644 _old/src/make-files/express-ts/controller.js create mode 100644 _old/src/make-files/express-ts/controller.ts create mode 100644 _old/src/make-files/express-ts/interface.js create mode 100644 _old/src/make-files/express-ts/interface.ts create mode 100644 _old/src/make-files/express-ts/middleware.js create mode 100644 _old/src/make-files/express-ts/middleware.ts create mode 100644 _old/src/make-files/express-ts/model.js create mode 100644 _old/src/make-files/express-ts/model.ts create mode 100644 _old/src/make-files/express-ts/route.js create mode 100644 _old/src/make-files/express-ts/route.ts create mode 100644 _old/src/make-files/express-ts/service.js create mode 100644 _old/src/make-files/express-ts/service.ts create mode 100644 _old/src/make-files/express-ts/test.js create mode 100644 _old/src/make-files/express-ts/view.ejs create mode 100644 _old/src/skeletons/express-js/.env.example create mode 100644 _old/src/skeletons/express-js/.gitignore create mode 100644 _old/src/skeletons/express-js/README.md create mode 100644 _old/src/skeletons/express-js/norkconfig.json create mode 100644 _old/src/skeletons/express-js/package.json create mode 100644 _old/src/skeletons/express-js/src/app.js create mode 100644 _old/src/skeletons/express-js/src/controllers/rootController.js create mode 100644 _old/src/skeletons/express-js/src/middlewares/index.js create mode 100644 _old/src/skeletons/express-js/src/middlewares/sayHiMiddleware.js create mode 100644 _old/src/skeletons/express-js/src/public/expressjs.png create mode 100644 _old/src/skeletons/express-js/src/public/nodejs_logo.svg create mode 100644 _old/src/skeletons/express-js/src/routes/index.js create mode 100644 _old/src/skeletons/express-js/src/routes/rootRoutes.js create mode 100644 _old/src/skeletons/express-js/src/tests/home.test.js create mode 100644 _old/src/skeletons/express-js/src/tests/modules/reqRes.module.js create mode 100644 _old/src/skeletons/express-js/src/utils/REAME.md create mode 100644 _old/src/skeletons/express-js/src/views/home.ejs create mode 100644 _old/src/skeletons/express-ts/.gitignore create mode 100644 _old/src/skeletons/express-ts/README.md create mode 100644 _old/src/skeletons/express-ts/jest.config.js create mode 100644 _old/src/skeletons/express-ts/norkconfig.json create mode 100644 _old/src/skeletons/express-ts/package.json create mode 100644 _old/src/skeletons/express-ts/src/.env.example create mode 100644 _old/src/skeletons/express-ts/src/app.js create mode 100644 _old/src/skeletons/express-ts/src/app.ts create mode 100644 _old/src/skeletons/express-ts/src/controllers/rootController.js create mode 100644 _old/src/skeletons/express-ts/src/controllers/rootController.ts create mode 100644 _old/src/skeletons/express-ts/src/interfaces/globalInterface.js create mode 100644 _old/src/skeletons/express-ts/src/interfaces/globalInterface.ts create mode 100644 _old/src/skeletons/express-ts/src/middlewares/index.js create mode 100644 _old/src/skeletons/express-ts/src/middlewares/index.ts create mode 100644 _old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js create mode 100644 _old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.ts create mode 100644 _old/src/skeletons/express-ts/src/public/expressjs.png create mode 100644 _old/src/skeletons/express-ts/src/public/nodejs_logo.svg create mode 100644 _old/src/skeletons/express-ts/src/routes/index.js create mode 100644 _old/src/skeletons/express-ts/src/routes/index.ts create mode 100644 _old/src/skeletons/express-ts/src/routes/rootRoutes.js create mode 100644 _old/src/skeletons/express-ts/src/routes/rootRoutes.ts create mode 100644 _old/src/skeletons/express-ts/src/server.js create mode 100644 _old/src/skeletons/express-ts/src/server.ts create mode 100644 _old/src/skeletons/express-ts/src/services/globalService.js create mode 100644 _old/src/skeletons/express-ts/src/services/globalService.ts create mode 100644 _old/src/skeletons/express-ts/src/services/rootService.js create mode 100644 _old/src/skeletons/express-ts/src/services/rootService.ts create mode 100644 _old/src/skeletons/express-ts/src/tests/home.test.js create mode 100644 _old/src/skeletons/express-ts/src/tests/modules/reqRes.module.js create mode 100644 _old/src/skeletons/express-ts/src/utils/copyAssets.js create mode 100644 _old/src/skeletons/express-ts/src/utils/copyAssets.ts create mode 100644 _old/src/skeletons/express-ts/src/utils/environment.js create mode 100644 _old/src/skeletons/express-ts/src/utils/environment.ts create mode 100644 _old/src/skeletons/express-ts/src/views/home.ejs create mode 100644 _old/src/skeletons/express-ts/tsconfig.json create mode 100644 norkconfig.json create mode 100644 progress-blog.md create mode 100644 src/app.ts create mode 100644 src/controllers/test.ts create mode 100644 src/controllers/undefined.ts create mode 100644 src/global.ts create mode 100644 src/help.ts create mode 100644 src/interfaces/GlobalInterface.ts create mode 100644 src/interfaces/SetupInterface.ts create mode 100644 src/interfaces/test.ts create mode 100644 src/interfaces/undefined.ts create mode 100644 src/make.ts create mode 100644 src/middlewares/test.ts create mode 100644 src/middlewares/undefined.ts create mode 100644 src/models/test.ts create mode 100644 src/models/undefined.ts create mode 100644 src/routes.ts create mode 100644 src/routes/test.ts create mode 100644 src/routes/undefined.ts create mode 100644 src/services/test.ts create mode 100644 src/services/undefined.ts create mode 100644 src/setup.ts create mode 100644 src/skeletons/express-ts/src/app.js create mode 100644 src/skeletons/express-ts/src/controllers/rootController.js create mode 100644 src/skeletons/express-ts/src/interfaces/globalInterface.js create mode 100644 src/skeletons/express-ts/src/middlewares/index.js create mode 100644 src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js create mode 100644 src/skeletons/express-ts/src/routes/index.js create mode 100644 src/skeletons/express-ts/src/routes/rootRoutes.js create mode 100644 src/skeletons/express-ts/src/server.js create mode 100644 src/skeletons/express-ts/src/services/globalService.js create mode 100644 src/skeletons/express-ts/src/services/rootService.js create mode 100644 src/skeletons/express-ts/src/utils/copyAssets.js create mode 100644 src/skeletons/express-ts/src/utils/environment.js create mode 100644 src/tests/help.test.ts create mode 100644 src/tests/router.test.ts create mode 100644 src/tests/setup.test.ts create mode 100644 src/tests/test.test.ts.old create mode 100644 src/tests/version.test.ts create mode 100644 src/version.ts create mode 100644 src/views/test.ejs create mode 100644 src/views/undefined.ejs create mode 100644 tsconfig.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..db9915a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,39 @@ +{ + "env": { + "es2021": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 6, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "indent": [ + "error", + "tab" + ], + "linebreak-style": [ + "error", + "unix" + ], + "quotes": [ + "error", + "single", + { + "allowTemplateLiterals": true + } + ], + "semi": [ + "error", + "never" + ] + } +} diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000..3cac628 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,4 @@ +{ + "require": ["ts-node/register"], + "watch-files": ["./src/**/*.ts"] +} \ No newline at end of file diff --git a/_old/LICENSE b/_old/LICENSE new file mode 100644 index 0000000..d369008 --- /dev/null +++ b/_old/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Filip Rojek + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/_old/README.md b/_old/README.md new file mode 100644 index 0000000..813f51f --- /dev/null +++ b/_old/README.md @@ -0,0 +1,37 @@ +# Nork +Simple node.js tool that extends express projects. + + - [About](#about) + - [Installation](#installation) + - [How to use](#how-to-use) + +## About +The point of this tool is to add to express some feeling of php framework Laravel. Primarily get simply express app into MVC architecture. + +## Installation +``` +npm install -g nork +``` +This will install nork globally. If you would like to install nork for only one project, you can also install it locally. For local installation: + ``` + npm install nork +``` +## How to use +``` +Usage: nork [options] + +Options: + -v, --version output the version number + -h, --help output usage information + +Commands: + create [app-name] create a new project + create [app-name] -i create a new project in current directory + make controller [name] create a new controller + make middleware [name] create a new middleware + make model [name] create a new model + make route [name] create a new route + make test [name] create a new test + make view [name] create a new view + setup set up an existing project for nork +``` diff --git a/_old/package.json b/_old/package.json new file mode 100644 index 0000000..2866afb --- /dev/null +++ b/_old/package.json @@ -0,0 +1,32 @@ +{ + "name": "nork", + "version": "1.2.1", + "description": "The best node.js 'framework' :)", + "main": "src/app.js", + "bin": "src/app.js", + "scripts": { + "start": "node src/app.js" + }, + "keywords": [ + "node", + "framework", + "express", + "mvc" + ], + "author": "Filip Rojek", + "license": "MIT", + "dependencies": { + "colors": "^1.4.0", + "fs-extra": "^10.0.0", + "inquirer": "^8.1.2", + "pad": "^3.2.0" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/filiprojek/nork.git" + }, + "bugs": { + "url": "https://github.com/filiprojek/nork/issues" + }, + "homepage": "https://github.com/filiprojek/nork/blob/master/README.md" +} \ No newline at end of file diff --git a/src/app.js b/_old/src/app.js similarity index 100% rename from src/app.js rename to _old/src/app.js diff --git a/_old/src/make-files/express-js/controller.js b/_old/src/make-files/express-js/controller.js new file mode 100644 index 0000000..aaef9ae --- /dev/null +++ b/_old/src/make-files/express-js/controller.js @@ -0,0 +1,8 @@ +const root_get = (req, res) => { + res.render('home') + return true +} + +module.exports = { + root_get, +} diff --git a/_old/src/make-files/express-js/middleware.js b/_old/src/make-files/express-js/middleware.js new file mode 100644 index 0000000..154e3b2 --- /dev/null +++ b/_old/src/make-files/express-js/middleware.js @@ -0,0 +1,10 @@ +const { Router } = require('express') + +const router = Router() + +router.use((req, res, next) => { + console.log('Hi :)') + next() +}) + +module.exports = router diff --git a/_old/src/make-files/express-js/model.js b/_old/src/make-files/express-js/model.js new file mode 100644 index 0000000..877524f --- /dev/null +++ b/_old/src/make-files/express-js/model.js @@ -0,0 +1,17 @@ +const mongoose = require('mongoose') +const Schema = mongoose.Schema + +const modelSchema = new Schema( + { + title: { + type: String, + required: true, + }, + }, + { + timestamps: true, + }, +) + +const ModelName = mongoose.model('ModelName', modelSchema) +module.exports = ModelName diff --git a/_old/src/make-files/express-js/route.js b/_old/src/make-files/express-js/route.js new file mode 100644 index 0000000..9d0925b --- /dev/null +++ b/_old/src/make-files/express-js/route.js @@ -0,0 +1,8 @@ +const { Router } = require('express') +const rootController = require('../controllers/rootController') + +const router = Router() + +router.get('/', rootController.root_get) + +module.exports = router diff --git a/src/make-files/express-ts/test.js b/_old/src/make-files/express-js/test.js similarity index 100% rename from src/make-files/express-ts/test.js rename to _old/src/make-files/express-js/test.js diff --git a/_old/src/make-files/express-js/view.ejs b/_old/src/make-files/express-js/view.ejs new file mode 100644 index 0000000..faf15cc --- /dev/null +++ b/_old/src/make-files/express-js/view.ejs @@ -0,0 +1,15 @@ + + + + + + + New Project + + + + + + + + \ No newline at end of file diff --git a/_old/src/make-files/express-ts/controller.js b/_old/src/make-files/express-ts/controller.js new file mode 100644 index 0000000..68705a9 --- /dev/null +++ b/_old/src/make-files/express-ts/controller.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.root_get = void 0; +const root_get = (req, res) => { + res.render('home'); + return true; +}; +exports.root_get = root_get; diff --git a/_old/src/make-files/express-ts/controller.ts b/_old/src/make-files/express-ts/controller.ts new file mode 100644 index 0000000..4a94a0d --- /dev/null +++ b/_old/src/make-files/express-ts/controller.ts @@ -0,0 +1,6 @@ +import { Request, Response } from 'express' + +export const root_get = (req: Request, res: Response) => { + res.render('home') + return true +} diff --git a/_old/src/make-files/express-ts/interface.js b/_old/src/make-files/express-ts/interface.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/_old/src/make-files/express-ts/interface.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/_old/src/make-files/express-ts/interface.ts b/_old/src/make-files/express-ts/interface.ts new file mode 100644 index 0000000..727a759 --- /dev/null +++ b/_old/src/make-files/express-ts/interface.ts @@ -0,0 +1,4 @@ +export interface interfaceName { + hello: string + world: boolean | null | undefined +} diff --git a/_old/src/make-files/express-ts/middleware.js b/_old/src/make-files/express-ts/middleware.js new file mode 100644 index 0000000..097d0c8 --- /dev/null +++ b/_old/src/make-files/express-ts/middleware.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +exports.router = (0, express_1.Router)(); +exports.router.use((req, res, next) => { + console.log('Hi :)'); + next(); +}); diff --git a/_old/src/make-files/express-ts/middleware.ts b/_old/src/make-files/express-ts/middleware.ts new file mode 100644 index 0000000..32accc2 --- /dev/null +++ b/_old/src/make-files/express-ts/middleware.ts @@ -0,0 +1,8 @@ +import { Router, Request, Response, NextFunction } from 'express' + +export const router = Router() + +router.use((req: Request, res: Response, next: NextFunction) => { + console.log('Hi :)') + next() +}) diff --git a/_old/src/make-files/express-ts/model.js b/_old/src/make-files/express-ts/model.js new file mode 100644 index 0000000..64f6691 --- /dev/null +++ b/_old/src/make-files/express-ts/model.js @@ -0,0 +1,12 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = require("mongoose"); +const modelSchema = new mongoose_1.Schema({ + title: { + type: String, + required: true, + }, +}, { + timestamps: true, +}); +exports.default = (0, mongoose_1.model)('ModelName', modelSchema); diff --git a/_old/src/make-files/express-ts/model.ts b/_old/src/make-files/express-ts/model.ts new file mode 100644 index 0000000..cc22d18 --- /dev/null +++ b/_old/src/make-files/express-ts/model.ts @@ -0,0 +1,15 @@ +import { Schema, model } from 'mongoose' + +const modelSchema = new Schema( + { + title: { + type: String, + required: true, + }, + }, + { + timestamps: true, + }, +) + +export default model('ModelName', modelSchema) diff --git a/_old/src/make-files/express-ts/route.js b/_old/src/make-files/express-ts/route.js new file mode 100644 index 0000000..8102385 --- /dev/null +++ b/_old/src/make-files/express-ts/route.js @@ -0,0 +1,26 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const rootController = __importStar(require("@/controllers/rootController")); +exports.router = (0, express_1.Router)(); +exports.router.get('/', rootController.root_get); diff --git a/_old/src/make-files/express-ts/route.ts b/_old/src/make-files/express-ts/route.ts new file mode 100644 index 0000000..7374556 --- /dev/null +++ b/_old/src/make-files/express-ts/route.ts @@ -0,0 +1,6 @@ +import { Router } from 'express' +import * as rootController from '@/controllers/rootController' + +export const router = Router() + +router.get('/', rootController.root_get) diff --git a/_old/src/make-files/express-ts/service.js b/_old/src/make-files/express-ts/service.js new file mode 100644 index 0000000..7225519 --- /dev/null +++ b/_old/src/make-files/express-ts/service.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.helloWorld = void 0; +function helloWorld() { + console.log('hello world'); +} +exports.helloWorld = helloWorld; diff --git a/_old/src/make-files/express-ts/service.ts b/_old/src/make-files/express-ts/service.ts new file mode 100644 index 0000000..ccb388e --- /dev/null +++ b/_old/src/make-files/express-ts/service.ts @@ -0,0 +1,3 @@ +export function helloWorld() { + console.log('hello world') +} diff --git a/_old/src/make-files/express-ts/test.js b/_old/src/make-files/express-ts/test.js new file mode 100644 index 0000000..7949993 --- /dev/null +++ b/_old/src/make-files/express-ts/test.js @@ -0,0 +1,9 @@ +const { getReq, getRes } = require('./modules/reqRes.module.js') +const { root_get } = require('../controllers/rootController.ts') + +test('Home page render test', () => { + const req = getReq() + const res = getRes() + + expect(root_get(req, res)).toBe(true) +}) diff --git a/_old/src/make-files/express-ts/view.ejs b/_old/src/make-files/express-ts/view.ejs new file mode 100644 index 0000000..faf15cc --- /dev/null +++ b/_old/src/make-files/express-ts/view.ejs @@ -0,0 +1,15 @@ + + + + + + + New Project + + + + + + + + \ No newline at end of file diff --git a/_old/src/skeletons/express-js/.env.example b/_old/src/skeletons/express-js/.env.example new file mode 100644 index 0000000..b1a432b --- /dev/null +++ b/_old/src/skeletons/express-js/.env.example @@ -0,0 +1,2 @@ +APP_PORT = 8080 +DB_URI = 'mongodb://username:password@localhost:27017/database?authSource=admin' diff --git a/_old/src/skeletons/express-js/.gitignore b/_old/src/skeletons/express-js/.gitignore new file mode 100644 index 0000000..66e0c76 --- /dev/null +++ b/_old/src/skeletons/express-js/.gitignore @@ -0,0 +1,107 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and *not* Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# package lock file +package-lock.json \ No newline at end of file diff --git a/_old/src/skeletons/express-js/README.md b/_old/src/skeletons/express-js/README.md new file mode 100644 index 0000000..e69de29 diff --git a/_old/src/skeletons/express-js/norkconfig.json b/_old/src/skeletons/express-js/norkconfig.json new file mode 100644 index 0000000..1713bb4 --- /dev/null +++ b/_old/src/skeletons/express-js/norkconfig.json @@ -0,0 +1,3 @@ +{ + "lang": "js" +} \ No newline at end of file diff --git a/_old/src/skeletons/express-js/package.json b/_old/src/skeletons/express-js/package.json new file mode 100644 index 0000000..b0f19d4 --- /dev/null +++ b/_old/src/skeletons/express-js/package.json @@ -0,0 +1,24 @@ +{ + "name": "project-name", + "version": "1.0.0", + "description": "", + "main": "src/app.js", + "scripts": { + "start": "node src/app.js", + "dev": "nodemon src/app.js", + "test": "jest" + }, + "author": "", + "license": "ISC", + "dependencies": { + "cors": "^2.8.5", + "dotenv": "^8.2.0", + "ejs": "^3.1.6", + "express": "^4.17.1", + "mongoose": "^5.12.3", + "morgan": "^1.10.0" + }, + "devDependencies": { + "jest": "^27.0.6" + } +} diff --git a/_old/src/skeletons/express-js/src/app.js b/_old/src/skeletons/express-js/src/app.js new file mode 100644 index 0000000..488bd3a --- /dev/null +++ b/_old/src/skeletons/express-js/src/app.js @@ -0,0 +1,41 @@ +const express = require('express') +const morgan = require('morgan') +const mongoose = require('mongoose') +const dotenv = require('dotenv').config() +const cors = require('cors') +const path = require('path') + +const routes = require('./routes') +const middlewares = require('./middlewares') + +const port = process.env.APP_PORT || 8080 +const app = express() + +// MongoDB +const dbURI = process.env.DB_URI +mongoose + .connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true }) + .then(result => { + console.log('connected to db') + app.listen(port, () => { + console.log(`server is running on http://localhost:${port}`) + }) + }) + .catch(err => { + console.log(err) + }) + +// View engine +app.set('view engine', 'ejs') + +// Middlewares +app.use(middlewares) +app.set('views', path.join(__dirname, 'views')) +app.use(express.static(path.join(__dirname, 'public'))) +app.use(cors()) +app.use(morgan('dev')) +app.use(express.urlencoded({ extended: true })) +app.use(express.json()) + +// Routes +app.use(routes) diff --git a/_old/src/skeletons/express-js/src/controllers/rootController.js b/_old/src/skeletons/express-js/src/controllers/rootController.js new file mode 100644 index 0000000..aaef9ae --- /dev/null +++ b/_old/src/skeletons/express-js/src/controllers/rootController.js @@ -0,0 +1,8 @@ +const root_get = (req, res) => { + res.render('home') + return true +} + +module.exports = { + root_get, +} diff --git a/_old/src/skeletons/express-js/src/middlewares/index.js b/_old/src/skeletons/express-js/src/middlewares/index.js new file mode 100644 index 0000000..ca227fd --- /dev/null +++ b/_old/src/skeletons/express-js/src/middlewares/index.js @@ -0,0 +1,8 @@ +const { Router } = require('express') +const sayHiMiddleware = require('./sayHiMiddleware') + +const router = Router() + +router.use(sayHiMiddleware) + +module.exports = router diff --git a/_old/src/skeletons/express-js/src/middlewares/sayHiMiddleware.js b/_old/src/skeletons/express-js/src/middlewares/sayHiMiddleware.js new file mode 100644 index 0000000..154e3b2 --- /dev/null +++ b/_old/src/skeletons/express-js/src/middlewares/sayHiMiddleware.js @@ -0,0 +1,10 @@ +const { Router } = require('express') + +const router = Router() + +router.use((req, res, next) => { + console.log('Hi :)') + next() +}) + +module.exports = router diff --git a/_old/src/skeletons/express-js/src/public/expressjs.png b/_old/src/skeletons/express-js/src/public/expressjs.png new file mode 100644 index 0000000000000000000000000000000000000000..487c5a83af37b9b93507a08a761c0788c764b169 GIT binary patch literal 5032 zcmbtXXEYp8lpdlaYJ!kNM5JhwFnSk#)X^DYL>WEW7+tg|(Su-&(Ty5JNrY(8joy1_ zm?+UZS^IN;?4I4T@0|C(ci(;AJKsI8og1MA0aH^vq5uE@)GEpfIsgFC&`m$)_N|+C zf&E+j4UpK#YRCcr6>*f8=A<|FQ%hwX4FJFq1pv6k0szx$06@qR0N}R+08HMv`NaSL z79Qlc>bC#@@rIVVp5niM|Mm|KF0Zcs?(Xd$9G;z@-{8^F@%j11_Re4Y24Q7w{owGZ zXJGj3?5uBSw7Yk3X=QD8e(C!98rL^?a(X&CF}1L?@@I2~?_>JR}lljHvi;Ih~ z$(e!Sv5h~Qxc;H7oxi;U!<*YX!()?k3rm|@+kJy06Vr1$e|HI+TZ1FxH;QNG7yF0D z)(L+KN-KjR;@^7&7+SoS(=?V)){})8>zmozx%qtvi;YjsEGnyR@9s^)@Miz4Dt?*8G@YKESHpF*M&TRVHAzodQpUYC-Qr>tkDZDQje9`_|JyRoIC z;dgssS=EikpAElblQ2p;rZx4=&23$I#osiIt+Y(6y@DdbS&C2)r7^SEK`}8@b zt*bXYE~T{UCn^)`;`6b#p~b}71b7BU)Hk=GCqXH+#K?^>PJF17eF4V1JS*~|8HS>SEGNk29bpt zSOM^fltuZ*xZ|R1X$v=1s+UN9&wn=Mqz0EP~jHe9sby7PhlLTawb zDF#zDFK~;FoSo*-b&(a|mMBchMtk|IbbKgh%dvP7*E{a6Ui8R4O>`e#?d{=$?i z`O|u*T;I>V!g@lIl=5BXEU#iN8<5%5? zP2sr@0>}%RtX+2rDKqyFVTp*wr^+UfG7(TJ$@Q-3v|0>PqHkN-MH`URa)J6wKUUH^}gz94}e&uPXw6!weC$9hFle%}sV(gKb=m)XIFEI0UhUKyp;{8`yE2 zPHKpE{dO;nxln_p%|X6Y@0%&uWfx}wISrNmHcf3M9W@=f?zui&S5JN7QUvc`k zafnSdDp(t84)02~z2Vm4O15lv9RN>tI}-R{1gb?K{ZLQy9gX;rp+PD)c}!b|g0ULR z&MHK=S#V)h5BM-jO09rcppC12-}WJ-#!8gOj7o`c{&2}g%ihG(BL?hT+D6zwnh~{% z$t$g7?O;?%d?{#9qeb(pNXCthr*lDczd%^6t@XPLXhPR^vlncs;r^u6sOk3SV0T&v zN+63PU0iu;zjvgLH}}0pSyxmAt_0(g%^S5ZIS4`NaIQujId{nG#^x@l58}F|d${NwQbP{nOSme^7`nMltgl@hVL=V& z!ze$@cwE64uGMz>6L9ajBx?a`V2Wn?qe@8nCs4ds%7{*V-;2v9chGd3szHK)#wF29 zkb$nM%E7WFY-vI{UmDHkj}a;r_@1|D1S8qng+U&k2C38#5BkNG0!jC|$@Z)B7G#V) zRreI;+~GaMjRj#({o$zbRAYaVM-I=;s{SI*A4RCwJrDE|?4`tt2Gc(PM$UvVt#GJT z@SA4&2aY~_C_oU(TqZBnOr!ebW>&`&+?{Lb>^2=(31x&$o*%(RUydg&Z%|40zZ4C0 z8$CgV2<+Uq8`Lr3Lw(FX9ZK88NVw=QvvsdZ6C5EuK?f#2M5?YPigXKtrM#eMW9hLE z%MpEzk5ZM=ZQHdQcP4MIg6*HxFSlYWdg5E=ztQC~bTU#c)0^B{F64cT_{(QP{2fuI z;Cjf%OuLFH6}lI8%3p9+UBSox6{vV`v6(?yk#_OXQRt+8SGiC9>{L)`*u77zcI*Qo zT*wJ3^Ikp{`eSL1VP*kG?}wH!u1Jv}5Tu*uGW=R@lQ9k(YBTkd?(?}lGi z(;!JC&m~6u`9giTnjyHAu5-6Fp0STh%xrSq2Y-B+*!))u&Yu!?`g^xar9EmgC&G;G zodSfg+7Bw0wqf8+vhaFj==Jg~-|r17CA$%!+FKQ;xk3m?NTISL#_yChvL7x??B_JlnmxX92TLxcG#+TPx!U!+D zPhZC;1}XF3@d}1lbX{WHqJ646kYpC4_w2bjE)v~1#3tC*2232THSXshMh=(}RdL8N znNL^!+$Qg#dg{5OJFvj#spkcer8LYJjl;b@4RP>Jb;nv&#_vgpuy1D^V_mXl{TlD= zee@L4WIk$p>;_g`*XwSzF*Gf&W_O%L#vO=|a=q3Lt5FEste|yx!rMYRLVmX`P8{RP z4CuR&!Bb#g#|zzhzqi%YA?D=(>+W;*8%USDd-gbz8Av@6VGX|b<{9+)JibYW);;7= zkBWSpGhUywM89BfUbJ2d!53kL<`+l_tXj<^UVo!>_stHT$}gkfO9Pt#;Xrxu*GH?ccwpC>e zxCiyk98emqun_UDvSmKkm(Qop-NPVXyp^_V`@QdMR^RhW9$^Ud#`Urm2hnb-X3v^o z1hy;y9a^g7Y`Qa@CX|=zF!-2k)mttDPOPy#j4dd!i6^0CrS5pMtSSglQWg^B#YX}_ZfUetcNAIEe>sE)TcgW?v=s0HGa3bgo#uuB%6hT>Gg^OCeost(&&St>g3wvdO&kd z`t6dl(c|EofNMaJM&}>xhjQJqP!9`^i{W}tz_$I)bDEVjzb#U@$0#GW|9iMIvwO%6 z0mT7sz;RJ-^m8`^8p(aJ@J?BwWSKS;nLW_E!ynC2-=1Vy=)p_V9v65CAD@$>i)T=X zSggVrqu)^KxzYzvXh*&jCbjxH)B5kuCH746M^@YW!aRSp6K|O6oB39rANU=FYWwz( zwlkuV!!G3uvknuKO@Rx=xft*s`~%lb(`7&(`>U`!brhqy zxu$D^sb^=~WDLSgxeV&u38_kJIUH;%RSTof%o1xk_vN=OgbP>+byvhi1+%o_jXuX) zg(70^ylv3@f!Ca}Rm>Q7tXT`4RzK*V^SZ=oA*XC_^vY3>Ii2d21Hm02VgWn9)_FA%zfwdw zLjP0NTfKF$a1C?&JMgn#??J(__-+jdYpZKvmA!;wg5&C;ddG|DpqKD;6k;r&b&J>9WAMEf{hHN*S{p{Lo)}ln_ zsBL%+y!o;VB4RM6M%u4cV`+^THHJWriSOebwJ%CKPDC30=O4-19I&)I2}1?`)Wo0KN`@8Iuajk}8?*CP(Yy8mFzwIfMz-Mm7 z_&x-pf<@?bDmdIDg*Y=j!XPrg$6%k3+&6e_ZG`NkZeI=M{eHnsvLnNG;ry(ZO!{l_ zf}Z~?91)$)KuLLfbCZ*3pmf+dl-`~A zqvfM|K0nQ}%H4gtl`)duSOh)~-&Klx=e8-p3oL#+m!oDJ*5{=IKX(7pT#ygDTmyWz{l#4z4E=>u*Q zZ$X}L$agW72wxt42zzDOAt{^rHo3FI#Mfla*>%nZ!cL##+Zg^YO1z zmH#n|O?b5UFFLUaC1}8Ybdz_#L@Gj&aC4-UxFy2s1_1mZK9ScT!Pop^dLVvrkg&J_ p|7(zlI0)3Nd(QY@2#(HhJ8SR%o=`y}SA0VNs3<}d%H+&~{{wT0#Ss7i literal 0 HcmV?d00001 diff --git a/_old/src/skeletons/express-js/src/public/nodejs_logo.svg b/_old/src/skeletons/express-js/src/public/nodejs_logo.svg new file mode 100644 index 0000000..41d044a --- /dev/null +++ b/_old/src/skeletons/express-js/src/public/nodejs_logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/_old/src/skeletons/express-js/src/routes/index.js b/_old/src/skeletons/express-js/src/routes/index.js new file mode 100644 index 0000000..27fb8d8 --- /dev/null +++ b/_old/src/skeletons/express-js/src/routes/index.js @@ -0,0 +1,13 @@ +const { Router } = require('express') +const rootRoutes = require('./rootRoutes') + +const router = Router() + +router.use(rootRoutes) + +// 404 +router.use((req, res) => { + res.status(404).send('E404') +}) + +module.exports = router diff --git a/_old/src/skeletons/express-js/src/routes/rootRoutes.js b/_old/src/skeletons/express-js/src/routes/rootRoutes.js new file mode 100644 index 0000000..9d0925b --- /dev/null +++ b/_old/src/skeletons/express-js/src/routes/rootRoutes.js @@ -0,0 +1,8 @@ +const { Router } = require('express') +const rootController = require('../controllers/rootController') + +const router = Router() + +router.get('/', rootController.root_get) + +module.exports = router diff --git a/_old/src/skeletons/express-js/src/tests/home.test.js b/_old/src/skeletons/express-js/src/tests/home.test.js new file mode 100644 index 0000000..188e0c3 --- /dev/null +++ b/_old/src/skeletons/express-js/src/tests/home.test.js @@ -0,0 +1,9 @@ +const { getReq, getRes } = require('./modules/reqRes.module.js') +const { root_get } = require('../controllers/rootController.js') + +test('Home page render test', () => { + const req = getReq() + const res = getRes() + + expect(root_get(req, res)).toBe(true) +}) diff --git a/_old/src/skeletons/express-js/src/tests/modules/reqRes.module.js b/_old/src/skeletons/express-js/src/tests/modules/reqRes.module.js new file mode 100644 index 0000000..0341a26 --- /dev/null +++ b/_old/src/skeletons/express-js/src/tests/modules/reqRes.module.js @@ -0,0 +1,16 @@ +module.exports.getReq = () => { + const req = {} + req.body = {} + return req +} + +module.exports.getRes = () => { + const res = {} + res.locals = {} + res.status = () => res + res.json = () => res + res.send = () => res + res.render = () => res + + return res +} diff --git a/_old/src/skeletons/express-js/src/utils/REAME.md b/_old/src/skeletons/express-js/src/utils/REAME.md new file mode 100644 index 0000000..4a554e0 --- /dev/null +++ b/_old/src/skeletons/express-js/src/utils/REAME.md @@ -0,0 +1 @@ +# Folder for utils and other config files \ No newline at end of file diff --git a/_old/src/skeletons/express-js/src/views/home.ejs b/_old/src/skeletons/express-js/src/views/home.ejs new file mode 100644 index 0000000..d841985 --- /dev/null +++ b/_old/src/skeletons/express-js/src/views/home.ejs @@ -0,0 +1,69 @@ + + + + + + + New Project + + + + + + +
+
+

Let's make something amazing!

+
+ node.js logo + express.js logo +
+
+ +
+ + \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/.gitignore b/_old/src/skeletons/express-ts/.gitignore new file mode 100644 index 0000000..66e0c76 --- /dev/null +++ b/_old/src/skeletons/express-ts/.gitignore @@ -0,0 +1,107 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# Next.js build output +.next + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and *not* Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# package lock file +package-lock.json \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/README.md b/_old/src/skeletons/express-ts/README.md new file mode 100644 index 0000000..420f4d2 --- /dev/null +++ b/_old/src/skeletons/express-ts/README.md @@ -0,0 +1 @@ +# New Project diff --git a/_old/src/skeletons/express-ts/jest.config.js b/_old/src/skeletons/express-ts/jest.config.js new file mode 100644 index 0000000..5839600 --- /dev/null +++ b/_old/src/skeletons/express-ts/jest.config.js @@ -0,0 +1,5 @@ +/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */ +module.exports = { + preset: 'ts-jest', + testEnvironment: 'node', +}; \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/norkconfig.json b/_old/src/skeletons/express-ts/norkconfig.json new file mode 100644 index 0000000..265d99b --- /dev/null +++ b/_old/src/skeletons/express-ts/norkconfig.json @@ -0,0 +1,3 @@ +{ + "lang": "ts" +} \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/package.json b/_old/src/skeletons/express-ts/package.json new file mode 100644 index 0000000..4ae4d96 --- /dev/null +++ b/_old/src/skeletons/express-ts/package.json @@ -0,0 +1,62 @@ +{ + "name": "project-name", + "version": "1.0.0", + "description": "", + "main": "app.js", + "scripts": { + "start": "node -r tsconfig-paths/register -r ts-node/register dist/server.js", + "dev": "nodemon src/server.ts", + "test": "jest", + "clean": "rimraf dist/*", + "copy-assets": "ts-node src/utils/copyAssets", + "tsc": "tsc -p .", + "build": "npm-run-all clean tsc copy-assets" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "colors": "^1.4.0", + "cookie-parser": "^1.4.5", + "cors": "^2.8.5", + "dotenv": "^8.2.0", + "ejs": "^3.1.6", + "express": "^4.17.1", + "fs-extra": "^10.0.0", + "mongoose": "^5.12.3", + "morgan": "^1.10.0" + }, + "devDependencies": { + "@types/cookie-parser": "^1.4.2", + "@types/cors": "^2.8.10", + "@types/ejs": "^3.0.6", + "@types/express": "^4.17.11", + "@types/fs-extra": "^9.0.12", + "@types/jest": "^27.0.1", + "@types/mongoose": "^5.10.5", + "@types/morgan": "^1.9.2", + "@types/node": "^14.14.41", + "@types/shelljs": "^0.8.9", + "jest": "^27.0.6", + "npm-run-all": "^4.1.5", + "rimraf": "^3.0.2", + "shelljs": "^0.8.4", + "ts-jest": "^27.0.5", + "ts-node": "^9.1.1", + "tsconfig-paths": "^3.11.0", + "typescript": "^4.2.4" + }, + "nodemonConfig": { + "ignore": [ + "**/*.test.ts", + "**/*.spec.ts", + ".git", + "node_modules" + ], + "watch": [ + "src" + ], + "exec": "node -r tsconfig-paths/register -r ts-node/register ./src/server.ts", + "ext": "ts, js" + } +} \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/src/.env.example b/_old/src/skeletons/express-ts/src/.env.example new file mode 100644 index 0000000..b1a432b --- /dev/null +++ b/_old/src/skeletons/express-ts/src/.env.example @@ -0,0 +1,2 @@ +APP_PORT = 8080 +DB_URI = 'mongodb://username:password@localhost:27017/database?authSource=admin' diff --git a/_old/src/skeletons/express-ts/src/app.js b/_old/src/skeletons/express-ts/src/app.js new file mode 100644 index 0000000..9e7e22f --- /dev/null +++ b/_old/src/skeletons/express-ts/src/app.js @@ -0,0 +1,39 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.app = void 0; +const express_1 = __importDefault(require("express")); +const morgan_1 = __importDefault(require("morgan")); +const path_1 = __importDefault(require("path")); +const cors_1 = __importDefault(require("cors")); +const cookie_parser_1 = __importDefault(require("cookie-parser")); +const routes_1 = require("@/routes"); +const middlewares_1 = require("@/middlewares"); +const corsWhitelist = ['http://localhost:8080', 'http://localhost:6060']; +const corsOptions = { + origin: function (origin, callback) { + if (!origin || corsWhitelist.indexOf(origin) !== -1) { + callback(null, true); + } + else { + callback(new Error('Not allowed by CORS')); + } + }, + optionsSuccessStatus: 200, + credentials: true, +}; +exports.app = (0, express_1.default)(); +// Middlewares +exports.app.use(middlewares_1.router); +exports.app.set('view engine', 'ejs'); +exports.app.set('views', path_1.default.join(__dirname, 'views')); +exports.app.use((0, cors_1.default)(corsOptions)); +exports.app.use((0, morgan_1.default)('dev')); +exports.app.use(express_1.default.urlencoded({ extended: true })); +exports.app.use(express_1.default.json()); +exports.app.use(express_1.default.static(path_1.default.join(__dirname, 'public'))); +exports.app.use((0, cookie_parser_1.default)()); +// Routes +exports.app.use(routes_1.router); diff --git a/_old/src/skeletons/express-ts/src/app.ts b/_old/src/skeletons/express-ts/src/app.ts new file mode 100644 index 0000000..f190a11 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/app.ts @@ -0,0 +1,36 @@ +import express from 'express' +import morgan from 'morgan' +import path from 'path' +import cors from 'cors' +import cookieParser from 'cookie-parser' +import { router as routes } from '@/routes' +import { router as middlewares } from '@/middlewares' + +const corsWhitelist = ['http://localhost:8080', 'http://localhost:6060'] +const corsOptions = { + origin: function (origin: any, callback: any) { + if (!origin || corsWhitelist.indexOf(origin) !== -1) { + callback(null, true) + } else { + callback(new Error('Not allowed by CORS')) + } + }, + optionsSuccessStatus: 200, + credentials: true, +} + +export const app = express() + +// Middlewares +app.use(middlewares) +app.set('view engine', 'ejs') +app.set('views', path.join(__dirname, 'views')) +app.use(cors(corsOptions)) +app.use(morgan('dev')) +app.use(express.urlencoded({ extended: true })) +app.use(express.json()) +app.use(express.static(path.join(__dirname, 'public'))) +app.use(cookieParser()) + +// Routes +app.use(routes) diff --git a/_old/src/skeletons/express-ts/src/controllers/rootController.js b/_old/src/skeletons/express-ts/src/controllers/rootController.js new file mode 100644 index 0000000..68705a9 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/controllers/rootController.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.root_get = void 0; +const root_get = (req, res) => { + res.render('home'); + return true; +}; +exports.root_get = root_get; diff --git a/_old/src/skeletons/express-ts/src/controllers/rootController.ts b/_old/src/skeletons/express-ts/src/controllers/rootController.ts new file mode 100644 index 0000000..4a94a0d --- /dev/null +++ b/_old/src/skeletons/express-ts/src/controllers/rootController.ts @@ -0,0 +1,6 @@ +import { Request, Response } from 'express' + +export const root_get = (req: Request, res: Response) => { + res.render('home') + return true +} diff --git a/_old/src/skeletons/express-ts/src/interfaces/globalInterface.js b/_old/src/skeletons/express-ts/src/interfaces/globalInterface.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/interfaces/globalInterface.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/_old/src/skeletons/express-ts/src/interfaces/globalInterface.ts b/_old/src/skeletons/express-ts/src/interfaces/globalInterface.ts new file mode 100644 index 0000000..4f4e882 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/interfaces/globalInterface.ts @@ -0,0 +1,4 @@ +export interface ErrType { + code: number + message: string +} diff --git a/_old/src/skeletons/express-ts/src/middlewares/index.js b/_old/src/skeletons/express-ts/src/middlewares/index.js new file mode 100644 index 0000000..db6924b --- /dev/null +++ b/_old/src/skeletons/express-ts/src/middlewares/index.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const sayHiMiddleware_1 = require("@/middlewares/sayHiMiddleware"); +exports.router = (0, express_1.Router)(); +exports.router.use(sayHiMiddleware_1.router); diff --git a/_old/src/skeletons/express-ts/src/middlewares/index.ts b/_old/src/skeletons/express-ts/src/middlewares/index.ts new file mode 100644 index 0000000..3ac1fdb --- /dev/null +++ b/_old/src/skeletons/express-ts/src/middlewares/index.ts @@ -0,0 +1,6 @@ +import { Router } from 'express' +import { router as sayHiMiddleware } from '@/middlewares/sayHiMiddleware' + +export const router = Router() + +router.use(sayHiMiddleware) diff --git a/_old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js b/_old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js new file mode 100644 index 0000000..097d0c8 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +exports.router = (0, express_1.Router)(); +exports.router.use((req, res, next) => { + console.log('Hi :)'); + next(); +}); diff --git a/_old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.ts b/_old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.ts new file mode 100644 index 0000000..bc3a6e1 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.ts @@ -0,0 +1,9 @@ +import { Router, Request, Response, NextFunction } from 'express' + +export const router = Router() + +router.use((req: Request, res: Response, next: NextFunction) => { + console.log('Hi :)') + + next() +}) diff --git a/_old/src/skeletons/express-ts/src/public/expressjs.png b/_old/src/skeletons/express-ts/src/public/expressjs.png new file mode 100644 index 0000000000000000000000000000000000000000..487c5a83af37b9b93507a08a761c0788c764b169 GIT binary patch literal 5032 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 literal 0 HcmV?d00001 diff --git a/_old/src/skeletons/express-ts/src/public/nodejs_logo.svg b/_old/src/skeletons/express-ts/src/public/nodejs_logo.svg new file mode 100644 index 0000000..41d044a --- /dev/null +++ b/_old/src/skeletons/express-ts/src/public/nodejs_logo.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/src/routes/index.js b/_old/src/skeletons/express-ts/src/routes/index.js new file mode 100644 index 0000000..238a7fd --- /dev/null +++ b/_old/src/skeletons/express-ts/src/routes/index.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const rootRoutes_1 = require("./rootRoutes"); +exports.router = (0, express_1.Router)(); +exports.router.use(rootRoutes_1.router); +// 404 +exports.router.use((req, res) => { + res.status(404).send('E404'); +}); diff --git a/_old/src/skeletons/express-ts/src/routes/index.ts b/_old/src/skeletons/express-ts/src/routes/index.ts new file mode 100644 index 0000000..fec3481 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/routes/index.ts @@ -0,0 +1,11 @@ +import { Request, Response, Router } from 'express' +import { router as rootRoutes } from './rootRoutes' + +export const router = Router() + +router.use(rootRoutes) + +// 404 +router.use((req: Request, res: Response) => { + res.status(404).send('E404') +}) diff --git a/_old/src/skeletons/express-ts/src/routes/rootRoutes.js b/_old/src/skeletons/express-ts/src/routes/rootRoutes.js new file mode 100644 index 0000000..8102385 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/routes/rootRoutes.js @@ -0,0 +1,26 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const rootController = __importStar(require("@/controllers/rootController")); +exports.router = (0, express_1.Router)(); +exports.router.get('/', rootController.root_get); diff --git a/_old/src/skeletons/express-ts/src/routes/rootRoutes.ts b/_old/src/skeletons/express-ts/src/routes/rootRoutes.ts new file mode 100644 index 0000000..7374556 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/routes/rootRoutes.ts @@ -0,0 +1,6 @@ +import { Router } from 'express' +import * as rootController from '@/controllers/rootController' + +export const router = Router() + +router.get('/', rootController.root_get) diff --git a/_old/src/skeletons/express-ts/src/server.js b/_old/src/skeletons/express-ts/src/server.js new file mode 100644 index 0000000..c102952 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/server.js @@ -0,0 +1,27 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +const app_1 = require("@/app"); +const environment_1 = __importDefault(require("@/utils/environment")); +const globalService_1 = require("@/services/globalService"); +const port = environment_1.default.APP_PORT || 8080; +// MongoDB +const dbURI = environment_1.default.DB_URI; +mongoose_1.default + .connect(dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, + useCreateIndex: true, +}) + .then(() => { + new globalService_1.Succ(200, 'connected to db'); + app_1.app.listen(port, () => { + new globalService_1.Succ(200, `Server is listening on http://localhost:${port}`); + }); +}) + .catch((err) => { + new globalService_1.Err(500, err); +}); diff --git a/_old/src/skeletons/express-ts/src/server.ts b/_old/src/skeletons/express-ts/src/server.ts new file mode 100644 index 0000000..7943293 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/server.ts @@ -0,0 +1,24 @@ +import mongoose from 'mongoose' +import { app } from '@/app' +import config from '@/utils/environment' +import { Err, Succ } from '@/services/globalService' + +const port: Number = config.APP_PORT || 8080 + +// MongoDB +const dbURI: string = config.DB_URI +mongoose + .connect(dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, + useCreateIndex: true, + }) + .then(() => { + new Succ(200, 'connected to db') + app.listen(port, () => { + new Succ(200, `Server is listening on http://localhost:${port}`) + }) + }) + .catch((err: any) => { + new Err(500, err) + }) diff --git a/_old/src/skeletons/express-ts/src/services/globalService.js b/_old/src/skeletons/express-ts/src/services/globalService.js new file mode 100644 index 0000000..b162618 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/services/globalService.js @@ -0,0 +1,37 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Succ = exports.Err = void 0; +const colors_1 = __importDefault(require("colors")); +class Err { + constructor(code, message) { + this.code = code; + this.message = message; + this.drop(); + } + drop() { + console.log(colors_1.default.bgRed(`${this.code}`) + colors_1.default.bgBlack.red(` ${this.message}`)); + return { + code: this.code, + message: this.message, + }; + } +} +exports.Err = Err; +class Succ { + constructor(code, message) { + this.code = code; + this.message = message; + this.drop(); + } + drop() { + console.log(colors_1.default.bgGreen.black(`${this.code}`) + colors_1.default.green.bgBlack(` ${this.message}`)); + return { + code: this.code, + message: this.message, + }; + } +} +exports.Succ = Succ; diff --git a/_old/src/skeletons/express-ts/src/services/globalService.ts b/_old/src/skeletons/express-ts/src/services/globalService.ts new file mode 100644 index 0000000..9464eed --- /dev/null +++ b/_old/src/skeletons/express-ts/src/services/globalService.ts @@ -0,0 +1,40 @@ +import colors from 'colors' +import { ErrType } from '@/interfaces/globalInterface' + +export class Err implements ErrType { + code: number + message: string + + constructor(code: number, message: string) { + this.code = code + this.message = message + this.drop() + } + + drop() { + console.log(colors.bgRed(`${this.code}`) + colors.bgBlack.red(` ${this.message}`)) + return { + code: this.code, + message: this.message, + } + } +} + +export class Succ { + code: number + message: string + + constructor(code: number, message: string) { + this.code = code + this.message = message + this.drop() + } + + drop() { + console.log(colors.bgGreen.black(`${this.code}`) + colors.green.bgBlack(` ${this.message}`)) + return { + code: this.code, + message: this.message, + } + } +} diff --git a/_old/src/skeletons/express-ts/src/services/rootService.js b/_old/src/skeletons/express-ts/src/services/rootService.js new file mode 100644 index 0000000..4fb2c86 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/services/rootService.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.helloWorld = void 0; +const helloWorld = () => { + console.log('hello world'); +}; +exports.helloWorld = helloWorld; diff --git a/_old/src/skeletons/express-ts/src/services/rootService.ts b/_old/src/skeletons/express-ts/src/services/rootService.ts new file mode 100644 index 0000000..75ca5d8 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/services/rootService.ts @@ -0,0 +1,3 @@ +export const helloWorld = () => { + console.log('hello world') +} diff --git a/_old/src/skeletons/express-ts/src/tests/home.test.js b/_old/src/skeletons/express-ts/src/tests/home.test.js new file mode 100644 index 0000000..7949993 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/tests/home.test.js @@ -0,0 +1,9 @@ +const { getReq, getRes } = require('./modules/reqRes.module.js') +const { root_get } = require('../controllers/rootController.ts') + +test('Home page render test', () => { + const req = getReq() + const res = getRes() + + expect(root_get(req, res)).toBe(true) +}) diff --git a/_old/src/skeletons/express-ts/src/tests/modules/reqRes.module.js b/_old/src/skeletons/express-ts/src/tests/modules/reqRes.module.js new file mode 100644 index 0000000..0341a26 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/tests/modules/reqRes.module.js @@ -0,0 +1,16 @@ +module.exports.getReq = () => { + const req = {} + req.body = {} + return req +} + +module.exports.getRes = () => { + const res = {} + res.locals = {} + res.status = () => res + res.json = () => res + res.send = () => res + res.render = () => res + + return res +} diff --git a/_old/src/skeletons/express-ts/src/utils/copyAssets.js b/_old/src/skeletons/express-ts/src/utils/copyAssets.js new file mode 100644 index 0000000..84d71ec --- /dev/null +++ b/_old/src/skeletons/express-ts/src/utils/copyAssets.js @@ -0,0 +1,27 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const shell = __importStar(require("shelljs")); +// Copy all the view templates +shell.cp('-R', 'src/views', 'dist/'); +shell.cp('-R', 'src/public', 'dist/'); +shell.cp('-R', 'src/models', 'dist/'); +shell.cp('-u', 'src/.env', 'dist/'); diff --git a/_old/src/skeletons/express-ts/src/utils/copyAssets.ts b/_old/src/skeletons/express-ts/src/utils/copyAssets.ts new file mode 100644 index 0000000..658c4c5 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/utils/copyAssets.ts @@ -0,0 +1,7 @@ +import * as shell from 'shelljs' + +// Copy all the view templates +shell.cp('-R', 'src/views', 'dist/') +shell.cp('-R', 'src/public', 'dist/') +shell.cp('-R', 'src/models', 'dist/') +shell.cp('-u', 'src/.env', 'dist/') diff --git a/_old/src/skeletons/express-ts/src/utils/environment.js b/_old/src/skeletons/express-ts/src/utils/environment.js new file mode 100644 index 0000000..5aaf9d9 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/utils/environment.js @@ -0,0 +1,11 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_1 = __importDefault(require("path")); +require('dotenv').config({ path: path_1.default.join(__dirname, '../.env') }); +exports.default = { + APP_PORT: Number(process.env.APP_PORT), + DB_URI: String(process.env.DB_URI), +}; diff --git a/_old/src/skeletons/express-ts/src/utils/environment.ts b/_old/src/skeletons/express-ts/src/utils/environment.ts new file mode 100644 index 0000000..6280b67 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/utils/environment.ts @@ -0,0 +1,7 @@ +import path from 'path' +require('dotenv').config({ path: path.join(__dirname, '../.env') }) + +export default { + APP_PORT: Number(process.env.APP_PORT), + DB_URI: String(process.env.DB_URI), +} diff --git a/_old/src/skeletons/express-ts/src/views/home.ejs b/_old/src/skeletons/express-ts/src/views/home.ejs new file mode 100644 index 0000000..d841985 --- /dev/null +++ b/_old/src/skeletons/express-ts/src/views/home.ejs @@ -0,0 +1,69 @@ + + + + + + + New Project + + + + + + +
+
+

Let's make something amazing!

+
+ node.js logo + express.js logo +
+
+ +
+ + \ No newline at end of file diff --git a/_old/src/skeletons/express-ts/tsconfig.json b/_old/src/skeletons/express-ts/tsconfig.json new file mode 100644 index 0000000..8f4eb08 --- /dev/null +++ b/_old/src/skeletons/express-ts/tsconfig.json @@ -0,0 +1,85 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', 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', 'react', 'react-jsx' or 'react-jsxdev'. */ + // "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": "./dist", /* Redirect output structure to the directory. */ + "rootDir": "./src", /* 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": true, /* 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. */ + // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */ + // "noPropertyAccessFromIndexSignature": true, /* Require undeclared properties from index signatures to use element accesses. */ + + /* 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": { + "@/*": ["src/","src/*"], + "@dist/*": ["dist/*"], + "@controllers/*": ["src/controllers/"], + "@interfaces/*": ["src/interfaces/*"], + "@middlewares/*": ["src/middlewares/*"], + "@models/*": ["src/models/*"], + "@public/*": ["src/public/*"], + "@routes/*": ["src/routes/*"], + "@services/*": ["src/services/*"], + "@test/*": ["src/test/*"], + "@utils/*": ["src/utils/*"], + "@validators/*": ["src/validators/*"], + "@views/*": ["src/views/*"], + }, + // "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. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} diff --git a/norkconfig.json b/norkconfig.json new file mode 100644 index 0000000..3e80a47 --- /dev/null +++ b/norkconfig.json @@ -0,0 +1 @@ +{"lang":"ts"} diff --git a/package.json b/package.json index 2866afb..37eba83 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,15 @@ { "name": "nork", - "version": "1.2.1", + "version": "2.0.0.1", "description": "The best node.js 'framework' :)", - "main": "src/app.js", - "bin": "src/app.js", + "main": "dist/app.js", + "bin": "dist/app.js", "scripts": { - "start": "node src/app.js" + "start": "npm run start:prod", + "start:dev": "ts-node src/app.ts", + "start:prod": "node dist/app.js", + "build": "rimraf dist && tsc -p .", + "test": "mocha --config .mocharc.json --watch src/**/*.test.ts" }, "keywords": [ "node", @@ -21,6 +25,20 @@ "inquirer": "^8.1.2", "pad": "^3.2.0" }, + "devDependencies": { + "@types/chai": "^4.2.22", + "@types/fs-extra": "^9.0.13", + "@types/inquirer": "^8.1.3", + "@types/mocha": "^9.0.0", + "@typescript-eslint/eslint-plugin": "^5.5.0", + "@typescript-eslint/parser": "^5.5.0", + "chai": "^4.3.4", + "eslint": "^8.3.0", + "mocha": "^9.1.3", + "rimraf": "^3.0.2", + "ts-node": "^10.4.0", + "typescript": "^4.5.2" + }, "repository": { "type": "git", "url": "git+https://github.com/filiprojek/nork.git" @@ -29,4 +47,4 @@ "url": "https://github.com/filiprojek/nork/issues" }, "homepage": "https://github.com/filiprojek/nork/blob/master/README.md" -} \ No newline at end of file +} diff --git a/progress-blog.md b/progress-blog.md new file mode 100644 index 0000000..f9f3454 --- /dev/null +++ b/progress-blog.md @@ -0,0 +1,10 @@ +/* spell-checker: disable */ + +### 11-24-2021 +- zacal jsem predelavat nork do OOP +- co jsem udelal: + - [x] --help + - [x] --version + - [x] setup + - [x] make + - [ ] create \ No newline at end of file diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..aa5fc3f --- /dev/null +++ b/src/app.ts @@ -0,0 +1,9 @@ +import Routes from './routes' + +export class App { + constructor() { + Routes.router() + } +} + +new App() diff --git a/src/controllers/test.ts b/src/controllers/test.ts new file mode 100644 index 0000000..4a94a0d --- /dev/null +++ b/src/controllers/test.ts @@ -0,0 +1,6 @@ +import { Request, Response } from 'express' + +export const root_get = (req: Request, res: Response) => { + res.render('home') + return true +} diff --git a/src/controllers/undefined.ts b/src/controllers/undefined.ts new file mode 100644 index 0000000..4a94a0d --- /dev/null +++ b/src/controllers/undefined.ts @@ -0,0 +1,6 @@ +import { Request, Response } from 'express' + +export const root_get = (req: Request, res: Response) => { + res.render('home') + return true +} diff --git a/src/global.ts b/src/global.ts new file mode 100644 index 0000000..9739a7a --- /dev/null +++ b/src/global.ts @@ -0,0 +1,16 @@ +import colors from 'colors' + +export default class Global { + static logSuccess = (msg: boolean | string = false): string => { + if (!msg) { + msg = 'Success!' + } + console.log(colors.cyan(String(msg))) + return String(msg) + } + + static logError(errorMsg: string) { + console.log(colors.bgYellow.red(errorMsg)) + return + } +} diff --git a/src/help.ts b/src/help.ts new file mode 100644 index 0000000..b48cd75 --- /dev/null +++ b/src/help.ts @@ -0,0 +1,66 @@ +import pad from 'pad' +import colors from 'colors' + +export default class Help { + constructor() { + // this.logHelp() + } + // log help & returns status in string for tests + static makeHelp(): string { + const spc = 27 + return ` +Usage: make:[component] + +${pad(' make controller [name]', spc)} create a new controller +${pad(' make middleware [name]', spc)} create a new middleware +${pad(' make model [name]', spc)} create a new model +${pad(' make route [name]', spc)} create a new route +${pad(' make test [name]', spc)} create a new test +${pad(' make view [name]', spc)} create a new view + ` + } + + static allHelp(): string { + const spc = 27 + + return ` +Usage: nork [options] + +Options: +${pad(' -v, --version', spc)} output the version number +${pad(' -h, --help', spc)} output usage information + +Commands: +${pad(' create [app-name]', spc)} create a new project +${pad(' create [app-name] -i', spc)} create a new project in current directory +${pad(' make controller [name]', spc)} create a new controller +${pad(' make interface [name]', spc)} create a new interface +${pad(' make middleware [name]', spc)} create a new middleware +${pad(' make model [name]', spc)} create a new model +${pad(' make route [name]', spc)} create a new route +${pad(' make service [name]', spc)} create a new service +${pad(' make test [name]', spc)} create a new test +${pad(' make view [name]', spc)} create a new view +${pad(' setup', spc)} set up an existing project for nork + + Run ${colors.cyan('nork help ')} for detailed usage of given command. + ` + } + + static specificHelp(specific: string): string { + return `Usage: ${specific} [options]` + } + + static logHelp = (specific: boolean | string = false): string => { + if (specific) { + // log specific help + if (specific == 'make') { + return this.makeHelp() + } + // else return specific help + return this.specificHelp(String(specific)) + } + // if nothing return help all + return this.allHelp() + } +} diff --git a/src/interfaces/GlobalInterface.ts b/src/interfaces/GlobalInterface.ts new file mode 100644 index 0000000..8ae4c94 --- /dev/null +++ b/src/interfaces/GlobalInterface.ts @@ -0,0 +1,3 @@ +export interface Norkcfg { + lang: string +} diff --git a/src/interfaces/SetupInterface.ts b/src/interfaces/SetupInterface.ts new file mode 100644 index 0000000..8681030 --- /dev/null +++ b/src/interfaces/SetupInterface.ts @@ -0,0 +1,15 @@ +export interface Questions { + type: string + message: string + name: string + choices: [ + { + name: string + value: string + }, + { + name: string + value: string + }, + ] +} diff --git a/src/interfaces/test.ts b/src/interfaces/test.ts new file mode 100644 index 0000000..727a759 --- /dev/null +++ b/src/interfaces/test.ts @@ -0,0 +1,4 @@ +export interface interfaceName { + hello: string + world: boolean | null | undefined +} diff --git a/src/interfaces/undefined.ts b/src/interfaces/undefined.ts new file mode 100644 index 0000000..727a759 --- /dev/null +++ b/src/interfaces/undefined.ts @@ -0,0 +1,4 @@ +export interface interfaceName { + hello: string + world: boolean | null | undefined +} diff --git a/src/make.ts b/src/make.ts new file mode 100644 index 0000000..81e1454 --- /dev/null +++ b/src/make.ts @@ -0,0 +1,76 @@ +import path from 'path' +import fs from 'fs-extra' +import global from './global' +import { Norkcfg } from './interfaces/GlobalInterface' + +export default class Make { + static component(component: string) { + // const norkcfg = require(path.join(process.cwd(), 'norkconfig.json')) + const norkcfg: Norkcfg = fs.readJsonSync(path.join(process.cwd(), 'norkconfig.json')) + + const tsComponents = ['controller', 'middleware', 'route', 'service'] + + if (tsComponents.includes(component)) { + const src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.' + norkcfg.lang) + const dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.' + norkcfg.lang) + + try { + fs.copySync(src, dest, { overwrite: false, errorOnExist: true }) + } catch (err: any) { + return global.logError(err.message) + } + return global.logSuccess() + } + + if (component == 'model') { + const src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.' + norkcfg.lang) + const dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.' + norkcfg.lang) + try { + fs.copySync(src, dest, { overwrite: false, errorOnExist: true }) + } catch (err: any) { + return global.logError(err.message) + } + return global.logSuccess() + } + + if (component == 'view') { + const src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.ejs') + const dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.ejs') + + try { + fs.copySync(src, dest, { overwrite: false, errorOnExist: true }) + } catch (err: any) { + return global.logError(err.message) + } + return global.logSuccess() + } + + if (component == 'test') { + const src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.js') + const dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.test.js') + + try { + fs.copySync(src, dest, { overwrite: false, errorOnExist: true }) + } catch (err: any) { + return global.logError(err.message) + } + return global.logSuccess() + } + if (component == 'interface') { + if (norkcfg.lang != 'ts') { + return global.logError('error - this is typescript only component') + } + const src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.ts') + const dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.ts') + + try { + fs.copySync(src, dest, { overwrite: false, errorOnExist: true }) + } catch (err: any) { + return global.logError(err.message) + } + return global.logSuccess() + } + + return global.logError(`error - unknown component ${component}`) + } +} diff --git a/src/middlewares/test.ts b/src/middlewares/test.ts new file mode 100644 index 0000000..32accc2 --- /dev/null +++ b/src/middlewares/test.ts @@ -0,0 +1,8 @@ +import { Router, Request, Response, NextFunction } from 'express' + +export const router = Router() + +router.use((req: Request, res: Response, next: NextFunction) => { + console.log('Hi :)') + next() +}) diff --git a/src/middlewares/undefined.ts b/src/middlewares/undefined.ts new file mode 100644 index 0000000..32accc2 --- /dev/null +++ b/src/middlewares/undefined.ts @@ -0,0 +1,8 @@ +import { Router, Request, Response, NextFunction } from 'express' + +export const router = Router() + +router.use((req: Request, res: Response, next: NextFunction) => { + console.log('Hi :)') + next() +}) diff --git a/src/models/test.ts b/src/models/test.ts new file mode 100644 index 0000000..cc22d18 --- /dev/null +++ b/src/models/test.ts @@ -0,0 +1,15 @@ +import { Schema, model } from 'mongoose' + +const modelSchema = new Schema( + { + title: { + type: String, + required: true, + }, + }, + { + timestamps: true, + }, +) + +export default model('ModelName', modelSchema) diff --git a/src/models/undefined.ts b/src/models/undefined.ts new file mode 100644 index 0000000..cc22d18 --- /dev/null +++ b/src/models/undefined.ts @@ -0,0 +1,15 @@ +import { Schema, model } from 'mongoose' + +const modelSchema = new Schema( + { + title: { + type: String, + required: true, + }, + }, + { + timestamps: true, + }, +) + +export default model('ModelName', modelSchema) diff --git a/src/routes.ts b/src/routes.ts new file mode 100644 index 0000000..eb73382 --- /dev/null +++ b/src/routes.ts @@ -0,0 +1,41 @@ +import Help from './help' +import Version from './version' +import Setup from './setup' +import Make from './make' + +export default class Routes { + static router(): string { + if (process.argv[2] == 'help' || process.argv[2] == '-h' || process.argv[2] == '--help') { + if (process.argv[3]) { + console.log(Help.logHelp(process.argv[3])) + return 'specific help' + } + console.log(Help.logHelp()) + return 'all help' + } + + if (process.argv[2] == '-v' || process.argv[2] == '--version') { + console.log(Version.show()) + return 'version' + } + + if (process.argv[2] == 'setup') { + if (process.argv[3] != 'test') { + Setup.setup() + } + return 'setup' + } + + if (process.argv[2] == 'make') { + if (process.argv[3]) { + if (process.argv[4] != 'test') { + Make.component(process.argv[3]) + } + return `make ${process.argv[3]}` + } + } + + console.log(Help.logHelp()) + return 'all help' + } +} diff --git a/src/routes/test.ts b/src/routes/test.ts new file mode 100644 index 0000000..7374556 --- /dev/null +++ b/src/routes/test.ts @@ -0,0 +1,6 @@ +import { Router } from 'express' +import * as rootController from '@/controllers/rootController' + +export const router = Router() + +router.get('/', rootController.root_get) diff --git a/src/routes/undefined.ts b/src/routes/undefined.ts new file mode 100644 index 0000000..7374556 --- /dev/null +++ b/src/routes/undefined.ts @@ -0,0 +1,6 @@ +import { Router } from 'express' +import * as rootController from '@/controllers/rootController' + +export const router = Router() + +router.get('/', rootController.root_get) diff --git a/src/services/test.ts b/src/services/test.ts new file mode 100644 index 0000000..ccb388e --- /dev/null +++ b/src/services/test.ts @@ -0,0 +1,3 @@ +export function helloWorld() { + console.log('hello world') +} diff --git a/src/services/undefined.ts b/src/services/undefined.ts new file mode 100644 index 0000000..ccb388e --- /dev/null +++ b/src/services/undefined.ts @@ -0,0 +1,3 @@ +export function helloWorld() { + console.log('hello world') +} diff --git a/src/setup.ts b/src/setup.ts new file mode 100644 index 0000000..d556aea --- /dev/null +++ b/src/setup.ts @@ -0,0 +1,24 @@ +import inquirer from 'inquirer' +import fs from 'fs-extra' +import path from 'path' +import Global from './global' +import { Questions } from './interfaces/SetupInterface' + +export default class Setup { + static async setup(test = false) { + if (!test) { + const questions: Questions = { + type: 'list', + message: `Pick the technology you're using:`, + name: 'lang', + choices: [ + { name: 'Typescript', value: 'ts' }, + { name: 'Javascript', value: 'js' }, + ], + } + const answers = await inquirer.prompt(Object(questions)) + fs.writeJsonSync(path.join(process.cwd(), './norkconfig.json'), answers) + } + return Global.logSuccess() + } +} diff --git a/src/skeletons/express-ts/src/app.js b/src/skeletons/express-ts/src/app.js new file mode 100644 index 0000000..9e7e22f --- /dev/null +++ b/src/skeletons/express-ts/src/app.js @@ -0,0 +1,39 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.app = void 0; +const express_1 = __importDefault(require("express")); +const morgan_1 = __importDefault(require("morgan")); +const path_1 = __importDefault(require("path")); +const cors_1 = __importDefault(require("cors")); +const cookie_parser_1 = __importDefault(require("cookie-parser")); +const routes_1 = require("@/routes"); +const middlewares_1 = require("@/middlewares"); +const corsWhitelist = ['http://localhost:8080', 'http://localhost:6060']; +const corsOptions = { + origin: function (origin, callback) { + if (!origin || corsWhitelist.indexOf(origin) !== -1) { + callback(null, true); + } + else { + callback(new Error('Not allowed by CORS')); + } + }, + optionsSuccessStatus: 200, + credentials: true, +}; +exports.app = (0, express_1.default)(); +// Middlewares +exports.app.use(middlewares_1.router); +exports.app.set('view engine', 'ejs'); +exports.app.set('views', path_1.default.join(__dirname, 'views')); +exports.app.use((0, cors_1.default)(corsOptions)); +exports.app.use((0, morgan_1.default)('dev')); +exports.app.use(express_1.default.urlencoded({ extended: true })); +exports.app.use(express_1.default.json()); +exports.app.use(express_1.default.static(path_1.default.join(__dirname, 'public'))); +exports.app.use((0, cookie_parser_1.default)()); +// Routes +exports.app.use(routes_1.router); diff --git a/src/skeletons/express-ts/src/controllers/rootController.js b/src/skeletons/express-ts/src/controllers/rootController.js new file mode 100644 index 0000000..68705a9 --- /dev/null +++ b/src/skeletons/express-ts/src/controllers/rootController.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.root_get = void 0; +const root_get = (req, res) => { + res.render('home'); + return true; +}; +exports.root_get = root_get; diff --git a/src/skeletons/express-ts/src/interfaces/globalInterface.js b/src/skeletons/express-ts/src/interfaces/globalInterface.js new file mode 100644 index 0000000..c8ad2e5 --- /dev/null +++ b/src/skeletons/express-ts/src/interfaces/globalInterface.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/src/skeletons/express-ts/src/middlewares/index.js b/src/skeletons/express-ts/src/middlewares/index.js new file mode 100644 index 0000000..db6924b --- /dev/null +++ b/src/skeletons/express-ts/src/middlewares/index.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const sayHiMiddleware_1 = require("@/middlewares/sayHiMiddleware"); +exports.router = (0, express_1.Router)(); +exports.router.use(sayHiMiddleware_1.router); diff --git a/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js b/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js new file mode 100644 index 0000000..097d0c8 --- /dev/null +++ b/src/skeletons/express-ts/src/middlewares/sayHiMiddleware.js @@ -0,0 +1,9 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +exports.router = (0, express_1.Router)(); +exports.router.use((req, res, next) => { + console.log('Hi :)'); + next(); +}); diff --git a/src/skeletons/express-ts/src/routes/index.js b/src/skeletons/express-ts/src/routes/index.js new file mode 100644 index 0000000..238a7fd --- /dev/null +++ b/src/skeletons/express-ts/src/routes/index.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const rootRoutes_1 = require("./rootRoutes"); +exports.router = (0, express_1.Router)(); +exports.router.use(rootRoutes_1.router); +// 404 +exports.router.use((req, res) => { + res.status(404).send('E404'); +}); diff --git a/src/skeletons/express-ts/src/routes/rootRoutes.js b/src/skeletons/express-ts/src/routes/rootRoutes.js new file mode 100644 index 0000000..8102385 --- /dev/null +++ b/src/skeletons/express-ts/src/routes/rootRoutes.js @@ -0,0 +1,26 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.router = void 0; +const express_1 = require("express"); +const rootController = __importStar(require("@/controllers/rootController")); +exports.router = (0, express_1.Router)(); +exports.router.get('/', rootController.root_get); diff --git a/src/skeletons/express-ts/src/server.js b/src/skeletons/express-ts/src/server.js new file mode 100644 index 0000000..c102952 --- /dev/null +++ b/src/skeletons/express-ts/src/server.js @@ -0,0 +1,27 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const mongoose_1 = __importDefault(require("mongoose")); +const app_1 = require("@/app"); +const environment_1 = __importDefault(require("@/utils/environment")); +const globalService_1 = require("@/services/globalService"); +const port = environment_1.default.APP_PORT || 8080; +// MongoDB +const dbURI = environment_1.default.DB_URI; +mongoose_1.default + .connect(dbURI, { + useNewUrlParser: true, + useUnifiedTopology: true, + useCreateIndex: true, +}) + .then(() => { + new globalService_1.Succ(200, 'connected to db'); + app_1.app.listen(port, () => { + new globalService_1.Succ(200, `Server is listening on http://localhost:${port}`); + }); +}) + .catch((err) => { + new globalService_1.Err(500, err); +}); diff --git a/src/skeletons/express-ts/src/services/globalService.js b/src/skeletons/express-ts/src/services/globalService.js new file mode 100644 index 0000000..b162618 --- /dev/null +++ b/src/skeletons/express-ts/src/services/globalService.js @@ -0,0 +1,37 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Succ = exports.Err = void 0; +const colors_1 = __importDefault(require("colors")); +class Err { + constructor(code, message) { + this.code = code; + this.message = message; + this.drop(); + } + drop() { + console.log(colors_1.default.bgRed(`${this.code}`) + colors_1.default.bgBlack.red(` ${this.message}`)); + return { + code: this.code, + message: this.message, + }; + } +} +exports.Err = Err; +class Succ { + constructor(code, message) { + this.code = code; + this.message = message; + this.drop(); + } + drop() { + console.log(colors_1.default.bgGreen.black(`${this.code}`) + colors_1.default.green.bgBlack(` ${this.message}`)); + return { + code: this.code, + message: this.message, + }; + } +} +exports.Succ = Succ; diff --git a/src/skeletons/express-ts/src/services/rootService.js b/src/skeletons/express-ts/src/services/rootService.js new file mode 100644 index 0000000..4fb2c86 --- /dev/null +++ b/src/skeletons/express-ts/src/services/rootService.js @@ -0,0 +1,7 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.helloWorld = void 0; +const helloWorld = () => { + console.log('hello world'); +}; +exports.helloWorld = helloWorld; diff --git a/src/skeletons/express-ts/src/utils/copyAssets.js b/src/skeletons/express-ts/src/utils/copyAssets.js new file mode 100644 index 0000000..84d71ec --- /dev/null +++ b/src/skeletons/express-ts/src/utils/copyAssets.js @@ -0,0 +1,27 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const shell = __importStar(require("shelljs")); +// Copy all the view templates +shell.cp('-R', 'src/views', 'dist/'); +shell.cp('-R', 'src/public', 'dist/'); +shell.cp('-R', 'src/models', 'dist/'); +shell.cp('-u', 'src/.env', 'dist/'); diff --git a/src/skeletons/express-ts/src/utils/environment.js b/src/skeletons/express-ts/src/utils/environment.js new file mode 100644 index 0000000..5aaf9d9 --- /dev/null +++ b/src/skeletons/express-ts/src/utils/environment.js @@ -0,0 +1,11 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const path_1 = __importDefault(require("path")); +require('dotenv').config({ path: path_1.default.join(__dirname, '../.env') }); +exports.default = { + APP_PORT: Number(process.env.APP_PORT), + DB_URI: String(process.env.DB_URI), +}; diff --git a/src/tests/help.test.ts b/src/tests/help.test.ts new file mode 100644 index 0000000..d249e6e --- /dev/null +++ b/src/tests/help.test.ts @@ -0,0 +1,23 @@ +import { assert } from 'chai' +import Help from '../help' +import pad from 'pad' + +describe('should return help', () => { + it('returns all help', () => { + const help = Help.logHelp() + const correct = Help.allHelp() + assert.equal(help, correct) + }) + + it('returns make help', () => { + const help = Help.logHelp('make') + const correct = Help.makeHelp() + assert.equal(help, correct) + }) + + it('returns specific help', () => { + const help = Help.logHelp('setup') + const correct = Help.specificHelp('setup') + assert.equal(help, correct) + }) +}) diff --git a/src/tests/router.test.ts b/src/tests/router.test.ts new file mode 100644 index 0000000..f5f8340 --- /dev/null +++ b/src/tests/router.test.ts @@ -0,0 +1,58 @@ +import { assert } from 'chai' +import Routes from '../routes' + +describe('should return help', () => { + process.argv = [] + it('return all help', () => { + const options = ['-h', '--help'] + for (let i = 0; i < options.length; i++) { + process.argv[2] = options[i] + process.argv[3] = '' + const routes = Routes.router() + assert.equal(routes, 'all help') + } + }) + + it('return specific help', () => { + const options = ['-h', '--help'] + for (let i = 0; i < options.length; i++) { + process.argv[2] = options[i] + process.argv[3] = 'make' + const routes = Routes.router() + assert.equal(routes, 'specific help') + } + }) +}) + +describe('should return version', () => { + it('return version', () => { + const options = ['-v', '--version'] + for (let i = 0; i < options.length; i++) { + process.argv[2] = options[i] + const routes = Routes.router() + assert.equal(routes, 'version') + } + }) +}) + +describe('should return setup', () => { + it('return setup', () => { + process.argv[2] = 'setup' + process.argv[3] = 'test' + const routes = Routes.router() + assert.equal(routes, 'setup') + }) +}) + +describe('should return make', () => { + const options = ['controller', 'middleware', 'route', 'service', 'model', 'view', 'test', 'interface'] + for (let i = 0; i < options.length; i++) { + it(`return make ${options[i]}`, () => { + process.argv[2] = 'make' + process.argv[3] = options[i] + process.argv[4] = 'test' + const routes = Routes.router() + assert.equal(routes, `make ${options[i]}`) + }) + } +}) diff --git a/src/tests/setup.test.ts b/src/tests/setup.test.ts new file mode 100644 index 0000000..a3d827d --- /dev/null +++ b/src/tests/setup.test.ts @@ -0,0 +1,11 @@ +import { assert } from 'chai' +import Setup from '../setup' +import Global from '../global' + +describe('should setup project', () => { + it('setup project', async () => { + const correct: string = Global.logSuccess() + const setup = await Setup.setup(true) + assert.equal(setup, correct) + }) +}) diff --git a/src/tests/test.test.ts.old b/src/tests/test.test.ts.old new file mode 100644 index 0000000..ec27c00 --- /dev/null +++ b/src/tests/test.test.ts.old @@ -0,0 +1,20 @@ +import { assert } from 'chai' +import { App } from '../app' + +// Describe tests +describe('some demo tests', () => { + // Create tests + it('adds two number together', () => { + assert(2 + 3 === 5) + }) + + it('should return Hello plus my name', () => { + assert.equal(App.sayHello('Filip'), 'Hello Filip') + assert.notEqual(App.sayHello('Adam'), 'Hello Filip') + }) + + it('should return Hello plus my name within instance', () => { + const app = new App('Filip') + assert.equal(app.pozdrav(), 'Hello Filip') + }) +}) diff --git a/src/tests/version.test.ts b/src/tests/version.test.ts new file mode 100644 index 0000000..501e440 --- /dev/null +++ b/src/tests/version.test.ts @@ -0,0 +1,11 @@ +import { assert } from 'chai' +import Version from '../version' +import path from 'path' + +describe('should return version', () => { + it('return version', () => { + const pkgJson = require(path.join(__dirname, '../../package')) + const actualVersion = pkgJson.version + assert.equal(Version.show(), `nork ${actualVersion}`) + }) +}) diff --git a/src/version.ts b/src/version.ts new file mode 100644 index 0000000..52e31c3 --- /dev/null +++ b/src/version.ts @@ -0,0 +1,10 @@ +import fs from 'fs-extra' +import path from 'path' + +export default class Version { + static show(): string { + const pkgJson = fs.readJsonSync(path.join(__dirname, '../package.json')) + const log = `nork ${pkgJson.version}` + return log + } +} diff --git a/src/views/test.ejs b/src/views/test.ejs new file mode 100644 index 0000000..faf15cc --- /dev/null +++ b/src/views/test.ejs @@ -0,0 +1,15 @@ + + + + + + + New Project + + + + + + + + \ No newline at end of file diff --git a/src/views/undefined.ejs b/src/views/undefined.ejs new file mode 100644 index 0000000..faf15cc --- /dev/null +++ b/src/views/undefined.ejs @@ -0,0 +1,15 @@ + + + + + + + New Project + + + + + + + + \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..75e90d9 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + "module": "commonjs", /* Specify what module code is generated. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + "rootDir": "./src", /* Specify the root folder within your source files. */ + "strict": true, /* Enable all strict type-checking options. */ + "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */ + "skipLibCheck": true, /* Skip type checking all .d.ts files. */ + "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + }, + "exclude": [ + "_old" + ] +}