Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-north committed Nov 22, 2017
1 parent 0aa9a05 commit 18bb647
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 72 deletions.
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"bracketSpacing": true,
"trailingComma": "none",
"useTabs": false,
"tabWidth": 2,
"printWidth": 80,
"semi": true
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"**/dist": true,
"**/node_modules": true,
"**/bower_components": true
}
},
"editor.formatOnSave": true
}
15 changes: 3 additions & 12 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
{
"ignore": [
"*.sqlite",
".git",
"dist/**",
"node_modules/**"
],
"watch": [
"src",
"views",
"public"
],
"ignore": ["*.sqlite", ".git", "dist/**", "node_modules/**"],
"watch": ["src", "views", "public"],
"ext": "ts hbs handlebars js json yaml yml css"
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
"dependencies": {
"chalk": "^2.3.0",
"express": "^4.16.2",
"express-handlebars": "^3.0.0",
"express-winston": "^2.4.0",
"fs-extra": "^4.0.2",
"lodash": "^4.17.4",
"scripty": "^1.7.2",
Expand All @@ -38,8 +40,6 @@
"@types/node": "^8.0.53",
"@types/sqlite3": "^3.1.1",
"@types/winston": "^2.3.7",
"express-handlebars": "^3.0.0",
"express-winston": "^2.4.0",
"nodemon": "^1.12.1",
"tslint": "^5.8.0",
"typescript": "^2.6.1"
Expand Down
6 changes: 3 additions & 3 deletions public/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ body {
background: #eee;
}

ul.nav, ul.collection {
ul.nav,
ul.collection {
list-style: none;
padding: 0;
margin: 0;
Expand All @@ -29,7 +30,6 @@ ul.collection > li {
display: block;
}


ul.collection > li a {
display: block;
color: inherit;
Expand All @@ -48,4 +48,4 @@ ul.collection > li a:hover {
text-transform: uppercase;
padding: 2px 8px;
border-radius: 2px;
}
}
2 changes: 1 addition & 1 deletion src/data/employees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export async function getAllEmployees(): Promise<Employee[]> {
return await db.all('SELECT * FROM Employee');
}

export async function getEmployee(id: string|number): Promise<Employee[]> {
export async function getEmployee(id: string | number): Promise<Employee[]> {
const db = await getDb('dev');
return await db.get('SELECT * FROM Employee WHERE id = $1', id);
}
4 changes: 3 additions & 1 deletion src/db/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const copyFile = promisify(fs.copyFile);
export async function initializeDb(dbName = 'dev') {
let pth = dbPath(dbName);
if (!fs.existsSync(pth)) {
logger.debug(`Database ${dbName} was not found at ${pth}... creating it now`);
logger.debug(
`Database ${dbName} was not found at ${pth}... creating it now`
);
await copyFile(MASTER_DB_FILE, pth);
}
}
3 changes: 2 additions & 1 deletion src/db/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as path from 'path';
import * as sqlite from 'sqlite';
import { PROJECT_ROOT } from '../constants';

export const dbPath = (name: string) => path.join(PROJECT_ROOT, `${name}.sqlite`);
export const dbPath = (name: string) =>
path.join(PROJECT_ROOT, `${name}.sqlite`);

const dbPromises: { [key: string]: Promise<sqlite.Database> } = {};

Expand Down
62 changes: 41 additions & 21 deletions src/express-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,59 @@ async function startListening(app: express.Express): Promise<http.Server> {
}

async function setupTemplating(app: express.Application) {
app.engine('.hbs', exphbs({
defaultLayout: 'main',
extname: '.hbs',
helpers: await loadHandlebarsHelpers()
}));
app.engine(
'.hbs',
exphbs({
defaultLayout: 'main',
extname: '.hbs',
helpers: await loadHandlebarsHelpers()
})
);
app.set('view engine', '.hbs');
}

function installMiddlewares(app: express.Application) {
app.use(expressWinston.logger({
// expressFormat: true,
meta: false,
msg: '{{req.method}}: {{res.statusCode}} ({{res.responseTime}}ms)\t{{req.url}}',
transports: [
new winston.transports.Console({
colorize: true
})
],
skip(req: express.Request, res: express.Response) {
return /^\/static\//.test(req.path);
}
}));

app.use(
expressWinston.logger({
// expressFormat: true,
meta: false,
msg:
'{{req.method}}: {{res.statusCode}} ({{res.responseTime}}ms)\t{{req.url}}',
transports: [
new winston.transports.Console({
colorize: true
})
],
skip(req: express.Request, res: express.Response) {
return /^\/static\//.test(req.path);
}
})
);
}

async function setupRouting(app: express.Application) {
app.use(router);
app.use('/static', express.static('public'));
}

export async function startExpressServer(): Promise<[express.Application, http.Server]> {
const app = express();
async function setupDevMiddleware(app: express.Application) {
app.enable('x-powered-by');
}

async function setupProdMiddleware(app: express.Application) {
app.disable('x-powered-by');
}

export async function startExpressServer(): Promise<
[express.Application, http.Server]
> {
const app = express();

if (process.env.NODE_ENV !== 'prod') {
await setupDevMiddleware(app);
} else {
await setupProdMiddleware(app);
}

await setupTemplating(app);
await installMiddlewares(app);
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ const pkg = require('../package.json');
(async function main() {
await initializeDb('dev');
const [app, server] = await startExpressServer();
}());
})();
6 changes: 4 additions & 2 deletions src/load-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ async function readdir(name: string): Promise<string[]> {

async function getHelperNames() {
let files: string[] = await readdir(join(PROJECT_ROOT, 'src', 'helpers'));
return files.map((f) => f.split('.')[0]);
return files.map(f => f.split('.')[0]);
}

export async function loadHandlebarsHelpers(): Promise<HelperSet> {
let helperNames = await getHelperNames();
let helpers: HelperSet = {};
helperNames.reduce<HelperSet>((set, name) => {
return Object.assign(set, { [`${name}`]: require(`./helpers/${name}`).default});
return Object.assign(set, {
[`${name}`]: require(`./helpers/${name}`).default
});
}, helpers);
return helpers;
}
4 changes: 2 additions & 2 deletions src/types/db-entities.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
type DBRecordReference = number | string;

interface DBRecord {
Id: DBRecordReference
Id: DBRecordReference;
}

interface Category extends DBRecord {
Expand Down Expand Up @@ -84,7 +84,7 @@ interface Shipper extends DBRecord {
}

interface Supplier extends Customer {
HomePage: string
HomePage: string;
}

interface Territory extends DBRecord {
Expand Down
2 changes: 1 addition & 1 deletion src/types/express-winston.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
declare module 'express-winston';
declare module 'express-winston';
8 changes: 3 additions & 5 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"extends": "tslint:recommended",
"rules": {
"semicolon": [
true,
"always"
],
"semicolon": [true, "always"],
"interface-name": false,
"trailing-comma": false,
"quotemark": [true, "single"],
"arrow-parens": [false],
"prefer-const": [false]
}
}
}
10 changes: 6 additions & 4 deletions views/customers/show.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
<div class="mui-col-md-6">
<h3>Contact Info</h3>
<p>
<strong>{{customer.ContactName}}</strong><br>
{{customer.ContactTitle}}
<strong>{{customer.ContactName}}</strong>
<br> {{customer.ContactTitle}}
</p>
<p>
<div><strong>Phone: </strong> {{customer.Phone}}</div>
<div><strong>Fax: </strong> {{customer.Fax}}</div>
<div>
<strong>Phone: </strong> {{customer.Phone}}</div>
<div>
<strong>Fax: </strong> {{customer.Fax}}</div>
</p>
<p>
<div>{{customer.Address}}</div>
Expand Down
20 changes: 11 additions & 9 deletions views/employees/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
<h1>All Employees</h1>
<ul class='collection'>
{{#each employees as |e|}}
<li>
<a class='mui-panel' href="/employees/{{e.Id}}">
<span class='mui-badge mui--pull-right'>{{e.Title}}</span>
<h3 class='mui-panel__title'>{{e.LastName}}, {{e.FirstName}}</h3>
<p><strong>Region: </strong> {{e.Region}}</p>
<p><strong>Hired: </strong> {{e.HireDate}}</p>
</a>
</li>
<li>
<a class='mui-panel' href="/employees/{{e.Id}}">
<span class='mui-badge mui--pull-right'>{{e.Title}}</span>
<h3 class='mui-panel__title'>{{e.LastName}}, {{e.FirstName}}</h3>
<p>
<strong>Region: </strong> {{e.Region}}</p>
<p>
<strong>Hired: </strong> {{e.HireDate}}</p>
</a>
</li>
{{else}}
<li>No employees</li>
<li>No employees</li>
{{/each}}
</ul>
</div>
4 changes: 2 additions & 2 deletions views/layouts/main.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</head>

<body>
{{> 'appbar'}}
{{{body}}}
{{> 'appbar'}} {{{body}}}
<script src="/static/js/mui.min.js"></script>
</body>

</html>
16 changes: 12 additions & 4 deletions views/partials/appbar.hbs
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
<div class="mui-appbar">
<div class="mui-container">
<ul class="nav">
<li class='nav-item'><a class='mui--appbar-height' href="/employees">Employees</a></li>
<li class='nav-item'><a class='mui--appbar-height' href="/customers">Customers</a></li>
<li class='nav-item'><a class='mui--appbar-height' href="/suppliers">Suppliers</a></li>
<li class='nav-item'><a class='mui--appbar-height' href="/orders">Orders</a></li>
<li class='nav-item'>
<a class='mui--appbar-height' href="/employees">Employees</a>
</li>
<li class='nav-item'>
<a class='mui--appbar-height' href="/customers">Customers</a>
</li>
<li class='nav-item'>
<a class='mui--appbar-height' href="/suppliers">Suppliers</a>
</li>
<li class='nav-item'>
<a class='mui--appbar-height' href="/orders">Orders</a>
</li>
</ul>
</div>
</div>

0 comments on commit 18bb647

Please sign in to comment.