##// END OF EJS Templates
improved core/build.gradle script
cin -
r4:f88a0de08cfb default
parent child
Show More
@@ -0,0 +1,27
1 {
2 "env": {
3 "browser": true,
4 "commonjs": true,
5 "amd": true,
6 "node": true
7 },
8 "parserOptions": {
9 "ecmaFeatures": {
10 "jsx": true
11 },
12 "sourceType": "module"
13 },
14 "extends": "eslint:recommended",
15 "rules": {
16 "no-const-assign": "warn",
17 "no-this-before-super": "warn",
18 "no-undef": "error",
19 "no-unreachable": "warn",
20 "no-unused-vars": "warn",
21 "constructor-super": "warn",
22 "valid-typeof": "warn",
23 "semi" : "warn",
24 "no-invalid-this" : "error",
25 "no-console": "off"
26 }
27 } No newline at end of file
@@ -1,58 +1,63
1 1
2 2 println "version: $version"
3 3
4 String makePackageName(String group, String name, String ver) {
5 def sb = new StringBuilder();
6 if(group)
7 sb
8 .append('@')
9 .append(group)
10 .append('/');
11
12 sb.append(name);
4 def distDir = "$buildDir/dist"
5 def testDir = "$buildDir/test"
13 6
14 if (ver)
15 sb.append('@').append(ver);
16
17 return sb.toString();
18 }
19
20 configurations {
21 compile
22 peer
23 dev
7 task clean {
8 doLast {
9 delete buildDir
10 }
24 11 }
25 12
26 dependencies {
27 compile ":eslint:1.x || >=2.5.0 || 5.0.0 - 7.2.3"
28 compile (name: 'foo') {
29 ext.location = "http://some/package/location"
13 task cleanNpm {
14 doLast {
15 delete 'node_modules'
30 16 }
31 peer "dojo:core"
32 17 }
33 18
34 task prepare(type: Copy) {
35 from('src/js/')
36 from('.') {
37 include 'readme.md', 'license', 'history.md', 'package.json'
38 }
39 into(buildDir)
40 }
41
42 task installDeps {
43 configurations.compile.allDependencies.forEach { d ->
44 println makePackageName(d.group, d.name, d.version);
45 if(d.hasProperty('location')) {
46 println d.location
19 task _npmInstall() {
20 inputs.file("package.json")
21 outputs.dir("node_modules")
22 doLast {
23 exec {
24 commandLine 'npm', 'install'
47 25 }
48 26 }
49 27 }
50 28
51 task build(dependsOn: prepare) {
29 task _legacyJs(type:Copy) {
30 from 'src/js/'
31 into distDir
32 }
33
34 task _packageMeta(type: Copy) {
35 inputs.property("version", version)
36 from('.') {
37 include 'package.json', 'readme.md', 'license', 'history.md'
38 }
39 into distDir
40 doLast {
41 exec {
42 workingDir distDir
43 commandLine 'npm', 'version', version
44 }
45 }
46 }
47
48 task build(dependsOn: [_npmInstall, _legacyJs, _packageMeta]) {
49
50 }
51
52 task _localInstall(dependsOn: build, type: Exec) {
53 inputs.file("$distDir/package.json")
54 outputs.upToDateWhen { true }
55
56 commandLine 'npm', 'install', '--no-save', '--force', distDir
52 57 }
53 58
54 59 task pack(dependsOn: build, type: Exec) {
55 60 workingDir = buildDir
56 61
57 62 commandLine 'npm', 'pack'
58 63 } No newline at end of file
@@ -0,0 +1,22
1 Copyright 2017-2018 Implab team
2
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions are met:
5
6 1. Redistributions of source code must retain the above copyright notice, this
7 list of conditions and the following disclaimer.
8
9 2. Redistributions in binary form must reproduce the above copyright notice,
10 this list of conditions and the following disclaimer in the documentation
11 and/or other materials provided with the distribution.
12
13 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
17 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. No newline at end of file
@@ -1,18 +1,19
1 1 {
2 2 "name": "@implab/core",
3 "version": "1.0.1",
3 "version": "0.0.1-dev",
4 4 "description": "Dependency injection, logging, simple and fast text template engine",
5 5 "main": "main.js",
6 6 "scripts": {
7 7 "test": "echo \"Error: no test specified\" && exit 1"
8 8 },
9 9 "keywords": [
10 10 "di",
11 11 "ioc",
12 12 "logging",
13 13 "template engine",
14 14 "dependency injection"
15 15 ],
16 "author": "Sergey Smirnov",
17 "license": "MIT"
16 "author": "Implab team",
17 "license": "BSD",
18 "repository": "https://bitbucket.org/implab/implabjs"
18 19 }
@@ -1,323 +1,323
1 1 define([],
2 2
3 3 function () {
4 4 var _create = Object.create,
5 5 _keys = Object.keys;
6 6
7 7 var safe = null;
8 8 safe = {
9 9 argumentNotNull: function (arg, name) {
10 10 if (arg === null || arg === undefined)
11 11 throw new Error("The argument " + name + " can't be null or undefined");
12 12 },
13 13
14 14 argumentNotEmptyString: function (arg, name) {
15 15 if (typeof (arg) !== "string" || !arg.length)
16 16 throw new Error("The argument '" + name + "' must be a not empty string");
17 17 },
18 18
19 19 argumentNotEmptyArray: function (arg, name) {
20 20 if (!(arg instanceof Array) || !arg.length)
21 21 throw new Error("The argument '" + name + "' must be a not empty array");
22 22 },
23 23
24 24 argumentOfType: function (arg, type, name) {
25 25 if (!(arg instanceof type))
26 26 throw new Error("The argument '" + name + "' type doesn't match");
27 27 },
28 28
29 29 isNull: function (arg) {
30 30 return (arg === null || arg === undefined);
31 31 },
32 32
33 33 isPrimitive: function (arg) {
34 34 return (arg === null || arg === undefined || typeof (arg) === "string" ||
35 35 typeof (arg) === "number" || typeof (arg) === "boolean");
36 36 },
37 37
38 38 isInteger: function (arg) {
39 39 return parseInt(arg) == arg;
40 40 },
41 41
42 42 isNumber: function (arg) {
43 43 return parseFloat(arg) == arg;
44 44 },
45 45
46 46 isString: function (val) {
47 47 return typeof (val) == "string" || val instanceof String;
48 48 },
49 49
50 50 isNullOrEmptyString: function (str) {
51 51 if (str === null || str === undefined ||
52 52 ((typeof (str) == "string" || str instanceof String) && str.length === 0))
53 53 return true;
54 54 },
55 55
56 56 isNotEmptyArray: function (arg) {
57 57 return (arg instanceof Array && arg.length > 0);
58 58 },
59 59
60 60 /**
61 61 * Выполняет метод для каждого элемента массива, останавливается, когда
62 62 * либо достигнут конец массива, либо функция <c>cb</c> вернула
63 63 * значение.
64 64 *
65 65 * @param{Array | Object} obj массив элементов для просмотра
66 66 * @param{Function} cb функция, вызываемая для каждого элемента
67 67 * @param{Object} thisArg значение, которое будет передано в качестве
68 68 * <c>this</c> в <c>cb</c>.
69 69 * @returns Результат вызова функции <c>cb</c>, либо <c>undefined</c>
70 70 * если достигнут конец массива.
71 71 */
72 72 each: function (obj, cb, thisArg) {
73 73 safe.argumentNotNull(cb, "cb");
74 74 var i, x;
75 75 if (obj instanceof Array) {
76 76 for (i = 0; i < obj.length; i++) {
77 77 x = cb.call(thisArg, obj[i], i);
78 78 if (x !== undefined)
79 79 return x;
80 80 }
81 81 } else {
82 82 var keys = _keys(obj);
83 83 for (i = 0; i < keys.length; i++) {
84 84 var k = keys[i];
85 85 x = cb.call(thisArg, obj[k], k);
86 86 if (x !== undefined)
87 87 return x;
88 88 }
89 89 }
90 90 },
91 91
92 92 /**
93 93 * Копирует свойства одного объекта в другой.
94 94 *
95 95 * @param{Any} dest объект в который нужно скопировать значения
96 96 * @param{Any} src источник из которого будут копироваться значения
97 97 * @tmpl{Object|Array} tmpl шаблон по которому будет происходить
98 98 * копирование. Если шаблон является массивом
99 99 * (список свойств), тогда значения этого массива
100 100 * являются именами свойсвт которые будут
101 101 * скопированы. Если шаблон является объектом (карта
102 102 * преобразования имен свойств src->dst), тогда
103 103 * копирование будет осуществляться только
104 104 * собственных свойств источника, присутсвующих в
105 105 * шаблоне, при этом значение свойства шаблона
106 106 * является именем свойства в которое будет
107 107 * произведено коприрование
108 108 */
109 109 mixin: function (dest, src, tmpl) {
110 110 safe.argumentNotNull(dest, "dest");
111 111 if (!src)
112 112 return dest;
113 113
114 114 var keys, i, p;
115 115 if (arguments.length < 3) {
116 116 keys = _keys(src);
117 117 for (i = 0; i < keys.length; i++) {
118 118 p = keys[i];
119 119 dest[p] = src[p];
120 120 }
121 121 } else {
122 122 if (tmpl instanceof Array) {
123 123 for (i = 0; i < tmpl.length; i++) {
124 124 p = tmpl[i];
125 125 if (p in src)
126 126 dest[p] = src[p];
127 127 }
128 128
129 129 } else {
130 130 keys = _keys(src);
131 131 for (i = 0; i < keys.length; i++) {
132 132 p = keys[i];
133 133 if (p in tmpl)
134 134 dest[tmpl[p]] = src[p];
135 135 }
136 136 }
137 137 }
138 138 return dest;
139 139 },
140 140
141 141 /** Wraps the specified function to emulate an asynchronous execution.
142 142 * @param{Object} thisArg [Optional] Object which will be passed as 'this' to the function.
143 143 * @param{Function|String} fn [Required] Function wich will be wrapped.
144 144 */
145 145 async: function (fn, thisArg) {
146 146 if (arguments.length == 2 && !(fn instanceof Function))
147 147 fn = thisArg[fn];
148 148
149 149 if (fn == null)
150 150 throw new Error("The function must be specified");
151 151
152 152 function wrapresult(x, e) {
153 153 if (e) {
154 154 return {
155 155 then: function (cb, eb) {
156 156 try {
157 157 return eb ? wrapresult(eb(e)) : this;
158 158 } catch (e2) {
159 159 return wrapresult(null, e2);
160 160 }
161 161 }
162 162 };
163 163 } else {
164 164 if (x && x.then)
165 165 return x;
166 166 return {
167 167 then : function(cb) {
168 168 try {
169 169 return cb ? wrapresult(cb(x)) : this;
170 170 } catch(e2) {
171 171 return wrapresult(e2);
172 172 }
173 173 }
174 174 };
175 175 }
176 176 }
177 177
178 178 try {
179 179 return wrapresult(fn.apply(thisArg, arguments));
180 180 } catch (e) {
181 181 return wrapresult(null, e);
182 };
182 }
183 183 },
184 184
185 185 create: function () {
186 186 if (console && console.warn)
187 187 console.warn("implab/safe::create is deprecated use Object.create instead");
188 188 _create.apply(this, arguments);
189 189 },
190 190
191 191 delegate: function (target, method) {
192 192 if (!(method instanceof Function)) {
193 193 this.argumentNotNull(target, "target");
194 194 method = target[method];
195 195 }
196 196
197 197 if (!(method instanceof Function))
198 198 throw new Error("'method' argument must be a Function or a method name");
199 199
200 200 return function () {
201 201 return method.apply(target, arguments);
202 202 };
203 203 },
204 204
205 205 /**
206 206 * Для каждого элемента массива вызывает указанную функцию и сохраняет
207 207 * возвращенное значение в массиве результатов.
208 208 *
209 209 * @remarks cb может выполняться асинхронно, при этом одновременно будет
210 210 * только одна операция.
211 211 *
212 212 * @async
213 213 */
214 214 pmap: function (items, cb) {
215 215 safe.argumentNotNull(cb, "cb");
216 216
217 217 if (items && items.then instanceof Function)
218 218 return items.then(function (data) {
219 219 return safe.pmap(data, cb);
220 220 });
221 221
222 222 if (safe.isNull(items) || !items.length)
223 223 return items;
224 224
225 225 var i = 0,
226 226 result = [];
227 227
228 228 function next() {
229 229 var r, ri;
230 230
231 231 function chain(x) {
232 232 result[ri] = x;
233 233 return next();
234 234 }
235 235
236 236 while (i < items.length) {
237 237 r = cb(items[i], i);
238 238 ri = i;
239 239 i++;
240 240 if (r && r.then) {
241 241 return r.then(chain);
242 242 } else {
243 243 result[ri] = r;
244 244 }
245 245 }
246 246 return result;
247 247 }
248 248
249 249 return next();
250 250 },
251 251
252 252 /**
253 253 * Для каждого элемента массива вызывает указанную функцию, результаты
254 254 * не сохраняются
255 255 *
256 256 * @remarks cb может выполняться асинхронно, при этом одновременно будет
257 257 * только одна операция.
258 258 * @async
259 259 */
260 260 pfor: function (items, cb) {
261 261 safe.argumentNotNull(cb, "cb");
262 262
263 263 if (items && items.then instanceof Function)
264 264 return items.then(function (data) {
265 265 return safe.pmap(data, cb);
266 266 });
267 267
268 268 if (safe.isNull(items) || !items.length)
269 269 return items;
270 270
271 271 var i = 0;
272 272
273 273 function next() {
274 274 while (i < items.length) {
275 275 var r = cb(items[i], i);
276 276 i++;
277 277 if (r && r.then)
278 278 return r.then(next);
279 279 }
280 280 }
281 281
282 282 return next();
283 283 },
284 284
285 285 /**
286 286 * Выбирает первый элемент из последовательности, или обещания, если в
287 287 * качестве параметра используется обещание, оно должно вернуть массив.
288 288 *
289 289 * @param{Function} cb обработчик результата, ему будет передан первый
290 290 * элемент последовательности в случае успеха
291 291 * @param{Fucntion} err обработчик исключения, если массив пустой, либо
292 292 * не массив
293 293 *
294 294 * @remarks Если не указаны ни cb ни err, тогда функция вернет либо
295 295 * обещание, либо первый элемент.
296 296 * @async
297 297 */
298 298 first: function (sequence, cb, err) {
299 299 if (sequence) {
300 300 if (sequence.then instanceof Function) {
301 301 return sequence.then(function (res) {
302 302 return safe.first(res, cb, err);
303 303 }, err);
304 304 } else if (sequence && "length" in sequence) {
305 305 if (sequence.length === 0) {
306 306 if (err)
307 307 return err(new Error("The sequence is empty"));
308 308 else
309 309 throw new Error("The sequence is empty");
310 310 }
311 311 return cb ? cb(sequence[0]) : sequence[0];
312 312 }
313 313 }
314 314
315 315 if (err)
316 316 return err(new Error("The sequence is required"));
317 317 else
318 318 throw new Error("The sequence is required");
319 319 }
320 320 };
321 321
322 322 return safe;
323 323 }); No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now