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EAAS,QAAQ,KAAK,CAClB,aAAgB,mBAChB,KAAQ,cACR,QAAU,EACV,UAAY,IAGhB,IAAK,IAAI,KAAQ,KAAK,QAClB,GAAI,KAAK,QAAQ,eAAe,GAAO,CACnC,MAAM,EAAc,EAAO,eAG3B,GAAG,cAAc,EAAO,IAAM,EAAa,KAAK,QAAQ,GAAM,UAE9D,EAAS,QAAQ,KAAK,CAClB,aAAgB,EAChB,KAAQ,EACR,QAAU,GAElB,CAGA,GAAe,SAAS,cAAc,EAAO,iBAAkB,EACvE,CAEA,WAAA,EAAY,KAAC,IAET,KAAK,sBAEL,IAAK,MAAM,KAAK,KAAK,OACjB,GAAI,KAAK,OAAO,eAAe,GAAI,CAC/B,MAAM,EAAK,KAAK,OAAO,GAEvB,IAAI,EACJ,MAAM,EAAM,CAAC,MAAO,CAAC,EAAG,OAAQ,CAAC,GAAI,EAAM,CACvC,SAAU,OACP,KAAM,GAAQ,EAAQ,GAE7B,KAAK,YAAY,EAAG,EAApB,CAAwB,EAAK,GAAK,MAAK,KACnC,IAAI,EAAS,GAAW,MAAN,EAA4B,EAAf,aAC1B,EAAK,SAAS,WAAU,GAAQ,SACrC,GAAG,cAAc,KAAK,KAAK,EAAM,GAAO,EAAM,GAEtD,CA2CR,GAsBJ,MAAM,iBAAmB,KAAK,KAAK","file":"/npm/page-helper@2.0.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/page-helper@2.0.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nconst path = require('path');\nconst gulp = require('gulp');\nconst minify = require(\"babel-minify\");\nconst Handlebars = require('handlebars');\nconst jsdom = require('jsdom');\nconst glob = require('glob');\nconst read = require('read-file');\nconst reload = require('reload');\nconst jsonfile = require('jsonfile');\nconst fs = require('fs');\nconst crypto = require(\"crypto\");\nconst copydir = require('copy-dir');\nconst request = require('request-json');\nconst babel = require(\"@babel/core\");\n\nconst regex = /{([^\\/]*)}/gm;\nconst whiteSpaceRegex = /\\s{2,}/gm;\nconst newLineRegex = /\\n/gm;\nconst subst = `:$1`;\n\nmodule.exports.Helper = class Helper {\n    constructor(config) {\n        this.defaultLocale = config.defaultLocale || '';\n        this.locales = [];\n        this.useBabel = config.useBabel || false;\n        this.watchable = [];\n        this.workingDir = config.workingDir || '.';\n        this.components = config.components || {};\n        this.routes = config.routes || {};\n\n        //todo:check routes\n\n        this.layouts = config.layouts || {};\n        this.resources = {\n            translations: {},\n        };\n\n        for (let locale in this.resources.translations) {\n            if (this.resources.translations.hasOwnProperty(locale)) {\n                this.locales.push(locale)\n            }\n        }\n\n        this.componentsId = crypto.randomBytes(12).toString('hex');\n        this.regex = /\\$(\\w+)/g; // api url variable replacement\n\n        if (config.hasOwnProperty('imports')) {\n            console.log(\"got imports\", config.imports);\n\n            config.imports.forEach(imp => {\n                if (imp && imp.hasOwnProperty('registerComponent')) {\n                    const c = imp.registerComponent();\n                    if (c) {\n                        //console.log(c);\n                        const component = this.createComponent(c.filepath);\n                        const mjs = './tmp/components/' + component.name + '.js';\n\n                        fs.mkdirSync('./tmp/components', {recursive: true});\n\n\n                        fs.writeFileSync(mjs, component.minifiedScript);\n\n                        const iii = require(path.resolve(mjs));\n                        //console.log(iii);\n\n                        /*import(mjs).then(t => {\n                            console.log(\"component imported\");\n                            //console.log(t);\n                            t.default();\n                        }).catch(err => {\n                            console.error(err)\n                        })*/\n                    }\n\n                }\n            })\n        }\n    }\n\n    getLayout(name, reload) {\n        if (this.layouts.hasOwnProperty(name)) {\n            const layout = this.layouts[name];\n            if (reload) {\n                layout.template = read.sync(layout.file, 'utf8');\n            }\n            return layout\n        }\n    }\n\n    getComponent(name, reload) {\n        if (this.components.hasOwnProperty(name)) {\n            const component = this.components[name];\n            if (reload) {\n                this.createComponent(component.file)\n            }\n            return this.components[name]\n        }\n    }\n\n    createComponent(filePath, skipWrite) {\n        const component = {\n            file: filePath,\n            name: path.basename(filePath, '.html'),\n            template: '',\n            skipWrite: skipWrite,\n            render: true,\n        };\n        const template = read.sync(component.file, 'utf8');\n        const dom = new jsdom.JSDOM(template, {\n            includeNodeLocations: true\n        });\n        const body = dom.window.document.head;\n        for (let i = 0; i < body.children.length; i++) {\n            let child = body.children[i];\n            if (child.nodeName === \"TEMPLATE\") {\n                const loc = dom.nodeLocation(child);\n                const start = loc.startTag.endOffset;\n                const end = loc.endOffset - start - 11;\n                component.template = template.substr(start, end);\n                component.template = component.template.replace(newLineRegex, ``);\n                component.template = component.template.replace(whiteSpaceRegex, ` `);\n                component.render = child.getAttribute('render') !== 'false'\n            } else if (child.nodeName === \"SCRIPT\") {\n                const {code, map} = minify(child.innerHTML, {\n                    mangle: {\n                        keepClassName: true\n                    }\n                });\n\n                if (this.useBabel) {\n                    component.minifiedScript = babel.transformSync(code, {presets: ['@babel/env']}).code;\n                    component.script = babel.transformSync(child.innerHTML, {presets: ['@babel/env']}).code;\n                } else {\n                    component.minifiedScript = code;\n                    component.script = child.innerHTML;\n                }\n            }\n        }\n\n        Handlebars.registerPartial(component.name, \"<\" + component.name + \">\" + (component.render ? component.template : \"\") + \"</\" + component.name + \">\");\n        component.precompiledTemplate = Handlebars.precompile(component.template);\n        component.precompiled = Handlebars.precompile(\"<\" + component.name + \">{{> _\" + component.name + \"}}</\" + component.name + \">\");\n        this.components[component.name] = component;\n        return component\n    }\n\n    createLayout(filePath) {\n        const layout = {\n            file: filePath,\n            name: path.basename(filePath, '.html'),\n        };\n        layout.template = read.sync(layout.file, 'utf8');\n        layout.template = layout.template.replace(newLineRegex, ``);\n        layout.template = layout.template.replace(whiteSpaceRegex, ` `);\n\n        layout.compiled = Handlebars.compile(layout.template);\n\n        this.layouts[layout.name] = layout;\n    }\n\n    createResource(filePath) {\n        const resource = read.sync(filePath, 'utf8');\n        const jsonResource = JSON.parse(resource);\n        if (jsonResource) {\n            this.resources = Object.assign(this.resources || {}, jsonResource)\n        }\n    }\n\n    parseLayout(pattern) {\n        this.watchable.push({pattern: pattern, type: 'layout'});\n        const files = glob.sync(pattern);\n        for (let i = 0; i < files.length; i++) {\n            this.createLayout(files[i])\n        }\n    }\n\n    parse(pattern, skipWrite) {\n        this.watchable.push({pattern: pattern, type: 'component'});\n        const files = glob.sync(pattern);\n        for (let i = 0; i < files.length; i++) {\n            this.createComponent(files[i], skipWrite)\n        }\n    }\n\n    parseResource(pattern) {\n        this.watchable.push({pattern: pattern, type: 'resource'});\n        const files = glob.sync(pattern);\n        for (let i = 0; i < files.length; i++) {\n            this.createResource(files[i])\n        }\n    }\n\n    buildRoute(h, route, basePath, parents) {\n        this.routeCount += 1;\n        route.parents = parents;\n        route.id = this.routeCount;\n        let newPath = path.posix.join(basePath, route.path);\n\n        // replace {param} with :param\n        newPath = newPath.replace(regex, subst);\n\n        if (newPath.slice(-1) !== \"/\" && (route.path === '/' || route.path.slice(-1) === \"/\")) {\n            newPath += '/'\n        }\n        if (!h.hasOwnProperty(newPath)) {\n            h[newPath] = [];\n        }\n        if (parents) {\n            h[newPath] = h[newPath].concat(parents)\n        }\n        if (!route.children || route.children.length === 0) {\n            h[newPath].push(route)\n        }\n        if (route.children && route.children.length > 0) {\n            let ps = parents || [];\n            ps.push(route);\n            for (let i = 0; i < route.children.length; i++) {\n                h = this.buildRoute(h, route.children[i], newPath, ps)\n            }\n        }\n        return h\n    }\n\n    changeDetected(watchable) {\n        return (event, path) => {\n            if (!path) return\n            if (watchable.type === 'component') {\n                this.createComponent(path)\n            } else if (watchable.type === 'layout') {\n                this.createLayout(path)\n            } else if (watchable.type === 'resource') {\n                this.createResource(path)\n            }\n            if (this.reload) {\n                this.reload.reload()\n            }\n        }\n    }\n\n    definitionsPartial(componentsId) {\n        return `<script>(function(){'use strict';window.context={{{contextObject}}} })()</script><script src=\"https://unpkg.com/@webcomponents/webcomponentsjs@2.2.9/webcomponents-bundle.js\"></script><script src=\"/${componentsId}.js\"></script>`;\n    }\n\n    setupForLayoutBuild() {\n        Handlebars.registerPartial('definitions', this.definitionsPartial(this.componentsId));\n        Handlebars.registerHelper(\"stringify\", k => JSON.stringify(k));\n\n        const appendStrings = (...k) => {\n            k.pop(); // pops last options param\n            let o = k[0];\n            switch (typeof o) {\n                case \"string\":\n                    return k.join(\"\")\n                case \"object\":\n                    if (Array.isArray(o)) {\n                        return [].concat.apply([], k)\n                    } else {\n                        return Object.assign({}, ...k)\n                    }\n                case \"bigint\":\n                case \"number\":\n                    return k.reduce((a, b) => a + b, 0)\n            }\n        };\n\n        // Appends strings, arrays, ...\n        Handlebars.registerHelper(\"append\", appendStrings);\n        Handlebars.registerHelper(\"append3\", appendStrings); // fix for server side\n\n        // translation helper\n        Handlebars.registerHelper(\"trans\", (locale, k) => this.resources.translations[locale][k]);\n\n        // translation helper\n        Handlebars.registerHelper(\"i18n\", k => this.resources.translations[this.defaultLocale][k]);\n\n        this.routeCount = -1;\n        this.handle = {}; // map of array of routes\n        for (let i = 0; i < this.routes.length; i++) this.handle = this.buildRoute(this.handle, this.routes[i], \"/\", [])\n    }\n\n    setupExpress(app, opt) {\n        this.setupForLayoutBuild()\n\n        // Serve components\n        app.use('/' + this.componentsId + '.js', (req, res, next) => {\n            const lang = req.query.lang || this.defaultLocale;\n            res.type('application/javascript');\n            res.send(this.packagedHandlebars(true));\n            //next()\n        });\n\n        // serve self-contained components\n        Object.keys(this.components).map(i => {\n            const component = this.components[i];\n            app.use('/' + component.name + '.component.js', (req, res, next) => {\n                res.type('application/javascript');\n                res.send(this.selfContainedComponent(component));\n                //next()\n            });\n        });\n\n        if (opt) {\n            if (opt.hasOwnProperty('liveReload') && opt.liveReload === true) {\n                reload(app).then(r => this.reload = r);\n                for (let i = 0; i < this.watchable.length; i++) {\n                    const w = this.watchable[i], watcher = gulp.watch([w.pattern])\n                    watcher.on('all', this.changeDetected(w))\n                }\n            }\n        }\n\n        for (const p in this.handle) {\n            if (this.handle.hasOwnProperty(p)) {\n                const rs = this.handle[p];\n                console.log(\"serving on path\", p, rs);\n                app.get(p, this.handleRoute(p, rs))\n            }\n        }\n    }\n\n    handleRoute(p, rs) {\n        return (req, res) => {\n            return new Promise((resolve, reject) => {\n                let context = {\n                    storage: this.resources\n                };\n                if (req.params) {\n                    context.query = req.params\n                }\n                context.query = Object.assign(context.query || {}, req.query);\n                if (req.query.hasOwnProperty('lang')) {\n                    this.locale = req.query.lang || this.defaultLocale\n                } else {\n                    this.locale = this.defaultLocale\n                }\n                let layoutName = 'index';\n\n                if (rs && rs.length > 0) {\n                    const r = rs[0];\n                    if (r && r.hasOwnProperty('layout') && r.layout.length > 0) {\n                        layoutName = r.layout\n                    }\n                }\n\n                const layout = this.getLayout(layoutName);\n                const registeredPages = [];\n                const selfContainedWaiting = [];\n                const requests = [];\n\n                let outletName = 'router-outlet';\n                for (let i = 0; i < rs.length; i++) {\n                    const r = rs[i];\n                    if (r.hasOwnProperty('redirect')) {\n                        res.redirect(308, r.redirect);\n                        return resolve()\n                    }\n                    if (r.hasOwnProperty('outlet') && !!r.outlet && r.outlet.length > 0) {\n                        outletName = r.outlet\n                    }\n                    registeredPages.push(outletName);\n                    const component = this.components[r.component];\n                    if (component.skipWrite) {\n                        selfContainedWaiting.push(component)\n                    }\n                    Handlebars.registerPartial(outletName, \"<\" + component.name + \">\" + (component.render ? component.template : \"\") + \"</\" + component.name + \">\");\n                    if (r.hasOwnProperty('requests')) {\n                        r.requests.forEach(_request => {\n                            const request = {\n                                url: _request.url,\n                                method: _request.method,\n                                headers: _request.headers,\n                                body: _request.body,\n                            };\n\n                            if (request.hasOwnProperty('url')) {\n                                /*let resolvedApiUri = request.url;*/\n                                request.url = request.url.replace(this.regex, function (match, param) {\n                                    return match.replace('$' + param, req.params[param]);\n                                });\n\n                                let split = request.url.split('?');\n                                request.url = split[0];\n                                let resolvedQuery = '';\n                                if (split.length > 1) {\n                                    resolvedQuery = split[1]\n                                }\n\n                                for (let k in req.query) {\n                                    if (req.query.hasOwnProperty(k)) {\n                                        if (resolvedQuery.length > 0) {\n                                            resolvedQuery += '&'\n                                        }\n                                        if (Array.isArray(req.query[k])) {\n                                            for (let l = 0; l < req.query[k].length; l++) {\n                                                if (resolvedQuery.length > 0) {\n                                                    resolvedQuery += '&'\n                                                }\n                                                resolvedQuery += k + '=' + req.query[k][l]\n                                            }\n                                        } else {\n                                            resolvedQuery += k + '=' + req.query[k]\n                                        }\n\n                                    }\n                                }\n\n                                request.url += '?' + resolvedQuery;\n                            }\n\n                            if (request.hasOwnProperty('body') && typeof request.body === \"object\") {\n                                /*let resolvedApiUri = request.url;*/\n                                const body = JSON.stringify(request.body).replace(this.regex, function (match, param) {\n                                    return match.replace('$' + param, req.params[param]);\n                                });\n\n                                request.body = JSON.parse(body);\n                            }\n\n                            if (request.hasOwnProperty('method') && typeof request.method === \"string\") {\n                                request.method = request.method.toUpperCase();\n                                switch (request.method) {\n                                    case \"GET\":\n                                    case \"POST\":\n                                        /*case \"PUT\":\n                                        case \"OPTIONS\":\n                                        case \"DELETE\":\n                                        case \"POST\":*/\n                                        break;\n                                    default:\n                                        reject(\"method not allowed: \" + request.method)\n                                }\n                            } else {\n                                request.method = \"GET\"\n                            }\n\n                            requests.push(request)\n                        });\n                    }\n                    if (r.hasOwnProperty('page')) {\n                        context = Object.assign(context, r.page);\n                    }\n                }\n\n                let selfContaining = \"\";\n                selfContainedWaiting.forEach(component => {\n                    selfContaining += this.selfContainedComponent(component)\n                });\n\n\n                // add locale\n                context['locale'] = this.locale;\n\n                // get api data\n                if (requests.length > 0) {\n                    const ps = [];\n                    context.data = {};\n\n                    requests.forEach((r, index) => {\n                        const client = request.createClient(r.url);\n                        if (r.headers) {\n                            for (let key in r.headers) {\n                                if (r.headers.hasOwnProperty(key)) {\n                                    client.headers[key] = r.headers[key]\n                                }\n                            }\n                        }\n                        switch (r.method) {\n                            case \"GET\":\n                                console.log('resolving GET ' + r.url);\n                                ps.push(new Promise((resolve1, reject1) => {\n                                    client.get('', function (err, response, body) {\n                                        context.data[index.toString()] = body;\n                                        resolve1()\n                                    });\n                                }));\n                                break;\n                            case \"POST\":\n                                console.log('resolving POST ' + r.url);\n                                ps.push(new Promise((resolve1, reject1) => {\n                                    client.post('', r.body, function (err, response, body) {\n                                        context.data[index.toString()] = body;\n                                        resolve1()\n                                    });\n                                }));\n                                break;\n                        }\n                    });\n\n                    Promise.all(ps).then(() => {\n                        context[\"contextObject\"] = JSON.stringify(context);\n                        res.send(layout.compiled(context));\n                        // remove pages from cache\n                        for (let i = 0; i < registeredPages.length; i++) {\n                            Handlebars.unregisterPartial(registeredPages[i])\n                        }\n                        resolve()\n                    })\n                } else {\n                    context[\"contextObject\"] = JSON.stringify(context);\n                    res.send(layout.compiled(context));\n                    // remove pages from cache\n                    for (let i = 0; i < registeredPages.length; i++) {\n                        Handlebars.unregisterPartial(registeredPages[i])\n                    }\n                    resolve()\n                }\n            })\n        }\n    }\n\n    packagedHandlebars(isLocal) {\n        const cArr = Object.keys(this.components).filter(i => {\n            if (!this.components[i].skipWrite) {\n                return this.components[i]\n            }\n        }).map(i => this.components[i]);\n\n        const resources = Object.assign({}, this.resources || {});\n        return `${handlebarsScript}(function(){'use strict';Handlebars.registerHelper(\"stringify\",function(k){return JSON.stringify(k)});const _appHelp=(...e)=>{e.pop();let r=e[0];switch(typeof r){case\"string\":return e.join(\"\");case\"object\":return Array.isArray(r)?[].concat.apply([],e):Object.assign({},...e);case\"bigint\":case\"number\":return e.reduce((e,r)=>e+r,0)}};Handlebars.registerHelper(\"append\",_appHelp);Handlebars.registerHelper(\"append3\",_appHelp);Handlebars.registerHelper(\"trans\",function(l,k){l = l || window.context.lang || window.context.locale;return (window.context.storage.translations[l] || {})[k]});Handlebars.registerHelper(\"i18n\",function(k){const l = window.context.lang || window.context.locale;return (window.context.storage.translations[l] || {})[k]});var template=Handlebars.template,templates=Handlebars.templates=Handlebars.templates || {};${cArr.map((component) => {\n            return `Handlebars.partials['${component.name}'] = template(${component.precompiled});Handlebars.partials['_${component.name}'] = template(${component.precompiledTemplate});`\n        }).join('')};WebComponents.waitFor=WebComponents.waitFor||function(p){return Promise.all([p].map(function(fn){return fn instanceof Function ? fn() : fn;}))};WebComponents.waitFor(function(){return new Promise(function(res){var cc=new function(){this.define=function(name,module){if(module&&module.hasOwnProperty('exports')){module.exports.prototype.template=function(c,o){return Handlebars.partials[\"_\"+name](c,o)};window.customElements.define(name,module.exports)}}};window['customComponents']=cc;${cArr.map((component) => {\n            return component.script ? `cc.define('${component.name}',(function(){var module={};${component.script};return module})());` : ''\n        }).join('')};res()})})${isLocal ? `;var r=document.createElement('script');r.setAttribute('src','/reload/reload.js');document.head.appendChild(r)` : ``}})();`\n    }\n\n    selfContainedComponent(component) {\n        return `(function(){'use strict';WebComponents.waitFor(()=>new Promise(n=>{var cc=new function(){this.define=function(n,e){e&&e.hasOwnProperty(\"exports\")&&(e.exports.prototype.template=function(e,t){return Handlebars.partials[n](e,t)},window.customElements.define(n,e.exports))}};Handlebars.partials['${component.name}']=Handlebars.template(${component.precompiled});cc.define('${component.name}',(function(){const module={};${component.minifiedScript ? component.minifiedScript : ''};return module})());n()}));})();`\n    }\n\n    build({dist, writeManifest = true}) {\n        // build manifest.json file\n        const componentsVersion = crypto.randomBytes(6).toString('hex');\n        const manifest = {\n            'imports': [],\n            'routes': this.routes,\n            'defaultLocale': this.defaultLocale,\n            'resources': this.resources,\n            'componentsVersion': componentsVersion,\n        };\n        for (let name in this.components) {\n            if (this.components.hasOwnProperty(name)) {\n                const component = this.components[name];\n\n                // write template\n                const templatePath = name + '.template.html';\n                fs.writeFileSync(dist + \"/\" + templatePath, component.template);\n\n                // write self-contained component\n                const componentPath = name + '.component.js';\n                fs.writeFileSync(dist + \"/\" + componentPath, this.selfContainedComponent(component));\n\n                manifest.imports.push({\n                    'templatePath': templatePath,\n                    'componentPath': componentPath,\n                    'name': name,\n                    'render': component.render,\n                })\n            }\n        }\n\n        // write singlefile packaged handlebars\n        const packagedHandlebars = componentsVersion + '.js';\n        fs.writeFileSync(dist + \"/\" + packagedHandlebars, this.packagedHandlebars());\n\n        // add definitions partial\n        fs.writeFileSync(dist + \"/definitions.html\", this.definitionsPartial(componentsVersion));\n        manifest.imports.push({\n            'templatePath': \"definitions.html\",\n            'name': \"definitions\",\n            'render': true,\n            'omitTags': true,\n        });\n\n        for (let name in this.layouts) {\n            if (this.layouts.hasOwnProperty(name)) {\n                const newFilePath = name + '.layout.html';\n\n                // write file\n                fs.writeFileSync(dist + '/' + newFilePath, this.layouts[name].template);\n\n                manifest.imports.push({\n                    'templatePath': newFilePath,\n                    'name': name,\n                    'layout': true,\n                })\n            }\n        }\n\n        if (writeManifest) jsonfile.writeFileSync(dist + '/manifest.json', manifest)\n    }\n\n    buildStatic({dist}) {\n\n        this.setupForLayoutBuild()\n\n        for (const p in this.handle) {\n            if (this.handle.hasOwnProperty(p)) {\n                const rs = this.handle[p];\n\n                let _html;\n                const req = {query: {}, params: {}}, res = {\n                    redirect: () => {\n                    }, send: html => _html = html\n                }\n                this.handleRoute(p, rs)(req, res).then(() => {\n                    let file = (!p || p === \"/\") ? \"index.html\" : p\n                    if (!file.endsWith(\".html\")) file += \".html\"\n                    fs.writeFileSync(path.join(dist, file), _html);\n                })\n            }\n        }\n\n        /*for (let name in this.components) {\n            if (this.components.hasOwnProperty(name)) {\n                const component = this.components[name];\n\n                let _html;\n                const req = {query: {}, params: {}}, res = {redirect: () => {}, send: html => _html = html}\n                this.handleRoute(null, rs)(req, res).then(() => {\n                    console.log(_html)\n                })\n\n                // write template\n                const templatePath = name + '.template.html';\n                fs.writeFileSync(dist + \"/\" + templatePath, component.template);\n\n                // write self-contained component\n                const componentPath = name + '.component.js';\n                fs.writeFileSync(dist + \"/\" + componentPath, this.selfContainedComponent(component));\n\n\n            }\n        }\n\n        // write singlefile packaged handlebars\n        const packagedHandlebars = componentsVersion + '.js';\n        fs.writeFileSync(dist + \"/\" + packagedHandlebars, this.packagedHandlebars());\n\n        // add definitions partial\n        fs.writeFileSync(dist + \"/definitions.html\", this.definitionsPartial(componentsVersion));\n\n\n        for (let name in this.layouts) {\n            if (this.layouts.hasOwnProperty(name)) {\n                const newFilePath = name + '.layout.html';\n\n                // write file\n                fs.writeFileSync(dist + '/' + newFilePath, this.layouts[name].template);\n\n\n            }\n        }*/\n    }\n};\n\nfunction mkDirByPathSync(targetDir, {isRelativeToScript = false} = {}) {\n    const sep = path.sep;\n    const initDir = path.isAbsolute(targetDir) ? sep : '';\n    const baseDir = isRelativeToScript ? __dirname : '.';\n    targetDir.split(sep).reduce((parentDir, childDir) => {\n            const curDir = path.resolve(baseDir, parentDir, childDir);\n            try {\n                fs.mkdirSync(curDir);\n            } catch (err) {\n                if (err.code !== 'EEXIST') {\n                    throw err;\n                }\n            }\n            return curDir;\n        },\n        initDir\n    )\n}\n\nconst handlebarsScript = read.sync('./node_modules/handlebars/dist/handlebars.min.js');\n"]}