let less = require('less/lib/less-node')
let path = require('path')
var stream_buffers = require('stream-buffers')
+let uglify_es = require('uglify-es')
let url = require('url')
let util = require('util')
let yauzl = require('yauzl')
this.build_cache_email = new BuildCache()
this.build_cache_json = new BuildCache()
this.build_cache_less = new BuildCache()
+ this.build_cache_min = new BuildCache()
this.build_cache_text = new BuildCache()
this.build_cache_zet = new BuildCache()
this.build_cache_zip = new BuildCache()
)
}
+Server.prototype.get_min = function(pathname) {
+ return /*await*/ this.build_cache_min.get(
+ pathname,
+ async result => {
+ let files = {}
+ files[pathname] = await fs_readFile(pathname, {encoding: 'utf-8'})
+ console.log('getting', pathname, 'as min')
+ let render = uglify_es.minify(
+ files,
+ {
+ //compress: {
+ //arrows : true,
+ //booleans : true,
+ //collapse_vars : true,
+ //comparisons : true,
+ //computed_props: true,
+ //conditionals : true,
+ //dead_code : true,
+ //drop_console : false,
+ //drop_debugger : true,
+ //ecma : 5,
+ //evaluate : true,
+ //expression : false,
+ //global_defs : {},
+ //hoist_funs : false,
+ //hoist_props : true,
+ //hoist_vars : false,
+ //ie8 : false,
+ //if_return : true,
+ //inline : true,
+ //join_vars : true,
+ //keep_classnames: false,
+ //keep_fargs : true,
+ //keep_fnames : false,
+ //keep_infinity : false,
+ //loops : true,
+ //negate_iife : true,
+ //passes : 1,
+ //properties : true,
+ //pure_getters : true && "strict",
+ //pure_funcs : null,
+ //reduce_funcs : true,
+ //reduce_vars : true,
+ //sequences : true,
+ //side_effects : true,
+ //switches : true,
+ //top_retain : null,
+ //toplevel : !!(options && options["top_retain"]),
+ //typeofs : true,
+ //unsafe : false,
+ //unsafe_arrows : false,
+ //unsafe_comps : false,
+ //unsafe_Function: false,
+ //unsafe_math : false,
+ //unsafe_methods: false,
+ //unsafe_proto : false,
+ //unsafe_regexp : false,
+ //unsafe_undefined: false,
+ //unused : true,
+ //warnings : false,
+ //},
+ //ecma: undefined,
+ //ie8: false,
+ //keep_classnames: undefined,
+ //keep_fnames: false,
+ //mangle: {},
+ //nameCache: null,
+ //output: {
+ //ascii_only : false,
+ //beautify : false,
+ //bracketize : false,
+ //comments : false,
+ //ecma : 5,
+ //ie8 : false,
+ //indent_level : 4,
+ //indent_start : 0,
+ //inline_script : true,
+ //keep_quoted_props: false,
+ //max_line_len : false,
+ //preamble : null,
+ //preserve_line : false,
+ //quote_keys : false,
+ //quote_style : 0,
+ //safari10 : false,
+ //semicolons : true,
+ //shebang : true,
+ //shorthand : undefined,
+ //source_map : null,
+ //webkit : false,
+ //width : 80,
+ //wrap_iife : false
+ //},
+ //parse: {
+ //bare_returns : false,
+ //ecma : 8,
+ //expression : false,
+ //filename : null,
+ //html5_comments : true,
+ //shebang : true,
+ //strict : false,
+ //toplevel : null
+ //},
+ //rename: undefined,
+ //safari10: false,
+ //sourceMap: false,
+ //timings: false,
+ toplevel: true //false,
+ //warnings: false,
+ //wrap: false
+ }
+ )
+ if (render.error !== undefined)
+ throw render.error
+ result.value = Buffer.from(render.code)
+ }
+ )
+}
+
Server.prototype.get_text = function(pathname) {
return /*await*/ this.build_cache_text.get(
pathname,
SiteRoot.prototype.get_less = function(pathname) {
return /*await*/ this.server.get_less(this.root + pathname, this.root)
}
+SiteRoot.prototype.get_min = function(pathname) {
+ return /*await*/ this.server.get_min(this.root + pathname)
+}
SiteRoot.prototype.get_text = function(pathname) {
return /*await*/ this.server.get_text(this.root + pathname)
}
return true
}
+SiteRoot.prototype.serve_min = async function(env, pathname) {
+ if (pathname.slice(-7) !== '.js.min')
+ return false
+
+ let data
+ try {
+ data = await this.server.get_min(pathname)
+ }
+ catch (err) {
+ if (!(err instanceof Error) || err.code !== 'ENOENT')
+ throw err
+ return false
+ }
+ this.serve(env, 200, data, 'min')
+ return true
+}
+
SiteRoot.prototype.serve_fs = async function(env, pathname) {
let data
try {
return
if (await this.serve_less(env, pathname + '.less'))
return
+ if (await this.serve_min(env, pathname + '.min'))
+ return
if (await this.serve_fs(env, pathname))
return
this.die(env, `file not found ${env.pathname}`)