@plotdb/srcbuild 0.0.43 → 0.0.46

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
@@ -91,7 +91,7 @@ Except common options, each builder may support different options:
91
91
  - additionally, a pug filter `i18n` is also available, which can be used like:
92
92
 
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
96
  - `lsc`:
97
97
  - `useGlslify`: default false. set to true if you need glslify of lsc files.
@@ -111,6 +111,8 @@ Except common options, each builder may support different options:
111
111
  ...
112
112
  }
113
113
  }
114
+ - `asset`: for copying asset files.
115
+ - `ext`: array of file extensions to copy. default `["png", "gif", "jpg", "svg", "json"]`
114
116
 
115
117
  These options are constructor options for corresponding builder, e.g., for pug builder:
116
118
 
@@ -126,6 +128,22 @@ When using shorthands like `srcbuild.lsp(...)`, you can also specify correspondi
126
128
  common options will be overwritten by scoped options.
127
129
 
128
130
 
131
+ ## Using custom builders
132
+
133
+ Send adapters to watcher from `getAdapter()` of each custom builders:
134
+
135
+ require! <[@plotdb/srcbuild/dist/watch @plotdb/srcbuild/dist/ext/pug]>
136
+ pugbuilder = new pug(...)
137
+ watcher = new watch({adapters: [pugbuilder.getAdapter]})
138
+
139
+ By default, watcher watches the current working directory. Change watcher behavior with following constructor options:
140
+
141
+ - `adapters`: array of adapters to use to handle file change events.
142
+ - `ignored`: array of glob strings to ignore when watching for changes. by default `[".git"]`.
143
+ - `root`: directory, or array of directories to watch. by default `["."]`.
144
+ - `logger`: optional. logger object with logging functions such as `info`, `warn` and `error`.
145
+
146
+
129
147
  ## ODB / On demand build
130
148
 
131
149
  use `watch.demand(target-file)` to force rebuild by request. e.g.,
@@ -0,0 +1,87 @@
1
+ // Generated by LiveScript 1.6.0
2
+ var fs, path, fsExtra, colors, base, aux, adapter, assetbuild;
3
+ fs = require('fs');
4
+ path = require('path');
5
+ fsExtra = require('fs-extra');
6
+ colors = require('@plotdb/colors');
7
+ base = require('./base');
8
+ aux = require('../aux');
9
+ adapter = require('../adapter');
10
+ assetbuild = function(opt){
11
+ opt == null && (opt = {});
12
+ this._ext = opt.ext || ['png', 'gif', 'jpg', 'svg', 'json'];
13
+ this.init(import$({
14
+ srcdir: 'src/assets',
15
+ desdir: 'static/assets'
16
+ }, opt));
17
+ this._re = new RegExp("^" + this.desdir + "/(.+?.(?:" + this._ext.join('|') + "))$");
18
+ return this;
19
+ };
20
+ assetbuild.prototype = import$(Object.create(base.prototype), {
21
+ getDependencies: function(file){
22
+ return [];
23
+ },
24
+ isSupported: function(file){
25
+ var ref$;
26
+ return in$((ref$ = file.split('.'))[ref$.length - 1] || '', this._ext) && file.startsWith(this.srcdir);
27
+ },
28
+ resolve: function(file){
29
+ var ret;
30
+ if (!(ret = this._re.exec(file))) {
31
+ return null;
32
+ }
33
+ return path.join(this.srcdir, ret[1] + "");
34
+ },
35
+ map: function(file){
36
+ return {
37
+ src: file,
38
+ des: file.replace(this.srcdir, this.desdir)
39
+ };
40
+ },
41
+ build: function(files){
42
+ var i$, len$, ref$, file, mtime, src, des, t1, desdir, t2, e, results$ = [];
43
+ for (i$ = 0, len$ = files.length; i$ < len$; ++i$) {
44
+ ref$ = files[i$], file = ref$.file, mtime = ref$.mtime;
45
+ try {
46
+ ref$ = this.map(file), src = ref$.src, des = ref$.des;
47
+ if (!fs.existsSync(src) || aux.newer(des, mtime)) {
48
+ continue;
49
+ }
50
+ t1 = Date.now();
51
+ desdir = path.dirname(des);
52
+ fsExtra.ensureDirSync(desdir);
53
+ fsExtra.copySync(src, des);
54
+ t2 = Date.now();
55
+ results$.push(this.log.info(src + " --> " + des + " ( " + (t2 - t1) + "ms )"));
56
+ } catch (e$) {
57
+ e = e$;
58
+ this.log.error((src + " failed: ").red);
59
+ results$.push(this.log.error(e.message.toString()));
60
+ }
61
+ }
62
+ return results$;
63
+ },
64
+ purge: function(files){
65
+ var i$, len$, ref$, file, mtime, src, des;
66
+ for (i$ = 0, len$ = files.length; i$ < len$; ++i$) {
67
+ ref$ = files[i$], file = ref$.file, mtime = ref$.mtime;
68
+ ref$ = this.map(file), src = ref$.src, des = ref$.des;
69
+ if (!fs.existsSync(des)) {
70
+ return;
71
+ }
72
+ fs.unlinkSync(des);
73
+ this.log.warn((src + " --> " + des + " deleted.").yellow);
74
+ }
75
+ }
76
+ });
77
+ module.exports = assetbuild;
78
+ function import$(obj, src){
79
+ var own = {}.hasOwnProperty;
80
+ for (var key in src) if (own.call(src, key)) obj[key] = src[key];
81
+ return obj;
82
+ }
83
+ function in$(x, xs){
84
+ var i = -1, l = xs.length >>> 0;
85
+ while (++i < l) if (x === xs[i]) return true;
86
+ return false;
87
+ }
package/dist/ext/pug.js CHANGED
@@ -24,6 +24,7 @@ pugbuild = function(opt){
24
24
  desdir: 'static'
25
25
  }, opt));
26
26
  this.viewdir = path.normalize(path.join(this.base, opt.viewdir || '.view'));
27
+ this._noView = opt.noView || false;
27
28
  return this;
28
29
  };
29
30
  pugbuild.prototype = import$(Object.create(base.prototype), {
@@ -151,7 +152,7 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
151
152
  if (!(lng = lng || this$.i18n.language)) {
152
153
  return p;
153
154
  }
154
- return path.join(this$.intlbase, lng, p);
155
+ return path.join('/', this$.intlbase, lng, p);
155
156
  };
156
157
  ret.intlbase = function(p, lng){
157
158
  p == null && (p = "");
@@ -159,7 +160,7 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
159
160
  if (!(lng = lng || this$.i18n.language)) {
160
161
  return p;
161
162
  }
162
- return path.join(this$.intlbase, lng, p);
163
+ return path.join('/', this$.intlbase, lng, p);
163
164
  };
164
165
  (ret.filters || (ret.filters = {})).i18n = function(t, o){
165
166
  return this$.i18n.t((t || '').trim());
@@ -220,7 +221,7 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
220
221
  for (i$ = 0, len$ = (ref$ = files).length; i$ < len$; ++i$) {
221
222
  ref1$ = ref$[i$], file = ref1$.file, mtime = ref1$.mtime;
222
223
  ref1$ = this$.map(file, intl), src = ref1$.src, desh = ref1$.desh, desv = ref1$.desv;
223
- if (!fs.existsSync(src) || aux.newer(desv, mtime)) {
224
+ if (!fs.existsSync(src) || aux.newer(this$._noView ? desh : desv, mtime)) {
224
225
  continue;
225
226
  }
226
227
  code = fs.readFileSync(src).toString();
@@ -229,17 +230,19 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
229
230
  if (/^\/\/- ?module ?/.exec(code)) {
230
231
  continue;
231
232
  }
232
- desvdir = path.dirname(desv);
233
- fsExtra.ensureDirSync(desvdir);
234
- ret = pug.compileClient(code, import$({
235
- filename: src,
236
- basedir: path.resolve(this$.srcdir),
237
- doctype: 'html'
238
- }, this$.extapi));
239
- ret = " (function() { " + ret + "; module.exports = template; })() ";
240
- fs.writeFileSync(desv, ret);
241
- t2 = Date.now();
242
- this$.log.info(src + " --> " + desv + " ( " + (t2 - t1) + "ms )");
233
+ if (!this$._noView) {
234
+ desvdir = path.dirname(desv);
235
+ fsExtra.ensureDirSync(desvdir);
236
+ ret = pug.compileClient(code, import$({
237
+ filename: src,
238
+ basedir: path.resolve(this$.srcdir),
239
+ doctype: 'html'
240
+ }, this$.extapi));
241
+ ret = " (function() { " + ret + "; module.exports = template; })() ";
242
+ fs.writeFileSync(desv, ret);
243
+ t2 = Date.now();
244
+ this$.log.info(src + " --> " + desv + " ( " + (t2 - t1) + "ms )");
245
+ }
243
246
  if (!/^\/\/- ?view ?/.exec(code)) {
244
247
  desdir = path.dirname(desh);
245
248
  fsExtra.ensureDirSync(desdir);
package/dist/watch.js CHANGED
@@ -17,6 +17,11 @@ watch = function(opt){
17
17
  ignored: opt.ignored || ['.git'],
18
18
  ignoreInitial: true
19
19
  };
20
+ this._root = opt.root
21
+ ? Array.isArray(opt.root)
22
+ ? opt.root
23
+ : [opt.root]
24
+ : ['.'];
20
25
  this.log = opt.logger || aux.logger;
21
26
  this.init();
22
27
  return this;
@@ -31,14 +36,14 @@ watch.prototype = import$(Object.create(Object.prototype), {
31
36
  },
32
37
  init: function(){
33
38
  var this$ = this;
34
- this.watcher = chokidar.watch(['.'], this.chokidarCfg).on('add', function(it){
39
+ this.watcher = chokidar.watch(this._root, this.chokidarCfg).on('add', function(it){
35
40
  return this$.add(path.normalize(it));
36
41
  }).on('change', function(it){
37
42
  return this$.change(path.normalize(it));
38
43
  }).on('unlink', function(it){
39
44
  return this$.unlink(path.normalize(it));
40
45
  });
41
- this.log.info("watching src for file change".cyan);
46
+ this.log.info(("watching " + this._root.join(' ') + " for file change").cyan);
42
47
  this.changeDebounced = debounce(function(){
43
48
  var files;
44
49
  files = Array.from(this$.buf.change);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "zbryikt",
3
3
  "name": "@plotdb/srcbuild",
4
- "version": "0.0.43",
4
+ "version": "0.0.46",
5
5
  "description": "",
6
6
  "main": "./dist/main.js",
7
7
  "files": [