@plotdb/srcbuild 0.0.49 → 0.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -13,10 +13,10 @@ setup a lsp ( livescript + stylus + pug ) watcher:
13
13
  where
14
14
 
15
15
  - `base`: root dir for `src` and `static` folders. default `.`
16
- - `i18n`: i18n object.
16
+ - `i18n`: i18n object.
17
17
  - `ignored`: files to be ignored. in [anymatch](https://github.com/micromatch/anymatch)-compatible definition.
18
18
  - by default ['.git']
19
- - `logger`: optional. for logging output. use `console.log` by default.
19
+ - `logger`: optional. for logging output. use `console.log` by default.
20
20
  - sample logger with `pino`:
21
21
 
22
22
  require! <[@plotdb/srcbuild pino]>
@@ -52,7 +52,7 @@ Extend base builder for a customized builder:
52
52
  with following user-defined functions:
53
53
 
54
54
  - `is-supported(file)`: return true if `file` is supported by this builder, otherwise return false.
55
- - `file`: file name for file to be verified. Relative to cwd.
55
+ - `file`: file name for file to be verified. Relative to cwd.
56
56
  - `get-dependencies(file)`: return a list of files that this file depends on.
57
57
  - `file`: same as `is-supported`
58
58
  - `build(files)`: should compile / generate target files of given file list `files`.
@@ -71,7 +71,7 @@ and the common options for `init` are as following:
71
71
  - `desdir`: directory for built files. should be relative to `base`. default `static` if omitted.
72
72
  - `logger`: logger for log output. use `console` if omitted.
73
73
 
74
- check `src/ext/lsc.ls` or `src/ext/pug.ls` for example.
74
+ check `src/ext/lsc.ls` or `src/ext/pug.ls` for example.
75
75
 
76
76
 
77
77
  ## Options for custom builder
@@ -93,6 +93,7 @@ Except common options, each builder may support different options:
93
93
  span:i18n translate this text
94
94
  - `noView`: default false. when true, js view files ( generated to `viewdir` ) won't be built.
95
95
  - `viewdir`: default `.view`. a directory for storing prebuilt pug files ( in .js format )
96
+ - `bundler`: default null. Auto packing will be possible only if this is provided.
96
97
  - `lsc`:
97
98
  - `useGlslify`: default false. set to true if you need glslify of lsc files.
98
99
  - *NOTE* this is an experiment feature and may be removed ( move to standalone builder ) in the future.
@@ -116,7 +117,7 @@ Except common options, each builder may support different options:
116
117
 
117
118
  These options are constructor options for corresponding builder, e.g., for pug builder:
118
119
 
119
- new pugbuild({ i18n: ... })
120
+ new pugbuild({ i18n: ... })
120
121
 
121
122
  When using shorthands like `srcbuild.lsp(...)`, you can also specify corresponding option in scope, such as:
122
123
 
@@ -146,7 +147,7 @@ By default, watcher watches the current working directory. Change watcher behavi
146
147
 
147
148
  ## ODB / On demand build
148
149
 
149
- use `watch.demand(target-file)` to force rebuild by request. e.g.,
150
+ use `watch.demand(target-file)` to force rebuild by request. e.g.,
150
151
 
151
152
  require! <[srcbuild]>
152
153
  watch = srcbuild.lsp!
@@ -238,6 +239,31 @@ Additionally, you can also use a list of modules:
238
239
  {name: "omit-everything"},
239
240
  ])
240
241
 
242
+ Use the second option object to specify additional parameters, including:
243
+
244
+ - `pack`: *experimental* default false. Enable auto packing or not.
245
+ - if true, enable auto packing which trigger bundling automatically to a filename from md5 of all script urls.
246
+ - require `bundler` option in pugbuild constructor.
247
+ - doesn't work with external urls.
248
+ - there are still issues about rebuilding and build from view.
249
+
250
+ #### Auto Packing Issue (TODO)
251
+
252
+ Auto packing works fine with static built files. However, there are two issues:
253
+
254
+ - it's kinda tricky to trigger a pack file rebuild if the pack file is mssing - since there is no clue from the hashed file name to the urls used.
255
+ - may slow down dynamic generated views since each rendering checks if the bundled file should be rebuilt against its source files.
256
+ - doesn't work for external urls.
257
+
258
+ For the above issues, we can:
259
+
260
+ - add additional information ( such as source pug name base64 string ) in the hashed file name for reversed resolving all source files
261
+ - completely ignore auto packing with dynamic view rendering, instead we support ODB of bundle files
262
+ - extend bundler to support remote file fetching
263
+
264
+ These solutions will be left in TODOs.
265
+
266
+
241
267
 
242
268
  ### Filters
243
269
 
@@ -83,9 +83,12 @@ bundlebuild.prototype = import$(Object.create(base.prototype), {
83
83
  }
84
84
  return (this.config[ret[1]][ret[2]] || [])[0];
85
85
  },
86
- build: function(files, force){
87
- var dirty, i$, len$, file, ret, key$, ps, type, name, desdir, des, this$ = this;
88
- force == null && (force = false);
86
+ build: function(files, opt){
87
+ var force, dirty, key$, nfs, ofs, ref$, i$, len$, file, ret, ps, type, name, desdir, des, this$ = this;
88
+ force = typeof opt === 'boolean' ? opt : false;
89
+ if (opt == null) {
90
+ opt = {};
91
+ }
89
92
  if (files.filter(function(it){
90
93
  return it.file === this$.configFile;
91
94
  }).length) {
@@ -98,13 +101,36 @@ bundlebuild.prototype = import$(Object.create(base.prototype), {
98
101
  files.splice(files.indexOf(this.configFile), 1);
99
102
  return this.build(files, true);
100
103
  }
101
- dirty = {};
102
- for (i$ = 0, len$ = files.length; i$ < len$; ++i$) {
103
- file = files[i$];
104
- if (!(ret = this.fileMap[file.file])) {
105
- continue;
104
+ if (opt.odb) {
105
+ dirty = {};
106
+ (dirty[key$ = opt.type] || (dirty[key$] = {}))[opt.name] = true;
107
+ nfs = files.map(function(f){
108
+ return path.join(this$._relativePath, f);
109
+ });
110
+ ofs = ((ref$ = this.config)[key$ = opt.type] || (ref$[key$] = {}))[opt.name] || [];
111
+ if (nfs.length !== ofs.length || nfs.filter(function(it){
112
+ return !in$(it, ofs);
113
+ }).length) {
114
+ force = true;
115
+ }
116
+ ((ref$ = this.config)[key$ = opt.type] || (ref$[key$] = {}))[opt.name] = nfs;
117
+ for (i$ = 0, len$ = (ref$ = this.config[opt.type][opt.name]).length; i$ < len$; ++i$) {
118
+ file = ref$[i$];
119
+ this.fileMap[file] = {
120
+ type: opt.type,
121
+ name: opt.name
122
+ };
123
+ this.fileList.add(file);
124
+ }
125
+ } else {
126
+ dirty = {};
127
+ for (i$ = 0, len$ = files.length; i$ < len$; ++i$) {
128
+ file = files[i$];
129
+ if (!(ret = this.fileMap[file.file])) {
130
+ continue;
131
+ }
132
+ (dirty[key$ = ret.type] || (dirty[key$] = {}))[ret.name] = true;
106
133
  }
107
- (dirty[key$ = ret.type] || (dirty[key$] = {}))[ret.name] = true;
108
134
  }
109
135
  ps = [];
110
136
  for (type in dirty) {
@@ -234,4 +260,9 @@ function import$(obj, src){
234
260
  var own = {}.hasOwnProperty;
235
261
  for (var key in src) if (own.call(src, key)) obj[key] = src[key];
236
262
  return obj;
263
+ }
264
+ function in$(x, xs){
265
+ var i = -1, l = xs.length >>> 0;
266
+ while (++i < l) if (x === xs[i]) return true;
267
+ return false;
237
268
  }
package/dist/ext/pug.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Generated by LiveScript 1.6.0
2
- var fs, path, fsExtra, pug, livescript, uglifyJs, uglifycss, stylus, jsYaml, marked, colors, base, aux, cwd, pugbuild;
2
+ var fs, path, fsExtra, pug, livescript, uglifyJs, uglifycss, stylus, jsYaml, marked, crypto, colors, base, aux, cwd, pugbuild;
3
3
  fs = require('fs');
4
4
  path = require('path');
5
5
  fsExtra = require('fs-extra');
@@ -10,6 +10,7 @@ uglifycss = require('uglifycss');
10
10
  stylus = require('stylus');
11
11
  jsYaml = require('js-yaml');
12
12
  marked = require('marked');
13
+ crypto = require('crypto');
13
14
  colors = require('@plotdb/colors');
14
15
  base = require('./base');
15
16
  aux = require('../aux');
@@ -20,6 +21,7 @@ pugbuild = function(opt){
20
21
  this.intlbase = opt.intlbase || 'intl';
21
22
  this.filters = opt.filters || {};
22
23
  this.extapi = this.getExtapi();
24
+ this.bundler = opt.bundler;
23
25
  this.init(import$({
24
26
  srcdir: 'src/pug',
25
27
  desdir: 'static'
@@ -138,6 +140,24 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
138
140
  }
139
141
  });
140
142
  return ret;
143
+ },
144
+ md5: function(str){
145
+ return crypto.createHash('md5').update(str).digest('hex');
146
+ },
147
+ hashfile: function(arg$){
148
+ var type, name, files;
149
+ type = arg$.type, name = arg$.name, files = arg$.files;
150
+ if (!this$.bundler) {
151
+ return;
152
+ }
153
+ files = files.map(function(file){
154
+ return path.relative(this$.base, path.join(this$.desdir, file));
155
+ });
156
+ return this$.bundler.build(files, {
157
+ type: type,
158
+ name: name,
159
+ odb: true
160
+ });
141
161
  }
142
162
  };
143
163
  if (this.i18n) {
package/dist/lib.pug CHANGED
@@ -14,6 +14,7 @@
14
14
 
15
15
  mixin script(os,cfg)
16
16
  -
17
+ var str = '', urls = [];
17
18
  if(!Array.isArray(os)) { os = [os]; }
18
19
  each o in os
19
20
  -
@@ -26,11 +27,22 @@ mixin script(os,cfg)
26
27
  - defer = (typeof(c.defer) == "undefined" ? true : !!c.defer);
27
28
  if /^https?:\/\/./.exec(url)
28
29
  script(type="text/javascript",src=url, defer=defer, async=!!c.async)
30
+ else if cfg && cfg.pack
31
+ -
32
+ str = str + ';' + url;
33
+ urls.push(url);
29
34
  else
30
35
  script(type="text/javascript",src=url + libLoader._v, defer=defer, async=!!c.async)
36
+ if cfg && cfg.pack
37
+ -
38
+ var name = md5(str);
39
+ var filename = "/js/pack/" + name + ".js";
40
+ hashfile({type: "js", name: name, files: urls});
41
+ script(type="text/javascript",src=filename + libLoader._v)
31
42
 
32
43
  mixin css(os,cfg)
33
44
  -
45
+ var str = '', urls = [];
34
46
  if(!Array.isArray(os)) { os = [os]; }
35
47
  each o in os
36
48
  -
@@ -40,4 +52,17 @@ mixin css(os,cfg)
40
52
  else { url = libLoader._r + "/" + o.name + "/" + (o.version || 'main') + "/" + (o.path || "index.min.css"); }
41
53
  if !libLoader.css.url[url]
42
54
  - libLoader.css.url[url] = true;
43
- link(rel="stylesheet",type="text/css",href=url + libLoader._v)
55
+ if /^https?:\/\/./.exec(url)
56
+ link(rel="stylesheet",type="text/css",href=url)
57
+ else if cfg && cfg.pack
58
+ -
59
+ str = str + ';' + url;
60
+ urls.push(url);
61
+ else
62
+ link(rel="stylesheet",type="text/css",href=url + libLoader._v)
63
+ if cfg && cfg.pack
64
+ -
65
+ var name = md5(str);
66
+ var filename = "/css/pack/" + name + ".css";
67
+ hashfile({type: "css", name: name, files: urls});
68
+ link(rel="stylesheet",type="text/css",href=filename + libLoader._v)
package/dist/main.js CHANGED
@@ -12,25 +12,28 @@ module.exports = {
12
12
  base: base,
13
13
  i18n: i18n,
14
14
  lsp: function(opt){
15
- var base, i$, len$, b, adapters, ref$, watcher;
15
+ var base, adapters, i$, len$, b, bundler, ref$, watcher;
16
16
  opt == null && (opt = {});
17
17
  base = opt.base || 'web';
18
18
  base = Array.isArray(base)
19
19
  ? base
20
20
  : [base];
21
+ adapters = [];
21
22
  for (i$ = 0, len$ = base.length; i$ < len$; ++i$) {
22
23
  b = base[i$];
23
- adapters = [
24
+ bundler = new bundle(import$((ref$ = {
25
+ base: b
26
+ }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.bundle || {}));
27
+ adapters = adapters.concat([
24
28
  new lsc(import$((ref$ = {
25
29
  base: b
26
30
  }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.lsc || {})), new stylus(import$((ref$ = {
27
31
  base: b
28
32
  }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.stylus || {})), new pug(import$((ref$ = {
29
- base: b
30
- }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.pug || {})), new bundle(import$((ref$ = {
31
- base: b
32
- }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.bundle || {}))
33
- ].map(fn$);
33
+ base: b,
34
+ bundler: bundler
35
+ }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.pug || {}))
36
+ ].map(fn$));
34
37
  }
35
38
  return watcher = new watch((ref$ = {
36
39
  adapters: adapters
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "zbryikt",
3
3
  "name": "@plotdb/srcbuild",
4
- "version": "0.0.49",
4
+ "version": "0.0.51",
5
5
  "description": "",
6
6
  "main": "./dist/main.js",
7
7
  "files": [
@@ -27,10 +27,10 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@loadingio/debounce.js": "^1.0.1",
30
+ "@plotdb/colors": "^0.0.1",
30
31
  "anymatch": "^3.1.2",
31
32
  "browserify": "^17.0.0",
32
33
  "chokidar": "^3.5.1",
33
- "@plotdb/colors": "^0.0.1",
34
34
  "fs-extra": "^9.1.0",
35
35
  "glslify": "^7.1.1",
36
36
  "i18next": "^19.9.2",
@@ -47,7 +47,21 @@
47
47
  "yargs": "^17.2.1"
48
48
  },
49
49
  "devDependencies": {
50
- "ldview": "^0.0.2",
50
+ "fedep": "^1.1.7",
51
+ "ldcolor": "^1.0.0",
52
+ "ldcover": "^3.2.1",
53
+ "ldloader": "^3.0.1",
54
+ "ldview": "^1.3.0",
51
55
  "shaderlib": "github:zbryikt/shaderlib"
56
+ },
57
+ "frontendDependencies": {
58
+ "root": "web/static/assets/lib",
59
+ "modules": [
60
+ "@loadingio/debounce.js",
61
+ "ldcover",
62
+ "ldloader",
63
+ "ldcolor",
64
+ "ldview"
65
+ ]
52
66
  }
53
67
  }