@plotdb/srcbuild 0.0.41 → 0.0.44

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
@@ -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
 
@@ -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
+ }
@@ -29,9 +29,15 @@ bundlebuild = function(opt){
29
29
  };
30
30
  bundlebuild.prototype = import$(Object.create(base.prototype), {
31
31
  prepareConfig: function(){
32
- var type, name, ref$, list, i$, len$, f, this$ = this;
32
+ var e, type, name, ref$, list, i$, len$, f, this$ = this;
33
33
  if (this.configFile && fs.existsSync(this.configFile)) {
34
- this.config = JSON.parse(fs.readFileSync(this.configFile).toString());
34
+ try {
35
+ this.config = JSON.parse(fs.readFileSync(this.configFile).toString());
36
+ } catch (e$) {
37
+ e = e$;
38
+ (this.log ? this.log : console).error(("bundle failed: parse error of config file " + this.configFile).red);
39
+ this.config = {};
40
+ }
35
41
  }
36
42
  if (typeof this._relativePath === 'string') {
37
43
  for (type in this.config) {
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
- if (this$.i18n.language) {
151
- return path.join(this$.intlbase, this$.i18n.language, p);
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
- if (this$.i18n.language) {
159
- return path.join(this$.intlbase, this$.i18n.language, p);
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
- 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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "author": "zbryikt",
3
3
  "name": "@plotdb/srcbuild",
4
- "version": "0.0.41",
4
+ "version": "0.0.44",
5
5
  "description": "",
6
6
  "main": "./dist/main.js",
7
7
  "files": [