mirror of
				https://github.com/filiprojek/nork.git
				synced 2025-02-20 01:22:58 +01:00 
			
		
		
		
	Rewrited to TypeScript, better file structure
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "name": "nork",
 | 
			
		||||
    "version": "2.0.0.1",
 | 
			
		||||
    "version": "3.0.0",
 | 
			
		||||
    "description": "The best node.js 'framework' :)",
 | 
			
		||||
    "main": "dist/app.js",
 | 
			
		||||
    "bin": "dist/app.js",
 | 
			
		||||
 
 | 
			
		||||
@@ -8,3 +8,10 @@
 | 
			
		||||
  - [x] setup
 | 
			
		||||
  - [x] make
 | 
			
		||||
  - [ ] 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
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +0,0 @@
 | 
			
		||||
import { Request, Response } from 'express'
 | 
			
		||||
 | 
			
		||||
export const root_get = (req: Request, res: Response) => {
 | 
			
		||||
	res.render('home')
 | 
			
		||||
	return true
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										69
									
								
								src/create.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								src/create.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
import pad from 'pad'
 | 
			
		||||
import colors from 'colors'
 | 
			
		||||
import fs from 'fs-extra'
 | 
			
		||||
import path from 'path'
 | 
			
		||||
import global from './global'
 | 
			
		||||
import { Create as CreateInterface } from './interfaces/CreateInterface'
 | 
			
		||||
import inquirer from 'inquirer'
 | 
			
		||||
 | 
			
		||||
export default class Create {
 | 
			
		||||
	static async project(projectName: string | boolean = false) {
 | 
			
		||||
		// get info about new project
 | 
			
		||||
		let projectPath
 | 
			
		||||
		const questions = [
 | 
			
		||||
			{
 | 
			
		||||
				type: 'input',
 | 
			
		||||
				name: 'project_name',
 | 
			
		||||
				message: 'Enter project name:',
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				type: 'list',
 | 
			
		||||
				message: `Pick the technology you're using:`,
 | 
			
		||||
				name: 'lang',
 | 
			
		||||
				choices: [
 | 
			
		||||
					{ name: 'Typescript', value: 'ts' },
 | 
			
		||||
					{ name: 'Javascript', value: 'js' },
 | 
			
		||||
				],
 | 
			
		||||
			},
 | 
			
		||||
			{
 | 
			
		||||
				type: 'input',
 | 
			
		||||
				name: 'author',
 | 
			
		||||
				message: 'Enter your name:',
 | 
			
		||||
			},
 | 
			
		||||
		]
 | 
			
		||||
		// remove first question if project name is already known
 | 
			
		||||
		if (projectName) {
 | 
			
		||||
			questions.shift()
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		const answers = await inquirer.prompt(questions)
 | 
			
		||||
		const data: CreateInterface = {
 | 
			
		||||
			project_name: answers.project_name ? answers.project_name : process.argv[3],
 | 
			
		||||
			lang: answers.lang,
 | 
			
		||||
			author: answers.author,
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// copy skeleton to new project
 | 
			
		||||
		process.argv.includes('-i') ? (projectPath = process.cwd()) : (projectPath = path.join(process.cwd(), data.project_name))
 | 
			
		||||
		fs.copySync(path.join(__dirname, './skeletons/express-' + data.lang), projectPath)
 | 
			
		||||
 | 
			
		||||
		// edit package.json file
 | 
			
		||||
		const pkgJson = fs.readJsonSync(path.join(projectPath, 'package.json'))
 | 
			
		||||
		// const pkgJson = require(path.join(projectPath, 'package.json'))
 | 
			
		||||
 | 
			
		||||
		pkgJson.name = data.project_name
 | 
			
		||||
		pkgJson.author = data.author
 | 
			
		||||
 | 
			
		||||
		fs.writeFile(path.join(projectPath, 'package.json'), JSON.stringify(pkgJson, null, 2), err => {
 | 
			
		||||
			if (err) return global.logError(err.message)
 | 
			
		||||
		})
 | 
			
		||||
 | 
			
		||||
		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), global.langToLanguage(String(data.lang)))
 | 
			
		||||
 | 
			
		||||
		return global.logSuccess(`Project ${data.project_name} created successfully!`)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -13,4 +13,15 @@ export default class Global {
 | 
			
		||||
		console.log(colors.bgYellow.red(errorMsg))
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	static langToLanguage(lang: string): string {
 | 
			
		||||
		switch (lang) {
 | 
			
		||||
			case 'js':
 | 
			
		||||
				return 'Javascript'
 | 
			
		||||
			case 'ts':
 | 
			
		||||
				return 'Typescript'
 | 
			
		||||
			default:
 | 
			
		||||
				return 'Unknown language'
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										5
									
								
								src/interfaces/CreateInterface.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								src/interfaces/CreateInterface.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,5 @@
 | 
			
		||||
export interface Create {
 | 
			
		||||
	project_name: string
 | 
			
		||||
	author: string
 | 
			
		||||
	lang: string
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
import { Router, Request, Response, NextFunction } from 'express'
 | 
			
		||||
 | 
			
		||||
export const router = Router()
 | 
			
		||||
 | 
			
		||||
router.use((req: Request, res: Response, next: NextFunction) => {
 | 
			
		||||
	console.log('Hi :)')
 | 
			
		||||
	next()
 | 
			
		||||
})
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
import { Schema, model } from 'mongoose'
 | 
			
		||||
 | 
			
		||||
const modelSchema = new Schema<any>(
 | 
			
		||||
	{
 | 
			
		||||
		title: {
 | 
			
		||||
			type: String,
 | 
			
		||||
			required: true,
 | 
			
		||||
		},
 | 
			
		||||
	},
 | 
			
		||||
	{
 | 
			
		||||
		timestamps: true,
 | 
			
		||||
	},
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
export default model('ModelName', modelSchema)
 | 
			
		||||
@@ -2,6 +2,7 @@ import Help from './help'
 | 
			
		||||
import Version from './version'
 | 
			
		||||
import Setup from './setup'
 | 
			
		||||
import Make from './make'
 | 
			
		||||
import Create from './create'
 | 
			
		||||
 | 
			
		||||
export default class Routes {
 | 
			
		||||
	static router(): string {
 | 
			
		||||
@@ -35,6 +36,13 @@ export default class Routes {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (process.argv[2] == 'create') {
 | 
			
		||||
			if (process.argv[4] != 'test') {
 | 
			
		||||
				Create.project(process.argv[3])
 | 
			
		||||
			}
 | 
			
		||||
			return `create ${process.argv[3]}`
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		console.log(Help.logHelp())
 | 
			
		||||
		return 'all help'
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +0,0 @@
 | 
			
		||||
import { Router } from 'express'
 | 
			
		||||
import * as rootController from '@/controllers/rootController'
 | 
			
		||||
 | 
			
		||||
export const router = Router()
 | 
			
		||||
 | 
			
		||||
router.get('/', rootController.root_get)
 | 
			
		||||
@@ -1,3 +0,0 @@
 | 
			
		||||
export function helloWorld() {
 | 
			
		||||
	console.log('hello world')
 | 
			
		||||
}
 | 
			
		||||
@@ -56,3 +56,13 @@ describe('should return make', () => {
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
describe('should return create', () => {
 | 
			
		||||
	it('return create testProject', () => {
 | 
			
		||||
		process.argv[2] = 'create'
 | 
			
		||||
		process.argv[3] = 'testProject'
 | 
			
		||||
		process.argv[4] = 'test'
 | 
			
		||||
		const routes = Routes.router()
 | 
			
		||||
		assert.equal(routes, 'create testProject')
 | 
			
		||||
	})
 | 
			
		||||
})
 | 
			
		||||
 
 | 
			
		||||
@@ -1,15 +0,0 @@
 | 
			
		||||
<!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>
 | 
			
		||||
		Reference in New Issue
	
	Block a user