Skip to content

Commit e172952

Browse files
XhmikosRphillipj
authored andcommitted
Switch to using stylus directly.
1 parent df1d635 commit e172952

File tree

4 files changed

+35
-57
lines changed

4 files changed

+35
-57
lines changed

build.js

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,26 @@
44

55
// BUILD.JS: This file is responsible for building static HTML pages
66

7+
const fs = require('fs')
8+
const path = require('path')
79
const Metalsmith = require('metalsmith')
8-
const autoprefixer = require('autoprefixer-stylus')
910
const collections = require('metalsmith-collections')
1011
const feed = require('metalsmith-feed')
1112
const discoverHelpers = require('metalsmith-discover-helpers')
1213
const discoverPartials = require('metalsmith-discover-partials')
1314
const layouts = require('metalsmith-layouts')
1415
const markdown = require('metalsmith-markdown')
1516
const prism = require('metalsmith-prism')
16-
const stylus = require('metalsmith-stylus')
1717
const permalinks = require('metalsmith-permalinks')
1818
const pagination = require('metalsmith-yearly-pagination')
1919
const defaultsDeep = require('lodash.defaultsdeep')
20+
const autoprefixer = require('autoprefixer-stylus')
2021
const marked = require('marked')
21-
const path = require('path')
22-
const fs = require('fs')
22+
const stylus = require('stylus')
2323
const ncp = require('ncp')
2424
const junk = require('junk')
2525

2626
const navigation = require('./scripts/plugins/navigation')
27-
const filterStylusPartials = require('./scripts/plugins/filter-stylus-partials')
2827
const anchorMarkdownHeadings = require('./scripts/plugins/anchor-markdown-headings')
2928
const loadVersions = require('./scripts/load-versions')
3029
const latestVersion = require('./scripts/helpers/latestversion')
@@ -238,33 +237,37 @@ function githubLinks (options) {
238237
}
239238

240239
// This function builds the layouts folder for all the Stylus files.
241-
function buildLayouts () {
242-
console.log('[metalsmith] build/layouts started')
243-
const labelForBuild = '[metalsmith] build/layouts finished'
240+
function buildCSS () {
241+
console.log('[stylus] static/css started')
242+
const labelForBuild = '[stylus] static/css finished'
244243
console.time(labelForBuild)
245244

246245
fs.mkdir(path.join(__dirname, 'build'), () => {
247-
fs.mkdir(path.join(__dirname, 'build', 'layouts'), () => {
248-
const metalsmith = Metalsmith(__dirname)
249-
metalsmith
250-
// Sets the build source as /layouts/css.
251-
.source(path.join(__dirname, 'layouts', 'css'))
252-
// Deletes Stylus partials since they'll be included in the main CSS
253-
// file anyways.
254-
.use(filterStylusPartials())
255-
.use(stylus({
256-
compress: process.env.NODE_ENV !== 'development',
257-
paths: [path.join(__dirname, 'layouts', 'css')],
258-
use: [autoprefixer()]
259-
}))
260-
// Pipes the generated files into /build/static/css.
261-
.destination(path.join(__dirname, 'build/static/css'))
246+
fs.mkdir(path.join(__dirname, 'build/static'), () => {
247+
fs.mkdir(path.join(__dirname, 'build/static/css'), () => {
248+
fs.readFile(path.join(__dirname, 'layouts/css/styles.styl'), 'utf8', (err, data) => {
249+
if (err) {
250+
throw err
251+
}
252+
253+
stylus(data)
254+
.set('compress', process.env.NODE_ENV !== 'development')
255+
.set('paths', [path.join(__dirname, 'layouts/css')])
256+
.use(autoprefixer())
257+
.render((error, css) => {
258+
if (error) {
259+
throw error
260+
}
262261

263-
// This actually executes the build and stops the internal timer after
264-
// completion.
265-
metalsmith.build((err) => {
266-
if (err) { throw err }
267-
console.timeEnd(labelForBuild)
262+
fs.writeFile(path.join(__dirname, 'build/static/css/styles.css'), css, (err) => {
263+
if (err) {
264+
throw err
265+
}
266+
267+
console.timeEnd(labelForBuild)
268+
})
269+
})
270+
})
268271
})
269272
})
270273
})
@@ -313,8 +316,8 @@ function fullBuild (opts) {
313316
const { selectedLocales, preserveLocale } = opts
314317
// Build static files.
315318
copyStatic()
316-
// Build layouts
317-
buildLayouts()
319+
// Build CSS
320+
buildCSS()
318321
getSource((err, source) => {
319322
if (err) { throw err }
320323

package-lock.json

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
"metalsmith-metadata": "0.0.4",
5454
"metalsmith-permalinks": "^2.2.0",
5555
"metalsmith-prism": "^3.1.1",
56-
"metalsmith-stylus": "^3.0.0",
5756
"metalsmith-yearly-pagination": "^4.0.0",
5857
"ncp": "^2.0.0",
5958
"node-version-data": "^1.1.0",
@@ -63,7 +62,8 @@
6362
"require-dir": "^1.2.0",
6463
"semver": "^6.3.0",
6564
"st": "^1.2.2",
66-
"strftime": "^0.10.0"
65+
"strftime": "^0.10.0",
66+
"stylus": "^0.54.7"
6767
},
6868
"devDependencies": {
6969
"cross-env": "^6.0.0",

scripts/plugins/filter-stylus-partials.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)