mirror of
https://github.com/filiprojek/nork.git
synced 2024-11-02 18:12:28 +01:00
nork create projectName -> done
This commit is contained in:
parent
df60d75317
commit
cb4954cc88
81
package-lock.json
generated
81
package-lock.json
generated
@ -11,8 +11,10 @@
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"commander": "^8.1.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"inquirer": "^8.1.2",
|
||||
"leven": "^4.0.0",
|
||||
"ncp": "^2.0.0",
|
||||
"pad": "^3.2.0"
|
||||
},
|
||||
"bin": {
|
||||
@ -200,6 +202,24 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/fs-extra": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz",
|
||||
"integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==",
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.8",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
|
||||
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
|
||||
},
|
||||
"node_modules/iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
@ -432,6 +452,17 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"dependencies": {
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/leven": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/leven/-/leven-4.0.0.tgz",
|
||||
@ -453,6 +484,14 @@
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
|
||||
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
|
||||
},
|
||||
"node_modules/ncp": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
|
||||
"integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M=",
|
||||
"bin": {
|
||||
"ncp": "bin/ncp"
|
||||
}
|
||||
},
|
||||
"node_modules/os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
|
||||
@ -583,6 +622,14 @@
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
|
||||
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
@ -708,6 +755,21 @@
|
||||
"escape-string-regexp": "^1.0.5"
|
||||
}
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz",
|
||||
"integrity": "sha512-C5owb14u9eJwizKGdchcDUQeFtlSHHthBk8pbX9Vc1PFZrLombudjDnNns88aYslCyF6IY5SUw3Roz6xShcEIQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"graceful-fs": {
|
||||
"version": "4.2.8",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.8.tgz",
|
||||
"integrity": "sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg=="
|
||||
},
|
||||
"iconv-lite": {
|
||||
"version": "0.4.24",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
|
||||
@ -862,6 +924,15 @@
|
||||
"resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz",
|
||||
"integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw=="
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6",
|
||||
"universalify": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"leven": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/leven/-/leven-4.0.0.tgz",
|
||||
@ -877,6 +948,11 @@
|
||||
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
|
||||
"integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
|
||||
},
|
||||
"ncp": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ncp/-/ncp-2.0.0.tgz",
|
||||
"integrity": "sha1-GVoh1sRuNh0vsSgbo4uR6d9727M="
|
||||
},
|
||||
"os-tmpdir": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz",
|
||||
@ -972,6 +1048,11 @@
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.1.0.tgz",
|
||||
"integrity": "sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A=="
|
||||
},
|
||||
"universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
|
@ -18,8 +18,10 @@
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
"commander": "^8.1.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
"inquirer": "^8.1.2",
|
||||
"leven": "^4.0.0",
|
||||
"ncp": "^2.0.0",
|
||||
"pad": "^3.2.0"
|
||||
},
|
||||
"repository": {
|
||||
|
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>
|
Loading…
Reference in New Issue
Block a user