commit 243c60ce05414ddf0cacdef8f555d66ad5866f1e
parent b88244d9d84fa706d692e879cd3d48fcc4a225d5
Author: Konstantin Tarkus <hello@tarkus.me>
Date: Wed, 12 Aug 2015 20:59:22 +0300
Watch for modifications in src/content/*.* files during debugging
Diffstat:
5 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/package.json b/package.json
@@ -34,6 +34,7 @@
"eslint": "^1.1.0",
"eslint-loader": "^1.0.0",
"eslint-plugin-react": "^3.2.2",
+ "gaze": "^0.5.1",
"git-push": "^0.1.1",
"glob": "^5.0.14",
"jest-cli": "^0.4.18",
diff --git a/tools/copy.js b/tools/copy.js
@@ -7,47 +7,32 @@
* LICENSE.txt file in the root directory of this source tree.
*/
-import { ncp as copy } from 'ncp';
+import path from 'path';
+import copy from './lib/copy';
+import watch from './lib/watch';
/**
* Copies static files such as robots.txt, favicon.ico to the
* output (build) folder.
*/
-export default () => {
+export default async () => {
console.log('copy');
- return Promise.all([
-
+ await Promise.all([
// Static files
- new Promise((resolve, reject) => {
- copy('src/public', 'build/public', err => {
- if (err) {
- reject(err);
- } else {
- resolve();
- }
- })
- }),
+ copy('src/public', 'build/public'),
// Files with content (e.g. *.md files)
- new Promise((resolve, reject) => {
- copy('src/content', 'build/content', err => {
- if (err) {
- reject(err);
- } else {
- resolve();
- }
- })
- }),
+ copy('src/content', 'build/content'),
// Website and email templates
- new Promise((resolve, reject) => {
- copy('src/templates', 'build/templates', err => {
- if (err) {
- reject(err);
- } else {
- resolve();
- }
- })
- })
+ copy('src/templates', 'build/templates')
]);
+
+ if (global.WATCH) {
+ const watcher = await watch('src/content/**/*.*');
+ watcher.on('changed', async (file) => {
+ file = file.substr(path.join(__dirname, '../src/content/').length);
+ await copy(`src/content/${file}`, `build/content/${file}`);
+ });
+ }
};
diff --git a/tools/lib/copy.js b/tools/lib/copy.js
@@ -0,0 +1,14 @@
+/**
+ * React Starter Kit (http://www.reactstarterkit.com/)
+ *
+ * Copyright © 2014-2015 Kriasoft, LLC. All rights reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE.txt file in the root directory of this source tree.
+ */
+
+import ncp from 'ncp';
+
+export default (source, dest) => new Promise((resolve, reject) => {
+ ncp(source, dest, err => err ? reject(err) : resolve());
+});
diff --git a/tools/lib/watch.js b/tools/lib/watch.js
@@ -0,0 +1,14 @@
+/**
+ * React Starter Kit (http://www.reactstarterkit.com/)
+ *
+ * Copyright © 2014-2015 Kriasoft, LLC. All rights reserved.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE.txt file in the root directory of this source tree.
+ */
+
+import gaze from 'gaze';
+
+export default (pattern) => new Promise((resolve, reject) => {
+ gaze(pattern, (err, watcher) => err ? reject(err) : resolve(watcher));
+});
diff --git a/tools/start.js b/tools/start.js
@@ -55,7 +55,9 @@ export default async () => {
// including full page reloads if HMR won't work
files: [
'build/public/**/*.css',
- 'build/public/**/*.html'
+ 'build/public/**/*.html',
+ 'build/content/**/*.*',
+ 'build/templates/**/*.*'
]
});
};