import { join } from 'path' ; import * as fs from 'fs-extra' ; import { Node } from './parser' ; /** Removes the front-matter from beginning of a string. */ const clean = ( md ) : string => { return md . replace ( /^---\n.*?\n---\n/s , '' ) ; } ; param node param source param destination export const transform = ( node , source , destination ) => { if ( node . type === 'category' ) { node . locales . forEach ( locale => { fs . mkdirpSync ( join ( destination , locale , node . id ) ) ; } ) ; node . children . forEach ( child => transform ( child , source , destination ) ) ; } else { node . locales . forEach ( locale => { const markdown = clean ( fs . readFileSync ( join ( source , locale , node . id ) ) . toString ( ) ) ; fs . writeFileSync ( join ( destination , locale , node . id ) , markdown ) ; } ) ; } } ;