Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bash-3.2$ npm start
- > @ start /Users/richb/github/react-starter-kit-richb
- > babel-node tools/run start
- [22:16:08] Starting 'start'...
- [22:16:08] Starting 'clean'...
- [22:16:08] Finished 'clean' after 42 ms
- [22:16:08] Starting 'bound copy'...
- build/package.json
- [22:16:08] Finished 'bound copy' after 149 ms
- webpack built 422ba140c5b05339f7a8 in 5251ms
- Child
- Time: 5251ms
- Asset Size Chunks Chunk Names
- main.js?422ba140c5b05339f7a8 3.39 MB 0 [emitted] main
- Child
- Time: 4803ms
- Asset Size Chunks Chunk Names
- server.js 228 kB 0 [emitted] main
- server.js.map 232 kB 0 [emitted] main
- ERROR in ./src/data/queries/content.js
- Module build failed: SyntaxError: /Users/richb/github/react-starter-kit-richb/src/data/queries/content.js: "success" is read-only (This is an error on an internal node. Probably an internal error. Location has been estimated.)
- 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 |
- 10 | import fs from 'fs';
- 11 | import { join } from 'path';
- 12 | import Promise from 'bluebird';
- 13 | import jade from 'jade';
- 14 | import fm from 'front-matter';
- 15 |
- 16 | import {
- 17 | GraphQLString as StringType,
- 18 | GraphQLNonNull as NonNull,
- 19 | } from 'graphql';
- 20 |
- 21 | import ContentType from '../types/ContentType';
- 22 |
- 23 | const md = require('markdown-it')();
- 24 |
- 25 | // A folder with Jade/Markdown/HTML content pages
- 26 | const CONTENT_DIR = join(__dirname, './content');
- 27 |
- 28 | // Extract 'front matter' metadata and generate HTML
- 29 | const parseContent = (path, fileContent, extension) => {
- 30 | const fmContent = fm(fileContent);
- 31 | let htmlContent;
- 32 | switch (extension) {
- 33 | case '.jade':
- 34 | htmlContent = jade.render(fmContent.body);
- 35 | break;
- 36 | case '.md':
- 37 | htmlContent = md.render(fmContent.body);
- 38 | break;
- 39 | case '.html':
- 40 | htmlContent = fmContent.body;
- 41 | break;
- 42 | default:
- 43 | return null;
- 44 | }
- 45 | return Object.assign({ path, content: htmlContent }, fmContent.attributes);
- 46 | };
- 47 |
- 48 | const readFile = Promise.promisify(fs.readFile);
- 49 | const fileExists = filename => new Promise(resolve => {
- 50 | fs.exists(filename, resolve);
- 51 | });
- 52 |
- 53 | async function resolveExtension(path, extension) {
- 54 | let fileNameBase = join(CONTENT_DIR, `${path === '/' ? '/index' : path}`);
- 55 | let ext = extension;
- 56 | if (!ext.startsWith('.')) {
- 57 | ext = `.${extension}`;
- 58 | }
- 59 |
- 60 | let fileName = fileNameBase + ext;
- 61 |
- 62 | if (!(await fileExists(fileName))) {
- 63 | fileNameBase = join(CONTENT_DIR, `${path}/index`);
- 64 | fileName = fileNameBase + ext;
- 65 | }
- 66 |
- 67 | if (!(await fileExists(fileName))) {
- 68 | return { success: false };
- 69 | }
- 70 |
- 71 | return { success: true, fileName };
- 72 | }
- 73 |
- 74 | async function resolveFileName(path) {
- 75 | const extensions = ['.jade', '.md', '.html'];
- 76 |
- 77 | for (const extension of extensions) {
- 78 | const maybeFileName = await resolveExtension(path, extension);
- 79 | if (maybeFileName.success) {
- 80 | return { success: true, fileName: maybeFileName.fileName, extension };
- 81 | }
- 82 | }
- 83 |
- 84 | return { success: false, fileName: null, extension: null };
- 85 | }
- 86 |
- 87 | export default {
- 88 | type: ContentType,
- 89 | args: {
- 90 | path: { type: new NonNull(StringType) },
- 91 | },
- 92 | async resolve({ request }, { path }) {
- 93 | const { success, fileName, extension } = await resolveFileName(path);
- 94 | if (!success) {
- 95 | return null;
- 96 | }
- 97 |
- 98 | const source = await readFile(fileName, { encoding: 'utf8' });
- 99 | return parseContent(path, source, extension);
- 100 | },
- 101 | };
- 102 |
- at File.buildCodeFrameError (/Users/richb/github/react-starter-kit-richb/node_modules/babel-core/lib/transformation/file/index.js:431:15)
- at NodePath.buildCodeFrameError (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/path/index.js:150:26)
- at PluginPass.Scope (/Users/richb/github/react-starter-kit-richb/node_modules/babel-plugin-check-es2015-constants/lib/index.js:33:29)
- at PluginPass.newFn (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/visitors.js:326:17)
- at newFn (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/visitors.js:293:19)
- at NodePath._call (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/path/context.js:75:18)
- at NodePath.call (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/path/context.js:47:17)
- at NodePath.visit (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/path/context.js:105:12)
- at TraversalContext.visitQueue (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/context.js:156:16)
- at TraversalContext.visitMultiple (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/context.js:108:17)
- at TraversalContext.visit (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/context.js:198:19)
- at Function.traverse.node (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/index.js:141:17)
- at NodePath.visit (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/path/context.js:115:22)
- at TraversalContext.visitQueue (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/context.js:156:16)
- at TraversalContext.visitMultiple (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/context.js:108:17)
- at TraversalContext.visit (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/context.js:198:19)
- at Function.traverse.node (/Users/richb/github/react-starter-kit-richb/node_modules/babel-traverse/lib/index.js:141:17)
- @ ./src/data/schema.js 14:15-43
- webpack: bundle is now VALID.
- /Users/richb/github/react-starter-kit-richb/build/webpack:/src/data/schema.js:20
- content: require('./queries/content').default,
- ^
- Error: Cannot find module "./queries/content"
- at webpackMissingModule (/Users/richb/github/react-starter-kit-richb/build/webpack:/src/data/schema.js:20:24)
- at Object.module.exports.Object.defineProperty.value (/Users/richb/github/react-starter-kit-richb/build/webpack:/src/data/schema.js:20:24)
- at __webpack_require__ (/Users/richb/github/react-starter-kit-richb/build/webpack:/webpack/bootstrap 28be67f138acd4b95a5f:19:1)
- at Object.<anonymous> (/Users/richb/github/react-starter-kit-richb/build/webpack:/webpack/bootstrap 28be67f138acd4b95a5f:39:1)
- at __webpack_require__ (/Users/richb/github/react-starter-kit-richb/build/webpack:/webpack/bootstrap 28be67f138acd4b95a5f:19:1)
- at /Users/richb/github/react-starter-kit-richb/build/webpack:/webpack/bootstrap 28be67f138acd4b95a5f:39:1
- at Object.<anonymous> (/Users/richb/github/react-starter-kit-richb/build/webpack:/webpack/bootstrap 28be67f138acd4b95a5f:39:1)
- at Module._compile (module.js:398:26)
- at Object.Module._extensions..js (module.js:405:10)
- at Module.load (module.js:344:32)
- at Function.Module._load (module.js:301:12)
- at Function.Module.runMain (module.js:430:10)
- at startup (node.js:141:18)
- at node.js:980:3
Advertisement
Add Comment
Please, Sign In to add comment