Skip to content

Commit 14f964d

Browse files
Dan WahlinDan Wahlin
Dan Wahlin
authored and
Dan Wahlin
committed
Moved code into src folder
1 parent 91393fd commit 14f964d

File tree

3,096 files changed

+224142
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,096 files changed

+224142
-0
lines changed

.modules/README.md

Whitespace-only changes.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const fs = require('fs'),
2+
path = require('path'),
3+
express = require('express');
4+
5+
class Router {
6+
7+
constructor() {
8+
this.startFolder = null;
9+
}
10+
11+
//Called once during initial server startup
12+
load(app, folderName) {
13+
14+
if (!this.startFolder) this.startFolder = path.basename(folderName);
15+
16+
fs.readdirSync(folderName).forEach((file) => {
17+
18+
const fullName = path.join(folderName, file);
19+
const stat = fs.lstatSync(fullName);
20+
21+
if (stat.isDirectory()) {
22+
//Recursively walk-through folders
23+
this.load(app, fullName);
24+
} else if (file.toLowerCase().indexOf('.js')) {
25+
//Grab path to JavaScript file and use it to construct the route
26+
let dirs = path.dirname(fullName).split(path.sep);
27+
28+
if (dirs[0].toLowerCase() === this.startFolder.toLowerCase()) {
29+
dirs.splice(0, 1);
30+
}
31+
32+
const router = express.Router();
33+
//Generate the route
34+
const baseRoute = '/' + dirs.join('/');
35+
console.log('Created route: ' + baseRoute + ' for ' + fullName);
36+
37+
//Load the JavaScript file ("controller") and pass the router to it
38+
39+
40+
}
41+
});
42+
}
43+
44+
}
45+
46+
module.exports = new Router();
47+
48+
49+
50+
51+
52+
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const express = require('express'),
2+
exphbs = require('express-handlebars'),
3+
hbsHelpers = require('handlebars-helpers'),
4+
hbsLayouts = require('handlebars-layouts'),
5+
bodyParser = require('body-parser'),
6+
session = require('express-session'),
7+
errorhandler = require('errorhandler'),
8+
csrf = require('csurf'),
9+
morgan = require('morgan'),
10+
favicon = require('serve-favicon'),
11+
12+
13+
database = require('./lib/database'),
14+
seeder = require('./lib/dbSeeder'),
15+
app = express(),
16+
port = 3000;
17+
18+
class Server {
19+
20+
constructor() {
21+
this.initViewEngine();
22+
this.initExpressMiddleWare();
23+
this.initCustomMiddleware();
24+
this.initDbSeeder();
25+
this.initRoutes();
26+
this.start();
27+
}
28+
29+
start() {
30+
app.listen(port, (err) => {
31+
console.log('[%s] Listening on http://localhost:%d', process.env.NODE_ENV, port);
32+
});
33+
}
34+
35+
initViewEngine() {
36+
const hbs = exphbs.create({
37+
extname: '.hbs',
38+
defaultLayout: 'master'
39+
});
40+
app.engine('hbs', hbs.engine);
41+
app.set('view engine', 'hbs');
42+
hbsLayouts.register(hbs.handlebars, {});
43+
}
44+
45+
initExpressMiddleWare() {
46+
app.use(favicon(__dirname + '/public/images/favicon.ico'));
47+
app.use(express.static(__dirname + '/public'));
48+
app.use(morgan('dev'));
49+
app.use(bodyParser.urlencoded({ extended: true }));
50+
app.use(bodyParser.json());
51+
app.use(session({
52+
secret: 'customermanagerdemo',
53+
saveUninitialized: true,
54+
resave: true })
55+
);
56+
app.use(errorhandler());
57+
app.use(csrf());
58+
59+
app.use(function (req, res, next) {
60+
res.locals._csrf = req.csrfToken();
61+
next();
62+
});
63+
64+
process.on('uncaughtException', function (err) {
65+
if (err) console.log(err, err.stack);
66+
});
67+
}
68+
69+
initCustomMiddleware() {
70+
if (process.platform === "win32") {
71+
require("readline").createInterface({
72+
input: process.stdin,
73+
output: process.stdout
74+
}).on("SIGINT", function () {
75+
console.log('SIGINT: Closing MongoDB connection');
76+
database.close();
77+
});
78+
}
79+
80+
process.on('SIGINT', function() {
81+
console.log('SIGINT: Closing MongoDB connection');
82+
database.close();
83+
});
84+
}
85+
86+
initDbSeeder() {
87+
database.open(function() {
88+
//Set NODE_ENV to 'development' and uncomment the following if to only run
89+
//the seeder when in dev mode
90+
//if (process.env.NODE_ENV === 'development') {
91+
// seeder.init();
92+
//}
93+
seeder.init();
94+
});
95+
}
96+
97+
initRoutes() {
98+
99+
100+
// redirect all others to the index (HTML5 history)
101+
app.all('/*', function(req, res) {
102+
res.sendFile(__dirname + '/public/index.html');
103+
});
104+
}
105+
106+
}
107+
108+
var server = new Server();

.modules/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "angular2-app-dev-course-code",
3+
"version": "1.0.0",
4+
"description": "Copies source code from destination folder into lab folders and overlays specific lab files.",
5+
"author": "Dan Wahlin",
6+
"scripts": {
7+
"start": "node setup.js"
8+
},
9+
"dependencies": {
10+
"fs-extra": "^0.30.0",
11+
"request": "^2.75.0",
12+
"adm-zip": "^0.4.7"
13+
}
14+
}

.modules/setup.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
'use strict';
2+
3+
var fse = require('fs-extra'),
4+
request = require('request'),
5+
url = require('url'),
6+
path = require('path'),
7+
fs = require('fs'),
8+
AdmZip = require('adm-zip');
9+
10+
function copyIntoDirectories(srcDir, startDir, copyToSubFolderName, dirsToIgnore, overlayFolder) {
11+
//Iterate through directories
12+
fse.readdirSync(startDir).forEach(function (dir) {
13+
var directory = startDir + '/' + dir,
14+
stat = fse.lstatSync(directory);
15+
16+
if (stat.isDirectory()) {
17+
if (dirsToIgnore.indexOf(dir) === -1) { //Make sure the ignoreDirs aren't involved in the copy operations
18+
var targetDir = directory + '/' + copyToSubFolderName, //Target directory src should be copied to
19+
overlayFolder = (overlayFolder) ? overlayFolder : 'Files';
20+
filesOverlaySrc = directory + '/' + overlayFolder, //If no srcDir is provided then we're overlaying lab files into the targetDir
21+
finalSrc = (srcDir) ? srcDir : filesOverlaySrc;
22+
23+
fse.copySync(finalSrc, targetDir);
24+
console.log('Copied ' + finalSrc + ' to ' + targetDir);
25+
}
26+
}
27+
});
28+
}
29+
30+
function copyIntoDirectory(srcDir, startDir, copyToSubFolderName, overlayFolder) {
31+
var targetDir = startDir + '/' + copyToSubFolderName, //Target directory src should be copied to
32+
overlayFolder = (overlayFolder) ? overlayFolder : 'Files',
33+
filesOverlaySrc = startDir + '/' + overlayFolder, //If no srcDir is provided then we're overlaying lab files into the targetDir
34+
finalSrc = (srcDir) ? srcDir : filesOverlaySrc;
35+
36+
if (fse.existsSync(finalSrc)) {
37+
fse.copySync(finalSrc, targetDir);
38+
console.log('Copied ' + finalSrc + ' to ' + targetDir);
39+
}
40+
}
41+
42+
function downloadAndExtractProjects(callback) {
43+
var repos = [{ name: '', url: '' } ];
44+
45+
let pending = repos.length;
46+
//if (!pending) { return callback(new Error('No files found to download')); }
47+
48+
repos.forEach(function(repo) {
49+
var filePath = './' + repo.name + '.zip';
50+
request(repo.url).pipe(
51+
fse.createWriteStream(filePath).addListener('finish', function() {
52+
console.log('Extracting: ' + filePath);
53+
var zip = new AdmZip(filePath);
54+
zip.extractAllTo('./', true);
55+
fse.unlink(filePath,function(err) {
56+
if (err) {
57+
console.log(err);
58+
return callback(err);
59+
}
60+
if (!--pending) { callback(null); }
61+
});
62+
})
63+
);
64+
});
65+
}
66+
67+
68+
69+
var beginFolder = 'begin',
70+
endFolder = 'end',
71+
beginFiles = 'files/beginFiles',
72+
endFiles = 'files/endFiles';
73+
74+
75+
//Copy src folder into begin folder of each module
76+
copyIntoDirectories('./src', './', beginFolder, null, beginFiles);
77+
78+
79+
File renamed without changes.
File renamed without changes.

README.md renamed to src/README.md

File renamed without changes.

app.js renamed to src/app.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/public/app/app.component.js

Lines changed: 26 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/app.component.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

src/public/app/app.module.js

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/app.module.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

src/public/app/app.routing.js

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/app.routing.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

src/public/app/core/core.module.js

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/public/app/core/core.module.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

0 commit comments

Comments
 (0)