lib/coderoom.js
function buildRooms(baseRoom, dir, depth, attachments) {
        depth++;

        // group attachments
        attachments = _.chain(attachments)
            .clone()
            .concat(baseRoom.getMedia(false).map(file => path.join('media', path.relative(commonFolder, file))))
            .uniq()
            .value();

        baseRoom.items.forEach((room, i) => {
            let itemPath = path.join(dir, i.toString());
            fs.ensureDirSync(itemPath);

            if (!room.hasFiles) {
                buildRooms(room, itemPath, depth, attachments);
            } else {
                const roomsFiles = room.parsedFiles.map(file => {
                    file.destination = path.join(itemPath, 'files', file.parse.base);
                    file.content = fs.readFileSync(file.file, 'utf8');
                    file.mode = file.parse.ext.replace('.', '');
                    fs.copySync(file.file, file.destination);
                    return file;
                });

                // room attachments
                attachments = _.chain(attachments)
                    .clone()
                    .concat(room.getMedia(false).map(file => path.join('media', path.relative(commonFolder, file))))
                    .uniq()
                    .value();

                const css_paths = _.chain(attachments)
                    .concat(roomsFiles.map(file => path.relative(targetDir, file.destination)))
                    .filter(file => _.endsWith(file, '.css'))
                    .map(file => normalizePath(file, false))
                    .value();

                const js_paths = _.chain(attachments)
                    .concat(roomsFiles.map(file => path.relative(targetDir, file.destination)))
                    .filter(file => _.endsWith(file, '.js'))
                    .map(file => normalizePath(file, false))
                    .value();

                // iframe.html
                fs.writeFileSync(
                    path.join(itemPath, 'iframe.html'),
                    handlebars.compile(iframe)({
                        depth,
                        css_paths,
                        js_paths,
                        html: roomsFiles[0],
                    })
                );

                // index.html
                fs.writeFileSync(
                    path.join(itemPath, 'index.html'),
                    handlebars.compile(index)({
                        depth,
                        roomsFiles,
                        settings,
                        root,
                        room,
                        css_paths,
                        js_paths,
                        hasCSS: css_paths.length > 0,
                        hasJS: js_paths.length > 0,
                    })
                );
            }
        });
    }
function buildRooms(baseRoom, dir, depth, attachments) {
        depth++;

        // group attachments
        attachments = _.chain(attachments)
            .clone()
            .concat(baseRoom.getMedia(false).map(file => path.join('media', path.relative(commonFolder, file))))
            .uniq()
            .value();

        baseRoom.items.forEach((room, i) => {
            let itemPath = path.join(dir, i.toString());
            fs.ensureDirSync(itemPath);

            if (!room.hasFiles) {
                buildRooms(room, itemPath, depth, attachments);
            } else {
                const roomsFiles = room.parsedFiles.map(file => {
                    file.destination = path.join(itemPath, 'files', file.parse.base);
                    file.content = fs.readFileSync(file.file, 'utf8');
                    file.mode = file.parse.ext.replace('.', '');
                    fs.copySync(file.file, file.destination);
                    return file;
                });

                // room attachments
                attachments = _.chain(attachments)
                    .clone()
                    .concat(room.getMedia(false).map(file => path.join('media', path.relative(commonFolder, file))))
                    .uniq()
                    .value();

                const css_paths = _.chain(attachments)
                    .concat(roomsFiles.map(file => path.relative(targetDir, file.destination)))
                    .filter(file => _.endsWith(file, '.css'))
                    .map(file => normalizePath(file, false))
                    .value();

                const js_paths = _.chain(attachments)
                    .concat(roomsFiles.map(file => path.relative(targetDir, file.destination)))
                    .filter(file => _.endsWith(file, '.js'))
                    .map(file => normalizePath(file, false))
                    .value();

                // iframe.html
                fs.writeFileSync(
                    path.join(itemPath, 'iframe.html'),
                    handlebars.compile(iframe)({
                        depth,
                        css_paths,
                        js_paths,
                        html: roomsFiles[0],
                    })
                );

                // index.html
                fs.writeFileSync(
                    path.join(itemPath, 'index.html'),
                    handlebars.compile(index)({
                        depth,
                        roomsFiles,
                        settings,
                        root,
                        room,
                        css_paths,
                        js_paths,
                        hasCSS: css_paths.length > 0,
                        hasJS: js_paths.length > 0,
                    })
                );
            }
        });
    }
function buildRooms ( baseRoom , dir , depth , attachments ) { depth ++ ; // group attachments attachments = _ . chain ( attachments ) . clone ( ) . concat ( baseRoom . getMedia ( false ) . map ( file => path . join ( 'media' , path . relative ( commonFolder , file ) ) ) ) . uniq ( ) . value ( ) ; baseRoom . items . forEach ( ( room , i ) => { let itemPath = path . join ( dir , i . toString ( ) ) ; fs . ensureDirSync ( itemPath ) ; if ( ! room . hasFiles ) { buildRooms ( room , itemPath , depth , attachments ) ; } else { const roomsFiles = room . parsedFiles . map ( file => { file . destination = path . join ( itemPath , 'files' , file . parse . base ) ; file . content = fs . readFileSync ( file . file , 'utf8' ) ; file . mode = file . parse . ext . replace ( '.' , '' ) ; fs . copySync ( file . file , file . destination ) ; return file ; } ) ; // room attachments attachments = _ . chain ( attachments ) . clone ( ) . concat ( room . getMedia ( false ) . map ( file => path . join ( 'media' , path . relative ( commonFolder , file ) ) ) ) . uniq ( ) . value ( ) ; const css_paths = _ . chain ( attachments ) . concat ( roomsFiles . map ( file => path . relative ( targetDir , file . destination ) ) ) . filter ( file => _ . endsWith ( file , '.css' ) ) . map ( file => normalizePath ( file , false ) ) . value ( ) ; const js_paths = _ . chain ( attachments ) . concat ( roomsFiles . map ( file => path . relative ( targetDir , file . destination ) ) ) . filter ( file => _ . endsWith ( file , '.js' ) ) . map ( file => normalizePath ( file , false ) ) . value ( ) ; // iframe.html fs . writeFileSync ( path . join ( itemPath , 'iframe.html' ) , handlebars . compile ( iframe ) ( { depth , css_paths , js_paths , html : roomsFiles [ 0 ] , } ) ) ; // index.html fs . writeFileSync ( path . join ( itemPath , 'index.html' ) , handlebars . compile ( index ) ( { depth , roomsFiles , settings , root , room , css_paths , js_paths , hasCSS : css_paths . length > 0 , hasJS : js_paths . length > 0 , } ) ) ; } } ) ; }
depth=2, fixes path to targetDir
depth = 2 fixes path to targetDir