Skip to content

Commit b3af18f

Browse files
committed
gen3-express app has been created.
0 parents  commit b3af18f

File tree

10 files changed

+154
-0
lines changed

10 files changed

+154
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/package-lock.json

bin/gen3-express.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env node
2+
3+
const path = require('path')
4+
const fse = require('fs-extra')
5+
const { program } = require('commander')
6+
7+
const templatePath = path.resolve(__dirname, '../template')
8+
9+
// function to copy template files.
10+
const createApp = async (appName) => {
11+
const destPath = path.resolve(process.cwd(), appName)
12+
try {
13+
await fse.copy(templatePath, destPath)
14+
console.log(`[+] Express app has been created at ${destPath}...`)
15+
} catch (error) {
16+
console.log(`[-] ${error.message}`)
17+
}
18+
}
19+
20+
program
21+
.version('1.0.0')
22+
.argument('<app-name>', 'Name of the application')
23+
.action(async (appName) => {
24+
// check if folder already exist.
25+
if (fse.existsSync(appName)) {
26+
console.error('[-] Express is app already exist...')
27+
return
28+
}
29+
await createApp(appName)
30+
})
31+
32+
program.parse(process.argv)

package.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"name": "gen3-express",
3+
"version": "1.0.0",
4+
"description": "A gen3 tool to generate get started express app",
5+
"main": "index.js",
6+
"bin": {
7+
"gen3-express": "./bin/gen3-express.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/OurCodeBase/gen3-express.git"
12+
},
13+
"keywords": [
14+
"boilerplate",
15+
"express",
16+
"generator",
17+
"create-express-app"
18+
],
19+
"author": "harsh vairagi",
20+
"license": "ISC",
21+
"bugs": {
22+
"url": "https://github.com/OurCodeBase/gen3-express/issues"
23+
},
24+
"homepage": "https://github.com/OurCodeBase/gen3-express#readme",
25+
"dependencies": {
26+
"commander": "^12.1.0",
27+
"fs-extra": "^11.2.0"
28+
}
29+
}

template/app.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const path = require('path')
2+
const nets = require('./nets')
3+
const express = require('express')
4+
5+
const app = express()
6+
const PORT = 3000
7+
8+
app.set('view engine', 'ejs')
9+
app.use(express.static('public'))
10+
app.use('/colors', express.static(
11+
path.join(__dirname,
12+
'node_modules',
13+
'material-dynamic-colors',
14+
'dist',
15+
'cdn'
16+
)
17+
))
18+
19+
app.get('/', (req, res) => res.render('home'))
20+
21+
app.listen(PORT, () => {
22+
console.log('Server has been started on...');
23+
nets.showAvailableNetworks(PORT)
24+
})

template/nets.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const os = require('os')
2+
3+
function availableNetworks() {
4+
const networkInterfaces = os.networkInterfaces()
5+
const networkAddresses = []
6+
for (const networkInterface of Object.keys(networkInterfaces)) {
7+
for (const interface of networkInterfaces[networkInterface]) {
8+
if (interface.family == 'IPv4'){
9+
networkAddresses.push(interface.address)
10+
}
11+
}
12+
}
13+
return networkAddresses
14+
}
15+
16+
function showAvailableNetworks(PORT) {
17+
for (const _ of availableNetworks()) {
18+
console.log(`http://${_}:${PORT}/`)
19+
}
20+
}
21+
22+
module.exports = { availableNetworks, showAvailableNetworks }

template/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "express-app",
3+
"version": "1.0.0",
4+
"main": "app.js",
5+
"scripts": {
6+
"server": "nodemon app.js",
7+
"sync": "browser-sync start --config sync.js"
8+
},
9+
"dependencies": {
10+
"ejs": "^3.1.10",
11+
"express": "^4.19.2",
12+
"material-dynamic-colors": "^1.1.2"
13+
},
14+
"devDependencies": {
15+
"nodemon": "^3.1.4",
16+
"browser-sync": "^3.0.2"
17+
}
18+
}

template/public/fonts/sans.woff

47.7 KB
Binary file not shown.

template/public/style.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@font-face {
2+
font-family: Sans;
3+
src: url(fonts/sans.woff);
4+
}
5+
6+
h1 {
7+
font-family: Sans;
8+
}

template/sync.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
proxy: 'http://localhost:3000',
3+
files: ["views/**/*.ejs", "public/**/*.{css,js}"],
4+
port: 3001,
5+
open: false,
6+
notify: false
7+
}

template/views/home.ejs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title></title>
7+
<link href="css/style.css" rel="stylesheet">
8+
</head>
9+
<body>
10+
<h1>Hello World!</h1>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)