diff --git a/.eslintrc.json b/.eslintrc.json index db9915a..5eff0bb 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,39 +1,25 @@ { - "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" - ] - } + "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 index 3cac628..911cec0 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,4 +1,4 @@ { - "require": ["ts-node/register"], - "watch-files": ["./src/**/*.ts"] -} \ No newline at end of file + "require": ["ts-node/register"], + "watch-files": ["./src/**/*.ts"] +} diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..ea161e1 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,15 @@ +{ + "tabWidth": 4, + "useTabs": true, + "singleQuote": true, + "semi": false, + "trailingComma": "none", + "jsxSingleQuote": true, + "jsxBracketSameLine": true, + "printWidth": 200, + "bracketSpacing": true, + "vueIndentScriptAndStyle": true, + "arrowParens": "always", + "bracketSameLine": false, + "endOfLine": "lf" +} diff --git a/README.md b/README.md index 813f51f..fa4db9d 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,29 @@ # Nork + Simple node.js tool that extends express projects. - - [About](#about) - - [Installation](#installation) - - [How to use](#how-to-use) +- [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 + ``` +npm install nork +``` + ## How to use + ``` Usage: nork [options] diff --git a/norkconfig.json b/norkconfig.json index 3e80a47..b07785a 100644 --- a/norkconfig.json +++ b/norkconfig.json @@ -1 +1 @@ -{"lang":"ts"} +{ "lang": "ts" } diff --git a/package.json b/package.json index 0adf78c..d6b7233 100644 --- a/package.json +++ b/package.json @@ -1,58 +1,60 @@ { - "name": "nork", - "version": "3.0.5", - "description": "The best node.js 'framework' :)", - "main": "dist/app.js", - "bin": "dist/app.js", - "types": "dist/app.d.ts", - "scripts": { - "start": "npm run start:prod", - "start:dev": "ts-node src/app.ts", - "start:prod": "node dist/app.js", - "tsc": "tsc -p .", - "clean": "rimraf dist", - "copy-assets": "ts-node src/utils/copyAssets", - "build": "npm-run-all clean tsc copy-assets", - "test": "mocha --config .mocharc.json --watch src/**/*.test.ts", - "prepublish": "npm-run-all build" - }, - "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" - }, - "devDependencies": { - "@types/chai": "^4.2.22", - "@types/fs-extra": "^9.0.13", - "@types/inquirer": "^8.1.3", - "@types/mocha": "^9.0.0", - "@types/shelljs": "^0.8.11", - "@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", - "npm-run-all": "^4.1.5", - "rimraf": "^3.0.2", - "shelljs": "^0.8.5", - "ts-node": "^10.4.0", - "typescript": "^4.5.2" - }, - "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" + "name": "nork", + "version": "3.0.5", + "description": "The best node.js 'framework' :)", + "main": "dist/app.js", + "bin": "dist/app.js", + "types": "dist/app.d.ts", + "scripts": { + "start": "npm run start:prod", + "start:dev": "ts-node src/app.ts", + "start:prod": "node dist/app.js", + "tsc": "tsc -p .", + "clean": "rimraf dist", + "copy-assets": "ts-node src/utils/copyAssets", + "build": "npm-run-all clean tsc copy-assets", + "test": "mocha --config .mocharc.json --watch src/**/*.test.ts", + "prepublish": "npm-run-all build", + "format": "npx prettier --write ." + }, + "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" + }, + "devDependencies": { + "@types/chai": "^4.2.22", + "@types/fs-extra": "^9.0.13", + "@types/inquirer": "^8.1.3", + "@types/mocha": "^9.0.0", + "@types/shelljs": "^0.8.11", + "@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", + "npm-run-all": "^4.1.5", + "prettier": "^2.7.1", + "rimraf": "^3.0.2", + "shelljs": "^0.8.5", + "ts-node": "^10.4.0", + "typescript": "^4.5.2" + }, + "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" } diff --git a/progress-blog.md b/progress-blog.md index 7771b49..c0fdc9b 100644 --- a/progress-blog.md +++ b/progress-blog.md @@ -1,36 +1,39 @@ -/* spell-checker: disable */ +/_ spell-checker: disable _/ # Todo: -- [ ] auth jwt refresh token based system - - https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/ -- [ ] version of nork control -- [ ] upgrade to newer version system -- [ ] updatnout make files (obzvlast modely a rozlisovat modely podle norkconfigu) -- [ ] vyzadovat aktualni verzi 3.#.# pro make commandy (pouzivaly se jiny predtim soubory) -- [ ] moznost vytvorit projekt bez db +- [ ] auth jwt refresh token based system + - https://auth0.com/blog/refresh-tokens-what-are-they-and-when-to-use-them/ +- [ ] version of nork control +- [ ] upgrade to newer version system +- [ ] updatnout make files (obzvlast modely a rozlisovat modely podle norkconfigu) +- [ ] vyzadovat aktualni verzi 3.#.# pro make commandy (pouzivaly se jiny predtim soubory) +- [ ] moznost vytvorit projekt bez db ### 11-24-2021 -- zacal jsem predelavat nork do OOP -- co jsem udelal: - - [x] --help - - [x] --version - - [x] setup - - [x] make - - [x] create - - delam na tom - - je treba dopsat par types a fixnout zbytek erroru - - zatim netestovana funkcnost + +- zacal jsem predelavat nork do OOP +- co jsem udelal: + - [x] --help + - [x] --version + - [x] setup + - [x] make + - [x] create + - delam na tom + - je treba dopsat par types a fixnout zbytek erroru + - zatim netestovana funkcnost ### 1-10-2022 -- dodelal jsem create a otestoval ho -- [x] create + +- dodelal jsem create a otestoval ho +- [x] create ### 7-30-2022 - - norkconfig se generuje lepe a actually ho pouzivam - - pri vytvareni projektu je mozne vybrat si orm (mongoose & sequlize) - - default modely pro db se kopiruji na zaklade parametru db z norkconfigu - - updatnutej ts skeleton - - dropnul jsem support pro js - - version update: 3.0.5 +- norkconfig se generuje lepe a actually ho pouzivam +- pri vytvareni projektu je mozne vybrat si orm (mongoose & sequlize) +- default modely pro db se kopiruji na zaklade parametru db z norkconfigu +- updatnutej ts skeleton +- dropnul jsem support pro js + +- version update: 3.0.5 diff --git a/src/create.ts b/src/create.ts index cdc609d..dc659ce 100644 --- a/src/create.ts +++ b/src/create.ts @@ -14,7 +14,7 @@ export default class Create { { type: 'input', name: 'project_name', - message: 'Enter project name:', + message: 'Enter project name:' }, { type: 'list', @@ -22,8 +22,8 @@ export default class Create { name: 'lang', choices: [ { name: 'Typescript', value: 'ts' }, - { name: 'Javascript - DEPRECATED', value: 'js' }, - ], + { name: 'Javascript - DEPRECATED', value: 'js' } + ] }, { type: 'list', @@ -32,24 +32,24 @@ export default class Create { choices: [ { name: 'MongoDB - Mongoose', value: { db: 'mongodb', orm: 'mongoose' } }, { name: 'MySQL - Sequelize', value: { db: 'mysql', orm: 'sequelize' } }, - { name: 'PostgreSQL - Sequelize', value: { db: 'postgresql', orm: 'sequelize' } }, - ], + { name: 'PostgreSQL - Sequelize', value: { db: 'postgresql', orm: 'sequelize' } } + ] }, { type: 'input', name: 'author', - message: 'Enter your name:', + message: 'Enter your name:' }, { type: 'input', name: 'email', - message: 'Enter your email:', + message: 'Enter your email:' }, { type: 'input', name: 'website', - message: 'Enter your website:', - }, + message: 'Enter your website:' + } ] // remove first question if project name is already known if (projectName) questions.shift() @@ -61,7 +61,7 @@ export default class Create { author: answers.author, database: answers.db, website: answers.website, - email: answers.email, + email: answers.email } // copy skeleton to new project @@ -76,7 +76,7 @@ export default class Create { const pkgJson = fs.readJsonSync(path.join(projectPath, 'package.json')) pkgJson.name = data.project_name pkgJson.author = `${data.author} <${data.email}> (${data.website})` - fs.writeFile(path.join(projectPath, 'package.json'), JSON.stringify(pkgJson, null, 2), err => { + fs.writeFile(path.join(projectPath, 'package.json'), JSON.stringify(pkgJson, null, 2), (err) => { if (err) return global.logError(err.message) }) diff --git a/src/interfaces/SetupInterface.ts b/src/interfaces/SetupInterface.ts index 8681030..7d12853 100644 --- a/src/interfaces/SetupInterface.ts +++ b/src/interfaces/SetupInterface.ts @@ -10,6 +10,6 @@ export interface Questions { { name: string value: string - }, + } ] } diff --git a/src/make-files/express-js/controller.js b/src/make-files/express-js/controller.js index aaef9ae..798dfa4 100644 --- a/src/make-files/express-js/controller.js +++ b/src/make-files/express-js/controller.js @@ -4,5 +4,5 @@ const root_get = (req, res) => { } module.exports = { - root_get, + root_get } diff --git a/src/make-files/express-js/model.js b/src/make-files/express-js/model.js index 877524f..60243a9 100644 --- a/src/make-files/express-js/model.js +++ b/src/make-files/express-js/model.js @@ -5,12 +5,12 @@ const modelSchema = new Schema( { title: { type: String, - required: true, - }, + required: true + } }, { - timestamps: true, - }, + timestamps: true + } ) const ModelName = mongoose.model('ModelName', modelSchema) diff --git a/src/make-files/express-ts/model.ts b/src/make-files/express-ts/model.ts index cc22d18..72ab514 100644 --- a/src/make-files/express-ts/model.ts +++ b/src/make-files/express-ts/model.ts @@ -4,12 +4,12 @@ const modelSchema = new Schema( { title: { type: String, - required: true, - }, + required: true + } }, { - timestamps: true, - }, + timestamps: true + } ) export default model('ModelName', modelSchema) diff --git a/src/setup.ts b/src/setup.ts index d556aea..9e16fcb 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -13,8 +13,8 @@ export default class Setup { name: 'lang', choices: [ { name: 'Typescript', value: 'ts' }, - { name: 'Javascript', value: 'js' }, - ], + { name: 'Javascript', value: 'js' } + ] } const answers = await inquirer.prompt(Object(questions)) fs.writeJsonSync(path.join(process.cwd(), './norkconfig.json'), answers) diff --git a/src/skeletons/express-js/norkconfig.json b/src/skeletons/express-js/norkconfig.json index 1713bb4..e8fbc3b 100644 --- a/src/skeletons/express-js/norkconfig.json +++ b/src/skeletons/express-js/norkconfig.json @@ -1,3 +1,3 @@ { - "lang": "js" -} \ No newline at end of file + "lang": "js" +} diff --git a/src/skeletons/express-js/src/app.js b/src/skeletons/express-js/src/app.js index 488bd3a..985765e 100644 --- a/src/skeletons/express-js/src/app.js +++ b/src/skeletons/express-js/src/app.js @@ -15,13 +15,13 @@ const app = express() const dbURI = process.env.DB_URI mongoose .connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex: true }) - .then(result => { + .then((result) => { console.log('connected to db') app.listen(port, () => { console.log(`server is running on http://localhost:${port}`) }) }) - .catch(err => { + .catch((err) => { console.log(err) }) diff --git a/src/skeletons/express-js/src/controllers/rootController.js b/src/skeletons/express-js/src/controllers/rootController.js index aaef9ae..798dfa4 100644 --- a/src/skeletons/express-js/src/controllers/rootController.js +++ b/src/skeletons/express-js/src/controllers/rootController.js @@ -4,5 +4,5 @@ const root_get = (req, res) => { } module.exports = { - root_get, + root_get } diff --git a/src/skeletons/express-js/src/utils/REAME.md b/src/skeletons/express-js/src/utils/REAME.md index 4a554e0..7e1a454 100644 --- a/src/skeletons/express-js/src/utils/REAME.md +++ b/src/skeletons/express-js/src/utils/REAME.md @@ -1 +1 @@ -# Folder for utils and other config files \ No newline at end of file +# Folder for utils and other config files diff --git a/src/skeletons/express-ts/.prettierrc b/src/skeletons/express-ts/.prettierrc index d0dd41b..ea161e1 100644 --- a/src/skeletons/express-ts/.prettierrc +++ b/src/skeletons/express-ts/.prettierrc @@ -11,5 +11,5 @@ "vueIndentScriptAndStyle": true, "arrowParens": "always", "bracketSameLine": false, - "endOfLine": "lf" + "endOfLine": "lf" } diff --git a/src/skeletons/express-ts/norkconfig.json b/src/skeletons/express-ts/norkconfig.json index cb5b32d..bc1c3b8 100644 --- a/src/skeletons/express-ts/norkconfig.json +++ b/src/skeletons/express-ts/norkconfig.json @@ -1,5 +1,5 @@ { - "lang": "ts", - "db": "", - "orm": "" -} \ No newline at end of file + "lang": "ts", + "db": "", + "orm": "" +} diff --git a/src/skeletons/express-ts/package.json b/src/skeletons/express-ts/package.json index e23f598..4d797b3 100644 --- a/src/skeletons/express-ts/package.json +++ b/src/skeletons/express-ts/package.json @@ -1,73 +1,73 @@ { - "name": "project-name", - "version": "1.0.0", - "description": "", - "main": "dist/server.js", - "private": "true", - "keywords": [], - "author": "", - "repository": "github:username/repo", - "license": "ISC", - "scripts": { - "start": "node dist/server.js", - "start:dev": "nodemon src/server.ts", - "test": "jest", - "clean": "rimraf dist/*", - "copy-assets": "npx ts-node src/utils/copyAssets", - "tsc": "tsc -p .", - "build": "npm-run-all clean tsc copy-assets", + "name": "project-name", + "version": "1.0.0", + "description": "", + "main": "dist/server.js", + "private": "true", + "keywords": [], + "author": "", + "repository": "github:username/repo", + "license": "ISC", + "scripts": { + "start": "node dist/server.js", + "start:dev": "nodemon src/server.ts", + "test": "jest", + "clean": "rimraf dist/*", + "copy-assets": "npx ts-node src/utils/copyAssets", + "tsc": "tsc -p .", + "build": "npm-run-all clean tsc copy-assets", "format": "npx prettier --write ." - }, - "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", - "express-validator": "^6.14.2", - "fs-extra": "^10.0.0", - "jsonwebtoken": "^8.5.1", - "mongoose": "^5.12.3", - "pg": "^8.7.1", - "pg-hstore": "^2.3.4", - "sequelize": "^6.15.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.5.2", - "@types/jsonwebtoken": "^8.5.8", - "@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.1.5", - "ts-node": "^10.8.1", - "typescript": "^4.2.4", - "morgan": "^1.10.0" - }, - "jest": { - "preset": "ts-jest", - "testEnvironment": "node" - }, - "nodemonConfig": { - "ignore": [ - "**/*.test.ts", - "**/*.spec.ts", - ".git", - "node_modules" - ], - "watch": [ - "src" - ], - "ext": "ts, js" - } + }, + "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", + "express-validator": "^6.14.2", + "fs-extra": "^10.0.0", + "jsonwebtoken": "^8.5.1", + "mongoose": "^5.12.3", + "pg": "^8.7.1", + "pg-hstore": "^2.3.4", + "sequelize": "^6.15.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.5.2", + "@types/jsonwebtoken": "^8.5.8", + "@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.1.5", + "ts-node": "^10.8.1", + "typescript": "^4.2.4", + "morgan": "^1.10.0" + }, + "jest": { + "preset": "ts-jest", + "testEnvironment": "node" + }, + "nodemonConfig": { + "ignore": [ + "**/*.test.ts", + "**/*.spec.ts", + ".git", + "node_modules" + ], + "watch": [ + "src" + ], + "ext": "ts, js" + } } diff --git a/src/skeletons/express-ts/tsconfig.json b/src/skeletons/express-ts/tsconfig.json index a6f9e39..a1fb18c 100644 --- a/src/skeletons/express-ts/tsconfig.json +++ b/src/skeletons/express-ts/tsconfig.json @@ -5,7 +5,7 @@ /* 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", diff --git a/src/skeletons/sequelize-models/User.ts b/src/skeletons/sequelize-models/User.ts index 49b8051..305080e 100644 --- a/src/skeletons/sequelize-models/User.ts +++ b/src/skeletons/sequelize-models/User.ts @@ -10,26 +10,26 @@ Instance.init( type: DataTypes.UUID, primaryKey: true, allowNull: false, - unique: true, + unique: true }, username: { type: DataTypes.STRING, - allowNull: false, + allowNull: false }, password: { type: DataTypes.STRING, - allowNull: false, + allowNull: false }, email: { type: DataTypes.STRING, allowNull: false, - unique: true, - }, + unique: true + } }, { sequelize: db, - tableName: path.basename(__filename).split('.')[0].toLowerCase(), - }, + tableName: path.basename(__filename).split('.')[0].toLowerCase() + } ) export default Instance diff --git a/tsconfig.json b/tsconfig.json index cdd1fd4..3ec4ba1 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,23 +1,15 @@ { - "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. */ - "declaration": true, - }, - "exclude": [ - "_old", - "node_modules", - "src/make-files", - "src/skeletons", - "src/tests", - "src/interfaces", - "src/utils" - ] + "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. */, + "declaration": true + }, + "exclude": ["_old", "node_modules", "src/make-files", "src/skeletons", "src/tests", "src/interfaces", "src/utils"] }