From 6f76fa1b9dc77320870a290198cf0e205a34c7bb Mon Sep 17 00:00:00 2001 From: XhmikosR Date: Sun, 29 Sep 2019 16:02:27 +0300 Subject: [PATCH] build.js: make use of `mkdir`'s `recursive` option --- build.js | 71 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/build.js b/build.js index e1b892088411f..a7e4d4cef8c66 100755 --- a/build.js +++ b/build.js @@ -236,39 +236,39 @@ 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) + }) }) - }) }) }) } @@ -276,14 +276,19 @@ function buildCSS () { // 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) }) }) }