Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- no longer generates .autocomplete/*.xml files
  • Loading branch information
puntorigen committed Dec 3, 2022
1 parent 49489a6 commit 834bf0a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 165 deletions.
203 changes: 41 additions & 162 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@
delete meta.func; //this.x_console.outT({ message:`DSL meta data`, color:'brightCyan', data:this.x_commands.meta });
//get x_commands name & language definitions

var apiLang = meta.name; // has the name of the compiler used (e.g. 'NuxtJS')
meta.name; // has the name of the compiler used (e.g. 'NuxtJS')

var lang = meta.language; // es,en (language for the autocomplete definitions)
//default autocomplete theme values
Expand All @@ -908,10 +908,6 @@
var custom_theme = meta.autocomplete && meta.autocomplete.theme ? meta.autocomplete.theme : {};
theme = _objectSpread2(_objectSpread2({}, theme), custom_theme);
lang = lang ? lang : 'es'; //default lang is es (spanish)
//prepare xml

var wrapper = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE api SYSTEM \"CompletionXml.dtd\" >\n<api language=\"".concat(apiLang, "\">\n\t<keywords>\n");
var wrapper_end = "\t</keywords>\n</api>"; //define translation keys

var poKeys = {
'en': {
Expand Down Expand Up @@ -961,7 +957,7 @@
*/


var cheerio = require('cheerio');
require('cheerio');

var attributesToHTMLTable = function attributesToHTMLTable() {
var attributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
Expand Down Expand Up @@ -1028,53 +1024,6 @@
return html;
};

var existsKeyword = /*#__PURE__*/function () {
var _ref = _asyncToGenerator(function* (keyword, xml) {
var xmlData = yield fs.readFile(xml, 'utf-8');
var $ = cheerio.load(xmlData, {
ignoreWhitespace: false,
xmlMode: true,
decodeEntities: false
});
var found = false;
$('keyword[name]').toArray().some(function (elem) {
var src = $(elem).attr('name');

if (src == keyword) {
found = true;
return true;
}
});
return found;
});

return function existsKeyword(_x, _x2) {
return _ref.apply(this, arguments);
};
}();

var addKeywordToXML = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator(function* (keywordXML, xml) {
var xmlData = yield fs.readFile(xml, 'utf-8');
var $ = cheerio.load(xmlData, {
ignoreWhitespace: false,
xmlMode: true,
decodeEntities: false
});
var found = false;
$('keyword[name]').toArray().some(function (elem) {
$(elem).parent('keywords').append(keywordXML);
return true;
});
yield fs.writeFile(xml, $.xml(), 'utf-8');
return found;
});

return function addKeywordToXML(_x3, _x4) {
return _ref2.apply(this, arguments);
};
}();

var replaceIcons = text_ => {
/* adds support for icons with {icon:x} within type */
var extract = require('extractjs')({
Expand All @@ -1096,74 +1045,7 @@
return new_;
};

var generateKeywordXML = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator(function* (record) {
var xml = "\t\t<keyword type=\"other\" name=\"".concat(record.text, "\">\n");
var html = "<BASE href=\"file://".concat(iconsPath, "/\">\n");

var default_render_icon = icon => {
return "<img src=\"".concat(icon, ".png\" align=\"left\" hspace=\"5\" vspace=\"5\" valign=\"middle\" />&nbsp;");
}; // mark inherited attributes/events
//this.debug('AUTOCOMPLETE RECORDS KEYS',Object.keys(this.autocomplete.texts));


if (record.extends_ && record.extends_ != '' && _this3.autocomplete.refs[record.extends_]) {
//const merge = require('deepmerge');
//this.debug('merging inherited attributes/events!!!! ',{ extends_:record.extends_, parent:this.autocomplete.texts[record.extends_] });
//record = merge(this.autocomplete.texts[record.extends_],record);
// determine which 'attributes' are from the extends_ record (inherited)
var parentAttribs = Object.keys(_this3.autocomplete.refs[record.extends_].attributes);
var recordAttribs = Object.keys(record.attributes);

for (var recAttrib of recordAttribs) {
if (parentAttribs.includes(recAttrib)) {
record.attributes[recAttrib].inherited_ = true;
}
} // determine which 'events' are from the extends_ record (inherited)


var parentEvents = Object.keys(_this3.autocomplete.refs[record.extends_].events);
var recordEvents = Object.keys(record.events);

for (var recEvent of recordEvents) {
if (parentEvents.includes(recEvent)) {
record.events[recEvent].inherited_ = true;
}
}
} //


html += yield _this3.autocompleteContentTemplate(record, {
icon: _icon => {
return "<img src=\"".concat(_icon, ".png\" align=\"left\" hspace=\"5\" vspace=\"5\" valign=\"middle\" />&nbsp;");
},
placeholders: (text, renderIcon) => {
if (renderIcon) {
//return attributesToHTMLTable(attrs,renderIcon);
return replaceIcons(text);
} else {
return replaceIcons(text);
}
},
attrs: (_attrs, renderIcon) => {
if (renderIcon) {
return attributesToHTMLTable(_attrs, renderIcon);
} else {
return attributesToHTMLTable(_attrs, default_render_icon);
}
}
});
xml += "\t\t\t<desc><![CDATA[\n".concat(html, "\n]]>\n</desc>\n");
xml += "\t\t</keyword>\n";
return xml;
});

return function generateKeywordXML(_x5) {
return _ref3.apply(this, arguments);
};
}();

var fs = require('fs').promises; //
require('fs').promises; //
// generate .autocomplete/autocomplete.json file
//

Expand Down Expand Up @@ -1213,49 +1095,46 @@
var json = JSON.stringify(autoJson, null, '\t'); //this.autocomplete.json

yield _this3.writeFile(file, json);
} //


for (var hash_ in _this3.autocomplete.records) {
var hash = _this3.autocomplete.records[hash_]; //this.x_console.outT({ message:`hash_ data ({hash_,hash})`, prefix:'autocomplete', data:{hash_,hash} });

var files = hash.keys;
} //@DEPRECATED: we are now using autocomplete.json

for (var file_ of files) {
//this.x_console.outT({ message:`processing file ${file_}.xml`, prefix:'autocomplete' });
if (file_ != undefined) {
var _file = path.join(_this3.autocomplete.path, file_ + '.xml'); //this.x_console.outT({ message:`full -> ${file}`, prefix:'autocomplete' });
//check if file exists and if it contains keyword[name=hash.text]


var exists = yield _this3.exists(_file);

if (exists == true) {
//if file exists, see if it contains the keyword
var alreadyExists = yield existsKeyword(hash.text, _file); //this.x_console.outT({ message:`existsKeyword -> ${alreadyExists}`, prefix:'autocomplete' });

if (alreadyExists == false) {
//add keyword to existing file (using cheerio)
yield addKeywordToXML(yield generateKeywordXML(hash), _file);
}
} else {
//xml file doesn't exist, create one with the keyword data
var newXML = "".concat(wrapper) + (yield generateKeywordXML(hash)) + "".concat(wrapper_end); //this.x_console.outT({ message:`saving new xml file -> ${file_}.xml`, prefix:'autocomplete', data:newXML });
//save xml file
/*
for (let hash_ in this.autocomplete.records) {
let hash = this.autocomplete.records[hash_];
//this.x_console.outT({ message:`hash_ data ({hash_,hash})`, prefix:'autocomplete', data:{hash_,hash} });
let files = hash.keys;
for (let file_ of files) {
//this.x_console.outT({ message:`processing file ${file_}.xml`, prefix:'autocomplete' });
if (file_!=undefined) {
let file = path.join(this.autocomplete.path,file_+'.xml');
//this.x_console.outT({ message:`full -> ${file}`, prefix:'autocomplete' });
//check if file exists and if it contains keyword[name=hash.text]
let exists = await this.exists(file);
if (exists==true) {
//if file exists, see if it contains the keyword
let alreadyExists = await existsKeyword(hash.text,file);
//this.x_console.outT({ message:`existsKeyword -> ${alreadyExists}`, prefix:'autocomplete' });
if (alreadyExists==false) {
//add keyword to existing file (using cheerio)
await addKeywordToXML(await generateKeywordXML(hash),file);
}
} else {
//xml file doesn't exist, create one with the keyword data
let newXML = `${wrapper}`+(await generateKeywordXML(hash))+`${wrapper_end}`;
//this.x_console.outT({ message:`saving new xml file -> ${file_}.xml`, prefix:'autocomplete', data:newXML });
//save xml file
try {
await fs.writeFile(file,newXML);
} catch(errPathE) {
// create .autocomplete path if it doesn't exist
let justpath_ = path.dirname(file) + path.sep;
await fs.mkdir(justpath_, { recursive:true });
//this.x_console.outT({ message:`error saving file ${file}`, prefix:'autocomplete', data:errPathE });
}
}
}
}
}*/

try {
yield fs.writeFile(_file, newXML);
} catch (errPathE) {
// create .autocomplete path if it doesn't exist
var justpath_ = path.dirname(_file) + path.sep;
yield fs.mkdir(justpath_, {
recursive: true
}); //this.x_console.outT({ message:`error saving file ${file}`, prefix:'autocomplete', data:errPathE });
}
}
}
}
}
})();
}
/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concepto/interface",
"version": "2.2.696",
"version": "2.2.7",
"description": "Concepto DSL - visually create and maintain modern node.js based apps (@interface)",
"keywords": [
"creador",
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ export default class concepto {
let json = JSON.stringify(autoJson,null,'\t'); //this.autocomplete.json
await this.writeFile(file,json);
}
//
//@DEPRECATED: we are now using autocomplete.json
/*
for (let hash_ in this.autocomplete.records) {
let hash = this.autocomplete.records[hash_];
//this.x_console.outT({ message:`hash_ data ({hash_,hash})`, prefix:'autocomplete', data:{hash_,hash} });
Expand Down Expand Up @@ -891,7 +892,7 @@ export default class concepto {
}
}
}
}
}*/
}

/**
Expand Down

0 comments on commit 834bf0a

Please sign in to comment.