@plotdb/srcbuild 0.0.70 → 0.1.0

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/dist/adapter.js CHANGED
@@ -17,6 +17,7 @@ adapter = function(opt){
17
17
  on: {},
18
18
  by: {}
19
19
  };
20
+ this.failed = new Set();
20
21
  if (that = opt.getDependencies) {
21
22
  this.getDependencies = that;
22
23
  }
@@ -52,10 +53,7 @@ adapter.prototype = import$(Object.create(Object.prototype), {
52
53
  list = (this.getDependencies(file) || []).map(path.normalize);
53
54
  } catch (e$) {
54
55
  e = e$;
55
- this.log.error(("analyse " + file + " failed: ").red);
56
- this.log.error(e.message.toString());
57
- throw ref$ = new Error(), ref$.name = 'lderror', ref$.id = 999, ref$;
58
- return;
56
+ throw ref$ = new Error(e.message), ref$.name = 'lderror', ref$.id = 999, ref$.cause = e, ref$;
59
57
  }
60
58
  Array.from(this.depends.by[file] || []).map(function(f){
61
59
  if (this$.depends.on[f]) {
@@ -82,19 +80,52 @@ adapter.prototype = import$(Object.create(Object.prototype), {
82
80
  mtime: 0
83
81
  };
84
82
  });
83
+ ret.map(function(it){
84
+ return this$.failed['delete'](it.file);
85
+ });
85
86
  return this.purge(ret);
86
87
  },
88
+ depMtime: function(file, memo){
89
+ var recurse, this$ = this;
90
+ memo == null && (memo = {});
91
+ recurse = function(f){
92
+ var that, stat, e;
93
+ if ((that = memo[f]) != null) {
94
+ return that;
95
+ }
96
+ memo[f] = 0;
97
+ if (!fs.existsSync(f)) {
98
+ return memo[f] = 0;
99
+ }
100
+ try {
101
+ stat = fs.statSync(f);
102
+ } catch (e$) {
103
+ e = e$;
104
+ return memo[f] = 0;
105
+ }
106
+ return memo[f] = Math.max.apply(Math, [+stat.mtime].concat(Array.from(this$.depends.by[f] || []).map(function(n){
107
+ return recurse(n);
108
+ })));
109
+ };
110
+ return recurse(file);
111
+ },
87
112
  change: function(files, opt){
88
- var affectedFiles, mtimes, queue, ret, now, file, e, mtime, this$ = this;
113
+ var affectedFiles, queued, queue, push, now, file, analysed, e, memo, ret, this$ = this;
89
114
  opt == null && (opt = {});
90
115
  affectedFiles = new Set();
91
- mtimes = {};
92
- queue = (Array.isArray(files)
116
+ queued = new Set();
117
+ queue = [];
118
+ push = function(f){
119
+ if (!queued.has(f)) {
120
+ queued.add(f);
121
+ return queue.push(f);
122
+ }
123
+ };
124
+ files = Array.isArray(files)
93
125
  ? files
94
- : [files]).map(function(it){
95
- return it;
96
- });
97
- ret = [];
126
+ : [files];
127
+ files.map(push);
128
+ Array.from(this.failed).map(push);
98
129
  now = Date.now();
99
130
  while (queue.length) {
100
131
  file = queue.pop();
@@ -102,68 +133,52 @@ adapter.prototype = import$(Object.create(Object.prototype), {
102
133
  continue;
103
134
  }
104
135
  if (this.isSupported(file)) {
136
+ analysed = true;
105
137
  try {
106
138
  this.logDependencies(file);
107
139
  } catch (e$) {
108
140
  e = e$;
109
- if (e.name === 'lderror' && e.id === 999) {
110
- continue;
141
+ if (!(e.name === 'lderror' && e.id === 999)) {
142
+ throw e;
111
143
  }
144
+ analysed = false;
145
+ }
146
+ if (analysed) {
147
+ if (this.failed.has(file)) {
148
+ this.failed['delete'](file);
149
+ this.log.info((file + " analysed successfully. dependency recovered.").green);
150
+ }
151
+ } else if (!this.failed.has(file)) {
152
+ this.failed.add(file);
153
+ this.log.error(("analyse " + file + " failed. will retry on next change.").red);
112
154
  }
113
155
  }
114
156
  affectedFiles.add(file);
115
- mtime = opt.force
116
- ? now
117
- : fs.existsSync(file) ? fs.statSync(file).mtime : now;
118
- if (!mtimes[file] || mtimes[file] < mtime) {
119
- mtimes[file] = mtime;
120
- }
121
157
  if (opt.nonRecursive) {
122
158
  continue;
123
159
  }
124
- Array.from(this.depends.on[file] || []).map(fn$);
160
+ Array.from(this.depends.on[file] || []).map(push);
125
161
  }
162
+ memo = {};
126
163
  ret = Array.from(affectedFiles).filter(function(it){
127
164
  return this$.isSupported(it);
128
165
  }).map(function(it){
129
166
  return {
130
167
  file: it,
131
- mtime: mtimes[it]
168
+ mtime: opt.force
169
+ ? now
170
+ : this$.depMtime(it, memo)
132
171
  };
133
172
  });
134
173
  return Promise.resolve(ret.length ? this.build(ret) : null);
135
- function fn$(f){
136
- if (!mtimes[f] || mtimes[f] < mtimes[file]) {
137
- mtimes[f] = mtimes[file];
138
- }
139
- return queue.push(f);
140
- }
141
174
  },
142
175
  dirtyCheck: function(files){
143
- var mtimes, recurse, this$ = this;
144
- mtimes = {};
145
- recurse = function(file){
146
- var that, stat, e;
147
- if (that = mtimes[file]) {
148
- return that;
149
- }
150
- if (!fs.existsSync(file)) {
151
- return 0;
152
- }
153
- try {
154
- stat = fs.statSync(file);
155
- } catch (e$) {
156
- e = e$;
157
- return 0;
158
- }
159
- return mtimes[file] = Math.max.apply(Math, [+stat.mtime].concat(Array.from(this$.depends.by[file] || []).map(function(f){
160
- return recurse(f);
161
- })));
162
- };
176
+ var memo, this$ = this;
177
+ memo = {};
163
178
  return this.build(files.map(function(file){
164
179
  return {
165
180
  file: file,
166
- mtime: recurse(file)
181
+ mtime: this$.depMtime(file, memo)
167
182
  };
168
183
  }));
169
184
  },
@@ -205,9 +220,11 @@ adapter.prototype = import$(Object.create(Object.prototype), {
205
220
  this$.logDependencies(file);
206
221
  } catch (e$) {
207
222
  e = e$;
208
- if (e.name === 'lderror' && e.id === 999) {
209
- continue;
223
+ if (!(e.name === 'lderror' && e.id === 999)) {
224
+ throw e;
210
225
  }
226
+ this$.failed.add(file);
227
+ this$.log.error(("analyse " + file + " failed. will retry on next change.").red);
211
228
  }
212
229
  results$.push(initBuilds.push(file));
213
230
  }
@@ -1,11 +1,13 @@
1
1
  // Generated by LiveScript 1.6.0
2
- var path, uglifyJs, uglifycss, debounce, base, aux, fs, spec, specmgr, build;
2
+ var path, crypto, uglifyJs, uglifycss, debounce, base, aux, hashstore, fs, spec, specmgr, build;
3
3
  path = require('path');
4
+ crypto = require('crypto');
4
5
  uglifyJs = require('uglify-js');
5
6
  uglifycss = require('uglifycss');
6
7
  debounce = require('@loadingio/debounce.js');
7
8
  base = require('./base');
8
9
  aux = require('../aux');
10
+ hashstore = require('../hashstore');
9
11
  fs = require("fs-extra");
10
12
  spec = function(o){
11
13
  var ref$;
@@ -55,9 +57,13 @@ spec.prototype = import$(Object.create(Object.prototype), {
55
57
  }
56
58
  });
57
59
  specmgr = function(o){
60
+ var this$ = this;
58
61
  o == null && (o = {});
59
62
  this.log = o.log;
60
63
  this.cachedir = o.cachedir;
64
+ this.clearDirty = debounce(1000, function(){
65
+ return this$.flushDirty();
66
+ });
61
67
  this.evthdr = {};
62
68
  this._ = {};
63
69
  this.codesrc = {};
@@ -105,19 +111,21 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
105
111
  this._dirty.add(this.key(o));
106
112
  return this.clearDirty();
107
113
  },
108
- clearDirty: debounce(1000, function(){
114
+ flushDirty: function(){
109
115
  var specs, this$ = this;
110
116
  specs = Array.from(this._dirty).map(function(k){
111
117
  return this$.get(k);
112
118
  }).filter(function(it){
113
119
  return it;
114
120
  });
115
- this.fire('build-by-spec', specs);
121
+ this.fire('build-by-spec', specs, {
122
+ force: true
123
+ });
116
124
  specs.map(function(s){
117
125
  return s.syncCache();
118
126
  });
119
127
  return this._dirty.clear();
120
- }),
128
+ },
121
129
  add: function(o, opt){
122
130
  var k, that, s, this$ = this;
123
131
  o == null && (o = {});
@@ -163,8 +171,9 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
163
171
  hasCode: function(f){
164
172
  return !!this.codesrc[f] || !!this.deps[f];
165
173
  },
166
- touchCode: function(files){
174
+ touchCode: function(files, opt){
167
175
  var keys, this$ = this;
176
+ opt == null && (opt = {});
168
177
  files = Array.isArray(files)
169
178
  ? files
170
179
  : [files];
@@ -186,10 +195,12 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
186
195
  });
187
196
  return this.fire('build-by-spec', Array.from(keys).map(function(k){
188
197
  return this$.get(k);
189
- }));
198
+ }).filter(function(it){
199
+ return it;
200
+ }), opt);
190
201
  },
191
202
  update: function(o){
192
- var k, dirty, s, this$ = this;
203
+ var k, dirty, s, i$, ref$, len$, f, next, this$ = this;
193
204
  o == null && (o = {});
194
205
  k = this.key(o);
195
206
  dirty = false;
@@ -208,6 +219,11 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
208
219
  : [o.src]).filter(function(it){
209
220
  return it;
210
221
  });
222
+ for (i$ = 0, len$ = (ref$ = ['codesrc', 'deps']).length; i$ < len$; ++i$) {
223
+ f = ref$[i$];
224
+ next = new Set(o[f] || []);
225
+ s[f].forEach(fn$);
226
+ }
211
227
  s.codesrc = new Set(o.codesrc || []);
212
228
  s.deps = new Set(o.deps || []);
213
229
  (Array.isArray(o.specsrc)
@@ -240,15 +256,54 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
240
256
  this.setDirty(s);
241
257
  }
242
258
  return dirty;
259
+ function fn$(n){
260
+ var u;
261
+ if (next.has(n)) {
262
+ return;
263
+ }
264
+ u = {
265
+ spec: s
266
+ };
267
+ u[f] = n;
268
+ return this$.unlink(u);
269
+ }
270
+ },
271
+ setDeps: function(spec, list){
272
+ var next, this$ = this;
273
+ next = new Set(list || []);
274
+ if (Array.from(spec.deps).sort().join(',') === Array.from(next).sort().join(',')) {
275
+ return false;
276
+ }
277
+ spec.deps.forEach(function(n){
278
+ if (!next.has(n)) {
279
+ return this$.unlink({
280
+ deps: n,
281
+ spec: spec
282
+ });
283
+ }
284
+ });
285
+ spec.deps = next;
286
+ next.forEach(function(n){
287
+ return this$.link({
288
+ deps: n,
289
+ spec: spec
290
+ });
291
+ });
292
+ spec.syncCache();
293
+ this.log.info("bundle " + this.key(spec) + " dependencies updated ( " + next.size + " )");
294
+ return true;
243
295
  },
244
296
  get: function(o){
245
297
  o == null && (o = {});
246
298
  return this._[this.key(o)];
247
299
  },
248
300
  'delete': function(o){
249
- var s, this$ = this;
301
+ var k, s, fn, this$ = this;
250
302
  o == null && (o = {});
251
- s = this._[this.key(o)];
303
+ k = this.key(o);
304
+ if (!(s = this._[k])) {
305
+ return;
306
+ }
252
307
  s.codesrc.forEach(function(n){
253
308
  return this$.unlink({
254
309
  codesrc: n,
@@ -267,7 +322,14 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
267
322
  spec: s
268
323
  });
269
324
  });
270
- return this.setDirty(o);
325
+ delete this._[k];
326
+ this._dirty['delete'](k);
327
+ fn = this.getCacheName(s);
328
+ if (fs.existsSync(fn)) {
329
+ fs.unlinkSync(fn);
330
+ }
331
+ this.log.info("bundle spec " + k + " removed. " + fn + " deleted.");
332
+ return this.fire('delete', s);
271
333
  },
272
334
  link: function(o){
273
335
  var f, s, that;
@@ -292,7 +354,7 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
292
354
  if (!(s = this[f][o[f]])) {
293
355
  return;
294
356
  }
295
- s.remove(this.key(o.spec));
357
+ s['delete'](this.key(o.spec));
296
358
  if (s.size) {
297
359
  return;
298
360
  }
@@ -303,14 +365,19 @@ specmgr.prototype = import$(Object.create(Object.prototype), {
303
365
  if (!(s = this.specsrc[n])) {
304
366
  return;
305
367
  }
306
- s.forEach(function(k){
368
+ Array.from(s).forEach(function(k){
307
369
  var spec;
308
370
  if (!(spec = this$.get(k))) {
309
371
  return;
310
372
  }
311
- spec.unlink({
312
- specsrc: n
373
+ spec.specsrc['delete'](n);
374
+ this$.unlink({
375
+ specsrc: n,
376
+ spec: spec
313
377
  });
378
+ if (!spec.specsrc.size) {
379
+ return this$['delete'](k);
380
+ }
314
381
  return this$.setDirty(k);
315
382
  });
316
383
  return ref1$ = (ref$ = this.specsrc)[n], delete ref$[n], ref1$;
@@ -331,6 +398,7 @@ build = function(o){
331
398
  : o.manager;
332
399
  this.defcfg = o.config || null;
333
400
  this.cachedir = path.join(o.base || '.', '.bundle-dep');
401
+ this.store = o.store || null;
334
402
  this.cfgfn = o.configFile ? path.join(o.base || '.', o.configFile) : null;
335
403
  this.reldir = typeof o.relativePath === 'string'
336
404
  ? o.relativePath
@@ -343,6 +411,18 @@ build = function(o){
343
411
  return this;
344
412
  };
345
413
  build.prototype = import$(Object.create(base.prototype), {
414
+ manifestUrl: function(arg$){
415
+ var type, name, min, ref$, des, desMin;
416
+ type = arg$.type, name = arg$.name, min = (ref$ = arg$.min) != null ? ref$ : true;
417
+ if (!this.store) {
418
+ return null;
419
+ }
420
+ ref$ = this.desPath({
421
+ name: name,
422
+ type: type
423
+ }), des = ref$.des, desMin = ref$.desMin;
424
+ return this.store.get(this.store.urlOf(min ? desMin : des));
425
+ },
346
426
  getPath: function(f){
347
427
  var version, p;
348
428
  if (typeof f === 'string') {
@@ -372,11 +452,15 @@ build.prototype = import$(Object.create(base.prototype), {
372
452
  cachedir: this.cachedir,
373
453
  log: this.log
374
454
  });
375
- return this.specmgr.on('build-by-spec', function(specs){
455
+ this.specmgr.on('build-by-spec', function(specs, opt){
456
+ opt == null && (opt = {});
376
457
  return specs.forEach(function(spec){
377
- return this$.buildBySpec(spec);
458
+ return this$.buildBySpec(spec, opt);
378
459
  });
379
460
  });
461
+ return this.specmgr.on('delete', function(spec){
462
+ return this$.purgeOutputs(spec);
463
+ });
380
464
  },
381
465
  loadCfg: function(opt){
382
466
  var cfgs, cfg, e, i$, len$, ref$, fn, lresult$, type, lresult1$, name, list, codesrc, results$ = [], this$ = this;
@@ -464,7 +548,7 @@ build.prototype = import$(Object.create(base.prototype), {
464
548
  });
465
549
  },
466
550
  delSpecsrc: function(n){
467
- return specmgr.delSpecsrc(n);
551
+ return this.specmgr.delSpecsrc(n);
468
552
  },
469
553
  addSpec: function(opts){
470
554
  var this$ = this;
@@ -518,6 +602,24 @@ build.prototype = import$(Object.create(base.prototype), {
518
602
  }
519
603
  });
520
604
  },
605
+ purgeOutputs: function(arg$){
606
+ var name, type, ref$, des, desMin, this$ = this;
607
+ name = arg$.name, type = arg$.type;
608
+ ref$ = this.desPath({
609
+ name: name,
610
+ type: type
611
+ }), des = ref$.des, desMin = ref$.desMin;
612
+ return [des, desMin].map(function(f){
613
+ if (this$.store) {
614
+ this$.store.drop(f);
615
+ }
616
+ if (!fs.existsSync(f)) {
617
+ return;
618
+ }
619
+ this$.log.info("bundle " + f + " removed with its spec.");
620
+ return fs.removeSync(f);
621
+ });
622
+ },
521
623
  getDependencies: function(file){
522
624
  return [];
523
625
  },
@@ -525,20 +627,27 @@ build.prototype = import$(Object.create(base.prototype), {
525
627
  return this.specmgr.hasCode(file);
526
628
  },
527
629
  purge: function(files){
528
- return this.build(files);
630
+ return this.build(files, {
631
+ force: true
632
+ });
529
633
  },
530
634
  build: function(files, opt){
531
- var force, this$ = this;
532
- force = typeof opt === 'boolean' ? opt : false;
533
- if (opt == null) {
534
- opt = {};
635
+ var ref$, cfgs, rest, this$ = this;
636
+ opt = typeof opt === 'boolean'
637
+ ? {
638
+ force: opt
639
+ }
640
+ : opt || {};
641
+ ref$ = [[], []], cfgs = ref$[0], rest = ref$[1];
642
+ files.map(function(f){
643
+ return (f.file === this$.cfgfn ? cfgs : rest).push(f);
644
+ });
645
+ if (cfgs.length) {
646
+ this.loadCfg();
535
647
  }
536
- if (files.filter(function(it){
537
- return it.file === this$.cfgfn;
538
- }).length) {
539
- return this.loadCfg();
648
+ if (rest.length) {
649
+ return this.specmgr.touchCode(rest, opt);
540
650
  }
541
- return this.specmgr.touchCode(files);
542
651
  },
543
652
  desPath: function(arg$){
544
653
  var name, type;
@@ -549,20 +658,37 @@ build.prototype = import$(Object.create(base.prototype), {
549
658
  type: type
550
659
  });
551
660
  },
552
- buildBySpec: function(spec){
661
+ buildBySpec: function(spec, opt){
553
662
  var this$ = this;
663
+ opt == null && (opt = {});
554
664
  return Promise.resolve().then(function(){
555
- var name, type, t1, srcs, ref$, desdir, des, desMin, ext;
665
+ var name, type, t1, srcs, watched, ref$, desdir, des, desMin, ext;
666
+ if (!spec) {
667
+ return;
668
+ }
556
669
  name = spec.name, type = spec.type;
557
670
  t1 = Date.now();
558
671
  srcs = Array.from(spec.codesrc);
672
+ watched = srcs.concat(Array.from(spec.deps));
559
673
  ref$ = this$.desPath({
560
674
  name: name,
561
675
  type: type
562
676
  }), desdir = ref$.desdir, des = ref$.des, desMin = ref$.desMin;
563
677
  ext = type === 'block' ? 'html' : type;
678
+ if (!opt.force && aux.newer(des, watched) && aux.newer(desMin, watched)) {
679
+ if (this$.store) {
680
+ [des, desMin].map(function(it){
681
+ return this$.store.ensure(it);
682
+ });
683
+ }
684
+ return {
685
+ type: type,
686
+ name: name,
687
+ skipped: true
688
+ };
689
+ }
564
690
  return fs.ensureDir(desdir).then(function(){
565
- var ps;
691
+ var ref$, re, reMin, ps;
566
692
  if (type === 'block') {
567
693
  if (!this$.mgr || !this$.mgr.bundle) {
568
694
  throw new Error("block bundling requires manager of @plotdb/block provided via bundler option.");
@@ -570,15 +696,25 @@ build.prototype = import$(Object.create(base.prototype), {
570
696
  return this$.mgr.bundle({
571
697
  blocks: spec.src
572
698
  }).then(function(ret){
573
- var code;
699
+ var deps, code;
700
+ if (ret.deps) {
701
+ deps = ret.deps;
702
+ this$.specmgr.setDeps(spec, ((deps.js || []).concat(deps.css || [], deps.block || [])).map(function(f){
703
+ return this$.getPath(f);
704
+ }));
705
+ }
574
706
  code = ret.code || ret;
575
- return Promise.all([fs.writeFile(des, code), fs.writeFile(desMin, code)]);
707
+ return {
708
+ code: code,
709
+ codeMin: code
710
+ };
576
711
  });
577
712
  } else {
713
+ ref$ = [new RegExp("\\.min\\." + ext + "$"), new RegExp("\\." + ext + "$")], re = ref$[0], reMin = ref$[1];
578
714
  ps = srcs.map(function(f){
579
715
  var fMin;
580
- f = f.replace(".min." + ext, "." + ext);
581
- fMin = f.replace("." + ext, ".min." + ext);
716
+ f = f.replace(re, "." + ext);
717
+ fMin = f.replace(reMin, ".min." + ext);
582
718
  return fs.readFile(f)['catch'](function(){
583
719
  return "";
584
720
  }).then(function(b){
@@ -613,22 +749,34 @@ build.prototype = import$(Object.create(base.prototype), {
613
749
  })
614
750
  : o.code;
615
751
  }).join('');
616
- return Promise.all([fs.writeFile(des, normal), fs.writeFile(desMin, minified)]);
752
+ return {
753
+ code: normal,
754
+ codeMin: minified
755
+ };
617
756
  });
618
757
  }
619
- }).then(function(){
620
- var ret, size, sizeMin, elapsed;
621
- ret = {
758
+ }).then(function(arg$){
759
+ var code, codeMin;
760
+ code = arg$.code, codeMin = arg$.codeMin;
761
+ return Promise.all([fs.writeFile(des, code), fs.writeFile(desMin, codeMin)]).then(function(){
762
+ if (!this$.store) {
763
+ return {};
764
+ }
765
+ return {
766
+ code: this$.store.put(des, code),
767
+ min: this$.store.put(desMin, codeMin)
768
+ };
769
+ });
770
+ }).then(function(out){
771
+ var elapsed;
772
+ elapsed = Date.now() - t1;
773
+ this$.log.info("bundle " + des + " ( " + fs.statSync(des).size + " bytes / " + elapsed + "ms )");
774
+ this$.log.info("bundle " + desMin + " ( " + fs.statSync(desMin).size + " bytes / " + elapsed + "ms )");
775
+ return import$({
622
776
  type: type,
623
777
  name: name,
624
- elapsed: Date.now() - t1,
625
- size: fs.statSync(des).size,
626
- sizeMin: fs.statSync(desMin).size
627
- };
628
- size = ret.size, sizeMin = ret.sizeMin, elapsed = ret.elapsed;
629
- this$.log.info("bundle " + des + " ( " + size + " bytes / " + elapsed + "ms )");
630
- this$.log.info("bundle " + desMin + " ( " + sizeMin + " bytes / " + elapsed + "ms )");
631
- return ret;
778
+ elapsed: elapsed
779
+ }, out);
632
780
  })['catch'](function(e){
633
781
  this$.log.error((des + " failed: ").red);
634
782
  return this$.log.error({
package/dist/ext/lsc.js CHANGED
@@ -15,6 +15,7 @@ browserify = null;
15
15
  lscbuild = function(opt){
16
16
  opt == null && (opt = {});
17
17
  this.useGlslify = opt.useGlslify;
18
+ this.store = opt.store;
18
19
  if (this.useGlslify && !glslify) {
19
20
  glslify = require("glslify");
20
21
  browserify = require("browserify");
@@ -57,6 +58,11 @@ lscbuild.prototype = import$(Object.create(base.prototype), {
57
58
  return Promise.resolve().then(function(){
58
59
  var code, desdir;
59
60
  if (!fs.existsSync(src) || aux.newer(des, mtime)) {
61
+ if (this$.store) {
62
+ [des, desMin].map(function(it){
63
+ return this$.store.ensure(it);
64
+ });
65
+ }
60
66
  return Promise.resolve();
61
67
  }
62
68
  code = fs.readFileSync(src).toString();
@@ -94,6 +100,10 @@ lscbuild.prototype = import$(Object.create(base.prototype), {
94
100
  codeMin = uglifyJs.minify(code).code || '';
95
101
  fs.writeFileSync(des, code);
96
102
  fs.writeFileSync(desMin, codeMin);
103
+ if (this$.store) {
104
+ this$.store.put(des, code);
105
+ this$.store.put(desMin, codeMin);
106
+ }
97
107
  t2 = Date.now();
98
108
  return this$.log.info(src + " --> " + des + " / " + desMin + " ( " + (t2 - t1) + "ms )");
99
109
  })['catch'](function(e){
@@ -111,6 +121,9 @@ lscbuild.prototype = import$(Object.create(base.prototype), {
111
121
  }
112
122
  return results$;
113
123
  function fn$(f){
124
+ if (this$.store) {
125
+ this$.store.drop(f);
126
+ }
114
127
  if (!fs.existsSync(f)) {
115
128
  return;
116
129
  }
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, crypto, colors, base, aux, bundle, cwd, pugbuild;
2
+ var fs, path, fsExtra, pug, livescript, uglifyJs, uglifycss, stylus, jsYaml, marked, crypto, colors, base, aux, bundle, hashstore, cwd, pugbuild;
3
3
  fs = require('fs');
4
4
  path = require('path');
5
5
  fsExtra = require('fs-extra');
@@ -15,6 +15,7 @@ colors = require('@plotdb/colors');
15
15
  base = require('./base');
16
16
  aux = require('../aux');
17
17
  bundle = require('./bundle');
18
+ hashstore = require('../hashstore');
18
19
  cwd = process.cwd();
19
20
  pugbuild = function(opt){
20
21
  opt == null && (opt = {});
@@ -24,6 +25,8 @@ pugbuild = function(opt){
24
25
  this.locals = opt.locals || {};
25
26
  this.extapi = this.getExtapi();
26
27
  this.bundler = opt.bundler;
28
+ this.store = opt.store || null;
29
+ this.urlrefs = {};
27
30
  this.init(import$({
28
31
  srcdir: 'src/pug',
29
32
  desdir: 'static'
@@ -34,6 +37,85 @@ pugbuild = function(opt){
34
37
  return this;
35
38
  };
36
39
  pugbuild.prototype = import$(Object.create(base.prototype), {
40
+ refUrl: function(url, src){
41
+ var that;
42
+ if (!(url && src)) {
43
+ return;
44
+ }
45
+ return ((that = this.urlrefs[url])
46
+ ? that
47
+ : this.urlrefs[url] = new Set()).add(src);
48
+ },
49
+ invalidateUrl: function(url){
50
+ var s, files;
51
+ if (!(s = this.urlrefs[url]) || !s.size) {
52
+ return Promise.resolve();
53
+ }
54
+ files = Array.from(s).filter(function(it){
55
+ return fs.existsSync(it);
56
+ });
57
+ this.log.info(path.join(this.desdir, url) + " changed --> rebuilding " + files.length + " page(s)");
58
+ return this.adapter.change(files, {
59
+ force: true
60
+ });
61
+ },
62
+ getStore: function(){
63
+ if (typeof this.store === 'function') {
64
+ return this.store();
65
+ } else {
66
+ return this.store;
67
+ }
68
+ },
69
+ assetUrl: function(url){
70
+ var store;
71
+ if (store = this.getStore()) {
72
+ return store.get(url);
73
+ }
74
+ return this.loadManifest()[url] || null;
75
+ },
76
+ bundleUrl: function(arg$){
77
+ var type, name, min, ref$, des;
78
+ type = arg$.type, name = arg$.name, min = (ref$ = arg$.min) != null ? ref$ : true;
79
+ des = bundle.desPath({
80
+ desdir: this.desdir,
81
+ name: name,
82
+ type: type
83
+ });
84
+ return this.assetUrl(this.urlOf(min
85
+ ? des.desMin
86
+ : des.des));
87
+ },
88
+ urlOf: function(file){
89
+ return '/' + path.relative(this.desdir, path.normalize(file)).split(path.sep).join('/');
90
+ },
91
+ loadManifest: function(){
92
+ var fn, mtime, e, raw, res$, k, v;
93
+ fn = hashstore.manifestPath(this.base);
94
+ try {
95
+ mtime = +fs.statSync(fn).mtime;
96
+ } catch (e$) {
97
+ e = e$;
98
+ return this._manifest = {};
99
+ }
100
+ if (this._manifest && this._manifestMtime === mtime) {
101
+ return this._manifest;
102
+ }
103
+ try {
104
+ raw = JSON.parse(fs.readFileSync(fn).toString());
105
+ res$ = {};
106
+ for (k in raw) {
107
+ v = raw[k];
108
+ res$[k] = (v || {}).url;
109
+ }
110
+ this._manifest = res$;
111
+ this._manifestMtime = mtime;
112
+ } catch (e$) {
113
+ e = e$;
114
+ this.log.error(("parse error of hash manifest " + fn).red);
115
+ this._manifest = {};
116
+ }
117
+ return this._manifest;
118
+ },
37
119
  pugResolve: function(fn, src, opt){
38
120
  var e;
39
121
  try {
@@ -99,7 +181,7 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
99
181
  });
100
182
  ret = "";
101
183
  opts.forEach(function(o){
102
- var list, name, str, spec, des, relDesMin, relDes;
184
+ var list, name, str, spec, des, plain, url;
103
185
  list = o.files;
104
186
  list.forEach(function(d){
105
187
  if (!d.type) {
@@ -142,14 +224,18 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
142
224
  desdir: this$.desdir
143
225
  }, spec));
144
226
  }
145
- relDesMin = path.relative(this$.desdir, des.desMin);
146
- relDes = path.relative(this$.desdir, des.des);
227
+ plain = "/" + path.relative(this$.desdir, des.desMin);
228
+ this$.refUrl(plain, _opt.filename);
229
+ url = this$.bundleUrl({
230
+ type: o.type,
231
+ name: name
232
+ }) || plain;
147
233
  if (o.type === 'css') {
148
- return ret += "<link rel=\"stylesheet\" type=\"text/css\" href=\"/" + relDesMin + "\"/>";
234
+ return ret += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + url + "\"/>";
149
235
  } else if (o.type === 'js') {
150
- return ret += "<script type=\"text/javascript\" src=\"/" + relDesMin + "\"></script>";
236
+ return ret += "<script type=\"text/javascript\" src=\"" + url + "\"></script>";
151
237
  } else if (o.type === 'block') {
152
- return ret += "<link rel=\"block\" href=\"/" + relDesMin + "\">";
238
+ return ret += "<link rel=\"block\" href=\"" + url + "\">";
153
239
  }
154
240
  });
155
241
  return ret;
@@ -213,6 +299,30 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
213
299
  md5: function(str){
214
300
  return crypto.createHash('md5').update(str).digest('hex');
215
301
  },
302
+ bundleurl: function(arg$){
303
+ var type, name, min, ref$, src, d;
304
+ type = arg$.type, name = arg$.name, min = (ref$ = arg$.min) != null ? ref$ : true, src = arg$.src;
305
+ d = bundle.desPath({
306
+ desdir: this$.desdir,
307
+ name: name,
308
+ type: type
309
+ });
310
+ this$.refUrl(this$.urlOf(min
311
+ ? d.desMin
312
+ : d.des), src);
313
+ return this$.bundleUrl({
314
+ type: type,
315
+ name: name,
316
+ min: min
317
+ });
318
+ },
319
+ asseturl: function(url, src){
320
+ if (!url || /^(https?:)?\/\//.exec(url)) {
321
+ return url;
322
+ }
323
+ this$.refUrl(url, src);
324
+ return this$.assetUrl(url) || url;
325
+ },
216
326
  hashfile: function(arg$){
217
327
  var type, name, files, src, spec;
218
328
  type = arg$.type, name = arg$.name, files = arg$.files, src = arg$.src;
@@ -332,19 +442,29 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
332
442
  : ((ref$ = this$.i18n).options || (ref$.options = {})).fallbackLng)
333
443
  : Promise.resolve();
334
444
  return p.then(function(){
335
- var i$, ref$, len$, ref1$, file, mtime, src, desh, desv, code, t1, desvdir, opt, ret, t2, desdir, e, results$ = [];
445
+ var i$, ref$, len$, ref1$, file, mtime, src, desh, desv, code, outs, t1, desvdir, opt, ret, t2, desdir, e, results$ = [];
336
446
  for (i$ = 0, len$ = (ref$ = files).length; i$ < len$; ++i$) {
337
447
  ref1$ = ref$[i$], file = ref1$.file, mtime = ref1$.mtime;
338
448
  ref1$ = this$.map(file, intl), src = ref1$.src, desh = ref1$.desh, desv = ref1$.desv;
339
- if (!fs.existsSync(src) || aux.newer(this$._noView ? desh : desv, mtime)) {
449
+ if (!fs.existsSync(src)) {
340
450
  continue;
341
451
  }
342
452
  code = fs.readFileSync(src).toString();
453
+ if (/^\/\/- ?module ?/.exec(code)) {
454
+ continue;
455
+ }
456
+ outs = [];
457
+ if (!this$._noView) {
458
+ outs.push(desv);
459
+ }
460
+ if (!/^\/\/- ?view ?/.exec(code)) {
461
+ outs.push(desh);
462
+ }
463
+ if (outs.length && outs.filter(fn$).length === outs.length) {
464
+ continue;
465
+ }
343
466
  try {
344
467
  t1 = Date.now();
345
- if (/^\/\/- ?module ?/.exec(code)) {
346
- continue;
347
- }
348
468
  if (!this$._noView) {
349
469
  desvdir = path.dirname(desv);
350
470
  fsExtra.ensureDirSync(desvdir);
@@ -380,6 +500,9 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
380
500
  }
381
501
  }
382
502
  return results$;
503
+ function fn$(it){
504
+ return aux.newer(it, mtime);
505
+ }
383
506
  });
384
507
  };
385
508
  lngs = [''].concat(this.i18n && this._buildIntl
@@ -412,6 +535,9 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
412
535
  for (i$ = 0, len$ = (ref$ = files).length; i$ < len$; ++i$) {
413
536
  ref1$ = ref$[i$], file = ref1$.file, mtime = ref1$.mtime;
414
537
  ref1$ = this$.map(file, intl), src = ref1$.src, desh = ref1$.desh, desv = ref1$.desv;
538
+ if (this$.bundler) {
539
+ this$.bundler.delSpecsrc(src);
540
+ }
415
541
  results$.push([desh, desv].filter(fn$));
416
542
  }
417
543
  return results$;
@@ -11,6 +11,7 @@ aux = require('../aux');
11
11
  adapter = require('../adapter');
12
12
  stylusbuild = function(opt){
13
13
  opt == null && (opt = {});
14
+ this.store = opt.store;
14
15
  return this.init(import$({
15
16
  srcdir: 'src/styl',
16
17
  desdir: 'static/css'
@@ -59,6 +60,9 @@ stylusbuild.prototype = import$(Object.create(base.prototype), {
59
60
  ref$ = files[i$], file = ref$.file, mtime = ref$.mtime;
60
61
  ref$ = this.map(file), src = ref$.src, des = ref$.des, desMin = ref$.desMin;
61
62
  if (!fs.existsSync(src) || aux.newer(des, mtime)) {
63
+ if (this.store) {
64
+ [des, desMin].map(fn$);
65
+ }
62
66
  continue;
63
67
  }
64
68
  try {
@@ -69,7 +73,7 @@ stylusbuild.prototype = import$(Object.create(base.prototype), {
69
73
  }
70
74
  desdir = path.dirname(des);
71
75
  fsExtra.ensureDirSync(desdir);
72
- results$.push(stylus(code).set('filename', src).render(fn$));
76
+ results$.push(stylus(code).set('filename', src).render(fn1$));
73
77
  } catch (e$) {
74
78
  e = e$;
75
79
  this.log.error((src + " failed: ").red);
@@ -77,7 +81,10 @@ stylusbuild.prototype = import$(Object.create(base.prototype), {
77
81
  }
78
82
  }
79
83
  return results$;
80
- function fn$(e, css){
84
+ function fn$(it){
85
+ return this$.store.ensure(it);
86
+ }
87
+ function fn1$(e, css){
81
88
  var codeMin, t2;
82
89
  if (e) {
83
90
  throw e;
@@ -87,6 +94,10 @@ stylusbuild.prototype = import$(Object.create(base.prototype), {
87
94
  });
88
95
  fs.writeFileSync(des, css);
89
96
  fs.writeFileSync(desMin, codeMin);
97
+ if (this$.store) {
98
+ this$.store.put(des, css);
99
+ this$.store.put(desMin, codeMin);
100
+ }
90
101
  t2 = Date.now();
91
102
  return this$.log.info(src + " --> " + des + " / " + desMin + " ( " + (t2 - t1) + "ms )");
92
103
  }
@@ -100,6 +111,9 @@ stylusbuild.prototype = import$(Object.create(base.prototype), {
100
111
  }
101
112
  return results$;
102
113
  function fn$(f){
114
+ if (this$.store) {
115
+ this$.store.drop(f);
116
+ }
103
117
  if (!fs.existsSync(f)) {
104
118
  return;
105
119
  }
@@ -0,0 +1,228 @@
1
+ // Generated by LiveScript 1.6.0
2
+ var path, crypto, aux, fs, hashstore;
3
+ path = require('path');
4
+ crypto = require('crypto');
5
+ aux = require('./aux');
6
+ fs = require("fs-extra");
7
+ hashstore = function(o){
8
+ var that;
9
+ o == null && (o = {});
10
+ this.base = o.base || '.';
11
+ this.root = path.normalize(o.root || path.join(this.base, 'static'));
12
+ this.fn = o.manifest || hashstore.manifestPath(this.base);
13
+ this.mode = o.mode === 'query' ? 'query' : 'filename';
14
+ this.keep = (that = o.keep) != null ? that : 3;
15
+ this.keepDays = (that = o.keepDays) != null ? that : 0;
16
+ this.log = o.logger || aux.logger;
17
+ this.evthdr = {};
18
+ this.load();
19
+ return this;
20
+ };
21
+ hashstore.manifestPath = function(base){
22
+ base == null && (base = '.');
23
+ return path.join(base, '.bundle-dep', 'manifest.json');
24
+ };
25
+ hashstore.normalizeGen = function(g){
26
+ if (Array.isArray(g)) {
27
+ return {
28
+ files: g,
29
+ at: 0
30
+ };
31
+ } else {
32
+ return {
33
+ files: g.files || [],
34
+ at: g.at || 0
35
+ };
36
+ }
37
+ };
38
+ hashstore.hashedName = function(name, hash){
39
+ var parts, at;
40
+ parts = name.split('.');
41
+ if (parts.length < 2) {
42
+ return name + "." + hash;
43
+ }
44
+ at = parts.length > 2 && parts[parts.length - 2] === 'min'
45
+ ? parts.length - 2
46
+ : parts.length - 1;
47
+ parts.splice(at, 0, hash);
48
+ return parts.join('.');
49
+ };
50
+ hashstore.prototype = import$(Object.create(Object.prototype), {
51
+ on: function(n, cb){
52
+ var this$ = this;
53
+ return (Array.isArray(n)
54
+ ? n
55
+ : [n]).map(function(n){
56
+ var ref$;
57
+ return ((ref$ = this$.evthdr)[n] || (ref$[n] = [])).push(cb);
58
+ });
59
+ },
60
+ fire: function(n){
61
+ var v, res$, i$, to$, ref$, len$, cb, results$ = [];
62
+ res$ = [];
63
+ for (i$ = 1, to$ = arguments.length; i$ < to$; ++i$) {
64
+ res$.push(arguments[i$]);
65
+ }
66
+ v = res$;
67
+ for (i$ = 0, len$ = (ref$ = this.evthdr[n] || []).length; i$ < len$; ++i$) {
68
+ cb = ref$[i$];
69
+ results$.push(cb.apply(this, v));
70
+ }
71
+ return results$;
72
+ },
73
+ urlOf: function(file){
74
+ return '/' + path.relative(this.root, path.normalize(file)).split(path.sep).join('/');
75
+ },
76
+ load: function(){
77
+ var e;
78
+ this.manifest = {};
79
+ if (!fs.existsSync(this.fn)) {
80
+ return;
81
+ }
82
+ try {
83
+ return this.manifest = JSON.parse(fs.readFileSync(this.fn).toString()) || {};
84
+ } catch (e$) {
85
+ e = e$;
86
+ this.log.error(("parse error of hash manifest " + this.fn).red);
87
+ return this.manifest = {};
88
+ }
89
+ },
90
+ save: function(){
91
+ var e;
92
+ try {
93
+ return fs.outputFileSync(this.fn, JSON.stringify(this.manifest, null, 2));
94
+ } catch (e$) {
95
+ e = e$;
96
+ return this.log.error(("failed to write " + this.fn + ": " + e.message).red);
97
+ }
98
+ },
99
+ get: function(url){
100
+ return (this.manifest[url] || {}).url || null;
101
+ },
102
+ ensure: function(file){
103
+ if (this.get(this.urlOf(file))) {
104
+ return null;
105
+ }
106
+ if (!fs.existsSync(file)) {
107
+ return null;
108
+ }
109
+ return this.put(file, fs.readFileSync(file));
110
+ },
111
+ hashedFileOf: function(url){
112
+ var e;
113
+ if (this.mode === 'query') {
114
+ return null;
115
+ }
116
+ if (!(e = this.manifest[url]) || !e.generations || !e.generations[0]) {
117
+ return null;
118
+ }
119
+ return hashstore.normalizeGen(e.generations[0]).files[0] || null;
120
+ },
121
+ put: function(file, code){
122
+ var url, hash, hashed, entry, prev, changed, now, cur, olds, gens, cutoff, ref$, kept, rest, dropped, alive, e, this$ = this;
123
+ url = this.urlOf(file);
124
+ hash = crypto.createHash('md5').update(code).digest('hex').substring(0, 12);
125
+ if (this.mode === 'query') {
126
+ return this.putQuery(url, hash);
127
+ }
128
+ hashed = path.join(path.dirname(file), hashstore.hashedName(path.basename(file), hash));
129
+ entry = {
130
+ url: this.urlOf(hashed)
131
+ };
132
+ prev = this.manifest[url] || {};
133
+ changed = prev.url !== entry.url;
134
+ now = Date.now();
135
+ cur = {
136
+ files: [hashed],
137
+ at: now
138
+ };
139
+ olds = (prev.generations || []).map(hashstore.normalizeGen);
140
+ gens = changed
141
+ ? [cur].concat(olds)
142
+ : [cur].concat(olds.slice(1));
143
+ cutoff = now - this.keepDays * 86400000;
144
+ ref$ = [gens.slice(0, this.keep), gens.slice(this.keep)], kept = ref$[0], rest = ref$[1];
145
+ gens = kept.concat(rest.filter(function(g){
146
+ return g.at > cutoff;
147
+ }));
148
+ dropped = rest.filter(function(g){
149
+ return !(g.at > cutoff);
150
+ });
151
+ alive = new Set([].concat.apply([], gens.map(function(it){
152
+ return it.files;
153
+ })));
154
+ try {
155
+ fs.outputFileSync(hashed, code);
156
+ [].concat.apply([], dropped.map(function(it){
157
+ return it.files;
158
+ })).filter(function(f){
159
+ return !alive.has(f);
160
+ }).map(function(f){
161
+ this$.log.info(f + " expired, deleted.");
162
+ try {
163
+ return fs.removeSync(f);
164
+ } catch (e$) {}
165
+ });
166
+ this.manifest[url] = (entry.generations = gens, entry);
167
+ this.save();
168
+ } catch (e$) {
169
+ e = e$;
170
+ this.log.error(("failed to write " + hashed + ": " + e.message).red);
171
+ return null;
172
+ }
173
+ if (changed) {
174
+ this.log.info(file + " --> " + hashed);
175
+ this.fire('change', {
176
+ url: url,
177
+ hashed: entry.url,
178
+ prev: prev.url || null
179
+ });
180
+ }
181
+ return ref$ = import$({}, entry), ref$.url = url, ref$.hashed = entry.url, ref$.changed = changed, ref$;
182
+ },
183
+ putQuery: function(url, hash){
184
+ var entry, prev, changed, ref$;
185
+ entry = {
186
+ url: url + "?v=" + hash
187
+ };
188
+ prev = this.manifest[url] || {};
189
+ changed = prev.url !== entry.url;
190
+ this.manifest[url] = (entry.generations = [], entry);
191
+ this.save();
192
+ if (changed) {
193
+ this.log.info(url + " --> " + entry.url);
194
+ this.fire('change', {
195
+ url: url,
196
+ hashed: entry.url,
197
+ prev: prev.url || null
198
+ });
199
+ }
200
+ return ref$ = import$({}, entry), ref$.url = url, ref$.hashed = entry.url, ref$.changed = changed, ref$;
201
+ },
202
+ drop: function(file){
203
+ var url, e, this$ = this;
204
+ url = this.urlOf(file);
205
+ if (!(e = this.manifest[url])) {
206
+ return;
207
+ }
208
+ delete this.manifest[url];
209
+ this.save();
210
+ return [].concat.apply([], (e.generations || []).map(hashstore.normalizeGen).map(function(it){
211
+ return it.files;
212
+ })).map(function(f){
213
+ if (!fs.existsSync(f)) {
214
+ return;
215
+ }
216
+ this$.log.info(f + " removed with its source.");
217
+ try {
218
+ return fs.removeSync(f);
219
+ } catch (e$) {}
220
+ });
221
+ }
222
+ });
223
+ module.exports = hashstore;
224
+ function import$(obj, src){
225
+ var own = {}.hasOwnProperty;
226
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
227
+ return obj;
228
+ }
package/dist/lib.pug CHANGED
@@ -32,14 +32,19 @@ mixin script(os,cfg)
32
32
  str = str + ';' + url;
33
33
  urls.push(url);
34
34
  else
35
- script(type="text/javascript",src=url + libLoader._v, defer=defer, async=!!c.async)
35
+ - var hurl = (typeof(asseturl) == "function") ? asseturl(url, locals.filename) : url;
36
+ script(type="text/javascript",src=hurl + (hurl == url ? libLoader._v : ""), defer=defer, async=!!c.async)
36
37
  if cfg && cfg.pack
37
38
  -
38
39
  var name = md5(str);
39
- //var filename = "/js/pack/" + name + "." + (typeof(cfg.min) == "undefined" || cfg.min ? "min" : "") + ".js";
40
- var fn = "/assets/bundle/" + name + "." + (typeof(cfg.min) == "undefined" || cfg.min ? "min" : "") + ".js";
40
+ var min = (typeof(cfg.min) == "undefined" || cfg.min);
41
41
  hashfile({type: "js", name: name, files: urls, src: locals.filename});
42
- script(type="text/javascript",src=fn + libLoader._v)
42
+ // content-addressed url when the bundle has been built. it needs no `_v`: the
43
+ // filename already changes with the content. before the first build there is no
44
+ // entry yet, so fall back to the plain name ( which does need `_v` ).
45
+ var fn = (typeof(bundleurl) == "function") ? bundleurl({type: "js", name: name, min: min, src: locals.filename}) : null;
46
+ if(!fn) { fn = "/assets/bundle/" + name + (min ? ".min" : "") + ".js" + libLoader._v; }
47
+ script(type="text/javascript",src=fn)
43
48
 
44
49
  mixin css(os,cfg)
45
50
  -
@@ -60,11 +65,13 @@ mixin css(os,cfg)
60
65
  str = str + ';' + url;
61
66
  urls.push(url);
62
67
  else
63
- link(rel="stylesheet",type="text/css",href=url + libLoader._v)
68
+ - var hurl = (typeof(asseturl) == "function") ? asseturl(url, locals.filename) : url;
69
+ link(rel="stylesheet",type="text/css",href=hurl + (hurl == url ? libLoader._v : ""))
64
70
  if cfg && cfg.pack
65
71
  -
66
72
  var name = md5(str);
67
- //var filename = "/css/pack/" + name + "." + (typeof(cfg.min) == "undefined" || cfg.min ? "min" : "") + ".css";
68
- var fn = "/assets/bundle/" + name + "." + (typeof(cfg.min) == "undefined" || cfg.min ? "min" : "") + ".css";
73
+ var min = (typeof(cfg.min) == "undefined" || cfg.min);
69
74
  hashfile({type: "css", name: name, files: urls, src: locals.filename});
70
- link(rel="stylesheet",type="text/css",href=fn + libLoader._v)
75
+ var fn = (typeof(bundleurl) == "function") ? bundleurl({type: "css", name: name, min: min, src: locals.filename}) : null;
76
+ if(!fn) { fn = "/assets/bundle/" + name + (min ? ".min" : "") + ".css" + libLoader._v; }
77
+ link(rel="stylesheet",type="text/css",href=fn)
package/dist/main.js CHANGED
@@ -1,8 +1,9 @@
1
1
  // Generated by LiveScript 1.6.0
2
- var fs, i18n, watch, pug, stylus, lsc, bundle, asset, base;
2
+ var fs, i18n, watch, hashstore, pug, stylus, lsc, bundle, asset, base;
3
3
  fs = require('fs');
4
4
  i18n = require('./i18n');
5
5
  watch = require('./watch');
6
+ hashstore = require('./hashstore');
6
7
  pug = require('./ext/pug');
7
8
  stylus = require('./ext/stylus');
8
9
  lsc = require('./ext/lsc');
@@ -12,39 +13,60 @@ base = require('./ext/base');
12
13
  module.exports = {
13
14
  base: base,
14
15
  i18n: i18n,
16
+ hashstore: hashstore,
15
17
  lsp: function(opt){
16
- var base, adapters, i$, len$, b, bundler, ref$, watcher;
18
+ var base, adapters, stores, watcher, ref$;
17
19
  opt == null && (opt = {});
18
20
  base = opt.base || 'web';
19
21
  base = Array.isArray(base)
20
22
  ? base
21
23
  : [base];
22
24
  adapters = [];
23
- for (i$ = 0, len$ = base.length; i$ < len$; ++i$) {
24
- b = base[i$];
25
- bundler = new bundle(import$((ref$ = {
25
+ stores = [];
26
+ base.map(function(b){
27
+ var store, ref$, bundler, pugbuilder;
28
+ store = (opt.hash || {}).enabled ? new hashstore(import$((ref$ = {
26
29
  base: b
30
+ }, ref$.logger = opt.logger, ref$), opt.hash)) : null;
31
+ if (store) {
32
+ stores.push(store);
33
+ }
34
+ bundler = new bundle(import$((ref$ = {
35
+ base: b,
36
+ store: store
27
37
  }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.bundle || {}));
38
+ pugbuilder = new pug(import$((ref$ = {
39
+ base: b,
40
+ bundler: bundler,
41
+ store: store
42
+ }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.pug || {}));
43
+ if (store) {
44
+ store.on('change', function(arg$){
45
+ var url;
46
+ url = arg$.url;
47
+ return pugbuilder.invalidateUrl(url);
48
+ });
49
+ }
28
50
  adapters.push(bundler.getAdapter());
29
- adapters = adapters.concat([
51
+ return adapters = adapters.concat([
30
52
  new lsc(import$((ref$ = {
31
- base: b
53
+ base: b,
54
+ store: store
32
55
  }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.lsc || {})), new stylus(import$((ref$ = {
33
- base: b
34
- }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.stylus || {})), new pug(import$((ref$ = {
35
56
  base: b,
36
- bundler: bundler
37
- }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.pug || {})), new asset(import$((ref$ = {
57
+ store: store
58
+ }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.stylus || {})), pugbuilder, new asset(import$((ref$ = {
38
59
  base: b
39
60
  }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$), opt.asset || {}))
40
- ].map(fn$));
41
- }
42
- return watcher = new watch((ref$ = {
61
+ ].map(function(it){
62
+ return it.getAdapter();
63
+ }));
64
+ });
65
+ watcher = new watch((ref$ = {
43
66
  adapters: adapters
44
67
  }, ref$.logger = opt.logger, ref$.i18n = opt.i18n, ref$.ignored = opt.ignored, ref$));
45
- function fn$(it){
46
- return it.getAdapter();
47
- }
68
+ watcher.stores = stores;
69
+ return watcher;
48
70
  }
49
71
  };
50
72
  function import$(obj, src){
package/dist/view/pug.js CHANGED
@@ -16,7 +16,8 @@ pugViewEngine = function(options){
16
16
  srcdir: options.srcdir,
17
17
  desdir: options.desdir,
18
18
  base: options.base,
19
- filters: options.filters
19
+ filters: options.filters,
20
+ store: options.store
20
21
  };
21
22
  for (k in opt) {
22
23
  v = opt[k];
@@ -24,7 +25,9 @@ pugViewEngine = function(options){
24
25
  delete opt[k];
25
26
  }
26
27
  }
27
- builder = new pugbuild(opt);
28
+ builder = new pugbuild(import$({
29
+ initScan: false
30
+ }, opt));
28
31
  extapi = builder.getExtapi();
29
32
  logger = options.logger;
30
33
  pugcache = {};
@@ -39,7 +42,7 @@ pugViewEngine = function(options){
39
42
  if (opt.settings.env === 'development') {
40
43
  lc.dev = true;
41
44
  }
42
- lc.useCache = true || opt.settings['view cache'];
45
+ lc.useCache = !!opt.settings['view cache'];
43
46
  intl = opt.i18n ? path.join("intl", opt._locals.language) : '';
44
47
  ref$ = builder.map(src, ''), src = ref$.src, desv = ref$.desv, desh = ref$.desh;
45
48
  startTime = Date.now();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "zbryikt",
3
3
  "name": "@plotdb/srcbuild",
4
- "version": "0.0.70",
4
+ "version": "0.1.0",
5
5
  "description": "",
6
6
  "main": "./dist/main.js",
7
7
  "files": [
@@ -13,7 +13,8 @@
13
13
  },
14
14
  "scripts": {
15
15
  "prepare": "mkdir -p ./node_modules/@plotdb/srcbuild/dist; cp dist/lib.pug ./node_modules/@plotdb/srcbuild/dist/",
16
- "start": "./node_modules/.bin/lsc watch.ls"
16
+ "start": "./node_modules/.bin/lsc watch.ls",
17
+ "test": "node test/index.js"
17
18
  },
18
19
  "license": "MIT",
19
20
  "homepage": "https://github.com/plotdb/srcbuild",
@@ -35,7 +36,7 @@
35
36
  "fs-extra": "^9.1.0",
36
37
  "glslify": "^7.1.1",
37
38
  "i18next": "^19.9.2",
38
- "i18next-fs-backend": "^2.6.6",
39
+ "i18next-fs-backend": "^2.6.7",
39
40
  "i18next-http-middleware": "^3.1.0",
40
41
  "js-yaml": "^4.0.0",
41
42
  "livescript": "^1.6.0",
@@ -56,7 +57,7 @@
56
57
  "bootstrap": "^4.6.1",
57
58
  "express": "^4.18.2",
58
59
  "fedep": "^1.6.0",
59
- "jsdom": "^20.0.3",
60
+ "jsdom": "^26.1.0",
60
61
  "ldcolor": "^1.1.3",
61
62
  "ldcover": "^3.5.6",
62
63
  "ldloader": "^3.0.3",
@@ -81,5 +82,8 @@
81
82
  "ldcolor",
82
83
  "ldview"
83
84
  ]
85
+ },
86
+ "volta": {
87
+ "node": "20.20.2"
84
88
  }
85
89
  }