/*
    doc.me -- MakeMe file for GoAhead documentation
 */

Me.load({
    targets: {
        api: {
            action: `
                apidoc('api/goahead.dox', '${SRC}/goahead.h', 'GoAhead')
                let files = Path().files(['api/goahead.html', me.dir.paks.join('*/doc/api/*.html')])
                for each (src in files) {
                    apiLayout(src, Path('dist/ref').join(src))
                }
            `
        },
        validate: {
            depends: [ 'gen-doc' ],
            action: `
                for each (f in Path('dist').files('**/*.html')) {
                    let data = f.readString()
                    data = data.replace('700|Open', '').
                        replace(/goahead.download.html/g, 'download/goahead.html').
                        replace(/pak.download.html/g, 'download/pak.html').
                        replace(/developers.contributors.html/g, 'scripts/contributors.esp').
                        replace(/nowrap="nowrap"/g, '').
                        replace(/https:..embedthis.com.goahead.licensing.html/g, 'https://embedthis.com/').
                        replace(/https:..embedthis.com.makeme.doc.guide.me.source.building.htm/g, 'https://embedthis.com/').
                        replace(/https:..embedthis.com.makeme.doc.source.building.htm/g, 'https://embedthis.com/').
                        replace(/https:..embedthis.com.makeme.doc.source/g, 'https://embedthis.com/').
                        replace(/https:..embedthis.com.developers./g, 'https://embedthis.com/').
                        replace(/nowrap/g, '')
                    trace('Patch', f)
                    f.write(data)
                }
                for each (f in Path('dist/man').files('*.html')) {
                    f.write(f.readString().toLowerCase())
                }
                trace('Listen', 'exp --nowatch')
                Cmd.run('exp --nowatch')
            `
        },
    },
})
