ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

commit 91f9612ff13dfd425c545148e9573d9f31d51941
parent c499bdb40b9d0db5da2c32f95270c83b38812848
Author: Konstantin Tarkus <hello@tarkus.me>
Date:   Wed, 18 Nov 2015 23:10:13 +0300

Move DOMUtils.js to ./src/core

Diffstat:
MCHANGELOG.md | 1+
MREADME.md | 3+--
Msrc/api/content.js | 14++++++++++----
Msrc/app.js | 2+-
Rsrc/utils/DOMUtils.js -> src/core/DOMUtils.js | 0
Dsrc/utils/fs.js | 19-------------------
6 files changed, 13 insertions(+), 26 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. ### [Unreleased][unreleased] +- Move `DOMUtils.js` to `src/core` folder; remove `src/utils` folder - Replace [cssnext](http://cssnext.io/) with [precss](https://github.com/jonathantneal/precss) - Update build automation scripts to use plain functions - Add support of `--release` and `--verbose` flags to build scripts diff --git a/README.md b/README.md @@ -40,11 +40,10 @@ Join [#react-starter-kit](https://gitter.im/kriasoft/react-starter-kit) chatroom │ ├── /components/ # React components │ ├── /constants/ # Constants (action types etc.) │ ├── /content/ # Static content (plain HTML or Markdown, Jade, you name it) -│ ├── /core/ # Core components (Flux dispatcher, base classes, utilities) +│ ├── /core/ # Core framework and utility functions │ ├── /decorators/ # Higher-order React components │ ├── /public/ # Static files which are copied into the /build/public folder │ ├── /stores/ # Stores contain the application state and logic -│ ├── /utils/ # Utility classes and functions │ ├── /app.js # Client-side startup script │ ├── /config.js # Global application settings │ ├── /routes.js # Universal (isomorphic) application routes diff --git a/src/api/content.js b/src/api/content.js @@ -1,10 +1,11 @@ /*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */ +import fs from 'fs'; import { join } from 'path'; import { Router } from 'express'; +import Promise from 'bluebird'; import jade from 'jade'; import fm from 'front-matter'; -import fs from '../utils/fs'; // A folder with Jade/Markdown/HTML content pages const CONTENT_DIR = join(__dirname, './content'); @@ -16,6 +17,11 @@ const parseJade = (path, jadeContent) => { return Object.assign({ path, content: htmlContent }, fmContent.attributes); }; +const readFile = Promise.promisify(fs.readFile); +const fileExists = filename => new Promise(resolve => { + fs.exists(filename, resolve); +}); + const router = new Router(); router.get('/', async (req, res, next) => { @@ -28,14 +34,14 @@ router.get('/', async (req, res, next) => { } let fileName = join(CONTENT_DIR, (path === '/' ? '/index' : path) + '.jade'); - if (!await fs.exists(fileName)) { + if (!await fileExists(fileName)) { fileName = join(CONTENT_DIR, path + '/index.jade'); } - if (!await fs.exists(fileName)) { + if (!await fileExists(fileName)) { res.status(404).send({error: `The page '${path}' is not found.`}); } else { - const source = await fs.readFile(fileName, { encoding: 'utf8' }); + const source = await readFile(fileName, { encoding: 'utf8' }); const content = parseJade(path, source); res.status(200).send(content); } diff --git a/src/app.js b/src/app.js @@ -5,7 +5,7 @@ import ReactDOM from 'react-dom'; import FastClick from 'fastclick'; import Router from './routes'; import Location from './core/Location'; -import { addEventListener, removeEventListener } from './utils/DOMUtils'; +import { addEventListener, removeEventListener } from './core/DOMUtils'; let cssContainer = document.getElementById('css'); const appContainer = document.getElementById('app'); diff --git a/src/utils/DOMUtils.js b/src/core/DOMUtils.js diff --git a/src/utils/fs.js b/src/utils/fs.js @@ -1,19 +0,0 @@ -/*! React Starter Kit | MIT License | http://www.reactstarterkit.com/ */ - -import fs from 'fs'; - -const exists = filename => new Promise(resolve => { - fs.exists(filename, resolve); -}); - -const readFile = filename => new Promise((resolve, reject) => { - fs.readFile(filename, 'utf8', (err, data) => { - if (err) { - reject(err); - } else { - resolve(data); - } - }); -}); - -export default { exists, readFile };