mirror of
https://github.com/filiprojek/nork.git
synced 2025-02-20 01:22:58 +01:00
nork create projectName -> done
This commit is contained in:
124
src/app.js
124
src/app.js
@ -1,50 +1,86 @@
|
||||
#!/usr/bin/env node
|
||||
const inquirer = require('inquirer')
|
||||
const path = require('path')
|
||||
|
||||
const main = async () => {
|
||||
if (process.argv[ 2 ] == 'create')
|
||||
{
|
||||
const data = {}
|
||||
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:',
|
||||
},
|
||||
]
|
||||
|
||||
if (process.argv[ 3 ]) {
|
||||
questions.shift()
|
||||
}
|
||||
|
||||
let answers = await inquirer.prompt(questions)
|
||||
data.project_name = answers.project_name ? answers.project_name : process.argv[3]
|
||||
data.lang = answers.lang
|
||||
data.author = answers.author
|
||||
|
||||
console.log(data)
|
||||
}
|
||||
|
||||
if (process.argv[ 2 ] == 'make')
|
||||
{
|
||||
const component = process.argv[ 3 ]
|
||||
|
||||
const fs = require('fs-extra')
|
||||
const colors = require('colors')
|
||||
const pad = require('pad')
|
||||
|
||||
const langToLanguage = lang => {
|
||||
switch (lang) {
|
||||
case 'js':
|
||||
return 'Javascript'
|
||||
break
|
||||
case 'ts':
|
||||
return 'Typescript'
|
||||
break
|
||||
default:
|
||||
return 'Unknown language'
|
||||
}
|
||||
}
|
||||
main()
|
||||
|
||||
;(async () => {
|
||||
if (process.argv[2] == 'create') {
|
||||
// get info about new project
|
||||
const data = { lang: 'ts' }
|
||||
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 (process.argv[3]) {
|
||||
questions.shift()
|
||||
}
|
||||
|
||||
let answers = await inquirer.prompt(questions)
|
||||
data.project_name = answers.project_name ? answers.project_name : process.argv[3]
|
||||
data.lang = answers.lang
|
||||
data.author = answers.author
|
||||
|
||||
// copy skeleton to new project
|
||||
fs.copySync(path.join(__dirname, './skeletons/express-' + data.lang), process.cwd())
|
||||
|
||||
// edit package.json file
|
||||
const pkgJson = require(path.join(process.cwd(), 'package.json'))
|
||||
|
||||
pkgJson.name = data.project_name
|
||||
pkgJson.author = data.author
|
||||
|
||||
fs.writeFile(path.join(process.cwd(), 'package.json'), JSON.stringify(pkgJson, null, 2), err => {
|
||||
if (err) return console.log(err)
|
||||
})
|
||||
|
||||
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))
|
||||
|
||||
console.log(colors.cyan(`Project ${ data.project_name } created successfully!`))
|
||||
return true
|
||||
}
|
||||
|
||||
if (process.argv[2] == 'make') {
|
||||
const component = process.argv[3]
|
||||
}
|
||||
if (!process.argv[2]) {
|
||||
// Help
|
||||
console.log('Help coming soon!')
|
||||
}
|
||||
})()
|
||||
|
@ -0,0 +1,10 @@
|
||||
import { Request, Response } from 'express'
|
||||
|
||||
const root_get = (req: Request, res: Response) => {
|
||||
res.render('home')
|
||||
return true
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
root_get,
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
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
|
||||
|
17
src/make-files/express-ts/model.js
Normal file
17
src/make-files/express-ts/model.js
Normal file
@ -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,8 @@
|
||||
const { Router } = require('express')
|
||||
const rootController = require('../controllers/rootController')
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.get('/', rootController.root_get)
|
||||
|
||||
module.exports = router
|
||||
|
9
src/make-files/express-ts/test.js
Normal file
9
src/make-files/express-ts/test.js
Normal file
@ -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-ts/view.ejs
Normal file
15
src/make-files/express-ts/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>
|
Reference in New Issue
Block a user