models.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. #!/usr/bin/env node
  2. /* jshint esversion: 6 */
  3. /* eslint "no-console": off */
  4. const fs = require('fs');
  5. const path = require('path');
  6. const process = require('process');
  7. const child_process = require('child_process');
  8. const http = require('http');
  9. const https = require('https');
  10. const util = require('util');
  11. const xmldom = require('xmldom');
  12. const json = require('../source/json');
  13. const protobuf = require('../source/protobuf');
  14. const flatbuffers = require('../source/flatbuffers');
  15. const sidebar = require('../source/view-sidebar.js');
  16. const view = require('../source/view.js');
  17. const zip = require('../source/zip');
  18. const gzip = require('../source/gzip');
  19. const tar = require('../source/tar');
  20. const base = require('../source/base');
  21. global.Int64 = base.Int64;
  22. global.Uint64 = base.Uint64;
  23. global.json = json;
  24. global.protobuf = protobuf;
  25. global.flatbuffers = flatbuffers;
  26. global.DOMParser = xmldom.DOMParser;
  27. global.TextDecoder = class {
  28. constructor(encoding) {
  29. if (encoding !== 'ascii') {
  30. this._decoder = new util.TextDecoder(encoding);
  31. }
  32. }
  33. decode(data) {
  34. if (this._decoder) {
  35. return this._decoder.decode(data);
  36. }
  37. if (data.length < 32) {
  38. return String.fromCharCode.apply(null, data);
  39. }
  40. const buffer = [];
  41. let start = 0;
  42. do {
  43. let end = start + 32;
  44. if (end > data.length) {
  45. end = data.length;
  46. }
  47. buffer.push(String.fromCharCode.apply(null, data.subarray(start, end)));
  48. start = end;
  49. }
  50. while (start < data.length);
  51. return buffer.join('');
  52. }
  53. };
  54. const filter = process.argv.length > 2 ? new RegExp('^' + process.argv[2].replace(/\./, '\\.').replace(/\*/, '.*')) : null;
  55. const dataFolder = path.normalize(__dirname + '/../third_party/test');
  56. const items = JSON.parse(fs.readFileSync(__dirname + '/models.json', 'utf-8'));
  57. class TestHost {
  58. constructor() {
  59. this._document = new HTMLDocument();
  60. }
  61. get document() {
  62. return this._document;
  63. }
  64. initialize(/* view */) {
  65. return Promise.resolve();
  66. }
  67. start() {
  68. }
  69. environment(name) {
  70. if (name == 'zoom') {
  71. return 'none';
  72. }
  73. return null;
  74. }
  75. screen(/* name */) {
  76. }
  77. require(id) {
  78. try {
  79. const file = path.join(path.join(__dirname, '../source'), id + '.js');
  80. return Promise.resolve(require(file));
  81. }
  82. catch (error) {
  83. return Promise.reject(error);
  84. }
  85. }
  86. request(file, encoding, base) {
  87. const pathname = path.join(base || path.join(__dirname, '../source'), file);
  88. if (!fs.existsSync(pathname)) {
  89. return Promise.reject(new Error("The file '" + file + "' does not exist."));
  90. }
  91. if (encoding) {
  92. const text = fs.readFileSync(pathname, encoding);
  93. return Promise.resolve(text);
  94. }
  95. const buffer = fs.readFileSync(pathname, null);
  96. const stream = new TestBinaryStream(buffer);
  97. return Promise.resolve(stream);
  98. }
  99. event(/* category, action, label, value */) {
  100. }
  101. exception(err /*, fatal */) {
  102. this._raise('exception', { exception: err });
  103. }
  104. on(event, callback) {
  105. this._events = this._events || {};
  106. this._events[event] = this._events[event] || [];
  107. this._events[event].push(callback);
  108. }
  109. _raise(event, data) {
  110. if (this._events && this._events[event]) {
  111. for (const callback of this._events[event]) {
  112. callback(this, data);
  113. }
  114. }
  115. }
  116. }
  117. class TestBinaryStream {
  118. constructor(buffer) {
  119. this._buffer = buffer;
  120. this._length = buffer.length;
  121. this._position = 0;
  122. }
  123. get position() {
  124. return this._position;
  125. }
  126. get length() {
  127. return this._length;
  128. }
  129. stream(length) {
  130. const buffer = this.read(length);
  131. return new TestBinaryStream(buffer.slice(0));
  132. }
  133. seek(position) {
  134. this._position = position >= 0 ? position : this._length + position;
  135. if (this._position > this._buffer.length) {
  136. throw new Error('Expected ' + (this._position - this._buffer.length) + ' more bytes. The file might be corrupted. Unexpected end of file.');
  137. }
  138. }
  139. skip(offset) {
  140. this._position += offset;
  141. if (this._position > this._buffer.length) {
  142. throw new Error('Expected ' + (this._position - this._buffer.length) + ' more bytes. The file might be corrupted. Unexpected end of file.');
  143. }
  144. }
  145. peek(length) {
  146. if (this._position === 0 && length === undefined) {
  147. return this._buffer;
  148. }
  149. const position = this._position;
  150. this.skip(length !== undefined ? length : this._length - this._position);
  151. const end = this._position;
  152. this.seek(position);
  153. return this._buffer.subarray(position, end);
  154. }
  155. read(length) {
  156. if (this._position === 0 && length === undefined) {
  157. this._position = this._length;
  158. return this._buffer;
  159. }
  160. const position = this._position;
  161. this.skip(length !== undefined ? length : this._length - this._position);
  162. return this._buffer.subarray(position, this._position);
  163. }
  164. byte() {
  165. const position = this._position;
  166. this.skip(1);
  167. return this._buffer[position];
  168. }
  169. }
  170. class TestContext {
  171. constructor(host, folder, identifier, stream, entries) {
  172. this._host = host;
  173. this._folder = folder;
  174. this._identifier = identifier;
  175. this._stream = stream;
  176. this._entries = entries;
  177. }
  178. get identifier() {
  179. return this._identifier;
  180. }
  181. get stream() {
  182. return this._stream;
  183. }
  184. get entries() {
  185. return this._entries;
  186. }
  187. request(file, encoding, base) {
  188. return this._host.request(file, encoding, base === undefined ? this._folder : base);
  189. }
  190. require(id) {
  191. return this._host.require(id);
  192. }
  193. exception(error, fatal) {
  194. this._host.exception(error, fatal);
  195. }
  196. }
  197. class HTMLDocument {
  198. constructor() {
  199. this._elements = {};
  200. this.documentElement = new HTMLHtmlElement();
  201. this.body = new HTMLBodyElement();
  202. }
  203. createElement(/* name */) {
  204. return new HTMLElement();
  205. }
  206. createElementNS(/* namespace, name */) {
  207. return new HTMLElement();
  208. }
  209. createTextNode(/* text */) {
  210. return new HTMLElement();
  211. }
  212. getElementById(id) {
  213. let element = this._elements[id];
  214. if (!element) {
  215. element = new HTMLElement();
  216. this._elements[id] = element;
  217. }
  218. return element;
  219. }
  220. addEventListener(/* event, callback */) {
  221. }
  222. removeEventListener(/* event, callback */) {
  223. }
  224. }
  225. class HTMLElement {
  226. constructor() {
  227. this._childNodes = [];
  228. this._attributes = new Map();
  229. this._style = new CSSStyleDeclaration();
  230. }
  231. get style() {
  232. return this._style;
  233. }
  234. appendChild(node) {
  235. this._childNodes.push(node);
  236. }
  237. setAttribute(name, value) {
  238. this._attributes.set(name, value);
  239. }
  240. hasAttribute(name) {
  241. return this._attributes.has(name);
  242. }
  243. getAttribute(name) {
  244. return this._attributes.get(name);
  245. }
  246. getBBox() {
  247. return { x: 0, y: 0, width: 10, height: 10 };
  248. }
  249. getElementsByClassName(name) {
  250. const elements = [];
  251. for (const node of this._childNodes) {
  252. if (node instanceof HTMLElement) {
  253. elements.push(...node.getElementsByClassName(name));
  254. if (node.hasAttribute('class') &&
  255. node.getAttribute('class').split(' ').find((text) => text === name)) {
  256. elements.push(node);
  257. }
  258. }
  259. }
  260. return elements;
  261. }
  262. addEventListener(/* event, callback */) {
  263. }
  264. removeEventListener(/* event, callback */) {
  265. }
  266. get classList() {
  267. return new DOMTokenList(this);
  268. }
  269. }
  270. class HTMLHtmlElement extends HTMLElement {
  271. }
  272. class HTMLBodyElement extends HTMLElement{
  273. }
  274. class CSSStyleDeclaration {
  275. constructor() {
  276. this._properties = new Map();
  277. }
  278. setProperty(name, value) {
  279. this._properties.set(name, value);
  280. }
  281. }
  282. class DOMTokenList {
  283. add(/* token */) {
  284. }
  285. }
  286. function makeDir(dir) {
  287. if (!fs.existsSync(dir)){
  288. fs.mkdirSync(dir, { recursive: true });
  289. }
  290. }
  291. function decompress(buffer) {
  292. let archive = null;
  293. if (buffer.length >= 18 && buffer[0] === 0x1f && buffer[1] === 0x8b) {
  294. archive = gzip.Archive.open(buffer);
  295. if (archive.entries.size == 1) {
  296. const stream = archive.entries.values().next().value;
  297. buffer = stream.peek();
  298. }
  299. }
  300. const formats = [ zip, tar ];
  301. for (const module of formats) {
  302. archive = module.Archive.open(buffer);
  303. if (archive) {
  304. break;
  305. }
  306. }
  307. return archive;
  308. }
  309. function request(location, cookie) {
  310. const options = { rejectUnauthorized: false };
  311. let httpRequest = null;
  312. const url = new URL(location);
  313. const protocol = url.protocol;
  314. switch (protocol) {
  315. case 'http:':
  316. httpRequest = http.request(location, options);
  317. break;
  318. case 'https:':
  319. httpRequest = https.request(location, options);
  320. break;
  321. }
  322. return new Promise((resolve, reject) => {
  323. if (!httpRequest) {
  324. reject(new Error("Unknown HTTP request."));
  325. }
  326. if (cookie && cookie.length > 0) {
  327. httpRequest.setHeader('Cookie', cookie);
  328. }
  329. httpRequest.on('response', (response) => {
  330. resolve(response);
  331. });
  332. httpRequest.on('error', (error) => {
  333. reject(error);
  334. });
  335. httpRequest.end();
  336. });
  337. }
  338. function downloadFile(location, cookie) {
  339. return request(location, cookie).then((response) => {
  340. const url = new URL(location);
  341. if (response.statusCode == 200 &&
  342. url.hostname == 'drive.google.com' &&
  343. response.headers['set-cookie'].some((cookie) => cookie.startsWith('download_warning_'))) {
  344. cookie = response.headers['set-cookie'];
  345. const download = cookie.filter((cookie) => cookie.startsWith('download_warning_')).shift();
  346. const confirm = download.split(';').shift().split('=').pop();
  347. location = location + '&confirm=' + confirm;
  348. return downloadFile(location, cookie);
  349. }
  350. if (response.statusCode == 301 || response.statusCode == 302) {
  351. if (response.headers.location.startsWith('http://') || response.headers.location.startsWith('https://')) {
  352. location = response.headers.location;
  353. }
  354. else {
  355. location = url.protocol + '//' + url.hostname + response.headers.location;
  356. }
  357. return downloadFile(location, cookie);
  358. }
  359. if (response.statusCode != 200) {
  360. throw new Error(response.statusCode.toString() + ' ' + location);
  361. }
  362. return new Promise((resolve, reject) => {
  363. let position = 0;
  364. const data = [];
  365. const length = response.headers['content-length'] ? Number(response.headers['content-length']) : -1;
  366. response.on('data', (chunk) => {
  367. position += chunk.length;
  368. if (length >= 0) {
  369. const label = location.length > 70 ? location.substring(0, 66) + '...' : location;
  370. process.stdout.write(' (' + (' ' + Math.floor(100 * (position / length))).slice(-3) + '%) ' + label + '\r');
  371. }
  372. else {
  373. process.stdout.write(' ' + position + ' bytes\r');
  374. }
  375. data.push(chunk);
  376. });
  377. response.on('end', () => {
  378. resolve(Buffer.concat(data));
  379. });
  380. response.on('error', (error) => {
  381. reject(error);
  382. });
  383. });
  384. });
  385. }
  386. function download(folder, targets, sources) {
  387. if (targets.every((file) => fs.existsSync(folder + '/' + file))) {
  388. return Promise.resolve();
  389. }
  390. if (!sources) {
  391. return Promise.reject(new Error('Download source not specified.'));
  392. }
  393. let source = '';
  394. let sourceFiles = [];
  395. const startIndex = sources.indexOf('[');
  396. const endIndex = sources.indexOf(']');
  397. if (startIndex != -1 && endIndex != -1 && endIndex > startIndex) {
  398. sourceFiles = sources.substring(startIndex + 1, endIndex).split(',').map((sourceFile) => sourceFile.trim());
  399. source = sources.substring(0, startIndex);
  400. sources = sources.substring(endIndex + 1);
  401. if (sources.startsWith(',')) {
  402. sources = sources.substring(1);
  403. }
  404. }
  405. else {
  406. const commaIndex = sources.indexOf(',');
  407. if (commaIndex != -1) {
  408. source = sources.substring(0, commaIndex);
  409. sources = sources.substring(commaIndex + 1);
  410. }
  411. else {
  412. source = sources;
  413. sources = '';
  414. }
  415. }
  416. for (const target of targets) {
  417. makeDir(path.dirname(folder + '/' + target));
  418. }
  419. return downloadFile(source).then((data) => {
  420. if (sourceFiles.length > 0) {
  421. if (process.stdout.clearLine) {
  422. process.stdout.clearLine();
  423. }
  424. process.stdout.write(' decompress...\r');
  425. const archive = decompress(data, source.split('?').shift().split('/').pop());
  426. for (const name of sourceFiles) {
  427. if (process.stdout.clearLine) {
  428. process.stdout.clearLine();
  429. }
  430. process.stdout.write(' write ' + name + '\n');
  431. if (name !== '.') {
  432. const stream = archive.entries.get(name);
  433. if (!stream) {
  434. throw new Error("Entry not found '" + name + '. Archive contains entries: ' + JSON.stringify(archive.entries.map((entry) => entry.name)) + " .");
  435. }
  436. const target = targets.shift();
  437. const buffer = stream.peek();
  438. const file = path.join(folder, target);
  439. fs.writeFileSync(file, buffer, null);
  440. }
  441. else {
  442. const target = targets.shift();
  443. const dir = path.join(folder, target);
  444. if (!fs.existsSync(dir)) {
  445. fs.mkdirSync(dir);
  446. }
  447. }
  448. }
  449. }
  450. else {
  451. const target = targets.shift();
  452. if (process.stdout.clearLine) {
  453. process.stdout.clearLine();
  454. }
  455. process.stdout.write(' write ' + target + '\r');
  456. fs.writeFileSync(folder + '/' + target, data, null);
  457. }
  458. if (process.stdout.clearLine) {
  459. process.stdout.clearLine();
  460. }
  461. if (sources.length > 0) {
  462. return download(folder, targets, sources);
  463. }
  464. return;
  465. });
  466. }
  467. function script(folder, targets, command, args) {
  468. if (targets.every((file) => fs.existsSync(folder + '/' + file))) {
  469. return Promise.resolve();
  470. }
  471. return new Promise((resolve, reject) => {
  472. try {
  473. const comspec = process.env.COMSPEC;
  474. if (process.platform === 'win32' && process.env.SHELL) {
  475. process.env.COMSPEC = process.env.SHELL;
  476. command = '/' + command.split(':').join('').split('\\').join('/');
  477. }
  478. child_process.execSync(command + ' ' + args, { stdio: [ 0, 1 , 2] });
  479. process.env.COMSPEC = comspec;
  480. resolve();
  481. }
  482. catch (error) {
  483. reject(error);
  484. }
  485. });
  486. }
  487. function loadModel(target, item) {
  488. const host = new TestHost();
  489. const exceptions = [];
  490. host.on('exception', (_, data) => {
  491. exceptions.push(data.exception);
  492. });
  493. const identifier = path.basename(target);
  494. const stat = fs.statSync(target);
  495. let context = null;
  496. if (stat.isFile()) {
  497. const buffer = fs.readFileSync(target, null);
  498. const reader = new TestBinaryStream(buffer);
  499. const dirname = path.dirname(target);
  500. context = new TestContext(host, dirname, identifier, reader);
  501. }
  502. else if (stat.isDirectory()) {
  503. const entries = new Map();
  504. const walk = (dir) => {
  505. for (const item of fs.readdirSync(dir)) {
  506. const pathname = path.join(dir, item);
  507. const stat = fs.statSync(pathname);
  508. if (stat.isDirectory()) {
  509. walk(pathname);
  510. }
  511. else if (stat.isFile()) {
  512. const buffer = fs.readFileSync(pathname, null);
  513. const stream = new TestBinaryStream(buffer);
  514. const name = pathname.split(path.sep).join(path.posix.sep);
  515. entries.set(name, stream);
  516. }
  517. }
  518. };
  519. walk(target);
  520. context = new TestContext(host, target, identifier, null, entries);
  521. }
  522. const modelFactoryService = new view.ModelFactoryService(host);
  523. let opened = false;
  524. return modelFactoryService.open(context).then((model) => {
  525. if (opened) {
  526. throw new Error("Model opened more than once '" + target + "'.");
  527. }
  528. opened = true;
  529. if (!model.format || (item.format && model.format != item.format)) {
  530. throw new Error("Invalid model format '" + model.format + "'.");
  531. }
  532. if (item.producer && model.producer != item.producer) {
  533. throw new Error("Invalid producer '" + model.producer + "'.");
  534. }
  535. if (item.runtime && model.runtime != item.runtime) {
  536. throw new Error("Invalid runtime '" + model.runtime + "'.");
  537. }
  538. if (item.assert) {
  539. for (const assert of item.assert) {
  540. const parts = assert.split('=').map((item) => item.trim());
  541. const properties = parts[0].split('.');
  542. const value = parts[1];
  543. let context = { model: model };
  544. while (properties.length) {
  545. const property = properties.shift();
  546. if (context[property] !== undefined) {
  547. context = context[property];
  548. continue;
  549. }
  550. const match = /(.*)\[(.*)\]/.exec(property);
  551. if (match.length === 3 && context[match[1]] !== undefined) {
  552. const array = context[match[1]];
  553. const index = parseInt(match[2], 10);
  554. if (array[index] !== undefined) {
  555. context = array[index];
  556. continue;
  557. }
  558. }
  559. throw new Error("Invalid property path: '" + parts[0]);
  560. }
  561. if (context !== value.toString()) {
  562. throw new Error("Invalid '" + value.toString() + "' != '" + assert + "'.");
  563. }
  564. }
  565. }
  566. model.version;
  567. model.description;
  568. model.author;
  569. model.license;
  570. for (const graph of model.graphs) {
  571. for (const input of graph.inputs) {
  572. input.name.toString();
  573. input.name.length;
  574. for (const argument of input.arguments) {
  575. argument.name.toString();
  576. argument.name.length;
  577. if (argument.type) {
  578. argument.type.toString();
  579. }
  580. }
  581. }
  582. for (const output of graph.outputs) {
  583. output.name.toString();
  584. output.name.length;
  585. for (const argument of output.arguments) {
  586. argument.name.toString();
  587. argument.name.length;
  588. if (argument.type) {
  589. argument.type.toString();
  590. }
  591. }
  592. }
  593. for (const node of graph.nodes) {
  594. node.type.toString();
  595. node.type.length;
  596. if (!node.type || typeof node.type.name != 'string') {
  597. throw new Error("Invalid node type '" + JSON.stringify(node.type) + "'.");
  598. }
  599. sidebar.DocumentationSidebar.formatDocumentation(node.type);
  600. node.name.toString();
  601. node.name.length;
  602. node.description;
  603. node.attributes.slice();
  604. for (const attribute of node.attributes) {
  605. attribute.name.toString();
  606. attribute.name.length;
  607. let value = sidebar.NodeSidebar.formatAttributeValue(attribute.value, attribute.type);
  608. if (value && value.length > 1000) {
  609. value = value.substring(0, 1000) + '...';
  610. }
  611. value = value.split('<');
  612. }
  613. for (const input of node.inputs) {
  614. input.name.toString();
  615. input.name.length;
  616. for (const argument of input.arguments) {
  617. argument.name.toString();
  618. argument.name.length;
  619. argument.description;
  620. if (argument.type) {
  621. argument.type.toString();
  622. }
  623. if (argument.initializer) {
  624. argument.initializer.toString();
  625. argument.initializer.type.toString();
  626. }
  627. }
  628. }
  629. for (const output of node.outputs) {
  630. output.name.toString();
  631. output.name.length;
  632. for (const argument of output.arguments) {
  633. argument.name.toString();
  634. argument.name.length;
  635. if (argument.type) {
  636. argument.type.toString();
  637. }
  638. }
  639. }
  640. if (node.chain) {
  641. for (const chain of node.chain) {
  642. chain.name.toString();
  643. chain.name.length;
  644. }
  645. }
  646. // new sidebar.NodeSidebar(host, node);
  647. }
  648. }
  649. if (exceptions.length > 0) {
  650. throw exceptions[0];
  651. }
  652. return model;
  653. });
  654. }
  655. function render(model) {
  656. try {
  657. const host = new TestHost();
  658. const currentView = new view.View(host);
  659. if (!currentView.showAttributes) {
  660. currentView.toggleAttributes();
  661. }
  662. if (!currentView.showInitializers) {
  663. currentView.toggleInitializers();
  664. }
  665. return currentView.renderGraph(model, model.graphs[0]);
  666. }
  667. catch (error) {
  668. return Promise.reject(error);
  669. }
  670. }
  671. function next() {
  672. if (items.length == 0) {
  673. return;
  674. }
  675. const item = items.shift();
  676. if (!item.type) {
  677. console.error("Property 'type' is required for item '" + JSON.stringify(item) + "'.");
  678. return;
  679. }
  680. const targets = item.target.split(',');
  681. const target = targets[0];
  682. const folder = dataFolder + '/' + item.type;
  683. const name = item.type + '/' + target;
  684. if (filter && !filter.test(name)) {
  685. next();
  686. return;
  687. }
  688. process.stdout.write(item.type + '/' + target + '\n');
  689. if (item.action && item.action.split(';').some((action) => action == 'skip')) {
  690. next();
  691. return;
  692. }
  693. if (process.stdout.clearLine) {
  694. process.stdout.clearLine();
  695. }
  696. let promise = null;
  697. if (item.script) {
  698. const index = item.script.search(' ');
  699. const root = path.dirname(__dirname);
  700. const command = path.resolve(root, item.script.substring(0, index));
  701. const args = item.script.substring(index + 1);
  702. promise = script(folder, targets, command, args);
  703. }
  704. else {
  705. const sources = item.source;
  706. promise = download(folder, targets, sources);
  707. }
  708. return promise.then(() => {
  709. return loadModel(folder + '/' + target, item).then((model) => {
  710. let promise = null;
  711. if (item.action && item.action.split(';').some((action) => action == 'skip-render')) {
  712. promise = Promise.resolve();
  713. }
  714. else {
  715. promise = render(model);
  716. }
  717. return promise.then(() => {
  718. if (item.error) {
  719. console.error('Expected error.');
  720. }
  721. else {
  722. return next();
  723. }
  724. });
  725. });
  726. }).catch((error) => {
  727. if (!item.error || item.error != error.message) {
  728. console.error(error.message);
  729. }
  730. else {
  731. return next();
  732. }
  733. });
  734. }
  735. next();