mirror of
https://github.com/filiprojek/nork.git
synced 2024-11-23 01:01:04 +01:00
v1 done
This commit is contained in:
parent
ab82b64fa1
commit
6a412ee673
@ -17,11 +17,8 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"colors": "^1.4.0",
|
"colors": "^1.4.0",
|
||||||
"commander": "^8.1.0",
|
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
"inquirer": "^8.1.2",
|
"inquirer": "^8.1.2",
|
||||||
"leven": "^4.0.0",
|
|
||||||
"ncp": "^2.0.0",
|
|
||||||
"pad": "^3.2.0"
|
"pad": "^3.2.0"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
import program from 'commander'
|
|
||||||
import leven from 'leven'
|
|
||||||
//import inquirer from 'inquirer'
|
|
||||||
import colors from 'colors'
|
|
||||||
//import pad from 'pad'
|
|
||||||
|
|
||||||
import { createProject } from './createProject.js'
|
|
||||||
import { make } from './make.js'
|
|
||||||
|
|
||||||
program.usage('<command> [options]')
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('create <app-name>')
|
|
||||||
.description('create a new project')
|
|
||||||
.action(app_name => {
|
|
||||||
createProject(app_name)
|
|
||||||
})
|
|
||||||
|
|
||||||
program
|
|
||||||
.command('make <component>')
|
|
||||||
.description('create components like controller, model ...')
|
|
||||||
.action(component => {
|
|
||||||
make(component)
|
|
||||||
})
|
|
||||||
|
|
||||||
// output help information on unknown commands
|
|
||||||
program.on('command:*', ([cmd]) => {
|
|
||||||
program.outputHelp()
|
|
||||||
console.log(` ` + colors.red(`Unknown command ${colors.yellow(cmd)}.`))
|
|
||||||
console.log()
|
|
||||||
suggestCommands(cmd)
|
|
||||||
process.exitCode = 1
|
|
||||||
})
|
|
||||||
program.commands.forEach(c => c.on('--help', () => console.log()))
|
|
||||||
|
|
||||||
program.parse(process.argv)
|
|
||||||
|
|
||||||
function suggestCommands(unknownCommand) {
|
|
||||||
const availableCommands = program.commands.map(cmd => cmd._name)
|
|
||||||
|
|
||||||
let suggestion
|
|
||||||
|
|
||||||
availableCommands.forEach(cmd => {
|
|
||||||
const isBestMatch =
|
|
||||||
leven(cmd, unknownCommand) < leven(suggestion || '', unknownCommand)
|
|
||||||
if (leven(cmd, unknownCommand) < 3 && isBestMatch) {
|
|
||||||
suggestion = cmd
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
if (suggestion) {
|
|
||||||
console.log(
|
|
||||||
` ` + colors.red(`Did you mean ${colors.yellow(suggestion)}?`),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,60 +0,0 @@
|
|||||||
//import program from 'commander'
|
|
||||||
//import leven from 'leven'
|
|
||||||
import inquirer from 'inquirer'
|
|
||||||
import colors from 'colors'
|
|
||||||
import pad from 'pad'
|
|
||||||
|
|
||||||
export function createProject(project_name)
|
|
||||||
{
|
|
||||||
const data = {
|
|
||||||
project_name: 'new_project',
|
|
||||||
author: '',
|
|
||||||
lang: '',
|
|
||||||
}
|
|
||||||
|
|
||||||
const questions = [
|
|
||||||
{
|
|
||||||
type: 'list',
|
|
||||||
name: 'lang',
|
|
||||||
message: 'Choose what you prefer',
|
|
||||||
choices: [
|
|
||||||
{ name: 'Typescript', value: 'ts' },
|
|
||||||
{ name: 'Javascript', value: 'js' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'input',
|
|
||||||
name: 'author',
|
|
||||||
message: 'Enter your name:',
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
const langToLanguage = lang => {
|
|
||||||
switch (lang) {
|
|
||||||
case 'js':
|
|
||||||
return 'Javascript'
|
|
||||||
break
|
|
||||||
case 'ts':
|
|
||||||
return 'Typescript'
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
return 'Unknown language'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data.project_name = project_name
|
|
||||||
|
|
||||||
inquirer.prompt(questions).then(function (answers) {
|
|
||||||
data.lang = answers.lang
|
|
||||||
data.author = answers.author
|
|
||||||
|
|
||||||
console.log(colors.yellow('Project settings'))
|
|
||||||
console.log(colors.yellow('------------------'))
|
|
||||||
console.log(pad(colors.gray('Project name: '), 30), data.project_name)
|
|
||||||
console.log(pad(colors.gray('Author: '), 30), data.author)
|
|
||||||
console.log(
|
|
||||||
pad(colors.gray('Language: '), 30),
|
|
||||||
langToLanguage(data.lang),
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
import fs from 'fs'
|
|
||||||
import colors from 'colors'
|
|
||||||
|
|
||||||
export function make(component)
|
|
||||||
{
|
|
||||||
console.log(component)
|
|
||||||
}
|
|
3
src.old/skeletons/express-ts/.gitignore
vendored
3
src.old/skeletons/express-ts/.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
node_modules/
|
|
||||||
.env
|
|
||||||
package-lock.json
|
|
@ -1 +0,0 @@
|
|||||||
# New Project
|
|
@ -1,5 +0,0 @@
|
|||||||
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
|
|
||||||
module.exports = {
|
|
||||||
preset: 'ts-jest',
|
|
||||||
testEnvironment: 'node',
|
|
||||||
};
|
|
@ -1,45 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "project-name",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "app.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "node dist/app.js",
|
|
||||||
"dev": "nodemon src/app.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": "Filip Rojek",
|
|
||||||
"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": {
|
|
||||||
"@types/cors": "^2.8.10",
|
|
||||||
"@types/ejs": "^3.0.6",
|
|
||||||
"@types/express": "^4.17.11",
|
|
||||||
"@types/fs-extra": "^9.0.12",
|
|
||||||
"@types/jest": "^26.0.24",
|
|
||||||
"@types/mongoose": "^5.10.5",
|
|
||||||
"@types/morgan": "^1.9.2",
|
|
||||||
"@types/node": "^14.14.41",
|
|
||||||
"@types/shelljs": "^0.8.9",
|
|
||||||
"fs-extra": "^10.0.0",
|
|
||||||
"jest": "^27.0.6",
|
|
||||||
"npm-run-all": "^4.1.5",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"shelljs": "^0.8.4",
|
|
||||||
"ts-jest": "^27.0.4",
|
|
||||||
"ts-node": "^9.1.1",
|
|
||||||
"typescript": "^4.2.4"
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,43 +0,0 @@
|
|||||||
import express from "express";
|
|
||||||
import morgan from "morgan";
|
|
||||||
import mongoose from "mongoose";
|
|
||||||
import path from "path";
|
|
||||||
import cors from "cors";
|
|
||||||
|
|
||||||
const config = require("./utils/environment");
|
|
||||||
const routes = require("./routes");
|
|
||||||
const middlewares = require("./middlewares");
|
|
||||||
|
|
||||||
const port: Number = config.APP_PORT;
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
// MongoDB
|
|
||||||
const dbURI: string = config.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 listening on http://localhost:${port}`);
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Middlewares
|
|
||||||
app.use(middlewares);
|
|
||||||
app.set("view engine", "ejs");
|
|
||||||
app.set("views", path.join(__dirname, "views"));
|
|
||||||
app.use(cors());
|
|
||||||
app.use(morgan("dev"));
|
|
||||||
app.use(express.urlencoded({ extended: true }));
|
|
||||||
app.use(express.json());
|
|
||||||
app.use(express.static(path.join(__dirname, "public")));
|
|
||||||
|
|
||||||
// Routes
|
|
||||||
app.use(routes);
|
|
@ -1,10 +0,0 @@
|
|||||||
import { Request, Response } from "express";
|
|
||||||
|
|
||||||
const root_get = (req: Request, res: Response) => {
|
|
||||||
res.render("home");
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
root_get,
|
|
||||||
};
|
|
@ -1,8 +0,0 @@
|
|||||||
import { Router } from "express";
|
|
||||||
const sayHiMiddleware = require("./sayHiMiddleware");
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.use(sayHiMiddleware);
|
|
||||||
|
|
||||||
module.exports = router;
|
|
@ -1,11 +0,0 @@
|
|||||||
import { Router, Request, Response, NextFunction } from "express";
|
|
||||||
|
|
||||||
const router = Router();
|
|
||||||
|
|
||||||
router.use((req: Request, res: Response, next: NextFunction) => {
|
|
||||||
console.log("Hi :)");
|
|
||||||
|
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = router;
|
|
@ -1,9 +0,0 @@
|
|||||||
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)
|
|
||||||
});
|
|
@ -1,16 +0,0 @@
|
|||||||
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;
|
|
||||||
};
|
|
@ -1,6 +0,0 @@
|
|||||||
import * as shell from "shelljs";
|
|
||||||
|
|
||||||
// Copy all the view templates
|
|
||||||
shell.cp("-R", "src/views", "dist/");
|
|
||||||
shell.cp("-R", "src/public", "dist/");
|
|
||||||
shell.cp("-u", "src/.env", "dist/");
|
|
@ -1,7 +0,0 @@
|
|||||||
import path from 'path'
|
|
||||||
require('dotenv').config({ path: path.join(__dirname, '../.env') })
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
APP_PORT: process.env.APP_PORT,
|
|
||||||
DB_URI: process.env.DB_URI
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
{
|
|
||||||
"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": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
|
||||||
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
|
||||||
// "typeRoots": [], /* List of folders to include type definitions from. */
|
|
||||||
// "types": [], /* Type declaration files to be included in compilation. */
|
|
||||||
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
|
||||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
|
||||||
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
|
||||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
||||||
|
|
||||||
/* Source Map Options */
|
|
||||||
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
|
||||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
||||||
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
|
||||||
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
|
||||||
|
|
||||||
/* Experimental Options */
|
|
||||||
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
|
||||||
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
|
||||||
|
|
||||||
/* Advanced Options */
|
|
||||||
"skipLibCheck": true, /* Skip type checking of declaration files. */
|
|
||||||
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
|
||||||
}
|
|
||||||
}
|
|
154
src/app.js
154
src/app.js
@ -4,18 +4,74 @@ const path = require('path')
|
|||||||
const fs = require('fs-extra')
|
const fs = require('fs-extra')
|
||||||
const colors = require('colors')
|
const colors = require('colors')
|
||||||
const pad = require('pad')
|
const pad = require('pad')
|
||||||
|
|
||||||
const langToLanguage = lang => {
|
const langToLanguage = lang => {
|
||||||
switch (lang) {
|
switch (lang) {
|
||||||
case 'js':
|
case 'js':
|
||||||
return 'Javascript'
|
return 'Javascript'
|
||||||
break
|
case 'ts':
|
||||||
case 'ts':
|
return 'Typescript'
|
||||||
return 'Typescript'
|
default:
|
||||||
break
|
return 'Unknown language'
|
||||||
default:
|
}
|
||||||
return 'Unknown language'
|
}
|
||||||
}
|
|
||||||
|
const logError = errorMsg => {
|
||||||
|
console.log(colors.bgYellow.red(errorMsg))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const logSuccess = (msg = false) => {
|
||||||
|
if (!msg) {
|
||||||
|
msg = 'Success!'
|
||||||
|
}
|
||||||
|
console.log(colors.cyan(msg))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const logHelp = (specific = false, command = false) => {
|
||||||
|
let spc = 40
|
||||||
|
|
||||||
|
if (specific) {
|
||||||
|
// log specific help
|
||||||
|
if (specific == 'make') {
|
||||||
|
console.log(`Usage: ${specific}:[component]`)
|
||||||
|
console.log()
|
||||||
|
console.log(pad(' make:controller', spc), 'create a new controller')
|
||||||
|
console.log(pad(' make:middleware', spc), 'create a new middleware')
|
||||||
|
console.log(pad(' make:model', spc), 'create a new model')
|
||||||
|
console.log(pad(' make:route', spc), 'create a new route')
|
||||||
|
console.log(pad(' make:test', spc), 'create a new test')
|
||||||
|
console.log(pad(' make:view', spc), 'create a new view')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(`Usage: ${specific} [options]`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Usage: nork <command> [options]')
|
||||||
|
console.log()
|
||||||
|
console.log('Options:')
|
||||||
|
console.log(pad(' -v, --version', spc), 'output the version number')
|
||||||
|
console.log(pad(' -h, --help', spc), 'output usage information')
|
||||||
|
console.log()
|
||||||
|
console.log('Commands:')
|
||||||
|
console.log(pad(' create [app-name]', spc), 'create a new project')
|
||||||
|
console.log(pad(' make:controller', spc), 'create a new controller')
|
||||||
|
console.log(pad(' make:middleware', spc), 'create a new middleware')
|
||||||
|
console.log(pad(' make:model', spc), 'create a new model')
|
||||||
|
console.log(pad(' make:route', spc), 'create a new route')
|
||||||
|
console.log(pad(' make:test', spc), 'create a new test')
|
||||||
|
console.log(pad(' make:view', spc), 'create a new view')
|
||||||
|
|
||||||
|
console.log()
|
||||||
|
console.log(' Run', colors.cyan('nork help <command>'), 'for detailed usage of given command.')
|
||||||
|
|
||||||
|
if (command) {
|
||||||
|
console.log(colors.red('Unknown command'), colors.bold.blue(command))
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
@ -63,7 +119,7 @@ const langToLanguage = lang => {
|
|||||||
pkgJson.author = data.author
|
pkgJson.author = data.author
|
||||||
|
|
||||||
fs.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(pkgJson, null, 2), err => {
|
fs.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(pkgJson, null, 2), err => {
|
||||||
if (err) return console.log(err)
|
if (err) return logError(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(colors.yellow('Project settings'))
|
console.log(colors.yellow('Project settings'))
|
||||||
@ -72,15 +128,79 @@ const langToLanguage = lang => {
|
|||||||
console.log(pad(colors.gray('Author: '), 30), data.author)
|
console.log(pad(colors.gray('Author: '), 30), data.author)
|
||||||
console.log(pad(colors.gray('Language: '), 30), langToLanguage(data.lang))
|
console.log(pad(colors.gray('Language: '), 30), langToLanguage(data.lang))
|
||||||
|
|
||||||
console.log(colors.cyan(`Project ${ data.project_name } created successfully!`))
|
return logSuccess(`Project ${data.project_name} created successfully!`)
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv[2] == 'make') {
|
if (process.argv[2] == 'make') {
|
||||||
|
if (!process.argv[3] || !process.argv[4]) return logHelp('make')
|
||||||
|
|
||||||
const component = process.argv[3]
|
const component = process.argv[3]
|
||||||
|
const norkcfg = require(path.join(process.cwd(), 'norkconfig.json'))
|
||||||
|
|
||||||
|
let tsComponents = ['controller', 'middleware', 'route']
|
||||||
|
|
||||||
|
if (tsComponents.includes(component)) {
|
||||||
|
let src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.' + norkcfg.lang)
|
||||||
|
let dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.' + norkcfg.lang)
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.copySync(src, dest, { overwrite: false, errorOnExist: true })
|
||||||
|
} catch (err) {
|
||||||
|
return logError(err.message)
|
||||||
|
}
|
||||||
|
return logSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component == 'model') {
|
||||||
|
let src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.js')
|
||||||
|
let dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.js')
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.copySync(src, dest, { overwrite: false, errorOnExist: true })
|
||||||
|
} catch (err) {
|
||||||
|
return logError(err.message)
|
||||||
|
}
|
||||||
|
return logSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component == 'view') {
|
||||||
|
let src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.ejs')
|
||||||
|
let dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.ejs')
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.copySync(src, dest, { overwrite: false, errorOnExist: true })
|
||||||
|
} catch (err) {
|
||||||
|
return logError(err.message)
|
||||||
|
}
|
||||||
|
return logSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (component == 'test') {
|
||||||
|
let src = path.join(__dirname, './make-files/express-' + norkcfg.lang + '/' + component + '.js')
|
||||||
|
let dest = path.join(process.cwd(), './src/' + component + 's' + '/' + process.argv[4] + '.test.js')
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.copySync(src, dest, { overwrite: false, errorOnExist: true })
|
||||||
|
} catch (err) {
|
||||||
|
return logError(err.message)
|
||||||
|
}
|
||||||
|
return logSuccess()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!process.argv[2]) {
|
|
||||||
// Help
|
if (process.argv[2] == '-v' || process.argv[2] == '--version') {
|
||||||
console.log('Help coming soon!')
|
const pkgJson = require(path.join(__dirname, '../package.json'))
|
||||||
|
return console.log('nork', pkgJson.version)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.argv[2] == 'help' || process.argv[2] == '-h' || process.argv[2] == '--help') {
|
||||||
|
if (process.argv[3]) {
|
||||||
|
return logHelp(process.argv[3])
|
||||||
|
}
|
||||||
|
return logHelp()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
process.argv.splice(0, 2)
|
||||||
|
logHelp(false, process.argv.join(' '))
|
||||||
})()
|
})()
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
const root_get = (req, res) => {
|
||||||
|
res.render('home')
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
root_get,
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
const { Router } = require('express')
|
||||||
|
|
||||||
|
const router = Router()
|
||||||
|
|
||||||
|
router.use((req, res, next) => {
|
||||||
|
console.log('Hi :)')
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
@ -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
|
@ -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)
|
||||||
|
})
|
15
src/make-files/express-js/view.ejs
Normal file
15
src/make-files/express-js/view.ejs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>New Project</title>
|
||||||
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||||
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Open+Sans&display=swap" rel="stylesheet">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
8
src/make-files/express-ts/route.ts
Normal file
8
src/make-files/express-ts/route.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Router } from 'express'
|
||||||
|
const rootController = require('../controllers/rootController')
|
||||||
|
|
||||||
|
const router = Router()
|
||||||
|
|
||||||
|
router.get('/', rootController.root_get)
|
||||||
|
|
||||||
|
module.exports = router
|
107
src/skeletons/express-js/.gitignore
vendored
Normal file
107
src/skeletons/express-js/.gitignore
vendored
Normal file
@ -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
|
3
src/skeletons/express-js/norkconfig.json
Normal file
3
src/skeletons/express-js/norkconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"lang": "js"
|
||||||
|
}
|
24
src/skeletons/express-js/package.json
Normal file
24
src/skeletons/express-js/package.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
41
src/skeletons/express-js/src/app.js
Normal file
41
src/skeletons/express-js/src/app.js
Normal file
@ -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)
|
@ -0,0 +1,8 @@
|
|||||||
|
const root_get = (req, res) => {
|
||||||
|
res.render('home')
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
root_get,
|
||||||
|
}
|
8
src/skeletons/express-js/src/middlewares/index.js
Normal file
8
src/skeletons/express-js/src/middlewares/index.js
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
const { Router } = require('express')
|
||||||
|
const sayHiMiddleware = require('./sayHiMiddleware')
|
||||||
|
|
||||||
|
const router = Router()
|
||||||
|
|
||||||
|
router.use(sayHiMiddleware)
|
||||||
|
|
||||||
|
module.exports = router
|
10
src/skeletons/express-js/src/middlewares/sayHiMiddleware.js
Normal file
10
src/skeletons/express-js/src/middlewares/sayHiMiddleware.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
const { Router } = require('express')
|
||||||
|
|
||||||
|
const router = Router()
|
||||||
|
|
||||||
|
router.use((req, res, next) => {
|
||||||
|
console.log('Hi :)')
|
||||||
|
next()
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = router
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 5.8 KiB After Width: | Height: | Size: 5.8 KiB |
@ -1,4 +1,4 @@
|
|||||||
import { Router } from 'express'
|
const { Router } = require('express')
|
||||||
const rootRoutes = require('./rootRoutes')
|
const rootRoutes = require('./rootRoutes')
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
9
src/skeletons/express-js/src/tests/home.test.js
Normal file
9
src/skeletons/express-js/src/tests/home.test.js
Normal file
@ -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)
|
||||||
|
})
|
16
src/skeletons/express-js/src/tests/modules/reqRes.module.js
Normal file
16
src/skeletons/express-js/src/tests/modules/reqRes.module.js
Normal file
@ -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
|
||||||
|
}
|
1
src/skeletons/express-js/src/utils/REAME.md
Normal file
1
src/skeletons/express-js/src/utils/REAME.md
Normal file
@ -0,0 +1 @@
|
|||||||
|
# Folder for utils and other config files
|
106
src/skeletons/express-ts/.gitignore
vendored
106
src/skeletons/express-ts/.gitignore
vendored
@ -1,3 +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/
|
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
|
||||||
package-lock.json
|
.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
|
3
src/skeletons/express-ts/norkconfig.json
Normal file
3
src/skeletons/express-ts/norkconfig.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"lang": "ts"
|
||||||
|
}
|
@ -13,7 +13,7 @@
|
|||||||
"build": "npm-run-all clean tsc copy-assets"
|
"build": "npm-run-all clean tsc copy-assets"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Filip Rojek",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
@ -21,7 +21,8 @@
|
|||||||
"ejs": "^3.1.6",
|
"ejs": "^3.1.6",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"mongoose": "^5.12.3",
|
"mongoose": "^5.12.3",
|
||||||
"morgan": "^1.10.0"
|
"morgan": "^1.10.0",
|
||||||
|
"fs-extra": "^10.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cors": "^2.8.10",
|
"@types/cors": "^2.8.10",
|
||||||
@ -33,7 +34,6 @@
|
|||||||
"@types/morgan": "^1.9.2",
|
"@types/morgan": "^1.9.2",
|
||||||
"@types/node": "^14.14.41",
|
"@types/node": "^14.14.41",
|
||||||
"@types/shelljs": "^0.8.9",
|
"@types/shelljs": "^0.8.9",
|
||||||
"fs-extra": "^10.0.0",
|
|
||||||
"jest": "^27.0.6",
|
"jest": "^27.0.6",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
@ -1,43 +1,43 @@
|
|||||||
import express from "express";
|
import express from 'express'
|
||||||
import morgan from "morgan";
|
import morgan from 'morgan'
|
||||||
import mongoose from "mongoose";
|
import mongoose from 'mongoose'
|
||||||
import path from "path";
|
import path from 'path'
|
||||||
import cors from "cors";
|
import cors from 'cors'
|
||||||
|
|
||||||
const config = require("./utils/environment");
|
const config = require('./utils/environment')
|
||||||
const routes = require("./routes");
|
const routes = require('./routes')
|
||||||
const middlewares = require("./middlewares");
|
const middlewares = require('./middlewares')
|
||||||
|
|
||||||
const port: Number = config.APP_PORT;
|
const port: Number = config.APP_PORT || 8080
|
||||||
const app = express();
|
const app = express()
|
||||||
|
|
||||||
// MongoDB
|
// MongoDB
|
||||||
const dbURI: string = config.DB_URI;
|
const dbURI: string = config.DB_URI
|
||||||
mongoose
|
mongoose
|
||||||
.connect(dbURI, {
|
.connect(dbURI, {
|
||||||
useNewUrlParser: true,
|
useNewUrlParser: true,
|
||||||
useUnifiedTopology: true,
|
useUnifiedTopology: true,
|
||||||
useCreateIndex: true,
|
useCreateIndex: true,
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then(result => {
|
||||||
console.log("connected to db");
|
console.log('connected to db')
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server is listening on http://localhost:${port}`);
|
console.log(`Server is listening on http://localhost:${port}`)
|
||||||
});
|
})
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.log(err);
|
console.log(err)
|
||||||
});
|
})
|
||||||
|
|
||||||
// Middlewares
|
// Middlewares
|
||||||
app.use(middlewares);
|
app.use(middlewares)
|
||||||
app.set("view engine", "ejs");
|
app.set('view engine', 'ejs')
|
||||||
app.set("views", path.join(__dirname, "views"));
|
app.set('views', path.join(__dirname, 'views'))
|
||||||
app.use(cors());
|
app.use(cors())
|
||||||
app.use(morgan("dev"));
|
app.use(morgan('dev'))
|
||||||
app.use(express.urlencoded({ extended: true }));
|
app.use(express.urlencoded({ extended: true }))
|
||||||
app.use(express.json());
|
app.use(express.json())
|
||||||
app.use(express.static(path.join(__dirname, "public")));
|
app.use(express.static(path.join(__dirname, 'public')))
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
app.use(routes);
|
app.use(routes)
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { Request, Response } from "express";
|
import { Request, Response } from 'express'
|
||||||
|
|
||||||
const root_get = (req: Request, res: Response) => {
|
const root_get = (req: Request, res: Response) => {
|
||||||
res.render("home");
|
res.render('home')
|
||||||
return true;
|
return true
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root_get,
|
root_get,
|
||||||
};
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Router } from "express";
|
import { Router } from 'express'
|
||||||
const sayHiMiddleware = require("./sayHiMiddleware");
|
const sayHiMiddleware = require('./sayHiMiddleware')
|
||||||
|
|
||||||
const router = Router();
|
const router = Router()
|
||||||
|
|
||||||
router.use(sayHiMiddleware);
|
router.use(sayHiMiddleware)
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Router, Request, Response, NextFunction } from "express";
|
import { Router, Request, Response, NextFunction } from 'express'
|
||||||
|
|
||||||
const router = Router();
|
const router = Router()
|
||||||
|
|
||||||
router.use((req: Request, res: Response, next: NextFunction) => {
|
router.use((req: Request, res: Response, next: NextFunction) => {
|
||||||
console.log("Hi :)");
|
console.log('Hi :)')
|
||||||
|
|
||||||
next();
|
next()
|
||||||
});
|
})
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const { Router } = require('express')
|
import { Router } from 'express'
|
||||||
const rootController = require('../controllers/rootController')
|
const rootController = require('../controllers/rootController')
|
||||||
|
|
||||||
const router = Router()
|
const router = Router()
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
const { getReq, getRes } = require("./modules/reqRes.module.js");
|
const { getReq, getRes } = require('./modules/reqRes.module.js')
|
||||||
const { root_get } = require("../controllers/rootController.ts");
|
const { root_get } = require('../controllers/rootController.ts')
|
||||||
|
|
||||||
test("Home page render test", () => {
|
test('Home page render test', () => {
|
||||||
const req = getReq();
|
const req = getReq()
|
||||||
const res = getRes();
|
const res = getRes()
|
||||||
|
|
||||||
expect(root_get(req, res)).toBe(true)
|
expect(root_get(req, res)).toBe(true)
|
||||||
});
|
})
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
module.exports.getReq = () => {
|
module.exports.getReq = () => {
|
||||||
const req = {};
|
const req = {}
|
||||||
req.body = {};
|
req.body = {}
|
||||||
return req;
|
return req
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports.getRes = () => {
|
module.exports.getRes = () => {
|
||||||
const res = {};
|
const res = {}
|
||||||
res.locals = {};
|
res.locals = {}
|
||||||
res.status = () => res;
|
res.status = () => res
|
||||||
res.json = () => res;
|
res.json = () => res
|
||||||
res.send = () => res;
|
res.send = () => res
|
||||||
res.render = () => res;
|
res.render = () => res
|
||||||
|
|
||||||
return res;
|
return res
|
||||||
};
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as shell from "shelljs";
|
import * as shell from 'shelljs'
|
||||||
|
|
||||||
// Copy all the view templates
|
// Copy all the view templates
|
||||||
shell.cp("-R", "src/views", "dist/");
|
shell.cp('-R', 'src/views', 'dist/')
|
||||||
shell.cp("-R", "src/public", "dist/");
|
shell.cp('-R', 'src/public', 'dist/')
|
||||||
shell.cp("-u", "src/.env", "dist/");
|
shell.cp('-u', 'src/.env', 'dist/')
|
||||||
|
@ -2,6 +2,6 @@ import path from 'path'
|
|||||||
require('dotenv').config({ path: path.join(__dirname, '../.env') })
|
require('dotenv').config({ path: path.join(__dirname, '../.env') })
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
APP_PORT: process.env.APP_PORT,
|
APP_PORT: process.env.APP_PORT,
|
||||||
DB_URI: process.env.DB_URI
|
DB_URI: process.env.DB_URI,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user