@plotdb/srcbuild 0.0.42 → 0.0.45
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 +21 -2
- package/dist/ext/asset.js +87 -0
- package/dist/ext/pug.js +23 -20
- package/dist/watch.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -86,11 +86,12 @@ Except common options, each builder may support different options:
|
|
|
86
86
|
- an additional function `i18n` will be available during pug compilation.
|
|
87
87
|
- `i18n(text)`: translate `text` based on the `i18n` object provided.
|
|
88
88
|
- `language()`: return current language. ( e.g., `zh-TW` )
|
|
89
|
-
- `intlbase(p)`: return a path to given `p`, based on current i18n setup.
|
|
89
|
+
- `intlbase(p, lng)`: return a path to given `p`, based on current i18n ( or specified `lng` arg ) setup.
|
|
90
|
+
- for example, `intlbase('link', 'kr')` may generate `/intl/kr/link`, based on he base dir config.
|
|
90
91
|
- additionally, a pug filter `i18n` is also available, which can be used like:
|
|
91
92
|
|
|
92
93
|
span:i18n translate this text
|
|
93
|
-
|
|
94
|
+
- `noView`: default false. when true, js view files ( generated to `viewdir` ) won't be built.
|
|
94
95
|
- `viewdir`: default `.view`. a directory for storing prebuilt pug files ( in .js format )
|
|
95
96
|
- `lsc`:
|
|
96
97
|
- `useGlslify`: default false. set to true if you need glslify of lsc files.
|
|
@@ -110,6 +111,8 @@ Except common options, each builder may support different options:
|
|
|
110
111
|
...
|
|
111
112
|
}
|
|
112
113
|
}
|
|
114
|
+
- `asset`: for copying asset files.
|
|
115
|
+
- `ext`: array of file extensions to copy. default `["png", "gif", "jpg", "svg", "json"]`
|
|
113
116
|
|
|
114
117
|
These options are constructor options for corresponding builder, e.g., for pug builder:
|
|
115
118
|
|
|
@@ -125,6 +128,22 @@ When using shorthands like `srcbuild.lsp(...)`, you can also specify correspondi
|
|
|
125
128
|
common options will be overwritten by scoped options.
|
|
126
129
|
|
|
127
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
|
+
|
|
128
147
|
## ODB / On demand build
|
|
129
148
|
|
|
130
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), {
|
|
@@ -145,21 +146,21 @@ pugbuild.prototype = import$(Object.create(base.prototype), {
|
|
|
145
146
|
ret.i18n.language = function(){
|
|
146
147
|
return this$.i18n.language;
|
|
147
148
|
};
|
|
148
|
-
ret.i18n.intlbase = function(p){
|
|
149
|
+
ret.i18n.intlbase = function(p, lng){
|
|
149
150
|
p == null && (p = "");
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
} else {
|
|
151
|
+
lng == null && (lng = "");
|
|
152
|
+
if (!(lng = lng || this$.i18n.language)) {
|
|
153
153
|
return p;
|
|
154
154
|
}
|
|
155
|
+
return path.join(this$.intlbase, lng, p);
|
|
155
156
|
};
|
|
156
|
-
ret.intlbase = function(p){
|
|
157
|
+
ret.intlbase = function(p, lng){
|
|
157
158
|
p == null && (p = "");
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
} else {
|
|
159
|
+
lng == null && (lng = "");
|
|
160
|
+
if (!(lng = lng || this$.i18n.language)) {
|
|
161
161
|
return p;
|
|
162
162
|
}
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
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,9 @@ watch = function(opt){
|
|
|
17
17
|
ignored: opt.ignored || ['.git'],
|
|
18
18
|
ignoreInitial: true
|
|
19
19
|
};
|
|
20
|
+
this._root = opt.root ? Array.isArray(opt.root)
|
|
21
|
+
? opt.root
|
|
22
|
+
: [opt.root] : void 8;
|
|
20
23
|
this.log = opt.logger || aux.logger;
|
|
21
24
|
this.init();
|
|
22
25
|
return this;
|
|
@@ -31,7 +34,7 @@ watch.prototype = import$(Object.create(Object.prototype), {
|
|
|
31
34
|
},
|
|
32
35
|
init: function(){
|
|
33
36
|
var this$ = this;
|
|
34
|
-
this.watcher = chokidar.watch(['.'], this.chokidarCfg).on('add', function(it){
|
|
37
|
+
this.watcher = chokidar.watch(this._root || ['.'], this.chokidarCfg).on('add', function(it){
|
|
35
38
|
return this$.add(path.normalize(it));
|
|
36
39
|
}).on('change', function(it){
|
|
37
40
|
return this$.change(path.normalize(it));
|