Skip to content

Commit

Permalink
build.js: make use of mkdir's recursive option
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored and phillipj committed Oct 3, 2019
1 parent 33f4cec commit 6f76fa1
Showing 1 changed file with 38 additions and 33 deletions.
71 changes: 38 additions & 33 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,54 +236,59 @@ function githubLinks (options) {
}
}

// This function builds the layouts folder for all the Stylus files.
// This function builds the static/css folder for all the Stylus files.
function buildCSS () {
console.log('[stylus] static/css started')
const labelForBuild = '[stylus] static/css finished'
console.time(labelForBuild)

fs.mkdir(path.join(__dirname, 'build'), () => {
fs.mkdir(path.join(__dirname, 'build/static'), () => {
fs.mkdir(path.join(__dirname, 'build/static/css'), () => {
fs.readFile(path.join(__dirname, 'layouts/css/styles.styl'), 'utf8', (err, data) => {
if (err) {
throw err
fs.mkdir(path.join(__dirname, 'build/static/css'), { recursive: true }, (err) => {
if (err) {
throw err
}

fs.readFile(path.join(__dirname, 'layouts/css/styles.styl'), 'utf8', (err, data) => {
if (err) {
throw err
}

stylus(data)
.set('compress', process.env.NODE_ENV !== 'development')
.set('paths', [path.join(__dirname, 'layouts/css')])
.use(autoprefixer())
.render((error, css) => {
if (error) {
throw error
}

stylus(data)
.set('compress', process.env.NODE_ENV !== 'development')
.set('paths', [path.join(__dirname, 'layouts/css')])
.use(autoprefixer())
.render((error, css) => {
if (error) {
throw error
}

fs.writeFile(path.join(__dirname, 'build/static/css/styles.css'), css, (err) => {
if (err) {
throw err
}

console.timeEnd(labelForBuild)
})
})
fs.writeFile(path.join(__dirname, 'build/static/css/styles.css'), css, (err) => {
if (err) {
throw err
}

console.timeEnd(labelForBuild)
})
})
})
})
})
}

// This function copies the rest of the static assets to their subfolder in the
// build directory.
function copyStatic () {
console.log('[metalsmith] build/static started')
console.time('[metalsmith] build/static finished')
fs.mkdir(path.join(__dirname, 'build'), () => {
fs.mkdir(path.join(__dirname, 'build', 'static'), () => {
ncp(path.join(__dirname, 'static'), path.join(__dirname, 'build', 'static'), (err) => {
if (err) { return console.error(err) }
console.timeEnd('[metalsmith] build/static finished')
})
console.log('[ncp] build/static started')
const labelForBuild = '[ncp] build/static finished'
console.time(labelForBuild)
fs.mkdir(path.join(__dirname, 'build/static'), { recursive: true }, (err) => {
if (err) {
throw err
}

ncp(path.join(__dirname, 'static'), path.join(__dirname, 'build/static'), (error) => {
if (error) {
return console.error(error)
}
console.timeEnd(labelForBuild)
})
})
}
Expand Down

0 comments on commit 6f76fa1

Please sign in to comment.