Skip to content

Commit 9525500

Browse files
prettier leo-core
1 parent f07f0d8 commit 9525500

24 files changed

+632
-667
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var getbabelRelayPlugin = require('babel-relay-plugin');
2-
import path from 'path';
1+
var getbabelRelayPlugin = require("babel-relay-plugin");
2+
import path from "path";
33

4-
var schema = require(path.resolve(process.cwd(), 'dist/api/schema.json'));
4+
var schema = require(path.resolve(process.cwd(), "dist/api/schema.json"));
55

66
module.exports = getbabelRelayPlugin(schema.data);
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import React, { Component } from 'react';
1+
import React, { Component } from "react";
22

33
export default class HTML extends Component {
4-
54
render() {
6-
const {
7-
bundleAssets,
8-
data,
9-
body,
10-
} = this.props;
5+
const { bundleAssets, data, body } = this.props;
116

127
return (
138
<html lang="en">
14-
<head>
15-
<meta charSet="utf-8"/>
16-
<meta httpEquiv="X-UA-Compatible" content="IE=edge"/>
17-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
18-
<link rel="stylesheet" type="text/css" href={`/${bundleAssets.static.css}`}/>
19-
</head>
20-
<body className="landing-page">
21-
<div id="react-mount" dangerouslySetInnerHTML={{__html: body}} />
22-
<script id="preloadedData"
23-
type="application/json"
24-
dangerouslySetInnerHTML={{__html: JSON.stringify(data)}}
25-
/>
26-
<script src={'/js/client.js'} />
27-
</body>
9+
<head>
10+
<meta charSet="utf-8" />
11+
<meta httpEquiv="X-UA-Compatible" content="IE=edge" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1" />
13+
<link
14+
rel="stylesheet"
15+
type="text/css"
16+
href={`/${bundleAssets.static.css}`}
17+
/>
18+
</head>
19+
<body className="landing-page">
20+
<div id="react-mount" dangerouslySetInnerHTML={{ __html: body }} />
21+
<script
22+
id="preloadedData"
23+
type="application/json"
24+
dangerouslySetInnerHTML={{ __html: JSON.stringify(data) }}
25+
/>
26+
<script src={"/js/client.js"} />
27+
</body>
2828
</html>
29-
)
29+
);
3030
}
3131
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import genSchema from '@sa-labs/graphql-directory-api/build/gen-schema';
1+
import genSchema from "@sa-labs/graphql-directory-api/build/gen-schema";
22

33
export const conf = __LEORC__;
44

55
const data = __DATA__;
66

7-
export const schema = genSchema({
8-
data,
9-
plugins: conf.plugins
10-
});
7+
export const schema = genSchema({ data, plugins: conf.plugins });
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import html from 'leohtml';
1+
import html from "leohtml";
22

33
/**
44
* This file exists for the sole purpose of not being the entry file because
@@ -7,5 +7,4 @@ import html from 'leohtml';
77
* the default react-router Routes structure
88
*
99
*/
10-
1110
export default html;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import conf from '.leorc';
1+
import conf from ".leorc";
22

33
/**
44
* This file exists for the sole purpose of not being the entry file because
@@ -7,5 +7,4 @@ import conf from '.leorc';
77
* default .leorc
88
*
99
*/
10-
1110
export default conf;
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import routes from 'leoroutes';
1+
import routes from "leoroutes";
22

33
/**
44
* This file exists for the sole purpose of not being the entry file because
@@ -7,5 +7,4 @@ import routes from 'leoroutes';
77
* the default react-router Routes structure
88
*
99
*/
10-
1110
export default routes;
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
import React, { Component } from 'react';
2-
import { Route, IndexRoute } from 'react-router';
1+
import React, { Component } from "react";
2+
import { Route, IndexRoute } from "react-router";
33

44
class NoMatch extends Component {
55
render() {
6-
return (
7-
<div>404</div>
8-
)
6+
return <div>404</div>;
97
}
108
}
119

1210
class App extends Component {
1311
render() {
14-
return <div>{this.props.children}</div>
12+
return <div>{this.props.children}</div>;
1513
}
1614
}
1715
class Home extends Component {
1816
render() {
19-
return <section>
17+
return (
18+
<section>
2019
<h1>Welcome to LEO</h1>
2120
<p>Write a routes.js file to get started</p>
22-
</section>
21+
</section>
22+
);
2323
}
2424
}
2525

2626
export default (
27-
<Route path='/' component={App}>
28-
<IndexRoute component={Home}/>
29-
<Route path='*' component={NoMatch} />
27+
<Route path="/" component={App}>
28+
<IndexRoute component={Home} />
29+
<Route path="*" component={NoMatch} />
3030
</Route>
3131
)

packages/leo-core/src/build.js

Lines changed: 64 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,85 @@
1-
const debug = require('debug')('leo:develop');
2-
import webpack from 'webpack';
3-
import path from 'path';
4-
import map from 'lodash/map';
5-
import uniq from 'lodash/uniq';
6-
import chalk from 'chalk';
7-
import {
8-
genDatabase
9-
} from '@sa-labs/graphql-directory-api';
1+
const debug = require("debug")("leo:develop");
2+
import webpack from "webpack";
3+
import path from "path";
4+
import map from "lodash/map";
5+
import uniq from "lodash/uniq";
6+
import chalk from "chalk";
7+
import { genDatabase } from "@sa-labs/graphql-directory-api";
108

11-
import config from './webpack.config.develop';
12-
import enablePlugins from 'utils/enable-plugins';
13-
import loadLeorc from 'utils/load-leorc';
9+
import config from "./webpack.config.develop";
10+
import enablePlugins from "utils/enable-plugins";
11+
import loadLeorc from "utils/load-leorc";
1412
import graphql, {
1513
GraphQLSchema,
1614
GraphQLObjectType,
1715
GraphQLNonNull
18-
} from 'graphql/type';
16+
} from "graphql/type";
1917

2018
export default () => {
2119
loadLeorc((err, conf) => {
22-
if(err) {
23-
throw new Error('error loading .leorc', err);
20+
if (err) {
21+
throw new Error("error loading .leorc", err);
2422
}
25-
genDatabase({
26-
// memoryFS: true,
27-
...conf,
28-
}, (err, data) => {
29-
if (err) {
30-
console.log(err);
31-
throw new Error('failed to generate database');
32-
};
23+
genDatabase(
24+
{
25+
// memoryFS: true,
26+
...conf
27+
},
28+
(err, data) => {
29+
if (err) {
30+
console.log(err);
31+
throw new Error("failed to generate database");
32+
}
3333

34-
/**
34+
/**
3535
* The following length comparison if intended to determine if we have
3636
* duplicate urls. That would mean we have two files trying to render
3737
* themselves at the same location.
3838
*/
39-
const totalURLs = conf.urls.concat(map(data, 'attributes.url'));
40-
const uniquedURLs = uniq(totalURLs);
41-
if(totalURLs.length !== uniquedURLs.length) {
42-
/**
39+
const totalURLs = conf.urls.concat(map(data, "attributes.url"));
40+
const uniquedURLs = uniq(totalURLs);
41+
if (totalURLs.length !== uniquedURLs.length) {
42+
/**
4343
* In the future, figure out which url it is to give better error
4444
* message
4545
*/
46-
throw new Error('Two documents have the same URL. You should try to fix this')
47-
}
48-
const configWithUrls = config({ conf, data, urls: uniquedURLs });
49-
/**
46+
throw new Error(
47+
"Two documents have the same URL. You should try to fix this"
48+
);
49+
}
50+
const configWithUrls = config({ conf, data, urls: uniquedURLs });
51+
/**
5052
* Enable third party plugins.
5153
* This is where we hook in to allow things like `npm i leo-blogpost`
5254
*/
53-
const configWithUrlsAndPlugins = Object.entries(configWithUrls)
54-
.map(([key, wpConfig]) => {
55-
return enablePlugins({
56-
bundleType: key,
57-
config: wpConfig,
58-
conf,
59-
});
60-
});
61-
debug('enabled plugins');
62-
webpack(configWithUrlsAndPlugins).run((err, stats) => {
63-
debug('ran client and static webpack builds');
64-
if (err) {
65-
// hard failure
66-
debug('hard failure');
67-
return console.error(chalk.red(err));
68-
}
69-
const jsonStats = stats.toJson();
70-
if (jsonStats.errors.length > 0) {
71-
//soft failure
72-
debug('soft failure');
73-
jsonStats.errors.forEach(e => console.error(chalk.red(e)))
74-
}
75-
if (jsonStats.warnings.length > 0) {
76-
debug('softer failure');
77-
jsonStats.warnings.forEach(warning => console.warn(chalk.yellow(warning)))
78-
}
79-
debug('built');
80-
});
81-
})
55+
const configWithUrlsAndPlugins = Object
56+
.entries(configWithUrls)
57+
.map(([ key, wpConfig ]) => {
58+
return enablePlugins({ bundleType: key, config: wpConfig, conf });
59+
});
60+
debug("enabled plugins");
61+
webpack(configWithUrlsAndPlugins).run((err, stats) => {
62+
debug("ran client and static webpack builds");
63+
if (err) {
64+
// hard failure
65+
debug("hard failure");
66+
return console.error(chalk.red(err));
67+
}
68+
const jsonStats = stats.toJson();
69+
if (jsonStats.errors.length > 0) {
70+
//soft failure
71+
debug("soft failure");
72+
jsonStats.errors.forEach(e => console.error(chalk.red(e)));
73+
}
74+
if (jsonStats.warnings.length > 0) {
75+
debug("softer failure");
76+
jsonStats.warnings.forEach(
77+
warning => console.warn(chalk.yellow(warning))
78+
);
79+
}
80+
debug("built");
81+
});
82+
}
83+
);
8284
});
83-
}
85+
};

packages/leo-core/src/db.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
1-
import fs from 'fs';
2-
const debug = require('debug')('leo:db');
3-
import {
4-
genDatabase
5-
} from '@sa-labs/graphql-directory-api';
1+
import fs from "fs";
2+
const debug = require("debug")("leo:db");
3+
import { genDatabase } from "@sa-labs/graphql-directory-api";
64

7-
import loadLeorc from 'utils/load-leorc';
5+
import loadLeorc from "utils/load-leorc";
86

97
export default ({ outputFile }) => {
108
loadLeorc((err, conf) => {
11-
if(err) {
12-
throw new Error('error loading .leorc', err);
9+
if (err) {
10+
throw new Error("error loading .leorc", err);
1311
}
1412
genDatabase(conf, (err, data) => {
1513
if (err) {
1614
console.log(err);
17-
throw new Error('failed to generate database');
15+
throw new Error("failed to generate database");
1816
} else {
19-
debug(conf.files)
17+
debug(conf.files);
2018
debug(data);
21-
fs.writeFileSync(outputFile || './database.json', JSON.stringify(data), 'utf-8');
19+
fs.writeFileSync(
20+
outputFile || "./database.json",
21+
JSON.stringify(data),
22+
"utf-8"
23+
);
2224
}
2325
});
24-
})
25-
}
26+
});
27+
};

0 commit comments

Comments
 (0)