Skip to content

Commit e587495

Browse files
committed
support less
1 parent 205977f commit e587495

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"babel-runtime": "^5.8.20",
2626
"express": "^4.13.3",
2727
"js-yaml": "^3.4.0",
28+
"less": "^2.7.1",
2829
"react": "^0.14.3",
2930
"sane": "^1.2.0",
3031
"webpack": "^1.12.1"

resources/Site.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ async function readSite(siteRoot) {
4444
}
4545

4646
function buildSite(buildRoot, site) {
47-
return Promise.all(site.files.map(file => {
48-
return writer(buildRoot, file, site);
49-
}));
47+
return Promise.all(site.files.map(file =>
48+
writer(buildRoot, file, site)
49+
));
5050
}
5151

5252

@@ -123,6 +123,11 @@ function urlToFile(file) {
123123
}
124124
}
125125

126+
// Convert .less to .css
127+
if (path.extname(url) === '.less') {
128+
url = url.slice(0, -5) + '.css';
129+
}
130+
126131
// Assume index.html stands for the parent directory
127132
if (path.basename(url) === 'index.html') {
128133
url = path.dirname(url);

resources/build.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ var Site = require('./Site');
1111

1212
module.exports = build;
1313

14-
process.on('unhandledRejection', error => {
14+
process.on('unhandledRejection', (error, promise) => {
1515
console.error('Unhandled Promise Rejection:');
1616
console.error(error && error.stack || error);
17+
console.error(promise);
1718
});
1819

1920
var pwd = process.env.PWD;

resources/writer.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var React = require('react');
1212
var fs = require('fs');
1313
var yaml = require('js-yaml');
1414
var path = require('path');
15+
var less = require('less');
1516
var renderReactPage = require('./renderReactPage');
1617
import { endsWith } from './util';
1718

@@ -21,6 +22,13 @@ module.exports = writer;
2122
async function writer(buildDir, file, site) {
2223
var writePath = getWritePath(buildDir, file);
2324

25+
// Render Less file
26+
if (endsWith(file.absPath, '.less')) {
27+
const input = await readFile(file.absPath);
28+
const output = await less.render(input, { filename: file.absPath });
29+
return await writeFile(writePath, output.css);
30+
}
31+
2432
// Non-modified content
2533
if (!file.content) {
2634
await promiseDirExists(path.dirname(writePath));
@@ -258,6 +266,14 @@ function getWritePath(buildDir, file) {
258266
return path.join(buildDir, writePath.slice(1));
259267
}
260268

269+
// Simple Promise wrapper around fs.writeFile
270+
function readFile(filePath, fmt) {
271+
return new Promise((resolve, reject) =>
272+
fs.readFile(filePath, fmt || 'utf8', (err, results) =>
273+
err ? reject(err) : resolve(results))
274+
);
275+
}
276+
261277
// Ensures directory exists, then writes file
262278
async function writeFile(filePath, data) {
263279
await promiseDirExists(path.dirname(filePath));
@@ -266,15 +282,9 @@ async function writeFile(filePath, data) {
266282

267283
// Simple Promise wrapper around fs.writeFile
268284
function _writeFile(filePath, data) {
269-
return new Promise((resolve, reject) => {
270-
fs.writeFile(filePath, data, err => {
271-
if (err) {
272-
reject(err);
273-
} else {
274-
resolve();
275-
}
276-
});
277-
});
285+
return new Promise((resolve, reject) =>
286+
fs.writeFile(filePath, data, err => err ? reject(err) : resolve())
287+
);
278288
}
279289

280290
function promisePipeEnds(pipe) {

site/_core/Site.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var Site = React.createClass({
2727

2828
<link rel="shortcut icon" href="/img/favicon.png" />
2929
<link rel="home" type="application/rss+xml" href="/blog/rss.xml" title="GraphQL Team Blog" />
30-
<link rel="stylesheet" href="/css/graphql.css" />
30+
<link rel="stylesheet" href="/style.css" />
3131
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Rubik:300|Roboto:300|Roboto+Mono:400,400i,600" />
3232
<link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css" />
3333
</head>

site/css/graphql.css renamed to site/_css/graphql.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {
19821982
.CodeMirror {
19831983
font-size: 13px;
19841984
line-height: 17px;
1985-
font-family:
1985+
font-family: 'Roboto Mono', Menlo, Monaco, monospace;
19861986
}
19871987

19881988
.miniGraphiQL {

site/style.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "_css/graphql.less";

0 commit comments

Comments
 (0)