Skip to content

Commit

Permalink
Add rimraf helper (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca authored Apr 1, 2020
1 parent 8560cc7 commit b012960
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions cli/builder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node
const fs = require('fs')
const execSync = require('child_process').execSync
const path = require('path')
const getPageNamespaces = require('../_helpers/getPageNamespaces').default

Expand All @@ -15,6 +14,24 @@ const {
logBuild = true,
} = require(process.cwd() + '/i18n.json') || {}

/**
* Similar to "rm -rf"
*/
function rimraf(pathname) {
if (!fs.existsSync(pathname)) return

fs.readdirSync(pathname).forEach((child) => {
const childPathname = path.join(pathname, child)

if (fs.lstatSync(childPathname).isDirectory()) {
rimraf(childPathname)
return
}
fs.unlinkSync(childPathname)
})
fs.rmdirSync(pathname)
}

function readDirR(dir) {
const parsedDir = dir.replace(/\\/g, '/')

Expand All @@ -35,7 +52,7 @@ createPagesDir(allLanguages)
* /pages/en/ - /pages/es/ ...
*/
async function createPagesDir(langs = []) {
execSync(`rm -rf ${finalPagesDir}`)
rimraf(finalPagesDir)
fs.mkdirSync(finalPagesDir)

langs.forEach(async (lang) => {
Expand Down

0 comments on commit b012960

Please sign in to comment.