copy.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * React Starter Kit (https://www.reactstarterkit.com/)
  3. *
  4. * Copyright © 2014-2016 Kriasoft, LLC. All rights reserved.
  5. *
  6. * This source code is licensed under the MIT license found in the
  7. * LICENSE.txt file in the root directory of this source tree.
  8. */
  9. import path from 'path';
  10. import gaze from 'gaze';
  11. import replace from 'replace';
  12. import Promise from 'bluebird';
  13. /**
  14. * Copies static files such as robots.txt, favicon.ico to the
  15. * output (build) folder.
  16. */
  17. async function copy({ watch } = {}) {
  18. const ncp = Promise.promisify(require('ncp'));
  19. await Promise.all([
  20. ncp('src/public', 'build/public'),
  21. ncp('src/content', 'build/content'),
  22. ncp('package.json', 'build/package.json'),
  23. ]);
  24. replace({
  25. regex: '"start".*',
  26. replacement: '"start": "node server.js"',
  27. paths: ['build/package.json'],
  28. recursive: false,
  29. silent: false,
  30. });
  31. if (watch) {
  32. const watcher = await new Promise((resolve, reject) => {
  33. gaze('src/content/**/*.*', (err, val) => err ? reject(err) : resolve(val));
  34. });
  35. watcher.on('changed', async (file) => {
  36. const relPath = file.substr(path.join(__dirname, '../src/content/').length);
  37. await ncp(`src/content/${relPath}`, `build/content/${relPath}`);
  38. });
  39. }
  40. }
  41. export default copy;