Skip to content

Commit

Permalink
Remove console for every sandbox file and add colors to sandbox creat…
Browse files Browse the repository at this point in the history
…e success and fail
  • Loading branch information
davidjerleke committed Dec 9, 2022
1 parent 8d4c11b commit 9f83f56
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import fs from 'fs'
import { readFiles, PATHS_TO_SANDBOX_FILES } from './build-utils'
import {
readFiles,
PATHS_TO_SANDBOX_FILES,
CONSOLE_FONT_COLOR_RED,
CONSOLE_FONT_COLOR_GREEN,
} from './build-utils'

PATHS_TO_SANDBOX_FILES.forEach((path) => {
readFiles(
`${path}/`,
(filename, content) => {
fs.writeFile(
filename,
content.replace(
/\/\* The TypeScript compiler won't clear this empty line! \*\//gm,
'',
),
(error) => {
if (error) return console.log(error)
console.log('The file was saved!')
},
)
},
(error) => {
throw error
},
)
try {
readFiles(
`${path}/`,
(filename, content) => {
fs.writeFile(
filename,
content.replace(
/\/\* The TypeScript compiler won't clear this empty line! \*\//gm,
'',
),
(error) => {
if (error) return console.log(error)
},
)
},
(error) => {
throw error
},
)

console.log(
CONSOLE_FONT_COLOR_GREEN,
`Sandboxes created succesfully: ${path}`,
)
} catch (error) {
console.log(CONSOLE_FONT_COLOR_RED, error)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,33 @@ import {
readFiles,
PATHS_TO_SANDBOX_FILES,
EMPTY_LINE_REGEX,
CONSOLE_FONT_COLOR_RED,
CONSOLE_FONT_COLOR_CYAN,
} from './build-utils'

PATHS_TO_SANDBOX_FILES.forEach((path) => {
readFiles(
`${path}/`,
(filename, content) => {
fs.writeFile(
filename,
content.replace(
EMPTY_LINE_REGEX,
`/* The TypeScript compiler won't clear this empty line! */ \n`,
),
(error) => {
if (error) return console.log(error)
console.log('The file was saved!')
},
)
},
(error) => {
throw error
},
)
console.log(CONSOLE_FONT_COLOR_CYAN, `Compiling sandboxes: ${path} ...`)

try {
readFiles(
`${path}/`,
(filename, content) => {
fs.writeFile(
filename,
content.replace(
EMPTY_LINE_REGEX,
`/* The TypeScript compiler won't clear this empty line! */ \n`,
),
(error) => {
if (error) return console.log(error)
},
)
},
(error) => {
throw error
},
)
} catch (error) {
console.log(CONSOLE_FONT_COLOR_RED, error)
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const PATHS_TO_SANDBOX_FILES = [
]

export const EMPTY_LINE_REGEX = /^\s*\n/gm
export const CONSOLE_FONT_COLOR_RED = '\x1b[31m'
export const CONSOLE_FONT_COLOR_GREEN = '\x1b[32m'
export const CONSOLE_FONT_COLOR_CYAN = '\x1b[36m%s\x1b[0m'

export const readFiles = (
dirname: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ import {
SANDBOX_LABELS,
} from 'components/CodeSandbox/sandboxLabels'

// TODO: Add sandboxVanillaFolders.ts and sandboxReactFolders.ts constants
// TODO: Add React.FC to all components!
// TODO: Make plugins a constant
// TODO: Fix Y-axis badges
// TODO: Remove "The file was saved!" from node script

const SHARED_CONFIG = {
slides: SLIDES,
Expand Down

0 comments on commit 9f83f56

Please sign in to comment.