diff --git a/bin/cli.js b/bin/cli.js index 79a61b5..686c750 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -1,6 +1,6 @@ #!/usr/bin/env node // Generated by LiveScript 1.6.0 -var t1, fs, path, yargs, colors, srcbuild, lib, server, watch, api, cfgfile, argv, root, doOpen, port, main, config; +var t1, fs, path, yargs, colors, srcbuild, lib, server, api, cfgfile, argv, root, doOpen, port, main, config; t1 = Date.now(); fs = require('fs'); path = require('path'); @@ -9,7 +9,6 @@ colors = require('colors'); srcbuild = require('@plotdb/srcbuild'); lib = path.dirname(fs.realpathSync(__filename)); server = require(lib + "/lib/server"); -watch = require(lib + "/lib/watch"); api = require(lib + "/api/index"); if (/\.json$/.exec(process.argv[2] || '')) { cfgfile = process.argv[2]; diff --git a/bin/lib/build/aux.js b/bin/lib/build/aux.js deleted file mode 100644 index b947d90..0000000 --- a/bin/lib/build/aux.js +++ /dev/null @@ -1,30 +0,0 @@ -// Generated by LiveScript 1.6.0 -var fs, aux; -fs = require('fs'); -aux = { - newer: function(f1, files, strict){ - var mtime; - files == null && (files = []); - strict == null && (strict = false); - if (!fs.existsSync(f1)) { - return false; - } - if (typeof files === 'number') { - mtime = files; - return strict - ? fs.statSync(f1).mtime - mtime > 0 - : fs.statSync(f1).mtime - mtime >= 0; - } - files = Array.isArray(files) - ? files - : [files]; - return files.length === files.filter(function(f2){ - if (strict) { - return !fs.existsSync(f2) || fs.statSync(f1).mtime - fs.statSync(f2).mtime > 0; - } else { - return !fs.existsSync(f2) || fs.statSync(f1).mtime - fs.statSync(f2).mtime >= 0; - } - }).length; - } -}; -module.exports = aux; \ No newline at end of file diff --git a/bin/lib/build/bundle.js b/bin/lib/build/bundle.js deleted file mode 100644 index eb95eef..0000000 --- a/bin/lib/build/bundle.js +++ /dev/null @@ -1,189 +0,0 @@ -// Generated by LiveScript 1.6.0 -var fs, fsExtra, livescript, stylus, path, colors, uglifyJs, uglifycss, aux, debounce, cwd, bundle, task, bundleFile, build, batch, main; -fs = require('fs'); -fsExtra = require('fs-extra'); -livescript = require('livescript'); -stylus = require('stylus'); -path = require('path'); -colors = require('colors'); -uglifyJs = require('uglify-js'); -uglifycss = require('uglifycss'); -aux = require('./aux'); -debounce = require('@loadingio/debounce.js'); -cwd = path.resolve(process.cwd()); -bundle = { - css: {}, - js: {} -}; -task = { - css: {}, - js: {} -}; -bundleFile = "bundle.json"; -build = function(arg$){ - var name, list, type, t1, outdir, outfile, outfilemin; - name = arg$.name, list = arg$.list, type = arg$.type; - t1 = Date.now(); - outdir = "static/" + type + "/pack/"; - outfile = path.join(outdir, name + "." + type); - outfilemin = path.join(outdir, name + ".min." + type); - return Promise.resolve().then(function(){ - return new Promise(function(res, rej){ - return fsExtra.ensureDir(outdir, function(){ - return res(); - }); - }); - }).then(function(){ - return Promise.all([ - Promise.all(list.map(function(f){ - return new Promise(function(res, rej){ - return fs.readFile(f, function(e, b){ - if (e) { - return rej(e); - } else { - return res({ - name: f, - code: b.toString() - }); - } - }); - }); - })), Promise.all(list.map(function(f){ - return new Promise(function(res, rej){ - var fm; - fm = f.replace(/\.(js|css)$/, '.min.$1'); - return fs.readFile(fm, function(e, b){ - if (e) { - return fs.readFile(f, function(e, b){ - if (e) { - return rej(e); - } else { - return res({ - name: fm, - code: b.toString() - }); - } - }); - } else { - return res({ - name: f, - code: b.toString() - }); - } - }); - }); - })) - ]); - }).then(function(ret){ - var normal, minified; - normal = ret[0].map(function(it){ - return it.code; - }).join(''); - minified = ret[1].map(function(arg$){ - var name, code; - name = arg$.name, code = arg$.code; - return /\.min\./.exec(name) - ? code - : type === 'js' - ? uglifyJs.minify(code).code - : type === 'css' ? uglifycss.processString(code, { - uglyComments: true - }) : code; - }).join(''); - return Promise.all([ - new Promise(function(res, rej){ - return fs.writeFile(outfile, normal, function(e, b){ - return res(b); - }); - }), new Promise(function(res, rej){ - return fs.writeFile(outfilemin, minified, function(e, b){ - return res(b); - }); - }) - ]); - }).then(function(){ - return { - type: type, - name: name, - elapsed: Date.now() - t1, - size: fs.statSync(outfile).size, - sizeMin: fs.statSync(outfilemin).size - }; - }); -}; -batch = debounce(500, function(){ - var promises, type, name, out; - promises = []; - for (type in task) { - for (name in task[type]) { - out = "static/" + type + "/pack/" + name + "." + type; - if (aux.newer(bundleFile, [out], true) || (task[type][name].length && !aux.newer(out, task[type][name]))) { - promises.push(build({ - type: type, - name: name, - list: bundle[type][name] - })); - } - } - } - task = { - css: {}, - js: {} - }; - return Promise.all(promises).then(function(list){ - var i$, len$, info, type, name, size, sizeMin, elapsed, results$ = []; - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - info = list[i$]; - type = info.type, name = info.name, size = info.size, sizeMin = info.sizeMin, elapsed = info.elapsed; - console.log("[BUILD] bundle static/" + type + "/pack/" + name + "." + type + " ( " + size + " bytes / " + elapsed + "ms )"); - results$.push(console.log("[BUILD] bundle static/" + type + "/pack/" + name + ".min." + type + " ( " + sizeMin + " bytes / " + elapsed + "ms )")); - } - return results$; - }); -}); -main = { - map: function(list){}, - build: function(list){ - var type, n, ref$, l, e, i$, len$, file; - if (in$(bundleFile, list)) { - try { - bundle = JSON.parse(fs.readFileSync(bundleFile).toString()); - for (type in bundle) { - for (n in ref$ = bundle[type]) { - l = ref$[n]; - bundle[type][n] = l.map(fn$); - } - } - } catch (e$) { - e = e$; - console.log(e); - return; - } - } - for (type in bundle) { - for (n in ref$ = bundle[type]) { - l = ref$[n]; - if (!task[type][n]) { - task[type][n] = []; - } - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - file = list[i$]; - if (in$(file, l)) { - task[type][n].push(file); - } - } - } - } - return batch(); - function fn$(it){ - return path.join('static', it); - } - }, - unlink: function(list){} -}; -module.exports = main; -function in$(x, xs){ - var i = -1, l = xs.length >>> 0; - while (++i < l) if (x === xs[i]) return true; - return false; -} \ No newline at end of file diff --git a/bin/lib/build/lsc.js b/bin/lib/build/lsc.js deleted file mode 100644 index d6f6264..0000000 --- a/bin/lib/build/lsc.js +++ /dev/null @@ -1,74 +0,0 @@ -// Generated by LiveScript 1.6.0 -var fs, fsExtra, livescript, path, colors, uglifyJs, aux, main; -fs = require('fs'); -fsExtra = require('fs-extra'); -livescript = require('livescript'); -path = require('path'); -colors = require('colors'); -uglifyJs = require('uglify-js'); -aux = require('./aux'); -main = { - map: function(list){ - return list.filter(function(it){ - return /^src\/ls/.exec(it.file || it); - }).map(function(it){ - var src, mtime, des, desMin; - src = it.file || it; - mtime = it.mtime || Date.now(); - des = path.normalize(src.replace(/^src\/ls/, "static/js/").replace(/\.ls/, ".js")); - desMin = des.replace(/\.js$/, '.min.js'); - return { - src: src, - des: des, - desMin: desMin, - mtime: mtime - }; - }); - }, - build: function(list){ - var i$, len$, ref$, src, des, desMin, mtime, t1, code, desdir, codeMin, t2, e; - list = this.map(list); - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - ref$ = list[i$], src = ref$.src, des = ref$.des, desMin = ref$.desMin, mtime = ref$.mtime; - if (!fs.existsSync(src) || aux.newer(des, mtime)) { - continue; - } - try { - t1 = Date.now(); - code = fs.readFileSync(src).toString(); - desdir = path.dirname(des); - fsExtra.ensureDirSync(desdir); - code = livescript.compile(fs.readFileSync(src).toString(), { - bare: true, - header: false - }); - codeMin = uglifyJs.minify(code).code; - fs.writeFileSync(des, code); - fs.writeFileSync(desMin, codeMin); - t2 = Date.now(); - console.log("[BUILD] " + src + " --> " + des + " / " + desMin + " ( " + (t2 - t1) + "ms )"); - } catch (e$) { - e = e$; - console.log(("[BUILD] " + src + " failed: ").red); - console.log(e.message.toString().red); - } - } - }, - unlink: function(list){ - var i$, len$, ref$, src, des, desMin, results$ = []; - list = this.map(list); - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - ref$ = list[i$], src = ref$.src, des = ref$.des, desMin = ref$.desMin; - if (fs.existsSync(des)) { - fs.unlinkSync(des); - console.log(("[BUILD] " + src + " --> " + des + " deleted.").yellow); - } - if (fs.existsSync(desMin)) { - fs.unlinkSync(desMin); - results$.push(console.log(("[BUILD] " + src + " --> " + desMin + " deleted.").yellow)); - } - } - return results$; - } -}; -module.exports = main; \ No newline at end of file diff --git a/bin/lib/build/pug.js b/bin/lib/build/pug.js deleted file mode 100644 index ae718b5..0000000 --- a/bin/lib/build/pug.js +++ /dev/null @@ -1,232 +0,0 @@ -// Generated by LiveScript 1.6.0 -var fs, path, fsExtra, pug, livescript, stylus, jsYaml, marked, aux, lc, mdOptions, resolve, pugExtapi, main; -fs = require('fs'); -path = require('path'); -fsExtra = require('fs-extra'); -pug = require('pug'); -livescript = require('livescript'); -stylus = require('stylus'); -path = require('path'); -jsYaml = require('js-yaml'); -marked = require('marked'); -aux = require('./aux'); -lc = { - i18n: {} -}; -mdOptions = { - html: { - breaks: true, - renderer: new marked.Renderer() - } -}; -marked.setOptions(mdOptions.html); -resolve = function(fn, src, opt){ - var e; - if (!/^@/.exec(fn)) { - return /^\//.exec(fn) - ? path.resolve(path.join(opt.basedir, fn)) - : path.resolve(path.join(path.dirname(src), fn)); - } - try { - if (/^@\//.exec(fn)) { - return require.resolve(fn.replace(/^@\//, "")); - } else if (/^@static\//.exec(fn)) { - return path.resolve(path.join(path.dirname(src), fn.replace(/^@static/, '/../../static/'))); - } - } catch (e$) { - e = e$; - throw new Error("no such file or directory: " + fn); - } -}; -pugExtapi = { - plugins: [{ - resolve: resolve - }], - filters: { - 'lsc': function(text, opt){ - return livescript.compile(text, { - bare: true, - header: false - }); - }, - 'lson': function(text, opt){ - return livescript.compile(text, { - bare: true, - header: false, - json: true - }); - }, - 'stylus': function(text, opt){ - return stylus(text).set('filename', 'inline').define('index', function(a, b){ - a = (a.string || a.val).split(' '); - return new stylus.nodes.Unit(a.indexOf(b.val)); - }).render(); - }, - 'md': function(text, opt){ - return marked(text); - } - }, - md: marked, - yaml: function(it){ - return jsYaml.safeLoad(fs.readFileSync(it)); - }, - yamls: function(dir){ - var ret; - ret = fs.readdirSync(dir).map(function(it){ - return dir + "/" + it; - }).filter(function(it){ - return /\.yaml$/.exec(it); - }).map(function(it){ - var e; - try { - return jsYaml.safeLoad(fs.readFileSync(it)); - } catch (e$) { - e = e$; - return console.log("[ERROR@" + it + "]: ", e); - } - }); - return ret; - } -}; -main = { - opt: function(opt){ - opt == null && (opt = {}); - if (opt.i18n) { - pugExtapi.i18n = function(it){ - return opt.i18n.t((it || '').trim()); - }; - pugExtapi.intlbase = function(p){ - p == null && (p = ""); - if (opt.i18n.language) { - return path.join("/intl", opt.i18n.language, p); - } else { - return p; - } - }; - (pugExtapi.filters || (pugExtapi.filters = {})).i18n = function(t, o){ - return opt.i18n.t((t || '').trim()); - }; - return lc.i18n = opt.i18n; - } - }, - map: function(list){ - return list.filter(function(it){ - return /^src\/pug/.exec(it.file || it); - }).map(function(it){ - return { - src: it.file || it, - des: path.normalize(it.file.replace(/^src\/pug/, "static/").replace(/\.pug$/, ".html")), - mtime: it.mtime || Date.now() - }; - }); - }, - compile: function(src, opt){ - var cwd; - opt == null && (opt = {}); - cwd = path.resolve(process.cwd()); - return pug.compile(fs.readFileSync(src).toString(), import$(import$({ - filename: src, - basedir: path.join(cwd, 'src/pug/') - }, pugExtapi), opt)); - }, - build: function(list, causedBy){ - var cwd, _, lngs, ref$, consume; - cwd = path.resolve(process.cwd()); - list = this.map(list); - _ = function(lng){ - var intl, p, that, ref$; - lng == null && (lng = ''); - intl = lng ? path.join("intl", lng) : ''; - p = lc.i18n.changeLanguage - ? lc.i18n.changeLanguage((that = lng) - ? that - : ((ref$ = lc.i18n).options || (ref$.options = {})).fallbackLng) - : Promise.resolve(); - return p.then(function(){ - var i$, ref$, len$, ref1$, src, des, mtime, desv, desh, code, t1, desvdir, ret, t2, desdir, e, results$ = []; - for (i$ = 0, len$ = (ref$ = list).length; i$ < len$; ++i$) { - ref1$ = ref$[i$], src = ref1$.src, des = ref1$.des, mtime = ref1$.mtime; - desv = des.replace('static/', path.join('.view', intl) + "/").replace(/\.html$/, '.js'); - desh = des.replace('static/', path.join('static', intl) + "/"); - if (!fs.existsSync(src) || aux.newer(desv, mtime)) { - continue; - } - code = fs.readFileSync(src).toString(); - try { - t1 = Date.now(); - if (/^\/\/- ?module ?/.exec(code)) { - continue; - } - if (fs.existsSync(src) && !aux.newer(desv, mtime)) { - desvdir = path.dirname(desv); - fsExtra.ensureDirSync(desvdir); - ret = pug.compileClient(code, import$({ - filename: src, - basedir: path.join(cwd, 'src/pug/') - }, pugExtapi)); - ret = " (function() { " + ret + "; module.exports = template; })() "; - fs.writeFileSync(desv, ret); - t2 = Date.now(); - console.log("[BUILD] " + src + " --> " + desv + " ( " + (t2 - t1) + "ms )"); - } - if (!/^\/\/- ?(view|module) ?/.exec(code)) { - desdir = path.dirname(desh); - fsExtra.ensureDirSync(desdir); - fs.writeFileSync(desh, pug.render(code, import$({ - filename: src, - basedir: path.join(cwd, 'src/pug/') - }, pugExtapi))); - t2 = Date.now(); - results$.push(console.log("[BUILD] " + src + " --> " + desh + " ( " + (t2 - t1) + "ms )")); - } - } catch (e$) { - e = e$; - console.log(("[BUILD] " + src + " failed: ").red); - results$.push(console.log(e.message.toString().red)); - } - } - return results$; - }); - }; - lngs = [''].concat(((ref$ = lc.i18n).options || (ref$.options = {})).lng || []); - consume = function(i){ - i == null && (i = 0); - if (i >= lngs.length) { - return; - } - return _(lngs[i]).then(function(){ - return consume(i + 1); - }); - }; - consume(); - }, - unlink: function(list){ - var i$, len$, ref$, src, des, e, results$ = []; - list = this.map(list); - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - ref$ = list[i$], src = ref$.src, des = ref$.des; - try { - if (fs.existsSync(des)) { - fs.unlinkSync(des); - console.log(("[BUILD] " + src + " --> " + des + " deleted.").yellow); - } - des = des.replace('static/', '.view/').replace(/\.html$/, '.js'); - if (fs.existsSync(des)) { - fs.unlinkSync(des); - results$.push(console.log(("[BUILD] " + src + " --> " + des + " deleted.").yellow)); - } - } catch (e$) { - e = e$; - results$.push(console.log(e)); - } - } - return results$; - }, - extapi: pugExtapi -}; -module.exports = main; -function import$(obj, src){ - var own = {}.hasOwnProperty; - for (var key in src) if (own.call(src, key)) obj[key] = src[key]; - return obj; -} \ No newline at end of file diff --git a/bin/lib/build/stylus.js b/bin/lib/build/stylus.js deleted file mode 100644 index 3717663..0000000 --- a/bin/lib/build/stylus.js +++ /dev/null @@ -1,81 +0,0 @@ -// Generated by LiveScript 1.6.0 -var fs, fsExtra, stylus, path, uglifycss, aux, main; -fs = require('fs'); -fsExtra = require('fs-extra'); -stylus = require('stylus'); -path = require('path'); -uglifycss = require('uglifycss'); -aux = require('./aux'); -main = { - map: function(list){ - return list.filter(function(it){ - return /^src\/styl/.exec(it.file || it); - }).map(function(it){ - var src, mtime, des, desMin; - src = it.file || it; - mtime = it.mtime || Date.now(); - des = path.normalize(src.replace(/^src\/styl/, "static/css/").replace(/\.styl/, ".css")); - desMin = des.replace(/\.css$/, '.min.css'); - return { - src: src, - des: des, - desMin: desMin, - mtime: mtime - }; - }); - }, - build: function(list, causedBy){ - var i$, len$, ref$, src, des, desMin, mtime, t1, code, desdir, e; - list = this.map(list); - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - ref$ = list[i$], src = ref$.src, des = ref$.des, desMin = ref$.desMin, mtime = ref$.mtime; - if (!fs.existsSync(src) || aux.newer(des, mtime)) { - continue; - } - try { - t1 = Date.now(); - code = fs.readFileSync(src).toString(); - if (/^\/\/- ?(module) ?/.exec(code)) { - continue; - } - desdir = path.dirname(des); - fsExtra.ensureDirSync(desdir); - stylus(code).set('filename', src).render(fn$); - } catch (e$) { - e = e$; - console.log(("[BUILD] " + src + " failed: ").red); - console.log(e.message.toString().red); - } - } - function fn$(e, css){ - var codeMin, t2; - if (e) { - throw e; - } - codeMin = uglifycss.processString(css, { - uglyComments: true - }); - fs.writeFileSync(des, css); - fs.writeFileSync(desMin, codeMin); - t2 = Date.now(); - return console.log("[BUILD] " + src + " --> " + des + " / " + desMin + " ( " + (t2 - t1) + "ms )"); - } - }, - unlink: function(list){ - var i$, len$, ref$, src, des, desMin, results$ = []; - list = this.map(list); - for (i$ = 0, len$ = list.length; i$ < len$; ++i$) { - ref$ = list[i$], src = ref$.src, des = ref$.des, desMin = ref$.desMin; - if (fs.existsSync(des)) { - fs.unlinkSync(des); - console.log(("[BUILD] " + src + " --> " + des + " deleted.").yellow); - } - if (fs.existsSync(desMin)) { - fs.unlinkSync(desMin); - results$.push(console.log(("[BUILD] " + src + " --> " + desMin + " deleted.").yellow)); - } - } - return results$; - } -}; -module.exports = main; \ No newline at end of file diff --git a/bin/lib/index.js b/bin/lib/index.js index 99b3821..74a661f 100644 --- a/bin/lib/index.js +++ b/bin/lib/index.js @@ -1,12 +1,10 @@ // Generated by LiveScript 1.6.0 -var server, watch, view, pug; +var server, view, pug; server = require('./server'); -watch = require('./watch'); view = require('./view'); pug = require('./build/pug'); module.exports = { server: server, - watch: watch, view: view, pug: pug }; \ No newline at end of file diff --git a/bin/lib/tree/DocTree.js b/bin/lib/tree/DocTree.js deleted file mode 100644 index 545c7b8..0000000 --- a/bin/lib/tree/DocTree.js +++ /dev/null @@ -1,86 +0,0 @@ -// Generated by LiveScript 1.6.0 -var fs, path, cwd, DocTree; -fs = require('fs'); -path = require('path'); -cwd = path.resolve(process.cwd()); -DocTree = function(opt){ - opt == null && (opt = {}); - this.opt = opt; - this.depend = { - by: {}, - on: {} - }; - this.root = opt.root || cwd; - this.type = opt.type; - if (opt.parser) { - this.parser = opt.parser; - } - return this; -}; -DocTree.prototype = import$(Object.create(Object.prototype), { - setRoot: function(it){ - return this.root = it; - }, - parse: function(it){ - var f, content, dir, ret, this$ = this; - f = it.file; - if (!fs.existsSync(f)) { - return []; - } - content = fs.readFileSync(f).toString(); - dir = path.dirname(path.relative(this.root, f)); - if (!this.parser) { - return; - } - this.depend.by[f] = ret = this.parser(content, f).map(function(it){ - return path.join(this$.root, path.normalize(it[0] === '/' - ? it - : path.join(dir, it))); - }); - ret.map(function(it){ - var ref$; - return ((ref$ = this$.depend.on)[it] || (ref$[it] = [])).push(f); - }); - return ret; - }, - affect: function(list){ - var ref$, ret, visited, f, k; - if (!Array.isArray(list)) { - list = [list]; - } - ref$ = [{}, {}], ret = ref$[0], visited = ref$[1]; - list.map(function(it){ - return ret[it.file] = true; - }); - while (list.length) { - f = path.normalize(path.relative(this.root, path.join(this.root, list.pop().file))); - if (!visited[f] && this.depend.on[f]) { - list = list.concat(this.depend.on[f].map(fn$)); - this.depend.on[f].map(fn1$); - } - visited[f] = true; - } - return (function(){ - var results$ = []; - for (k in ret) { - results$.push(k); - } - return results$; - }()); - function fn$(it){ - return { - file: it, - mtime: fs.statSync(it).mtime - }; - } - function fn1$(it){ - return ret[it] = true; - } - } -}); -module.exports = DocTree; -function import$(obj, src){ - var own = {}.hasOwnProperty; - for (var key in src) if (own.call(src, key)) obj[key] = src[key]; - return obj; -} \ No newline at end of file diff --git a/bin/lib/tree/PugTree.js b/bin/lib/tree/PugTree.js deleted file mode 100644 index d3f5907..0000000 --- a/bin/lib/tree/PugTree.js +++ /dev/null @@ -1,42 +0,0 @@ -// Generated by LiveScript 1.6.0 -var DocTree, pug, path, pugbuild, pugtree; -DocTree = require('./DocTree'); -pug = require('pug'); -path = require('path'); -pugbuild = require("../build/pug"); -pugtree = new DocTree({ - parser: function(c, f){ - /* use pug dependencies tracking */ - var cwd, ret, e; - cwd = path.resolve(path.join(process.cwd(), this.root)); - try { - ret = pug.compileClientWithDependenciesTracked(c, import$({ - basedir: path.join(cwd, path.dirname(f)), - filename: f - }, pugbuild.extapi)); - return ret.dependencies.map(function(it){ - return it.replace(cwd, '/../..'); - }); - } catch (e$) { - e = e$; - try { - return ret = c.split('\n').map(function(it){ - return /\s*(extend|include)\s+(.+)$/.exec(it); - }).filter(function(it){ - return it; - }).map(function(it){ - return it[2]; - }); - } catch (e$) { - e = e$; - return []; - } - } - } -}); -module.exports = pugtree; -function import$(obj, src){ - var own = {}.hasOwnProperty; - for (var key in src) if (own.call(src, key)) obj[key] = src[key]; - return obj; -} \ No newline at end of file diff --git a/bin/lib/tree/StylusTree.js b/bin/lib/tree/StylusTree.js deleted file mode 100644 index 4235d00..0000000 --- a/bin/lib/tree/StylusTree.js +++ /dev/null @@ -1,19 +0,0 @@ -// Generated by LiveScript 1.6.0 -var DocTree, styl; -DocTree = require('./DocTree'); -styl = new DocTree({ - parser: function(c){ - var ret; - ret = c.split('\n').map(function(it){ - return /\s*(@import)\s+(.+)$/.exec(it); - }).filter(function(it){ - return it; - }).map(function(it){ - return it[2].replace(/'/g, '').replace(/(\.styl)?$/, '.styl'); - }).map(function(it){ - return it; - }); - return ret; - } -}); -module.exports = styl; \ No newline at end of file diff --git a/lib/build/aux.ls b/lib/build/aux.ls deleted file mode 100644 index 4569030..0000000 --- a/lib/build/aux.ls +++ /dev/null @@ -1,16 +0,0 @@ -require! <[fs]> -aux = do - newer: (f1, files = [], strict = false) -> - if !fs.exists-sync(f1) => return false - if typeof(files) == \number => - mtime = files - return if strict => (fs.stat-sync(f1).mtime - mtime) > 0 - else (fs.stat-sync(f1).mtime - mtime) >= 0 - files = if Array.isArray(files) => files else [files] - return files.length == files - .filter (f2) -> - if strict => !fs.exists-sync(f2) or (fs.stat-sync(f1).mtime - fs.stat-sync(f2).mtime) > 0 - else !fs.exists-sync(f2) or (fs.stat-sync(f1).mtime - fs.stat-sync(f2).mtime) >= 0 - .length - -module.exports = aux diff --git a/lib/build/bundle.ls b/lib/build/bundle.ls deleted file mode 100644 index 560a3b7..0000000 --- a/lib/build/bundle.ls +++ /dev/null @@ -1,82 +0,0 @@ -require! <[fs fs-extra livescript stylus path colors uglify-js uglifycss ./aux @loadingio/debounce.js]> - -cwd = path.resolve process.cwd! - -bundle = {css: {}, js: {}} -task = {css: {}, js: {}} -bundle-file = "bundle.json" - -build = ({name, list, type}) -> - t1 = Date.now! - outdir = "static/#type/pack/" - outfile = path.join(outdir, "#name.#type") - outfilemin = path.join(outdir, "#name.min.#type") - Promise.resolve! - .then -> new Promise (res, rej) -> fs-extra.ensure-dir outdir, -> res! - .then -> - Promise.all [ - Promise.all(list.map((f) -> new Promise (res, rej) -> - fs.read-file(f, (e,b) -> if e => rej e else res {name: f, code: b.toString!}))), - Promise.all(list.map((f) -> new Promise (res, rej) -> - fm = f.replace /\.(js|css)$/, '.min.$1' - (e,b) <- fs.read-file fm, _ - if e => fs.read-file f,((e, b) -> if e => rej e else res {name: fm, code: b.toString!}) - else res {name: f, code: b.toString!} - )) - ] - .then (ret) -> - normal = ret.0.map(->it.code).join('') - minified = ret.1 - .map ({name,code}) -> - return if /\.min\./.exec(name) => code - else if type == \js => uglify-js.minify(code).code - else if type == \css => uglifycss.processString(code, uglyComments: true) - else code - .join('') - Promise.all [ - new Promise (res, rej) -> fs.write-file outfile, normal, (e, b) -> res b - new Promise (res, rej) -> fs.write-file outfilemin, minified, (e, b) -> res b - ] - .then -> - return do - type: type, name: name - elapsed: Date.now! - t1 - size: fs.stat-sync(outfile).size - size-min: fs.stat-sync(outfilemin).size - -batch = debounce 500, -> - promises = [] - for type of task => - for name of task[type] => - out = "static/#type/pack/#name.#type" - # out file is not newer than watched files? rebuild! - if aux.newer(bundle-file, [out], true) or (task[type][name].length and !aux.newer(out, task[type][name])) => - promises.push build({type, name, list: bundle[type][name]}) - task := {css: {}, js: {}} - Promise.all promises - .then (list) -> - for info in list => - {type,name,size,size-min,elapsed} = info - console.log "[BUILD] bundle static/#type/pack/#name.#type ( #size bytes / #{elapsed}ms )" - console.log "[BUILD] bundle static/#type/pack/#name.min.#type ( #size-min bytes / #{elapsed}ms )" - - -main = do - map: (list) -> - build: (list) -> - if bundle-file in list => - try - bundle := JSON.parse(fs.read-file-sync bundle-file .toString!) - for type of bundle => for n,l of bundle[type] => bundle[type][n] = l.map -> path.join(\static,it) - catch e - console.log e - return - for type of bundle => - for n,l of bundle[type] => - if !task[type][n] => task[type][n] = [] - for file in list => if file in l => task[type][n].push file - batch! - - unlink: (list) -> - -module.exports = main diff --git a/lib/build/lsc.ls b/lib/build/lsc.ls deleted file mode 100644 index e3a8793..0000000 --- a/lib/build/lsc.ls +++ /dev/null @@ -1,44 +0,0 @@ -require! <[fs fs-extra livescript path colors uglify-js ./aux]> - -main = do - map: (list) -> - list - .filter -> /^src\/ls/.exec(it.file or it) - .map (it) -> - src = it.file or it - mtime = it.mtime or Date.now! - des = path.normalize(src.replace(/^src\/ls/, "static/js/").replace(/\.ls/,".js")) - des-min = des.replace /\.js$/, '.min.js' - {src, des, des-min, mtime: mtime} - build: (list) -> - list = @map list - for {src,des, des-min,mtime} in list => - if !fs.exists-sync(src) or aux.newer(des, mtime) => continue - try - t1 = Date.now! - code = fs.read-file-sync src .toString! - desdir = path.dirname(des) - fs-extra.ensure-dir-sync desdir - code = livescript.compile(fs.read-file-sync(src)toString!,{bare: true, header: false}) - code-min = uglify-js.minify(code).code - fs.write-file-sync des, code - fs.write-file-sync des-min, code-min - t2 = Date.now! - console.log "[BUILD] #src --> #des / #des-min ( #{t2 - t1}ms )" - catch - console.log "[BUILD] #src failed: ".red - console.log e.message.toString!red - return - unlink: (list) -> - list = @map list - for {src,des,des-min} in list => - if fs.exists-sync des => - fs.unlink-sync des - console.log "[BUILD] #src --> #des deleted.".yellow - if fs.exists-sync des-min => - fs.unlink-sync des-min - console.log "[BUILD] #src --> #des-min deleted.".yellow - - -module.exports = main - diff --git a/lib/build/pug.ls b/lib/build/pug.ls deleted file mode 100644 index 40eddc4..0000000 --- a/lib/build/pug.ls +++ /dev/null @@ -1,128 +0,0 @@ -require! <[fs path fs-extra pug livescript stylus path js-yaml marked ./aux]> - -lc = {i18n: {}} -md-options = html: {breaks: true, renderer: new marked.Renderer!} -marked.set-options md-options.html - -resolve = (fn,src,opt) -> - if !/^@/.exec(fn) => - return if /^\//.exec(fn) => path.resolve(path.join(opt.basedir, fn)) - else path.resolve(path.join(path.dirname(src),fn)) - try - if /^@\//.exec(fn) => - return require.resolve(fn.replace /^@\//, "") - else if /^@static\//.exec(fn) => - return path.resolve(path.join(path.dirname(src), fn.replace(/^@static/,'/../../static/'))) - catch e - throw new Error("no such file or directory: #fn") - -pug-extapi = do - plugins: [{resolve}] - filters: do - 'lsc': (text, opt) -> return livescript.compile(text,{bare:true,header:false}) - 'lson': (text, opt) -> return livescript.compile(text,{bare:true,header:false,json:true}) - 'stylus': (text, opt) -> - stylus(text) - .set \filename, 'inline' - .define 'index', (a,b) -> - a = (a.string or a.val).split(' ') - return new stylus.nodes.Unit(a.indexOf b.val) - .render! - 'md': (text, opt) -> marked text - md: marked - yaml: -> js-yaml.safe-load fs.read-file-sync it - yamls: (dir) -> - ret = fs.readdir-sync dir - .map -> "#dir/#it" - .filter -> /\.yaml$/.exec(it) - .map -> - try - js-yaml.safe-load(fs.read-file-sync it) - catch e - console.log "[ERROR@#it]: ", e - return ret - -main = do - opt: (opt = {}) -> - if opt.i18n => - pug-extapi.i18n = -> opt.i18n.t((it or '').trim!) - pug-extapi.intlbase = (p = "") -> if opt.i18n.language => path.join("/intl",opt.i18n.language,p) else p - pug-extapi.{}filters.i18n = (t, o) -> opt.i18n.t((t or '').trim!) - lc.i18n = opt.i18n - map: (list) -> - list - .filter -> /^src\/pug/.exec(it.file or it) - .map -> do - src: it.file or it - des: path.normalize(it.file.replace(/^src\/pug/, "static/").replace(/\.pug$/,".html")) - mtime: it.mtime or Date.now! - # handy function to custom build quickly with the same configuration of server watcher. - compile: (src,opt = {}) -> - cwd = path.resolve process.cwd! - pug.compile( - fs.read-file-sync(src).toString!, - {filename: src, basedir: path.join(cwd, 'src/pug/')} <<< pug-extapi <<< opt - ) - build: (list, caused-by) -> - cwd = path.resolve process.cwd! - list = @map list - - _ = (lng = '') -> - intl = if lng => path.join("intl",lng) else '' - p = if lc.i18n.changeLanguage => - lc.i18n.changeLanguage(if lng => that else lc.i18n.{}options.fallbackLng) - else Promise.resolve! - p.then -> - for {src,des,mtime} in list => - desv = des.replace('static/', path.join('.view', intl) + "/").replace(/\.html$/, '.js') - desh = des.replace('static/', path.join('static', intl) + "/") - if !fs.exists-sync(src) or aux.newer(desv, mtime) => continue - code = fs.read-file-sync src .toString! - try - t1 = Date.now! - if /^\/\/- ?module ?/.exec(code) => continue - - if fs.exists-sync(src) and !aux.newer(desv, mtime) => - desvdir = path.dirname(desv) - fs-extra.ensure-dir-sync desvdir - ret = pug.compileClient code, {filename: src, basedir: path.join(cwd, 'src/pug/')} <<< pug-extapi - ret = """ (function() { #ret; module.exports = template; })() """ - fs.write-file-sync desv, ret - t2 = Date.now! - console.log "[BUILD] #src --> #desv ( #{t2 - t1}ms )" - if !(/^\/\/- ?(view|module) ?/.exec(code)) => - desdir = path.dirname(desh) - fs-extra.ensure-dir-sync desdir - fs.write-file-sync( - desh, pug.render code, {filename: src, basedir: path.join(cwd, 'src/pug/')} <<< pug-extapi - ) - t2 = Date.now! - console.log "[BUILD] #src --> #desh ( #{t2 - t1}ms )" - - catch - console.log "[BUILD] #src failed: ".red - console.log e.message.toString!red - - lngs = ([''] ++ (lc.i18n.{}options.lng or [])) - consume = (i=0) -> - if i >= lngs.length => return - _(lngs[i]).then -> consume(i+1) - consume! - - return - unlink: (list) -> - list = @map list - for {src,des} in list => - try - if fs.exists-sync des => - fs.unlink-sync des - console.log "[BUILD] #src --> #des deleted.".yellow - des = des.replace('static/', '.view/').replace(/\.html$/, '.js') - if fs.exists-sync des => - fs.unlink-sync des - console.log "[BUILD] #src --> #des deleted.".yellow - catch e - console.log e - extapi: pug-extapi - -module.exports = main diff --git a/lib/build/stylus.ls b/lib/build/stylus.ls deleted file mode 100644 index 50279e1..0000000 --- a/lib/build/stylus.ls +++ /dev/null @@ -1,46 +0,0 @@ -require! <[fs fs-extra stylus path uglifycss ./aux]> - -main = do - map: (list) -> - list - .filter -> /^src\/styl/.exec(it.file or it) - .map (it) -> - src = it.file or it - mtime = it.mtime or Date.now! - des = path.normalize(src.replace(/^src\/styl/, "static/css/").replace(/\.styl/,".css")) - des-min = des.replace /\.css$/, '.min.css' - {src, des, des-min, mtime: mtime } - build: (list, caused-by) -> - list = @map list - for {src,des,des-min,mtime} in list => - if !fs.exists-sync(src) or aux.newer(des, mtime) => continue - try - t1 = Date.now! - code = fs.read-file-sync src .toString! - if /^\/\/- ?(module) ?/.exec(code) => continue - desdir = path.dirname(des) - fs-extra.ensure-dir-sync desdir - stylus code - .set \filename, src - .render (e, css) -> - if e => throw e - code-min = uglifycss.processString(css, uglyComments: true) - fs.write-file-sync des, css - fs.write-file-sync des-min, code-min - t2 = Date.now! - console.log "[BUILD] #src --> #des / #des-min ( #{t2 - t1}ms )" - catch - console.log "[BUILD] #src failed: ".red - console.log e.message.toString!red - return - unlink: (list) -> - list = @map list - for {src,des,des-min} in list => - if fs.exists-sync des => - fs.unlink-sync des - console.log "[BUILD] #src --> #des deleted.".yellow - if fs.exists-sync des-min => - fs.unlink-sync des-min - console.log "[BUILD] #src --> #des-min deleted.".yellow - -module.exports = main diff --git a/lib/index.ls b/lib/index.ls index bb0ca8c..3d7dcdb 100644 --- a/lib/index.ls +++ b/lib/index.ls @@ -1,2 +1,2 @@ -require! <[./server ./watch ./view ./build/pug]> -module.exports = {server, watch, view, pug} +require! <[./server ./view ./build/pug]> +module.exports = {server, view, pug} diff --git a/lib/tree/DocTree.ls b/lib/tree/DocTree.ls deleted file mode 100644 index 3a67edc..0000000 --- a/lib/tree/DocTree.ls +++ /dev/null @@ -1,36 +0,0 @@ -require! <[fs path]> - -cwd = path.resolve process.cwd! - -DocTree = (opt={})-> - @ <<< opt: opt, depend: by: {}, on: {} - @ <<< root: opt.root or cwd, type: opt.type - if opt.parser => @parser = opt.parser - @ - -DocTree.prototype = Object.create(Object.prototype) <<< do - set-root: -> @root = it - parse: (it) -> - f = it.file - if !fs.exists-sync(f) => return [] - content = fs.read-file-sync f .toString! - dir = path.dirname path.relative(@root, f) - if !@parser => return - @depend.by[f] = ret = @parser content, f - .map ~> path.join(@root, path.normalize(if it.0 == \/ => it else path.join(dir, it))) - ret.map ~> @depend.on[][it].push f - ret - - affect: (list) -> - if !Array.isArray(list) => list = [list] - [ret, visited] = [{}, {}] - list.map -> ret[it.file] = true - while list.length - f = path.normalize(path.relative @root, path.join(@root, list.pop!file)) - if !visited[f] and @depend.on[f] => - list ++= @depend.on[f].map -> {file: it, mtime: fs.stat-sync(it).mtime} - @depend.on[f].map -> ret[it] = true - visited[f] = true - return [k for k of ret] - -module.exports = DocTree diff --git a/lib/tree/PugTree.ls b/lib/tree/PugTree.ls deleted file mode 100644 index 9ea8a4c..0000000 --- a/lib/tree/PugTree.ls +++ /dev/null @@ -1,25 +0,0 @@ -require! <[./DocTree pug path]> -pugbuild = require "../build/pug" - -pugtree = new DocTree do - parser: (c, f) -> - /* use pug dependencies tracking */ - cwd = path.resolve path.join(process.cwd!, @root) - try - ret = pug.compileClientWithDependenciesTracked( - c, - {basedir: path.join(cwd,path.dirname f), filename: f} <<< pugbuild.extapi - ) - return ret.dependencies.map(-> it.replace cwd, '/../..') - catch e - try - ret = c - .split \\n - .map -> /\s*(extend|include)\s+(.+)$/.exec(it) - .filter -> it - .map -> it.2 - catch e - return [] - - -module.exports = pugtree diff --git a/lib/tree/StylusTree.ls b/lib/tree/StylusTree.ls deleted file mode 100644 index b44e6e0..0000000 --- a/lib/tree/StylusTree.ls +++ /dev/null @@ -1,13 +0,0 @@ -require! <[./DocTree]> - -styl = new DocTree do - parser: (c) -> - ret = c - .split \\n - .map -> /\s*(@import)\s+(.+)$/.exec(it) - .filter -> it - .map -> it.2.replace(/'/g, '').replace(/(\.styl)?$/, '.styl') - .map -> it - return ret - -module.exports = styl diff --git a/server.ls b/server.ls index 2f988e4..b2227bd 100644 --- a/server.ls +++ b/server.ls @@ -4,7 +4,6 @@ require! <[fs path yargs colors @plotdb/srcbuild]> lib = path.dirname fs.realpathSync __filename server = require "#lib/lib/server" -watch = require "#lib/lib/watch" api = require "#lib/api/index" # legacy support. remove this in future version.